@@ -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
@@ -346,6 +349,7 @@ constructor(
346
349
}
347
350
}
348
351
352
+ fhirValidatorProvider.get().checkResourceValid(this )
349
353
defaultRepository.addOrUpdate(true , resource = this )
350
354
351
355
addMemberToConfiguredGroup(this , questionnaireConfig.groupResource)
@@ -368,6 +372,7 @@ constructor(
368
372
! currentQuestionnaireResponse.subject.reference.isNullOrEmpty() &&
369
373
questionnaireConfig.saveQuestionnaireResponse
370
374
) {
375
+ fhirValidatorProvider.get().checkResourceValid(currentQuestionnaireResponse)
371
376
defaultRepository.addOrUpdate(resource = currentQuestionnaireResponse)
372
377
}
373
378
}
@@ -514,6 +519,7 @@ constructor(
514
519
}
515
520
if (questionnaireHasAnswer) {
516
521
questionnaireResponse.status = QuestionnaireResponse .QuestionnaireResponseStatus .INPROGRESS
522
+ // fhirValidatorProvider.get().validateResource(questionnaireResponse)
517
523
defaultRepository.addOrUpdate(addMandatoryTags = true , resource = questionnaireResponse)
518
524
}
519
525
}
@@ -669,6 +675,7 @@ constructor(
669
675
* time anything linked to it in order to change the `_lastUpdated` timestamp. This helps us
670
676
* with order the last updated group (household) on the top of the register.
671
677
*/
678
+ fhirValidatorProvider.get().checkResourceValid(group)
672
679
defaultRepository.addOrUpdate(resource = group)
673
680
}
674
681
0 commit comments