StanfordSpezi / SpeziKt

Kotlin & Android Version of the Stanford Spezi Framework
http://spezi.health/SpeziKt/
MIT License
8 stars 2 forks source link

Create Health Connect to FHIR converter module #15

Closed vishnuravi closed 3 months ago

vishnuravi commented 4 months ago

Create Health Connect to FHIR converter module

The HealthConnectOnFHIR library provides a mapper that converts supported Android Health Connect Records to corresponding HL7® FHIR® R4 Observations with standardized codes (e.g. LOINC).

For more information, please refer to the API documentation.

Mapping Table

Health Connect Record FHIR Observation Category LOINC Code Unit Display
ActiveCaloriesBurnedRecord Activity 41981-2 kcal Calories burned
BloodGlucoseRecord 41653-7 mg/dL Glucose Glucometer (BldC) [Mass/Vol]
BloodPressureRecord Vital Signs 85354-9 mmHg Blood pressure panel with all children optional
BodyFatRecord 41982-0 % Percentage of body fat Measured
BodyTemperatureRecord Vital Signs 8310-5 Cel Body temperature
HeartRateRecord Vital Signs 8867-4 /min Heart rate
HeightRecord Vital Signs 8302-2 m Body height
OxygenSaturationRecord Vital Signs 59408-5 % Oxygen saturation in Arterial blood by Pulse oximetry
RespiratoryRateRecord Vital Signs 9279-1 /min Respiratory rate
StepsRecord Activity 55423-8 steps Number of steps
WeightRecord Vital Signs 29463-7 kg Body weight

Installation

HealthConnectOnFHIR can be installed into your Android Studio project via Jitpack.

Usage

// Initialize the mapper
val mapper = RecordToObservationMapperImpl()

// Query a `Record` from Health Connect
val record =  // ..

// Map the record to an HL7 FHIR Observation    
val observation = mapper.map(record)

Example

First, you will need to configure your application to use Android Health Connect. For more information, please see the official documentation.

// Initialize a `HealthConnectClient` (see Health Connect docs for full details)
val healthConnectClient = HealthConnectClient.getOrCreate(context)

// Define a time range for the query
val startTime = Instant.parse("2023-05-01T00:00:00Z")
val endTime = Instant.parse("2023-06-01T00:00:00Z")

// Query a list of `WeightRecord`s from Health Connect
val result = healthConnectClient.readRecords(
    ReadRecordsRequest(
        recordType = WeightRecord::class,
        timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
    )
).records

// Initialize the mapper
val mapper = RecordToObservationMapperImpl()

// Convert each weight record to a FHIR Observation
result.forEach { weightRecord ->
    val observations = mapper.map(weightRecord)
    observations.forEach { observation ->
        // Do something with the observation
    }
}

:pencil: Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 26.40%. Comparing base (b77e6ea) to head (4217b3b).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15/graphs/tree.svg?width=650&height=150&src=pr&token=rrQTC1h5A7&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi)](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) ```diff @@ Coverage Diff @@ ## main #15 +/- ## ============================================ + Coverage 19.38% 26.40% +7.02% - Complexity 146 193 +47 ============================================ Files 99 101 +2 Lines 2611 2860 +249 Branches 392 404 +12 ============================================ + Hits 506 755 +249 Misses 2063 2063 Partials 42 42 ``` | [Flag](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | `26.40% <100.00%> (+7.02%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | Coverage Δ | | |---|---|---| | [...ava/edu/stanford/healthconnectonfhir/MappedUnit.kt](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?src=pr&el=tree&filepath=modules%2Fhealthconnectonfhir%2Fsrc%2Fmain%2Fjava%2Fedu%2Fstanford%2Fhealthconnectonfhir%2FMappedUnit.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-bW9kdWxlcy9oZWFsdGhjb25uZWN0b25maGlyL3NyYy9tYWluL2phdmEvZWR1L3N0YW5mb3JkL2hlYWx0aGNvbm5lY3RvbmZoaXIvTWFwcGVkVW5pdC5rdA==) | `100.00% <100.00%> (ø)` | | | [...althconnectonfhir/RecordToObservationMapperImpl.kt](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?src=pr&el=tree&filepath=modules%2Fhealthconnectonfhir%2Fsrc%2Fmain%2Fjava%2Fedu%2Fstanford%2Fhealthconnectonfhir%2FRecordToObservationMapperImpl.kt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-bW9kdWxlcy9oZWFsdGhjb25uZWN0b25maGlyL3NyYy9tYWluL2phdmEvZWR1L3N0YW5mb3JkL2hlYWx0aGNvbm5lY3RvbmZoaXIvUmVjb3JkVG9PYnNlcnZhdGlvbk1hcHBlckltcGwua3Q=) | `100.00% <100.00%> (ø)` | | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Last update [b77e6ea...4217b3b](https://app.codecov.io/gh/StanfordSpezi/SpeziKt/pull/15?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi).
PSchmiedmayer commented 3 months ago

Thanks for the updates here @vishnuravi 🚀 Wondering if we can merge the PR in its current state for now?

vishnuravi commented 3 months ago

Thanks for the updates here @vishnuravi 🚀 Wondering if we can merge the PR in its current state for now?

We can merge it if everyone is OK with the updated method of implementing the mapper - can discuss at the meeting today.