-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor evaluation of cqf-calculatedValue in QuestionnaireViewModel
- Loading branch information
Showing
26 changed files
with
373 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"resourceType": "Questionnaire", | ||
"item": [ | ||
{ | ||
"linkId": "1", | ||
"text": "Enter a date", | ||
"type": "date", | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/entryFormat", | ||
"valueString": "yyyy-mm-dd" | ||
}, | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/minValue", | ||
"valueDate": "2023-12-14", | ||
"_valueDate": { | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue", | ||
"valueExpression": { | ||
"language": "text/fhirpath", | ||
"expression": "today() - 7days" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"item": [ | ||
{ | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/questionnaire-displayCategory", | ||
"valueCodeableConcept": { | ||
"coding": [ | ||
{ | ||
"system": "http://hl7.org/fhir/questionnaire-display-category", | ||
"code": "instructions" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"linkId": "1-most-recent", | ||
"text": "Use keyboard entry or date picker", | ||
"type": "display" | ||
} | ||
] | ||
} | ||
] | ||
} |
66 changes: 66 additions & 0 deletions
66
datacapture/src/androidTest/java/com/google/android/fhir/datacapture/JustTest.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,66 @@ | ||
/* | ||
* Copyright 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.datacapture | ||
|
||
import ca.uhn.fhir.context.FhirContext | ||
import ca.uhn.fhir.context.FhirVersionEnum | ||
import com.google.android.fhir.datacapture.fhirpath.fhirPathEngine | ||
import org.hl7.fhir.r4.model.Expression | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.hl7.fhir.r4.model.Type | ||
import org.junit.Test | ||
|
||
class JustTest { | ||
|
||
@Test | ||
fun just_testing() { | ||
val jsonString = readFileFromAssets("/test_date_cql-calculatedvalue.json") | ||
val parser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() | ||
val questionnaire = parser.parseResource(jsonString) as Questionnaire | ||
val minValExtension = | ||
questionnaire.item.first().extension.first { | ||
it.url == "http://hl7.org/fhir/StructureDefinition/minValue" | ||
} | ||
println(minValExtension.value) | ||
println( | ||
minValExtension.value.hasExtension( | ||
"http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue", | ||
), | ||
) | ||
|
||
val expression = | ||
minValExtension.value | ||
.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue") | ||
.value as Expression | ||
val evaluatedValue = | ||
fhirPathEngine.evaluate(minValExtension.value, expression.expression).singleOrNull()?.let { | ||
it as Type | ||
} | ||
evaluatedValue?.apply { extension = minValExtension.value.extension } | ||
minValExtension.setValue(evaluatedValue) | ||
|
||
println(minValExtension.value) | ||
println( | ||
minValExtension.value.hasExtension( | ||
"http://hl7.org/fhir/StructureDefinition/cqf-calculatedValue", | ||
), | ||
) | ||
} | ||
|
||
private fun readFileFromAssets(filename: String) = | ||
javaClass.getResourceAsStream(filename)!!.bufferedReader().use { it.readText() } | ||
} |
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
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
Oops, something went wrong.