google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
465 stars 246 forks source link

Add location mapping widget #800

Closed f-odhiambo closed 4 months ago

f-odhiambo commented 2 years ago

Is your feature request related to a problem? Please describe. Add a location widget that allows you to submit the location with GPS coordinates and location details as FHIR Location resources Describe the solution you'd like

  1. ANC Usecase In the ANC use case, add a location of a facility or a family residence or village during a family registration/enrollment Encounter that will in turn reference a Patient plus a Practioner. Tagged via Encounter.location This should submit a location payload tagged to a patient while enrolling ANC Clients or registering a family and its householder members
  2. Covax Usecase In the Covax demo app, allow a user to submit the location details of where the Vaccination is being done

The Widget should be able to trigger the GPS to collect Latitude and Longitude coordinates for a precise location

Sample location payload for an Immunization facility

{
  "resourceType": "Location",
  "status": "active",
  "name": "Arundel mobile clinic",
  "description": "Vaccination Site",
  "mode": "instance",
  "address": {
    "city": "Nairobi",
    "state": "MD",
    "country": "USA"
  },
  "physicalType": {
    "coding": [ {
      "system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
      "code": "bu",
      "display": "Vaccination Center"
    } ]
  },
  "position": {
    "longitude": 42.256500,
    "latitude": -83.694710
  }
}

Describe alternatives you've considered N/A

Additional context Sample location payload for an Immunization facility

{
  "resourceType": "Location",
  "status": "active",
  "name": "Arundel mobile clinic",
  "description": "Vaccination Site",
  "mode": "instance",
  "address": {
    "city": "Nairobi",
    "state": "MD",
    "country": "USA"
  },
  "physicalType": {
    "coding": [ {
      "system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
      "code": "bu",
      "display": "Vaccination Center"
    } ]
  },
  "position": {
    "longitude": 42.256500,
    "latitude": -83.694710
  }
}

Sample location payload for a Household location/home

{
  "resourceType": "Location",
  "status": "active",
  "name": "Kasera Village",
  "description": "The home village location",
  "mode": "instance",
  "address": {
    "city": "Nairobi",
    "state": "Kenya",
    "country": "Kenya"
  },
  "physicalType": {
    "coding": [ {
      "system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
      "code": "bu",
      "display": "Kasera Village"
    } ]
  },
  "position": {
    "longitude": 42.256500,
    "latitude": -83.694710
  }
}

Sample ANC mock

Screen Shot 2021-09-07 at 11 14 23 AM

NB. The accompanying details of the Location (address, display name) can be collected via a questionnaire and appended to the Questionnaire response before extraction and saving/posting/sync as a location resource

jingtang10 commented 2 years ago

What would the questionnaire response look like? It should be a response item to a single questionnaire item?

f-odhiambo commented 2 years ago

@jingtang10 There is an R5 ballot on the use of geolocation https://build.fhir.org/extension-geolocation.html. Added a zullip chat on this https://chat.fhir.org/#narrow/stream/179166-implementers/topic/Location.20mapping.20widget Will keep reviewing and try and draft a suitable QuestionnaireResponse

f-odhiambo commented 2 years ago

There is an R4 extension for GeoLocation http://hl7.org/fhir/extension-geolocation.html. Which could be used to append the location details directly to the Patient Resource or just used separately as in a Questionnaire to get location details. I think the QR can take the following form

{
  "resourceType": "QuestionnaireResponse",
  "status": "completed",
  "subject": {
    "reference": "Patient/969",
    "display": "Test Patient"
  },
  "authored": "2013-06-18T00:00:00+01:00",
  "author": {
    "reference": "Practitioner/970"
  },
  "source": {
    "reference": "Practitioner/970"
  },
  "item": [
    {
      "linkId": "1",
      "text": "General questions",
      "item": [
        {
          "linkId": "1.1",
          "text": "What is your Country of birth?",
          "answer": [
            {
              "valueString": "The Netherlands"
            }
          ]
        },
        {
          "linkId": "1.2",
          "text": "What is your City or State of birth?",
          "answer": [
            {
              "valueString": "Amsterdam"
            }
          ]
        },
        {
          "linkId": "1.3",
          "text": "What is your Village of birth?",
          "answer": [
            {
              "valueString": "Kraule"
            }
          ]
        }
      ]
    },
    {
      "linkId": "2",
      "text": "Location Details",
      "item": [
        {
          "linkId": "2.1",
          "text": "Latitude",
          "answer": [
            {
              "valueString": "52.3676"
            }
          ]
        },
        {
          "linkId": "2.2",
          "text": "Longitude",
          "answer": [
            {
              "valueString": "4.9041"
            }
          ]
        }
      ]
    }
  ]
}
puranjayK commented 2 years ago

Hi @f-odhiambo, I would like to work on this issue Could you please assign it to me

f-odhiambo commented 2 years ago

Hi @f-odhiambo, I would like to work on this issue Could you please assign it to me

Kindly tag me to the PR or leave a comment once a PR has been raised for this

puranjayK commented 2 years ago

@f-odhiambo @jingtang10 could you please help me with the questionnaire of the Location widget.

f-odhiambo commented 2 years ago

@f-odhiambo @jingtang10 could you please help me with the questionnaire of the Location widget.

Here you go http://turn-fhir.smartregister.org/fhir/Questionnaire/1922. You can add the widget to this questionnaire

f-odhiambo commented 2 years ago

Hey, @puranjayK Any progress update on this ? Perhaps we can link up on this sometime this week if available for more details. Let me know

f-odhiambo commented 2 years ago

@puranjayK Any progress update on this?

puranjayK commented 2 years ago

@puranjayK Any progress update on this?

Sorry I couldnt work on this, as the covid situation got worse in my country. I am having issues on how to make this widget and how the questionnaire is to be used

PallaviGanorkar commented 2 years ago

@jingtang10 @Tarun-Bhardwaj As discussed need to hold this issue for more requirement details.

f-odhiambo commented 2 years ago

HI @PallaviGanorkar , Are you going to be picking this issue ?

MnCSSJ4x commented 2 years ago

Hello I am new to contribution and would like to contribute to this issue if no one is on it.

f-odhiambo commented 2 years ago

Hi @MnCSSJ4x,Thanks for this , how can we connect to have a brief on this issue, can we ? CC @FikriMilano

MnCSSJ4x commented 2 years ago

we can connect via mail : xxxxx or if there is a slack channel please share an invite

FikriMilano commented 2 years ago

@f-odhiambo I assume this widget will retrieve the current device coordinates when the user clicks it?

f-odhiambo commented 2 years ago

@f-odhiambo I assume this widget will retrieve the current device coordinates when the user clicks it?

Yes

f-odhiambo commented 2 years ago

we can connect via mail : xxxxx or if there is a slack channel please share an invite

I copied and obscured your email . Thanks

FikriMilano commented 2 years ago

@f-odhiambo from this Questionnaire Response, what is 'Location Details' stands for? is it the Location widget? or it's simply a container from a 'group' type Questionnaire Item?

{
   "linkId":"2",
   "text":"Location Details",
   "item":[
      {
         "linkId":"2.1",
         "text":"Latitude",
         "answer":[
            {
               "valueString":"52.3676"
            }
         ]
      },
      {
         "linkId":"2.2",
         "text":"Longitude",
         "answer":[
            {
               "valueString":"4.9041"
            }
         ]
      }
   ]
}
f-odhiambo commented 2 years ago

It's a container from a 'group' type Questionnaire Item

FikriMilano commented 2 years ago

@f-odhiambo does that mean, there will be 2 location widgets to populate the Latitude and Longitude? (2.1 and 2.2)

f-odhiambo commented 2 years ago

@f-odhiambo does that mean, there will be 2 location widgets to populate the Latitude and Longitude? (2.1 and 2.2)

Not really the widget should allow you to invoke the get coordinated from the phone GPS and then use the results to populate the Latitude and Longitude for the specific location So the response will be something like this (0.0236, 37.9062) and then will need to split this comma separated value into Lat, Long as

"position": {
    "longitude": 42.256500,
    "latitude": -83.694710
  }
FikriMilano commented 2 years ago

Some useful reference: https://github.com/google/android-fhir/blob/master/datacapture/src/main/java/com/google/android/fhir/datacapture/QuestionnaireItemAdapter.kt

https://github.com/google/android-fhir/blob/master/catalog/src/main/java/com/google/android/fhir/catalog/CustomQuestionnaireFragment.kt

https://github.com/opensrp/fhircore/blob/main/android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/CustomPhotoCaptureFactory.kt

https://github.com/google/android-fhir/blob/master/datacapture/src/main/java/com/google/android/fhir/datacapture/contrib/views/barcode/QuestionnaireItemBarCodeReaderViewHolderFactory.kt

https://github.com/google/android-fhir/blob/master/datacapture/src/main/java/com/google/android/fhir/datacapture/views/QuestionnaireItemRadioGroupViewHolderFactory.kt

f-odhiambo commented 2 years ago

@MnCSSJ4x Whats the progress on this ?

MnCSSJ4x commented 2 years ago

Not much progress. Packed with exam till 12th. However took some time to review the material shared. However I am still confused whether I submit you a pull request or a design idea now !

MnCSSJ4x commented 2 years ago

@f-odhiambo

I would prefer to have an questionnaire the way you mentioned in the statement. For the location extraction using gps, I would prefer to use the fused Location Provider Client and then convert it to the FHIR is working on (this might involve splitting the data of latitude and longitude . After we get this processing done. We can create the payload in the way stated above (assuming that is the format the entire library follows) . Please let me know if this is what is expected, then I can start on the implementation side of things.

f-odhiambo commented 2 years ago

Yes this sounds good for a start @FikriMilano any additions to this ?

FikriMilano commented 2 years ago

@MnCSSJ4x could you send the Questionnaire and QuestionnaireResponse that you expect to look like? Just to make sure we have the same idea on this,

MnCSSJ4x commented 2 years ago

@FikriMilano I was planning to follow the sample format mentioned until and unless there is some limitation

FikriMilano commented 2 years ago

Alright, sounds good for me. Thanks for the feedback @MnCSSJ4x

f-odhiambo commented 2 years ago

Hi @MnCSSJ4x , how is the progress here ? CC @FikriMilano

MnCSSJ4x commented 2 years ago

@f-odhiambo I am having my semester exams this week. Will definitely address the coding part of the solution next week @FikriMilano can you provide me how you set up the environment locally to test ?

FikriMilano commented 2 years ago

@MnCSSJ4x you can just simply fork the repo, build the project then try to run the demo apps

f-odhiambo commented 2 years ago

@MnCSSJ4x Any progress made on this ticket?

f-odhiambo commented 1 year ago

@Tarun-Bhardwaj I think we can close this issue as it had been implemented on FHIR Core https://github.com/opensrp/fhircore/issues/1536

fredhersch commented 1 year ago

Thanks @f-odhiambo - would it be worth merging this back into the SDK? @jingtang10

f-odhiambo commented 1 year ago

Thanks @f-odhiambo - would it be worth merging this back into the SDK? @jingtang10

We can have a discussion on this , happy to elaborate more on the solution we took

dubdabasoduba commented 7 months ago

@ageryck I think you can re-open this ticket for the GPS picker work.

ageryck commented 7 months ago

@jingtang10 this can be re-assigned since the implementation in the attached PR was something different

LZRS commented 7 months ago

@f-odhiambo @f-odhiambo I had a suggestion of maybe using a normal Questionnaire item of type string with a custom extension to render the widget

 {
          "linkId": "Location widget",
          "type": "string",
          "text": "Record GPS Location",
          "required": true,
          "extension": [
            {
              "url": "https://github.com/google/android-fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "https://github.com/google/android-fhir/questionnaire-item-control",
                    "code": "location-widget"
                  }
                ]
              }
            }
          ]
        }

and to render, instead of having it as single "record gps location", maybe have it render similar to the datepicker populating the textview with comma-separated latitude, longitude, altitude. This way we would probably still be able to use the already implemented utilities for example, adding extensions for help, attachment, translations and also show validation error incase field is required

sample

cc: @ageryck @FikriMilano @dubdabasoduba

LZRS commented 6 months ago

After reviewing the above implementation idea, we felt it may have had deficiencies of may be not being able to separate between latitude and longitude in consistent way. And so, with the help of the fhir org team, we had another idea that would be viable, to use a Questionnaire item of type group. The Questionnaire item would have a custom extension to represent location-widget and also have child items of type string with custom extensions to specify latitude, longitude and altitude - these would be used in the ui to render and populate the coordinates.

Essentially, it would look like

 {
          "linkId": "location-widget",
          "type": "group",
          "extension": [
            {
              "url": "https://github.com/google/android-fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "https://github.com/google/android-fhir/questionnaire-item-control",
                    "code": "location-widget"
                  }
                ]
              }
            }
          ],
        "item": [
          {
            "linkId": "latitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "latitude"
              }
            ]
          },
          {
            "linkId": "longitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "longitude"
              }
            ]
          }
        ]
        }

@jingtang10 would love to hear what you think

cc @f-odhiambo @ageryck

jingtang10 commented 6 months ago

I think defining custom widgets (together with custom extensions) in the SDC library is a great approach. This is fine.

The important thing is documentation and making sure people using your questionnaires are aware of the extensions you define otherwise your questionnaire will not be usable.

Be good to share this with the fhir chat community as well, especially to get grahame and lloyd's opinion.

dubdabasoduba commented 6 months ago

After reviewing the above implementation idea, we felt it may have had deficiencies of may be not being able to separate between latitude and longitude in consistent way. And so, with the help of the fhir org team, we had another idea that would be viable, to use a Questionnaire item of type group. The Questionnaire item would have a custom extension to represent location-widget and also have child items of type string with custom extensions to specify latitude, longitude and altitude - these would be used in the ui to render and populate the coordinates.

Essentially, it would look like

 {
          "linkId": "location-widget",
          "type": "group",
          "extension": [
            {
              "url": "https://github.com/google/android-fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "https://github.com/google/android-fhir/questionnaire-item-control",
                    "code": "location-widget"
                  }
                ]
              }
            }
          ],
        "item": [
          {
            "linkId": "latitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "latitude"
              }
            ]
          },
          {
            "linkId": "longitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "longitude"
              }
            ]
          }
        ]
        }

@jingtang10 would love to hear what you think

cc @f-odhiambo @ageryck

@LZRS how does this look on the QR? Do you mind sharing a sample?

LZRS commented 6 months ago

After reviewing the above implementation idea, we felt it may have had deficiencies of may be not being able to separate between latitude and longitude in consistent way. And so, with the help of the fhir org team, we had another idea that would be viable, to use a Questionnaire item of type group. The Questionnaire item would have a custom extension to represent location-widget and also have child items of type string with custom extensions to specify latitude, longitude and altitude - these would be used in the ui to render and populate the coordinates. Essentially, it would look like

 {
          "linkId": "location-widget",
          "type": "group",
          "extension": [
            {
              "url": "https://github.com/google/android-fhir/StructureDefinition/questionnaire-itemControl",
              "valueCodeableConcept": {
                "coding": [
                  {
                    "system": "https://github.com/google/android-fhir/questionnaire-item-control",
                    "code": "location-widget"
                  }
                ]
              }
            }
          ],
        "item": [
          {
            "linkId": "latitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "latitude"
              }
            ]
          },
          {
            "linkId": "longitude",
            "type": "string",
            "required": true,
            "readOnly": true,
            "extension": [
              {
                "url": "gps-coordinate",
                "value": "longitude"
              }
            ]
          }
        ]
        }

@jingtang10 would love to hear what you think cc @f-odhiambo @ageryck

@LZRS how does this look on the QR? Do you mind sharing a sample?

The QuestionnaireResponse would probably look like this

{
  "linkId": "location-widget",
  "item": [
    {
      "linkId": "latitude",
      "answer": [
        {
          "valueString": "41.40338"
        }
      ]
    },
    {
      "linkId": "longitude",
      "answer": [
        {
          "valueString": "2.17403"
        }
      ]
    }
  ]
}