33import org .hl7 .fhir .dstu3 .model .AllergyIntolerance ;
44import org .hl7 .fhir .dstu3 .model .Bundle ;
55import org .hl7 .fhir .dstu3 .model .CodeableConcept ;
6+ import org .hl7 .fhir .dstu3 .model .Observation ;
7+ import org .hl7 .fhir .dstu3 .model .ResourceType ;
68import org .junit .jupiter .api .AfterEach ;
79import org .junit .jupiter .api .BeforeEach ;
810import org .junit .jupiter .api .Test ;
2830import uk .nhs .adaptors .gp2gp .utils .ResourceTestFileUtils ;
2931
3032import java .time .Instant ;
33+ import java .util .Optional ;
3134import java .util .stream .Stream ;
3235
3336import static org .assertj .core .api .Assertions .assertThat ;
@@ -46,6 +49,7 @@ public class EhrExtractMapperComponentTest {
4649 private static final String OUTPUT_PATH = TEST_FILE_DIRECTORY + OUTPUT_DIRECTORY ;
4750
4851 private static final String JSON_INPUT_FILE = "gpc-access-structured.json" ;
52+ private static final String JSON_INPUT_FILE_WITH_NOPAT = "gpc-access-structured-with-nopat.json" ;
4953 private static final String DUPLICATE_RESOURCE_BUNDLE = INPUT_PATH + "duplicated-resource-bundle.json" ;
5054 private static final String ONE_CONSULTATION_RESOURCE_BUNDLE = INPUT_PATH + "1-consultation-resource.json" ;
5155 private static final String FHIR_BUNDLE_WITHOUT_EFFECTIVE_TIME = "fhir-bundle-without-effective-time.json" ;
@@ -64,6 +68,7 @@ public class EhrExtractMapperComponentTest {
6468 private static final String EXPECTED_XML_FOR_ONE_CONSULTATION_RESOURCE = "ExpectedResponseFrom1ConsultationResponse.xml" ;
6569
6670 private static final String EXPECTED_XML_TO_JSON_FILE = "expected-ehr-extract-response-from-json.xml" ;
71+ private static final String EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT = "expected-ehr-extract-response-from-json-with-nopat.xml" ;
6772 private static final String EXPECTED_XML_WITHOUT_EFFECTIVE_TIME = "expected-xml-without-effective-time.xml" ;
6873 private static final String EXPECTED_XML_WITHOUT_HIGH_EFFECTIVE_TIME = "expected-xml-without-high-effective-time.xml" ;
6974 private static final String EXPECTED_XML_WITH_EFFECTIVE_TIME = "expected-xml-with-effective-time.xml" ;
@@ -81,6 +86,10 @@ public class EhrExtractMapperComponentTest {
8186 private static final String TEST_TO_ODS_CODE = "test-to-ods-code" ;
8287 private static final String TEST_DATE_TIME = "2020-01-01T01:01:01.01Z" ;
8388
89+ private static final String CONFIDENTIALITY_CODE =
90+ "<confidentialityCode code=\" NOPAT\" codeSystem=\" 2.16.840.1.113883.4.642.3.47\" "
91+ + "displayName=\" no disclosure to patient, family or caregivers without attending provider's authorization\" />" ;
92+
8493 private static GetGpcStructuredTaskDefinition getGpcStructuredTaskDefinition ;
8594
8695 @ Mock
@@ -220,6 +229,33 @@ public void tearDown() {
220229 messageContext .resetMessageContext ();
221230 }
222231
232+ @ Test
233+ public void When_MappingUncategorizedObservationWithNOPAT_Expect_ObservationStatementWithConfidentialityCode () {
234+
235+ String expectedJsonToXmlContent = ResourceTestFileUtils .getFileContent (OUTPUT_PATH + EXPECTED_XML_TO_JSON_FILE_WITH_NOPAT );
236+ String inputJsonFileContent = ResourceTestFileUtils .getFileContent (INPUT_PATH + JSON_INPUT_FILE_WITH_NOPAT );
237+ Bundle bundle = new FhirParseService ().parseResource (inputJsonFileContent , Bundle .class );
238+
239+ Observation uncategorizedObservation = bundle .getEntry ().stream ()
240+ .map (Bundle .BundleEntryComponent ::getResource )
241+ .filter (resource -> ResourceType .Observation .equals (resource .getResourceType ()))
242+ .map (Observation .class ::cast )
243+ .filter (o -> "Observation/FB5E6E97-3152-46EB-B46A-B48D21FC1099" .equals (o .getId ()))
244+ .findFirst ()
245+ .get ();
246+
247+ when (confidentialityService .generateConfidentialityCode (uncategorizedObservation )).thenReturn (Optional .of (CONFIDENTIALITY_CODE ));
248+
249+ messageContext .initialize (bundle );
250+
251+ EhrExtractTemplateParameters ehrExtractTemplateParameters = ehrExtractMapper .mapBundleToEhrFhirExtractParams (
252+ getGpcStructuredTaskDefinition ,
253+ bundle );
254+ String output = ehrExtractMapper .mapEhrExtractToXml (ehrExtractTemplateParameters );
255+
256+ assertThat (output ).isEqualToIgnoringWhitespace (expectedJsonToXmlContent );
257+ }
258+
223259 @ ParameterizedTest
224260 @ MethodSource ("testData" )
225261 public void When_MappingProperJsonRequestBody_Expect_ProperXmlOutput (String input , String expected ) {
0 commit comments