Skip to content

Commit 831e89f

Browse files
* Add additional test for populating original text when codeable concept has only non-snomed codes.
1 parent b78be88 commit 831e89f

File tree

1 file changed

+204
-5
lines changed

1 file changed

+204
-5
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/CodeableConceptCdMapperTest.java

Lines changed: 204 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ private static Stream<Arguments> getTestArgumentsAllergyActive() {
6464
return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY_ALLERGY_ACTIVE);
6565
}
6666

67-
// private static Stream<Arguments> getTestArgumentsBloodPressure() {
68-
// return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY_BLOOD_PRESSURE);
69-
// }
70-
7167
private static Stream<Arguments> getTestArgumentsMedication() {
7268
return TestArgumentsLoaderUtil.readTestCases(TEST_FILE_DIRECTORY_MEDICATION);
7369
}
@@ -234,6 +230,7 @@ void When_MappingStubbedCodeableConceptAsActiveAllergy_Expect_HL7CdObjectXml(Str
234230

235231
@Nested
236232
class WhenMappingStubbedCodeableConceptForBloodPressure {
233+
237234
@Test
238235
void When_WithoutCoding_Expect_NullFlavorCdXmlWithoutOriginalText() {
239236
var inputJson = """
@@ -588,7 +585,13 @@ void When_WithSnomedCodingNoTextNoDisplayWithNonDescriptionExtension_Expect_Snom
588585
"code": "852471000000107",
589586
"extension": [
590587
{
591-
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-some-otherUrl"
588+
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid",
589+
"extension": [
590+
{
591+
"url": "descriptionDisplay",
592+
"valueString": "Prothrombin time (observed)"
593+
}
594+
]
592595
}
593596
]
594597
}
@@ -605,8 +608,204 @@ void When_WithSnomedCodingNoTextNoDisplayWithNonDescriptionExtension_Expect_Snom
605608

606609
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
607610
}
611+
612+
@Test
613+
void When_WithNonSnomedCodingWithText_Expect_SnomedCdXmlWithOriginalTexFromText() {
614+
var inputJson = """
615+
{
616+
"resourceType": "Observation",
617+
"code": {
618+
"coding": [
619+
{
620+
"system": "http://read.info/readv2",
621+
"code": "42Q5.00",
622+
"display": "Observed Prothrombin time"
623+
}
624+
],
625+
"text": "Prothrombin time (observed)"
626+
}
627+
}""";
628+
629+
var expectedOutput = """
630+
<code nullFlavor="UNK">
631+
<originalText>Prothrombin time (observed)</originalText>
632+
</code>""";
633+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
634+
635+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
636+
637+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
638+
}
639+
640+
@Test
641+
void When_WithNonSnomedCodingWithNoTextWithNonDescriptionExtension_Expect_SnomedCdXmlWithOriginalTextFromDisplay() {
642+
var inputJson = """
643+
{
644+
"resourceType": "Observation",
645+
"code": {
646+
"coding": [
647+
{
648+
"system": "http://read.info/readv2",
649+
"code": "42Q5.00",
650+
"display": "Observed Prothrombin time",
651+
"extension": [
652+
{
653+
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-some-otherUrl",
654+
"extension": [
655+
{
656+
"url": "descriptionDisplay",
657+
"valueString": "Prothrombin time"
658+
}
659+
]
660+
}
661+
]
662+
}
663+
]
664+
}
665+
}""";
666+
667+
var expectedOutput = """
668+
<code nullFlavor="UNK">
669+
<originalText>Observed Prothrombin time</originalText>
670+
</code>""";
671+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
672+
673+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
674+
675+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
676+
}
677+
678+
@Test
679+
void When_WithNonSnomedCodingWithNoTextWithDescriptionExtensionNoDisplayExtension_Expect_SnomedCdXmlWithOriginalTextFromDisplay() {
680+
var inputJson = """
681+
{
682+
"resourceType": "Observation",
683+
"code": {
684+
"coding": [
685+
{
686+
"system": "http://read.info/readv2",
687+
"code": "42Q5.00",
688+
"display": "Observed Prothrombin time",
689+
"extension": [
690+
{
691+
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid",
692+
"extension": [
693+
{
694+
"url": "descriptionId",
695+
"valueString": "123456789"
696+
}
697+
]
698+
}
699+
]
700+
}
701+
]
702+
}
703+
}""";
704+
705+
var expectedOutput = """
706+
<code nullFlavor="UNK">
707+
<originalText>Observed Prothrombin time</originalText>
708+
</code>""";
709+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
710+
711+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
712+
713+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
714+
}
715+
716+
@Test
717+
void When_WithNonSnomedCodingNoTextWithDescriptionExtWithDisplayExt_Expect_SnomedCdXmlWithOriginalTextFromDisplayExtension() {
718+
var inputJson = """
719+
{
720+
"resourceType": "Observation",
721+
"code": {
722+
"coding": [
723+
{
724+
"system": "http://read.info/readv2",
725+
"code": "42Q5.00",
726+
"display": "Observed Prothrombin time",
727+
"extension": [
728+
{
729+
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-coding-sctdescid",
730+
"extension": [
731+
{
732+
"url": "descriptionDisplay",
733+
"valueString": "Prothrombin time"
734+
}
735+
]
736+
}
737+
]
738+
}
739+
]
740+
}
741+
}""";
742+
743+
var expectedOutput = """
744+
<code nullFlavor="UNK">
745+
<originalText>Prothrombin time</originalText>
746+
</code>""";
747+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
748+
749+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
750+
751+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
752+
}
753+
754+
@Test
755+
void When_WithNonSnomedCodingNoTextNoDescriptionExtension_Expect_SnomedCdXmlWithOriginalTextFromDisplay() {
756+
var inputJson = """
757+
{
758+
"resourceType": "Observation",
759+
"code": {
760+
"coding": [
761+
{
762+
"system": "http://read.info/readv2",
763+
"code": "42Q5.00",
764+
"display": "Observed Prothrombin time"
765+
}
766+
]
767+
}
768+
}""";
769+
770+
var expectedOutput = """
771+
<code nullFlavor="UNK">
772+
<originalText>Observed Prothrombin time</originalText>
773+
</code>""";
774+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
775+
776+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
777+
778+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
779+
}
780+
781+
@Test
782+
void When_WithNonSnomedCodingNoDisplayNoTextNoDescriptionExtension_Expect_SnomedCdXmlWithNoOriginalText() {
783+
var inputJson = """
784+
{
785+
"resourceType": "Observation",
786+
"code": {
787+
"coding": [
788+
{
789+
"system": "http://read.info/readv2",
790+
"code": "42Q5.00"
791+
}
792+
]
793+
}
794+
}""";
795+
796+
var expectedOutput = """
797+
<code nullFlavor="UNK">
798+
</code>""";
799+
var codeableConcept = fhirParseService.parseResource(inputJson, Observation.class).getCode();
800+
801+
var outputMessage = codeableConceptCdMapper.mapToNullFlavorCodeableConcept(codeableConcept);
802+
803+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
804+
}
608805
}
609806

807+
808+
610809
@ParameterizedTest
611810
@MethodSource("getTestArgumentsForTopicRelatedProblem")
612811
@SneakyThrows

0 commit comments

Comments
 (0)