Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer expression catalog #1960

Merged
merged 27 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5cccbab
Answer expression catalog
maimoonak Apr 7, 2023
e559a09
Spotless apply
maimoonak Apr 7, 2023
7e519e4
Remove unneccessary files
maimoonak Apr 7, 2023
9bde001
simplify data bundle entries
maimoonak Apr 7, 2023
00f80c2
Merge branch 'master' into answer-expression-catalog
dubdabasoduba Apr 19, 2023
f9824b4
Update catalog/src/main/java/com/google/android/fhir/catalog/CatalogA…
maimoonak Apr 27, 2023
ce6da61
Merge branch 'master' into answer-expression-catalog
maimoonak Apr 27, 2023
1576b4a
Merge branch 'master' into answer-expression-catalog
maimoonak May 3, 2023
2d547e0
Merge branch 'master' into answer-expression-catalog
maimoonak May 18, 2023
a53f6be
Merge branch 'master' into answer-expression-catalog
f-odhiambo May 25, 2023
37193ba
covid questionnaire test
maimoonak May 26, 2023
696cdc5
Temp commit for covid 19 questoinnaire
maimoonak May 29, 2023
e62bc06
Merge branch 'master' into answer-expression-catalog
maimoonak Jun 12, 2023
d995be5
Merge master and fix conflicts
maimoonak Jun 19, 2023
c7d751b
Merge branch 'master' into answer-expression-catalog
maimoonak Jun 21, 2023
a7c2647
Merge branch 'master' into answer-expression-catalog
f-odhiambo Jun 26, 2023
0259029
Merge branch 'master' into answer-expression-catalog
maimoonak Jul 25, 2023
6d13500
remove test only mode
maimoonak Jul 25, 2023
a4d78a4
Merge branch 'answer-expression-catalog' of https://github.com/opensr…
maimoonak Jul 25, 2023
51fd2ad
fix spot less issues
maimoonak Jul 25, 2023
c985c52
Merge branch 'master' into answer-expression-catalog
maimoonak Aug 8, 2023
962e5f4
Merge branch 'master' into answer-expression-catalog
maimoonak Sep 19, 2023
7ea6106
revert variable test change
maimoonak Sep 19, 2023
be5d97b
Merge branch 'answer-expression-catalog' of https://github.com/opensr…
maimoonak Sep 19, 2023
0bb8db9
Simplify the answer expression questionnaire
maimoonak Sep 19, 2023
47b7772
Merge branch 'master' into answer-expression-catalog
maimoonak Sep 19, 2023
9310607
Merge branch 'master' into answer-expression-catalog
jingtang10 Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation(Dependencies.Navigation.navUiKtx)

implementation(project(path = ":datacapture"))
implementation(project(path = ":engine"))
implementation(project(path = ":contrib:barcode"))

testImplementation(Dependencies.junit)
Expand Down
1 change: 1 addition & 0 deletions catalog/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/>

<application
android:name=".CatalogApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_card_file_box"
android:label="@string/app_name"
Expand Down
34 changes: 34 additions & 0 deletions catalog/src/main/assets/behavior_answer_expression.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"resourceType": "Questionnaire",
"item": [
{
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-answerExpression",
"valueExpression": {
"language": "application/x-fhir-query",
"expression": "Task?subject=Patient/P1&code=33879002&status=ready&_sort=period"
}
},
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-choiceColumn",
"extension": [
{
"url": "path",
"valueString": "description + ' - ' + reasonCode.coding.where(system='http://snomed.info/sct').display"
},
{
"url": "forDisplay",
"valueBoolean": true
}
]
}
],
"linkId": "vaccines",
"text": "Which vaccine tasks were completed?",
"type": "reference",
"required": true,
"repeats": true
}
]
}
116 changes: 116 additions & 0 deletions catalog/src/main/assets/resource_data_bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"resourceType": "Bundle",
"entry": [
{
"resource": {
"resourceType" : "Patient",
"id" : "P1"
}
},
{
"resource": {
"resourceType": "Task",
"id": "b8e13d21-1a62-4172-a9ef-57670e6ac238",
"status": "ready",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "33879002",
"display": "Vaccination routine"
}
]
},
"description": "BCG at birth",
"for": {
"reference": "Patient/P1"
},
"reasonCode": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "42284007",
"display": "BCG vaccine"
},
{
"system": "https://smartregister.org/immunization/vaccine-codes",
"code": "bcg",
"display": "BCG"
}
],
"text": "BCG"
}
}
},
{
"resource": {
"resourceType": "Task",
"id": "4090ba9a-fbbb-4634-a06d-0cbe938ab090",
"status": "cancelled",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "33879002",
"display": "Vaccination routine"
}
]
},
"description": "OPV 0 at birth",
"for": {
"reference": "Patient/P1"
},
"reasonCode": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "111164008",
"display": "Poliovirus vaccine"
},
{
"system": "https://smartregister.org/immunization/vaccine-codes",
"code": "opv0",
"display": "OPV 0"
}
],
"text": "OPV 0"
}
}
},
{
"resource": {
"resourceType": "Task",
"id": "087e82c6-e346-4725-8db1-7e10aec99be9",
"status": "ready",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "33879002",
"display": "Vaccination routine"
}
]
},
"description": "OPV 1 at 6 weeks",
"for": {
"reference": "Patient/P1"
},
"reasonCode": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "111164008",
"display": "Poliovirus vaccine"
},
{
"system": "https://smartregister.org/immunization/vaccine-codes",
"code": "opv1",
"display": "OPV 1"
}
],
"text": "OPV 1"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class BehaviorListViewModel(application: Application) : AndroidViewModel(applica
R.string.behavior_name_calculated_expression,
"behavior_calculated_expression.json",
),
ANSWER_EXPRESSION(
R.drawable.ic_answers_behavior,
R.string.behavior_name_answer_expression,
"behavior_answer_expression.json",
),
CONTEXT_VARIABLES(
R.drawable.ic_context,
R.string.behavior_name_context_variables,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2022-2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.catalog

import android.app.Application
import ca.uhn.fhir.context.FhirContext
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.FhirEngineConfiguration
import com.google.android.fhir.FhirEngineProvider
import com.google.android.fhir.datacapture.DataCaptureConfig
import com.google.android.fhir.search.search
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.Bundle

class CatalogApplication : Application(), DataCaptureConfig.Provider {
// Only initiate the FhirEngine when used for the first time, not when the app is created.
private val fhirEngine: FhirEngine by lazy { FhirEngineProvider.getInstance(this) }

private lateinit var dataCaptureConfig: DataCaptureConfig

override fun onCreate() {
super.onCreate()

FhirEngineProvider.init(FhirEngineConfiguration())

dataCaptureConfig =
DataCaptureConfig(xFhirQueryResolver = { fhirEngine.search(it).map { it.resource } })

CoroutineScope(Dispatchers.IO).launch {
assets
.open("resource_data_bundle.json")
.bufferedReader()
.use { bufferedReader -> bufferedReader.readText() }
.let { stringValue ->
FhirContext.forR4Cached().newJsonParser().parseResource(stringValue) as Bundle
}
.entry
.map { bundleEntryComponent -> bundleEntryComponent.resource }
.let { resources -> fhirEngine.create(*resources.toTypedArray()) }
}
}

override fun getDataCaptureConfig(): DataCaptureConfig = dataCaptureConfig
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import ca.uhn.fhir.context.FhirContext
import com.google.android.fhir.catalog.ModalBottomSheetFragment.Companion.BUNDLE_ERROR_KEY
import com.google.android.fhir.catalog.ModalBottomSheetFragment.Companion.REQUEST_ERROR_KEY
import com.google.android.fhir.datacapture.QuestionnaireFragment
import com.google.android.fhir.datacapture.QuestionnaireFragment.Companion.SUBMIT_REQUEST_KEY
import com.google.android.material.card.MaterialCardView
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.Patient

class DemoQuestionnaireFragment : Fragment() {
private val viewModel: DemoQuestionnaireViewModel by viewModels()
Expand Down Expand Up @@ -164,7 +166,15 @@ class DemoQuestionnaireFragment : Fragment() {
setReorderingAllowed(true)
replace(
R.id.container,
QuestionnaireFragment.builder().setQuestionnaire(questionnaireJsonString).build(),
QuestionnaireFragment.builder()
.setQuestionnaire(questionnaireJsonString)
.setQuestionnaireLaunchContexts(
FhirContext.forR4Cached()
.newJsonParser()
.encodeResourceToString(Patient().apply { id = "P1" })
.let { listOf(it) },
)
.build(),
QUESTIONNAIRE_FRAGMENT_TAG,
)
}
Expand Down
23 changes: 23 additions & 0 deletions catalog/src/main/res/drawable/ic_answers_behavior.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="194dp"
android:height="128dp"
android:viewportWidth="194"
android:viewportHeight="128"
>
<group>
<clip-path
android:pathData="M194,64C194,78.359 182.359,90 168,90L0,90L0,38L168,38C182.359,38 194,49.641 194,64V64Z"
/>
<path
android:pathData="M128,76C128,79.866 124.866,83 121,83L-1,83L-1,45L121,45C124.866,45 128,48.134 128,52L128,76Z"
android:strokeWidth="2"
android:fillColor="#ffffff"
android:strokeColor="#4285F4"
/>
</group>
<path
android:pathData="M101.5,61L109,68.5L116.5,61H101.5Z"
android:fillColor="#1A73E8"
/>
</vector>
1 change: 1 addition & 0 deletions catalog/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string
name="behavior_name_calculated_expression"
>Calculated Expression</string>
<string name="behavior_name_answer_expression">Answer Expression</string>
<string name="toolbar_text">Structured data capture \n Catalog</string>
<string
name="questionnaire_response_title"
Expand Down