-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restricting DatePicker to select date from outside the defined Range …
…(Min/Max). Added support for fhir path expression in Min / Max Validators (#1442) * WIP configured Date picker to pick min and max value dates from extension to make a range * added cqf-calculated value expression support for date picker * PR Feedback : refactored methods in MoreQuestionnaireItemComponents * added unit test cases for fhir path expression for min value validator * fixed added dyanmic date * added unit test cases for MoreQuestionnaireItemComponents * Refactored unit tests for MoreQuestionnaireItemComponents * added instrumentation test for DatePickerViewFactory * WIP feedback * Moved cql parsing related methods to ValidationUtil * refactored ValidationUtil * Refactored ValidationUtil * tests fixed, spotless ran again * tests updated * SPOTLESS ran * spotless rechecked * WIP fixing feedback * WIP fixing feedback * feedback incorporated, updated the unit test cases * spotless ran * spotless ran * added instrumentation test for QuestionnaireItemDatePickerViewHolderFactoryEspressoTest * fixed a test case handled exception * fixed imports - feedback * feedback incorporated * spotless ran * throwing an exception when minValue is greater than maxValue * implementation updated to use compositedatevalidator to restrict min and max dates
- Loading branch information
1 parent
eb894de
commit 75ac755
Showing
8 changed files
with
546 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
datacapture/src/main/java/com/google/android/fhir/datacapture/validation/ValidationUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* https://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.datacapture.validation | ||
|
||
import ca.uhn.fhir.context.FhirContext | ||
import ca.uhn.fhir.context.FhirVersionEnum | ||
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport | ||
import com.google.android.fhir.datacapture.CQF_CALCULATED_EXPRESSION_URL | ||
import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext | ||
import org.hl7.fhir.r4.model.Expression | ||
import org.hl7.fhir.r4.model.Type | ||
import org.hl7.fhir.r4.utils.FHIRPathEngine | ||
|
||
fun Type.valueOrCalculateValue(): Type? { | ||
return if (this.hasExtension()) { | ||
this.extension.firstOrNull { it.url == CQF_CALCULATED_EXPRESSION_URL }?.let { | ||
val expression = (it.value as Expression).expression | ||
fhirPathEngine.evaluate(this, expression).firstOrNull()?.let { it as Type } | ||
} | ||
} else { | ||
this | ||
} | ||
} | ||
|
||
private val fhirPathEngine: FHIRPathEngine = | ||
with(FhirContext.forCached(FhirVersionEnum.R4)) { | ||
FHIRPathEngine(HapiWorkerContext(this, DefaultProfileValidationSupport(this))) | ||
} |
Oops, something went wrong.