File tree Expand file tree Collapse file tree
main/java/uk/nhs/adaptors/gp2gp/ehr/mapper
test/java/uk/nhs/adaptors/gp2gp/ehr/mapper Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package uk .nhs .adaptors .gp2gp .ehr .mapper ;
22
3+ import org .apache .commons .lang3 .StringUtils ;
34import org .hl7 .fhir .dstu3 .model .BooleanType ;
45import org .hl7 .fhir .dstu3 .model .Extension ;
56import org .hl7 .fhir .dstu3 .model .Quantity ;
@@ -71,6 +72,10 @@ private ObservationValueQuantityMapper() {
7172 }
7273
7374 public static String processQuantity (Quantity valueQuantity ) {
75+ if (!valueQuantity .hasValue ()) {
76+ return StringUtils .EMPTY ;
77+ }
78+
7479 var stringBuilder = new StringBuilder ();
7580
7681 if (isUncertaintyCodePresent (valueQuantity )) {
Original file line number Diff line number Diff line change @@ -114,6 +114,16 @@ public void When_MappingQuantityWithUncertaintyExtension_Expect_XmlContainsUncer
114114 assertThat (mappedQuantity ).isEqualTo (expectedXml );
115115 }
116116
117+ @ Test
118+ public void When_MappingQuantityWithNullValue_ExpectedEmptyString () {
119+ var quantity = (Quantity ) new Quantity ()
120+ .setSystem (UOM_SYSTEM )
121+ .setCode (CODE_CEL );
122+ var mappedQuantity = ObservationValueQuantityMapper .processQuantity (quantity );
123+
124+ assertThat (mappedQuantity ).isEmpty ();
125+ }
126+
117127 @ Test
118128 public void When_MappingQuantityWithUOMSystemAndCode_Expect_PQXmlWithValueAndQuantitySetAndNoTranslation () {
119129 var quantity = new Quantity ()
@@ -239,19 +249,6 @@ public void When_MappingQuantityWithAnyOrNoSystemWithoutUnitOrCode_Expect_PQXmlW
239249 assertThat (mappedQuantity ).isEqualTo (expectedXml );
240250 }
241251
242- @ Test
243- public void When_MappingQuantityWithoutSystemOrUnitOrCode_Expect_PQXmlWithValueSetAndUnitSetToOne () {
244- var quantity = new Quantity ()
245- .setValue (VALUE_37_1 );
246-
247- var expectedXml = """
248- <value xsi:type="PQ" value="37.1" unit="1" />""" ;
249-
250- var mappedQuantity = ObservationValueQuantityMapper .processQuantity (quantity );
251-
252- assertThat (mappedQuantity ).isEqualTo (expectedXml );
253- }
254-
255252 @ Test
256253 public void When_MappingQuantityWithUncertaintyAndComparatorExtension_Expect_XmlContainsUncertaintyCode () {
257254 var quantity = (Quantity ) new Quantity ()
You can’t perform that action at this time.
0 commit comments