-
Notifications
You must be signed in to change notification settings - Fork 314
Fix answer option match for coding initial expression #2887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
parthfloyd
wants to merge
3
commits into
google:master
Choose a base branch
from
parthfloyd:fix-answer-option-match-for-coding-initialExpression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
eaafdee
- updated logic for handling Coding type in initialExpression population
parthfloyd 45b1029
added test cases for Coding type in populate initial values.
parthfloyd dca05b5
Merge branch 'google:master' into fix-answer-option-match-for-coding-…
parthfloyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -3144,6 +3144,175 @@ class ResourceMapperTest { | |
} | ||
} | ||
|
||
@Test | ||
fun `populate() should select coding answerOption when only display differs`() = runBlocking { | ||
val matchingAnswerOption = | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "12345-6" | ||
version = "1.0" | ||
display = "Answer option display" | ||
} | ||
val questionnaire = | ||
createObservationChoiceQuestionnaire( | ||
matchingAnswerOption, | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "65432-1" | ||
display = "Fallback display" | ||
}, | ||
) | ||
|
||
val observationCoding = | ||
Coding().apply { | ||
system = matchingAnswerOption.system | ||
code = matchingAnswerOption.code | ||
version = matchingAnswerOption.version | ||
display = "Observation display" | ||
} | ||
|
||
val questionnaireResponse = | ||
ResourceMapper.populate( | ||
questionnaire, | ||
mapOf("observation" to observationWithCoding(observationCoding)), | ||
) | ||
|
||
val question = questionnaire.item.single() | ||
val selectedOption = | ||
question.answerOption.first { (it.value as Coding).code == matchingAnswerOption.code } | ||
|
||
assertThat(selectedOption.initialSelected).isTrue() | ||
assertThat(question.answerOption.count { it.initialSelected }).isEqualTo(1) | ||
|
||
val responseItem = questionnaireResponse.item.single() | ||
assertThat(responseItem.hasAnswer()).isTrue() | ||
val answerCoding = responseItem.answer.single().value as Coding | ||
assertThat(answerCoding.code).isEqualTo(matchingAnswerOption.code) | ||
assertThat(answerCoding.system).isEqualTo(matchingAnswerOption.system) | ||
assertThat(answerCoding.version).isEqualTo(matchingAnswerOption.version) | ||
assertThat(answerCoding.display).isEqualTo(matchingAnswerOption.display) | ||
} | ||
|
||
@Test | ||
fun `populate() should not select coding answerOption when codes differ`() = runBlocking { | ||
val matchingAnswerOption = | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "12345-6" | ||
version = "1.0" | ||
display = "Answer option display" | ||
} | ||
val questionnaire = | ||
createObservationChoiceQuestionnaire( | ||
matchingAnswerOption, | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "65432-1" | ||
display = "Fallback display" | ||
}, | ||
) | ||
|
||
val questionnaireResponse = | ||
ResourceMapper.populate( | ||
questionnaire, | ||
mapOf( | ||
"observation" to | ||
observationWithCoding( | ||
Coding().apply { | ||
system = matchingAnswerOption.system | ||
code = "different-code" | ||
version = matchingAnswerOption.version | ||
display = "Observation display" | ||
}, | ||
), | ||
), | ||
) | ||
|
||
val question = questionnaire.item.single() | ||
assertThat(question.answerOption.none { it.initialSelected }).isTrue() | ||
assertThat(questionnaireResponse.item.single().hasAnswer()).isFalse() | ||
} | ||
|
||
@Test | ||
fun `populate() should not select coding answerOption when systems differ`() = runBlocking { | ||
val matchingAnswerOption = | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "12345-6" | ||
version = "1.0" | ||
display = "Answer option display" | ||
} | ||
val questionnaire = | ||
createObservationChoiceQuestionnaire( | ||
matchingAnswerOption, | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "65432-1" | ||
display = "Fallback display" | ||
}, | ||
) | ||
|
||
val questionnaireResponse = | ||
ResourceMapper.populate( | ||
questionnaire, | ||
mapOf( | ||
"observation" to | ||
observationWithCoding( | ||
Coding().apply { | ||
system = "http://snomed.info/sct" | ||
code = matchingAnswerOption.code | ||
version = matchingAnswerOption.version | ||
display = "Observation display" | ||
}, | ||
), | ||
), | ||
) | ||
|
||
val question = questionnaire.item.single() | ||
assertThat(question.answerOption.none { it.initialSelected }).isTrue() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line the same |
||
assertThat(questionnaireResponse.item.single().hasAnswer()).isFalse() | ||
} | ||
|
||
@Test | ||
fun `populate() should not select coding answerOption when versions differ`() = runBlocking { | ||
val matchingAnswerOption = | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "12345-6" | ||
version = "1.0" | ||
display = "Answer option display" | ||
} | ||
val questionnaire = | ||
createObservationChoiceQuestionnaire( | ||
matchingAnswerOption, | ||
Coding().apply { | ||
system = "http://loinc.org" | ||
code = "65432-1" | ||
display = "Fallback display" | ||
}, | ||
) | ||
|
||
val questionnaireResponse = | ||
ResourceMapper.populate( | ||
questionnaire, | ||
mapOf( | ||
"observation" to | ||
observationWithCoding( | ||
Coding().apply { | ||
system = matchingAnswerOption.system | ||
code = matchingAnswerOption.code | ||
version = "2.0" | ||
display = "Observation display" | ||
}, | ||
), | ||
), | ||
) | ||
|
||
val question = questionnaire.item.single() | ||
assertThat(question.answerOption.none { it.initialSelected }).isTrue() | ||
assertThat(questionnaireResponse.item.single().hasAnswer()).isFalse() | ||
} | ||
|
||
@Test | ||
fun `populate() should select single answer for non repeating question with answerOption`() = | ||
runBlocking { | ||
|
@@ -3596,6 +3765,54 @@ class ResourceMapperTest { | |
assertThat(patient.name.first().family).isEqualTo("John Doe") | ||
} | ||
|
||
private fun createObservationChoiceQuestionnaire( | ||
vararg answerOptions: Coding, | ||
): Questionnaire = | ||
Questionnaire() | ||
.apply { | ||
addExtension().apply { | ||
url = EXTENSION_SDC_QUESTIONNAIRE_LAUNCH_CONTEXT | ||
extension = | ||
listOf( | ||
Extension( | ||
"name", | ||
Coding( | ||
CODE_SYSTEM_LAUNCH_CONTEXT, | ||
"observation", | ||
"Test Observation", | ||
), | ||
), | ||
Extension("type", CodeType("Observation")), | ||
) | ||
} | ||
} | ||
.addItem( | ||
Questionnaire.QuestionnaireItemComponent().apply { | ||
linkId = "observation-choice" | ||
type = Questionnaire.QuestionnaireItemType.CHOICE | ||
extension = | ||
listOf( | ||
Extension( | ||
ITEM_INITIAL_EXPRESSION_URL, | ||
Expression().apply { | ||
language = "text/fhirpath" | ||
expression = "%observation.value.coding" | ||
}, | ||
), | ||
) | ||
answerOption = | ||
answerOptions | ||
.map { coding -> Questionnaire.QuestionnaireItemAnswerOptionComponent(coding) } | ||
.toMutableList() | ||
}, | ||
) | ||
|
||
private fun observationWithCoding(coding: Coding): Observation = | ||
Observation().apply { | ||
status = Observation.ObservationStatus.FINAL | ||
value = CodeableConcept().apply { this.coding = mutableListOf(coding) } | ||
} | ||
|
||
private fun readFileFromResourcesAsString(filename: String) = | ||
readFileFromResources(filename).bufferedReader().use { it.readText() } | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just testing the
createObservationChoiceQuestionnaire
function no? i don't think this is necessary.the important thing in the test case is below: the generated questionnaire response from the population process includes selected answers.
=====
actually, this reveals a problem in the populate function (thanks laz for pointing out) i dont' think it should change the questionnaire... can you fix that?