@@ -22,6 +22,7 @@ import androidx.lifecycle.LiveData
22
22
import androidx.lifecycle.MutableLiveData
23
23
import androidx.lifecycle.ViewModel
24
24
import androidx.lifecycle.viewModelScope
25
+ import ca.uhn.fhir.validation.FhirValidator
25
26
import com.google.android.fhir.datacapture.mapping.ResourceMapper
26
27
import com.google.android.fhir.datacapture.mapping.StructureMapExtractionContext
27
28
import com.google.android.fhir.datacapture.validation.NotValidated
@@ -35,6 +36,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
35
36
import java.util.Date
36
37
import java.util.UUID
37
38
import javax.inject.Inject
39
+ import javax.inject.Provider
38
40
import kotlinx.coroutines.SupervisorJob
39
41
import kotlinx.coroutines.launch
40
42
import kotlinx.coroutines.withContext
@@ -45,7 +47,6 @@ import org.hl7.fhir.r4.model.Group
45
47
import org.hl7.fhir.r4.model.IdType
46
48
import org.hl7.fhir.r4.model.ListResource
47
49
import org.hl7.fhir.r4.model.ListResource.ListEntryComponent
48
- import org.hl7.fhir.r4.model.Patient
49
50
import org.hl7.fhir.r4.model.Questionnaire
50
51
import org.hl7.fhir.r4.model.QuestionnaireResponse
51
52
import org.hl7.fhir.r4.model.RelatedPerson
@@ -55,6 +56,7 @@ import org.hl7.fhir.r4.model.StringType
55
56
import org.smartregister.fhircore.engine.configuration.GroupResourceConfig
56
57
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
57
58
import org.smartregister.fhircore.engine.data.local.DefaultRepository
59
+ import org.smartregister.fhircore.engine.di.checkResourceValid
58
60
import org.smartregister.fhircore.engine.domain.model.ActionParameter
59
61
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
60
62
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
@@ -93,6 +95,7 @@ constructor(
93
95
val transformSupportServices: TransformSupportServices ,
94
96
val sharedPreferencesHelper: SharedPreferencesHelper ,
95
97
val fhirOperator: FhirOperator ,
98
+ val fhirValidatorProvider: Provider <FhirValidator >,
96
99
val fhirPathDataExtractor: FhirPathDataExtractor ,
97
100
) : ViewModel () {
98
101
@@ -268,6 +271,8 @@ constructor(
268
271
questionnaireConfig : QuestionnaireConfig ,
269
272
currentQuestionnaireResponse : QuestionnaireResponse ,
270
273
) {
274
+ // todo: validate extracted resources here
275
+
271
276
val extractionDate = Date ()
272
277
273
278
// Create a ListResource to store the references for generated resources
@@ -346,6 +351,8 @@ constructor(
346
351
}
347
352
}
348
353
354
+ // todo: validate as bundle to ensure nothing gets saved
355
+ fhirValidatorProvider.get().checkResourceValid(this )
349
356
defaultRepository.addOrUpdate(true , resource = this )
350
357
351
358
addMemberToConfiguredGroup(this , questionnaireConfig.groupResource)
0 commit comments