diff --git a/android/engine/build.gradle b/android/engine/build.gradle
index 514a4a3577..a9602c241b 100644
--- a/android/engine/build.gradle
+++ b/android/engine/build.gradle
@@ -114,7 +114,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
- implementation 'com.google.android.material:material:1.7.0'
+ implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation 'androidx.fragment:fragment-ktx:1.5.5'
diff --git a/android/engine/src/main/res/color/checkbox_checked_background_border.xml b/android/engine/src/main/res/color/checkbox_checked_background_border.xml
new file mode 100644
index 0000000000..f6b810b666
--- /dev/null
+++ b/android/engine/src/main/res/color/checkbox_checked_background_border.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/color/checkbox_checked_background_solid.xml b/android/engine/src/main/res/color/checkbox_checked_background_solid.xml
new file mode 100644
index 0000000000..1d96af39de
--- /dev/null
+++ b/android/engine/src/main/res/color/checkbox_checked_background_solid.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/color/checkbox_checked_color.xml b/android/engine/src/main/res/color/checkbox_checked_color.xml
new file mode 100644
index 0000000000..e62a918558
--- /dev/null
+++ b/android/engine/src/main/res/color/checkbox_checked_color.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/color/input_field_border_color.xml b/android/engine/src/main/res/color/input_field_border_color.xml
new file mode 100644
index 0000000000..793737e5e1
--- /dev/null
+++ b/android/engine/src/main/res/color/input_field_border_color.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/drawable-ldrtl/checkbox_inset.xml b/android/engine/src/main/res/drawable-ldrtl/checkbox_inset.xml
new file mode 100644
index 0000000000..9ee4808a0b
--- /dev/null
+++ b/android/engine/src/main/res/drawable-ldrtl/checkbox_inset.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/android/engine/src/main/res/drawable-ldrtl/radio_button_inset.xml b/android/engine/src/main/res/drawable-ldrtl/radio_button_inset.xml
new file mode 100644
index 0000000000..83bbe45206
--- /dev/null
+++ b/android/engine/src/main/res/drawable-ldrtl/radio_button_inset.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/android/engine/src/main/res/drawable/checkbox_background.xml b/android/engine/src/main/res/drawable/checkbox_background.xml
new file mode 100644
index 0000000000..aeec7cd58e
--- /dev/null
+++ b/android/engine/src/main/res/drawable/checkbox_background.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/drawable/checkbox_checked_background.xml b/android/engine/src/main/res/drawable/checkbox_checked_background.xml
new file mode 100644
index 0000000000..53acd3ba24
--- /dev/null
+++ b/android/engine/src/main/res/drawable/checkbox_checked_background.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/drawable/checkbox_icon.xml b/android/engine/src/main/res/drawable/checkbox_icon.xml
new file mode 100644
index 0000000000..f0a2d0e3f5
--- /dev/null
+++ b/android/engine/src/main/res/drawable/checkbox_icon.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/android/engine/src/main/res/drawable/checkbox_inset.xml b/android/engine/src/main/res/drawable/checkbox_inset.xml
new file mode 100644
index 0000000000..1953472738
--- /dev/null
+++ b/android/engine/src/main/res/drawable/checkbox_inset.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/android/engine/src/main/res/drawable/checkbox_unchecked_background.xml b/android/engine/src/main/res/drawable/checkbox_unchecked_background.xml
new file mode 100644
index 0000000000..0e2d9abb8f
--- /dev/null
+++ b/android/engine/src/main/res/drawable/checkbox_unchecked_background.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/drawable/ic_checkbox_checked.xml b/android/engine/src/main/res/drawable/ic_checkbox_checked.xml
new file mode 100644
index 0000000000..a293ac7226
--- /dev/null
+++ b/android/engine/src/main/res/drawable/ic_checkbox_checked.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/android/engine/src/main/res/drawable/ic_checkbox_unchecked.xml b/android/engine/src/main/res/drawable/ic_checkbox_unchecked.xml
new file mode 100644
index 0000000000..8ddc896671
--- /dev/null
+++ b/android/engine/src/main/res/drawable/ic_checkbox_unchecked.xml
@@ -0,0 +1,11 @@
+
+
+
diff --git a/android/engine/src/main/res/drawable/ic_radio_button_checked.xml b/android/engine/src/main/res/drawable/ic_radio_button_checked.xml
new file mode 100644
index 0000000000..b2fcfbeb24
--- /dev/null
+++ b/android/engine/src/main/res/drawable/ic_radio_button_checked.xml
@@ -0,0 +1,17 @@
+
+
+
+
diff --git a/android/engine/src/main/res/drawable/ic_radio_button_unchecked.xml b/android/engine/src/main/res/drawable/ic_radio_button_unchecked.xml
new file mode 100644
index 0000000000..7868f479b5
--- /dev/null
+++ b/android/engine/src/main/res/drawable/ic_radio_button_unchecked.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/android/engine/src/main/res/drawable/radio_button_icon.xml b/android/engine/src/main/res/drawable/radio_button_icon.xml
new file mode 100644
index 0000000000..d0824c9c7c
--- /dev/null
+++ b/android/engine/src/main/res/drawable/radio_button_icon.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/android/engine/src/main/res/drawable/radio_button_inset.xml b/android/engine/src/main/res/drawable/radio_button_inset.xml
new file mode 100644
index 0000000000..590a904e06
--- /dev/null
+++ b/android/engine/src/main/res/drawable/radio_button_inset.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/android/engine/src/main/res/drawable/rounded_submit_button.xml b/android/engine/src/main/res/drawable/rounded_submit_button.xml
new file mode 100644
index 0000000000..dd2dd8e548
--- /dev/null
+++ b/android/engine/src/main/res/drawable/rounded_submit_button.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/values/colors.xml b/android/engine/src/main/res/values/colors.xml
index b93b1541c9..f5a359a6a2 100644
--- a/android/engine/src/main/res/values/colors.xml
+++ b/android/engine/src/main/res/values/colors.xml
@@ -2,7 +2,7 @@
#DD0000
#f2d0d3
- #005084
+ #006EB8
#003D66
#006EB8
#0283DA
diff --git a/android/engine/src/main/res/values/dimens.xml b/android/engine/src/main/res/values/dimens.xml
new file mode 100644
index 0000000000..55344e5192
--- /dev/null
+++ b/android/engine/src/main/res/values/dimens.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/android/engine/src/main/res/values/styles.xml b/android/engine/src/main/res/values/styles.xml
index df3c1423e8..9a28822b72 100644
--- a/android/engine/src/main/res/values/styles.xml
+++ b/android/engine/src/main/res/values/styles.xml
@@ -8,7 +8,7 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/quest/src/main/AndroidManifest.xml b/android/quest/src/main/AndroidManifest.xml
index 667beaf888..824aee0aee 100644
--- a/android/quest/src/main/AndroidManifest.xml
+++ b/android/quest/src/main/AndroidManifest.xml
@@ -19,12 +19,7 @@
-
-
-
-
-
+ android:exported="false">
+ android:exported="true"
+ android:theme="@style/AppTheme">
+
+
+
+
+
+
+
diff --git a/android/quest/src/main/assets/component_attachment.json b/android/quest/src/main/assets/component_attachment.json
new file mode 100644
index 0000000000..db9c7faa63
--- /dev/null
+++ b/android/quest/src/main/assets/component_attachment.json
@@ -0,0 +1,363 @@
+{
+ "title": "Multiple choice",
+ "status": "active",
+ "version": "0.0.1",
+ "resourceType": "Questionnaire",
+ "item": [
+ {
+ "linkId": "1.1",
+ "text": "Register new patient",
+ "type": "string",
+ "item": [
+ {
+ "linkId": "1-first-name",
+ "text": "First Name",
+ "type": "display",
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "flyover",
+ "display": "Fly-over"
+ }
+ ],
+ "text": "Flyover"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "linkId": "1",
+ "type": "choice",
+ "repeats": true,
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "open-choice",
+ "display": "Open choice"
+ }
+ ],
+ "text": "Open choice"
+ }
+ }
+ ],
+ "text": "Do you have any pre-existing health conditions?",
+ "item": [
+ {
+ "linkId": "1.1",
+ "text": "Health conditions",
+ "type": "display",
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "flyover"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ],
+ "answerOption": [
+ {
+ "valueCoding": {
+ "code": "dm",
+ "display": "Diabetes Melitus (DM)"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "ht",
+ "display": "Hypertension (HT)"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "ihd",
+ "display": "Ischemic Heart Disease (IHD/CHD/CCF)"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "tb",
+ "display": "Tuberculosis (TB)"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "copd",
+ "display": "Asthma/COPD"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "kidney",
+ "display": "Chronic Kidney Disease"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "none",
+ "display": "None"
+ }
+ }
+ ]
+ },
+ {
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "radio-button",
+ "display": "Radio Button"
+ }
+ ]
+ }
+ }
+ ],
+ "linkId": "1",
+ "text": "Choose one from the options below",
+ "type": "choice",
+ "answerOption": [
+ {
+ "valueCoding": {
+ "code": "option-1",
+ "display": "Option 1"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-2",
+ "display": "Option 2"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-3",
+ "display": "Option 3"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "mother",
+ "display": "Option 4"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "sibling",
+ "display": "Option 5"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "other",
+ "display": "Option 6"
+ }
+ }
+ ],
+ "item": [
+ {
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-display-category",
+ "code": "instructions"
+ }
+ ]
+ }
+ }
+ ],
+ "linkId": "1-select-one",
+ "text": "Select one",
+ "type": "display"
+ }
+ ]
+ },
+
+ {
+ "linkId": "1",
+ "type": "choice",
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "drop-down",
+ "display": "Drop down"
+ }
+ ],
+ "text": "Drop down"
+ }
+ }
+ ],
+ "text": "Choose one from the options below",
+ "answerOption": [
+ {
+ "valueCoding": {
+ "code": "option-1",
+ "display": "Option 1"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-2",
+ "display": "Option 2"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-3",
+ "display": "Option 3"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-4",
+ "display": "Option 4"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-5",
+ "display": "Option 5"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "option-6",
+ "display": "Option 6"
+ }
+ }
+ ],
+ "item": [
+ {
+ "linkId": "1-relationship",
+ "text": "State",
+ "type": "display",
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "flyover",
+ "display": "Fly-over"
+ }
+ ],
+ "text": "Flyover"
+ }
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "linkId": "1.0.0",
+ "text": "What’s the reason for today’s visit?",
+ "type": "choice",
+ "repeats": true,
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-item-control",
+ "code": "check-box",
+ "display": "Checkbox"
+ }
+ ],
+ "text": "Checkbox"
+ }
+ }
+ ],
+ "answerOption": [
+ {
+ "valueCoding": {
+ "code": "code_1",
+ "display": "ANC",
+ "system": "http://snomed.info/sct"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "code_2",
+ "display": "Immunization",
+ "system": "http://snomed.info/sct"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "code_3",
+ "display": "Malaria Testing",
+ "system": "http://snomed.info/sct"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "code_4",
+ "display": "Feeling sick",
+ "system": "http://snomed.info/sct"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "code_5",
+ "display": "Family planning",
+ "system": "http://snomed.info/sct"
+ }
+ },
+ {
+ "valueCoding": {
+ "code": "code_6",
+ "display": "Lab Tests",
+ "system": "http://snomed.info/sct"
+ }
+ }
+ ],
+ "item": [
+ {
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://hl7.org/fhir/questionnaire-display-category",
+ "code": "instructions"
+ }
+ ]
+ }
+ }
+ ],
+ "linkId": "1-select-one",
+ "text": "Select all that apply",
+ "type": "display"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/android/quest/src/main/assets/configs/app/sync_config.json b/android/quest/src/main/assets/configs/app/sync_config.json
index 305c3c96c0..63164bbe4b 100644
--- a/android/quest/src/main/assets/configs/app/sync_config.json
+++ b/android/quest/src/main/assets/configs/app/sync_config.json
@@ -2,118 +2,5 @@
"resourceType": "Parameters",
"configType": "sync",
"parameter": [
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "_id",
- "code": "_id",
- "base": [
- "Encounter",
- "Observation",
- "Condition",
- "CarePlan",
- "QuestionnaireResponse",
- "Task",
- "RelatedPerson",
- "Patient"
- ]
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "_id",
- "code": "_id",
- "base": [
- "Practitioner"
- ]
- },
- "type": "token",
- "expression": "130845,94398"
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "publisher",
- "code": "publisher",
- "base": [
- "Questionnaire"
- ],
- "type": "token",
- "expression": "#publisher"
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "_id",
- "code": "_id",
- "base": [
- "StructureMap",
- "PlanDefinition",
- "PractitionerRole",
- "OrganizationAffiliation",
- "Organization",
- "Location"
- ]
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "_id",
- "code": "_id",
- "base": [
- "Library"
- ]
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "_id",
- "code": "_id",
- "base": [
- "Measure"
- ]
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "organization",
- "code": "_tag",
- "base": [
- "MeasureReport"
- ],
- "type": "token",
- "expression": "#organization"
- }
- },
- {
- "resource": {
- "resourceType": "SearchParameter",
- "name": "count",
- "code": "_count",
- "base": [
- "Patient",
- "Encounter",
- "Observation",
- "Condition",
- "CarePlan",
- "QuestionnaireResponse",
- "Questionnaire",
- "StructureMap",
- "Task",
- "Group",
- "Practitioner",
- "PlanDefinition",
- "Library",
- "Measure"
- ],
- "type": "token",
- "expression": "#count"
- }
- }
]
}
diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt
index 44b2696546..a3585c19da 100644
--- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt
+++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireActivity.kt
@@ -108,10 +108,7 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
intent.getSerializableExtra(QUESTIONNAIRE_COMPUTED_VALUES_MAP) as Map?
?: emptyMap()
- questionnaireConfig =
- (intent.getSerializableExtra(QUESTIONNAIRE_CONFIG) as QuestionnaireConfig).interpolate(
- computedValuesMap
- )
+ questionnaireConfig = QuestionnaireConfig("a")
actionParams =
intent.getSerializableExtra(QUESTIONNAIRE_ACTION_PARAMETERS) as List?
@@ -135,10 +132,10 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
val loadProgress = showProgressAlert(this, R.string.loading)
lifecycleScope.launch(dispatcherProvider.io()) {
- questionnaireViewModel.run {
- questionnaire =
- loadQuestionnaire(questionnaireConfig.id, questionnaireConfig.type, prePopulationParams)!!
- }
+// questionnaireViewModel.run {
+//// questionnaire =
+//// loadQuestionnaire(questionnaireConfig.id, questionnaireConfig.type, prePopulationParams)!!
+// }
// Only add the fragment once, when the activity is first created.
if (savedInstanceState == null) renderFragment()
@@ -161,7 +158,7 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
ViewGroup.LayoutParams
.MATCH_PARENT // Override by Styles xml does not seem to work for this layout param
- if (questionnaireConfig.type.isReadOnly() || questionnaire.experimental) {
+ if (questionnaireConfig.type.isReadOnly()) {
text = context.getString(R.string.done)
} else if (questionnaireConfig.type.isEditMode()) {
// setting the save button text from Questionnaire Config
@@ -181,7 +178,7 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
private suspend fun renderFragment() {
fragment =
QuestQuestionnaireFragment().apply {
- val questionnaireString = parser.encodeResourceToString(questionnaire)
+ val questionnaireString = questionnaireViewModel.getQuestionnaireJson()
// Generate Fragment bundle arguments. This is the Questionnaire & QuestionnaireResponse
// pass questionnaire and questionnaire-response to fragment
@@ -233,12 +230,12 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
val loadProgress = showProgressAlert(this, R.string.loading)
lifecycleScope.launch(dispatcherProvider.io()) {
// Reload the questionnaire and reopen the fragment
- questionnaire =
- questionnaireViewModel.loadQuestionnaire(
- questionnaireConfig.id,
- questionnaireConfig.type,
- prePopulationParams
- )!!
+// questionnaire =
+// questionnaireViewModel.loadQuestionnaire(
+// questionnaireConfig.id,
+// questionnaireConfig.type,
+// prePopulationParams
+// )!!
supportFragmentManager.commit { detach(fragment) }
renderFragment()
withContext(dispatcherProvider.main()) {
diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt
index 72b6f985b2..3c642a83f1 100644
--- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt
+++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt
@@ -16,9 +16,11 @@
package org.smartregister.fhircore.quest.ui.questionnaire
+import android.app.Application
import android.content.Context
import android.content.Intent
import android.widget.Toast
+import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -79,6 +81,7 @@ import timber.log.Timber
open class QuestionnaireViewModel
@Inject
constructor(
+ application: Application,
val defaultRepository: DefaultRepository,
val configurationRegistry: ConfigurationRegistry,
val transformSupportServices: TransformSupportServices,
@@ -87,7 +90,11 @@ constructor(
val libraryEvaluator: LibraryEvaluator,
val fhirCarePlanGenerator: FhirCarePlanGenerator,
val jsonParser: IParser
-) : ViewModel() {
+) : AndroidViewModel(application) {
+
+
+ private val backgroundContext = viewModelScope.coroutineContext
+ private var questionnaireJson: String? = null
val extractionProgress = MutableLiveData()
@@ -109,22 +116,29 @@ constructor(
?.extractLogicalIdUuid()
}
- suspend fun loadQuestionnaire(
- id: String,
- type: QuestionnaireType,
- prePopulationParams: List? = emptyList()
- ): Questionnaire? =
- defaultRepository.loadResource(id)?.apply {
- if (type.isReadOnly() || type.isEditMode()) {
- item.prepareQuestionsForReadingOrEditing(QUESTIONNAIRE_RESPONSE_ITEM, type.isReadOnly())
- }
- // prepopulate questionnaireItems with initial values
- if (prePopulationParams?.isNotEmpty() == true) {
- item.prePopulateInitialValues(prePopulationParams)
+// suspend fun loadQuestionnaire(
+// id: String,
+// type: QuestionnaireType,
+// prePopulationParams: List? = emptyList()
+// ): Questionnaire? {
+// getQuestionnaireJson()
+// }
+
+ suspend fun getQuestionnaireJson(): String {
+ return withContext(backgroundContext) {
+ if (questionnaireJson == null) {
+ questionnaireJson = readFileFromAssets("component_attachment.json")
}
+ questionnaireJson!!
+ }
+ }
+
+
+ val QUESTIONNAIRE_FILE_PATH_KEY = "questionnaire-file-path-key"
- // TODO https://github.com/opensrp/fhircore/issues/991#issuecomment-1027872061
- this.url = this.url ?: this.referenceValue()
+ private suspend fun readFileFromAssets(filename: String) =
+ withContext(backgroundContext) {
+ getApplication().assets.open(filename).bufferedReader().use { it.readText() }
}
suspend fun fetchStructureMap(structureMapUrl: String?): StructureMap? {