From e9e54b9e071aafbe112ae8115aae22412082fd98 Mon Sep 17 00:00:00 2001 From: martin-nhs <127403254+martin-nhs@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:40:36 +0100 Subject: [PATCH] NIAD-3134 - Add `confidentialityCode` support for `DocumentReference` (#739) * [NIAD-3134] Added unit test * [NIAD-3134] Updated DocumentReferenceMapper.java to support confidentialityCode * [NIAD-3134] Updated test to use External Document over Narrative Statement. * [NIAD-3134] Updated production code to use ExternalDocument over NarrativeStatement * [NIAD-3134] Updated CHANGELOG.md --- CHANGELOG.md | 2 + .../mapper/DocumentReferenceMapper.java | 30 ++- .../adaptors/pss/translator/TestUtility.java | 8 + .../mapper/DocumentReferenceMapperTest.java | 186 +++++++++++++----- ...ferred_to_external_document_with_nopat.xml | 51 +++++ 5 files changed, 220 insertions(+), 57 deletions(-) create mode 100644 gp2gp-translator/src/test/resources/xml/DocumentReference/narrative_statement_has_referred_to_external_document_with_nopat.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 008f862c9..56af196ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ corresponding FHIR resource will now be [appropriately populated][nopat-docs]. corresponding FHIR resource will now be [appropriately populated][nopat-docs]. * If a `linkset` record includes a `confidentialityCode`, the `meta.security` field of the corresponding FHIR resource will now be [appropriately populated][nopat-docs]. +* If a `documentReference` record includes a `confidentialityCode`, the `meta.security` field of the + corresponding FHIR resource will now be [appropriately populated][nopat-docs]. * If an `immunization` record includes a `confidentialityCode`, the `meta.security` field of the corresponding FHIR resource will now be [appropriately populated][nopat-docs]. diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java index 0198e7a96..1ce0998e0 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapper.java @@ -18,17 +18,20 @@ import org.hl7.fhir.dstu3.model.DocumentReference; import org.hl7.fhir.dstu3.model.Encounter; import org.hl7.fhir.dstu3.model.InstantType; +import org.hl7.fhir.dstu3.model.Meta; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.v3.RCMRMT030101UKEhrComposition; import org.hl7.v3.RCMRMT030101UKEhrExtract; +import org.hl7.v3.RCMRMT030101UKExternalDocument; import org.hl7.v3.RCMRMT030101UKNarrativeStatement; import org.springframework.stereotype.Service; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import uk.nhs.adaptors.connector.model.PatientAttachmentLog; +import uk.nhs.adaptors.pss.translator.service.ConfidentialityService; import uk.nhs.adaptors.pss.translator.util.DateFormatUtil; import uk.nhs.adaptors.pss.translator.util.DegradedCodeableConcepts; import uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil; @@ -40,12 +43,13 @@ public class DocumentReferenceMapper extends AbstractMapper { // TODO: Add file Size using the uncompressed/un-encoded size of the document (NIAD-2030) - private static final String META_PROFILE = "https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-DocumentReference-1"; + private static final String META_PROFILE = "DocumentReference-1"; private static final String ABSENT_ATTACHMENT = "AbsentAttachment"; private static final String PLACEHOLDER_VALUE = "GP2GP generated placeholder. Original document not available. See notes for details"; private static final String INVALID_CONTENT_TYPE = "Content type was not a valid MIME type"; private CodeableConceptMapper codeableConceptMapper; + private ConfidentialityService confidentialityService; public List mapResources(RCMRMT030101UKEhrExtract ehrExtract, Patient patient, List encounterList, Organization organization, @@ -75,7 +79,7 @@ private DocumentReference mapDocumentReference(RCMRMT030101UKNarrativeStatement List encounterList, Organization organization, List attachments) { - DocumentReference documentReference = new DocumentReference(); + final DocumentReference documentReference = new DocumentReference(); // document references actually use the narrative statement id rather than the referenceDocument root id in EMIS data // if EMIS is incorrect, replace the id below with the following... @@ -84,7 +88,7 @@ private DocumentReference mapDocumentReference(RCMRMT030101UKNarrativeStatement documentReference.addIdentifier(buildIdentifier(id, organization.getIdentifierFirstRep().getValue())); documentReference.setId(id); - documentReference.getMeta().addProfile(META_PROFILE); + documentReference.setMeta(generateMeta(narrativeStatement)); documentReference.setStatus(DocumentReferenceStatus.CURRENT); documentReference.setType(getType(narrativeStatement)); documentReference.setSubject(new Reference(patient)); @@ -111,6 +115,18 @@ private DocumentReference mapDocumentReference(RCMRMT030101UKNarrativeStatement return documentReference; } + private Meta generateMeta(RCMRMT030101UKNarrativeStatement narrativeStatement) { + final RCMRMT030101UKExternalDocument externalDocument = narrativeStatement + .getReference() + .getFirst() + .getReferredToExternalDocument(); + + return confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent( + META_PROFILE, + externalDocument.getConfidentialityCode() + ); + } + private DateTimeType getCreatedTime(RCMRMT030101UKEhrComposition ehrComposition) { if (ehrComposition.hasAvailabilityTime() && ehrComposition.getAvailabilityTime().hasValue()) { return DateFormatUtil.parseToDateTimeType(ehrComposition.getAvailabilityTime().getValue()); @@ -128,7 +144,7 @@ private InstantType getIndexed(RCMRMT030101UKEhrComposition ehrComposition) { private CodeableConcept getType(RCMRMT030101UKNarrativeStatement narrativeStatement) { - var referenceToExternalDocument = narrativeStatement.getReference().get(0).getReferredToExternalDocument(); + var referenceToExternalDocument = narrativeStatement.getReference().getFirst().getReferredToExternalDocument(); CodeableConcept codeableConcept = null; if (referenceToExternalDocument != null && referenceToExternalDocument.hasCode()) { if (!referenceToExternalDocument.getCode().hasOriginalText() && referenceToExternalDocument.getCode().hasDisplayName()) { @@ -163,21 +179,21 @@ private String buildDescription(RCMRMT030101UKNarrativeStatement narrativeStatem if (isAbsentAttachment(narrativeStatement)) { return PLACEHOLDER_VALUE; } else { - return buildFileName(narrativeStatement.getReference().get(0) + return buildFileName(narrativeStatement.getReference().getFirst() .getReferredToExternalDocument().getText().getReference().getValue()); } } private boolean isAbsentAttachment(RCMRMT030101UKNarrativeStatement narrativeStatement) { - return narrativeStatement.getReference().get(0) + return narrativeStatement.getReference().getFirst() .getReferredToExternalDocument().getText().getReference().getValue().contains(ABSENT_ATTACHMENT); } private void setContentAttachments(DocumentReference documentReference, RCMRMT030101UKNarrativeStatement narrativeStatement, List patientAttachmentLogs) { - var referenceToExternalDocument = narrativeStatement.getReference().get(0).getReferredToExternalDocument(); + var referenceToExternalDocument = narrativeStatement.getReference().getFirst().getReferredToExternalDocument(); var attachment = new Attachment(); if (referenceToExternalDocument.hasText()) { var mediaType = referenceToExternalDocument.getText().getMediaType(); diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/TestUtility.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/TestUtility.java index eedfe328c..019eef5d2 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/TestUtility.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/TestUtility.java @@ -27,4 +27,12 @@ public static CV createCv(String code, String codeSystem, String displayName) { public static CV createCv(String code) { return createCv(code, "", ""); } + + public static class NoConfidentialityCodePresentException extends RuntimeException { + private static final String EXCEPTION_MESSAGE = "No confidentiality code is present within the test file."; + + public NoConfidentialityCodePresentException() { + super(EXCEPTION_MESSAGE); + } + } } diff --git a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapperTest.java b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapperTest.java index 60d2bfb3c..b8af5a3f2 100644 --- a/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapperTest.java +++ b/gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/mapper/DocumentReferenceMapperTest.java @@ -2,41 +2,56 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hl7.fhir.dstu3.model.Enumerations.DocumentReferenceStatus; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.springframework.util.ResourceUtils.getFile; +import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITHOUT_SECURITY; +import static uk.nhs.adaptors.pss.translator.MetaFactory.MetaType.META_WITH_SECURITY; import static uk.nhs.adaptors.pss.translator.util.XmlUnmarshallUtil.unmarshallFile; +import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; +import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.DocumentReference; import org.hl7.fhir.dstu3.model.Encounter; import org.hl7.fhir.dstu3.model.Identifier; +import org.hl7.fhir.dstu3.model.Meta; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.v3.CD; +import org.hl7.v3.CV; import org.hl7.v3.RCMRMT030101UKEhrExtract; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import lombok.SneakyThrows; import uk.nhs.adaptors.connector.model.PatientAttachmentLog; +import uk.nhs.adaptors.pss.translator.FileFactory; +import uk.nhs.adaptors.pss.translator.MetaFactory; +import uk.nhs.adaptors.pss.translator.TestUtility; +import uk.nhs.adaptors.pss.translator.service.ConfidentialityService; import uk.nhs.adaptors.pss.translator.util.DegradedCodeableConcepts; import static uk.nhs.adaptors.common.util.CodeableConceptUtils.createCodeableConcept; @ExtendWith(MockitoExtension.class) -public class DocumentReferenceMapperTest { +class DocumentReferenceMapperTest { - private static final String XML_RESOURCES_BASE = "xml/DocumentReference/"; private static final String NARRATIVE_STATEMENT_ROOT_ID = "5E496953-065B-41F2-9577-BE8F2FBD0757"; - private static final String META_PROFILE = "https://fhir.nhs.uk/STU3/StructureDefinition/CareConnect-GPC-DocumentReference-1"; + private static final String META_PROFILE = "DocumentReference-1"; private static final String CODING_DISPLAY = "Original Text document"; private static final String IDENTIFIER_SYSTEM = "https://PSSAdaptor/TESTPRACTISECODE"; private static final String NARRATIVE_STATEMENT_TYPE = "Record Attachment"; @@ -49,42 +64,49 @@ public class DocumentReferenceMapperTest { private static final Organization AUTHOR_ORG = new Organization().addIdentifier(new Identifier().setValue("TESTPRACTISECODE")); private static final String PLACEHOLDER = "GP2GP generated placeholder. Original document not available. See notes for details"; private static final Integer EXPECTED_DOCUMENT_REFERENCE_COUNT = 3; + private static final String TEST_FILES_DIRECTORY = "DocumentReference"; + private static final Meta META_WITH_SECURITY_ADDED = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE); + private static final Meta META_WITHOUT_SECURITY_ADDED = MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE); + private static final String NOPAT = "NOPAT"; private static final String SNOMED_SYSTEM = "http://snomed.info/sct"; - @InjectMocks - private DocumentReferenceMapper documentReferenceMapper; - @Mock private CodeableConceptMapper codeableConceptMapper; + @Mock + private ConfidentialityService confidentialityService; + @InjectMocks + private DocumentReferenceMapper documentReferenceMapper; + @Captor + private ArgumentCaptor> confidentialityCodeCaptor; @BeforeEach - public void setup() { - setUpCodeableConceptMock(); + void setup() { + configureCommonStubs(); } @Test - public void mapNarrativeStatementToDocumentReferenceWithValidData() { + void mapNarrativeStatementToDocumentReferenceWithValidData() { var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertFullValidData(documentReference); } @Test - public void mapNarrativeStatementToDocumentReferenceWithOptionalData() { + void mapNarrativeStatementToDocumentReferenceWithOptionalData() { var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_optional_data.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertOptionalValidData(documentReference); } @Test - public void mapMultpleNarrativeStatementToDocumentReference() { + void mapMultipleNarrativeStatementToDocumentReference() { var ehrExtract = unmarshallEhrExtract("multiple_narrative_statements_has_referred_to_external_document.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); @@ -93,58 +115,58 @@ public void mapMultpleNarrativeStatementToDocumentReference() { } @Test - public void mapNarrativeStatementToDocumentReferenceWithAttachments() { + void mapNarrativeStatementToDocumentReferenceWithAttachments() { var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertAttachmentData(documentReference); } @Test - public void mapNarrativeStatementToDocumentReferenceWithAbsentAttachment() { + void mapNarrativeStatementToDocumentReferenceWithAbsentAttachment() { var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_absent_attachment.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, new ArrayList<>()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertDocumentReferenceWithAbsentAttachment(documentReference); } @Test - public void mapNarrativeStatementToDocumentReferenceWithInvalidEncounterReference() { + void mapNarrativeStatementToDocumentReferenceWithInvalidEncounterReference() { var ehrExtract = unmarshallEhrExtract("narrative_statement_with_invalid_encounter.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertDocumentReferenceWithInvalidEncounter(documentReference); } @Test - public void mapNestedNarrativeStatement() { + void mapNestedNarrativeStatement() { var ehrExtract = unmarshallEhrExtract("nested_narrative_statements.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertDocumentReferenceMappedFromNestedNarrativeStatement(documentReference); } @Test - public void mapNarrativeStatementToDocumentReferenceWithNullFlavors() { + void mapNarrativeStatementToDocumentReferenceWithNullFlavors() { var ehrExtract = unmarshallEhrExtract("narrative_statement_null_flavors.xml"); List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertThat(documentReference.getCreatedElement().asStringValue()).isNull(); } @Test - public void mapNarrativeStatementWithSnomedCode() { + void mapNarrativeStatementWithSnomedCode() { var codeableConcept = createCodeableConcept(null, SNOMED_SYSTEM, CODING_DISPLAY); when(codeableConceptMapper.mapToCodeableConcept(any())).thenReturn(codeableConcept); @@ -152,13 +174,13 @@ public void mapNarrativeStatementWithSnomedCode() { List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertEquals(codeableConcept, documentReference.getType()); } @Test - public void mapNarrativeStatementWithoutSnomedCode() { + void mapNarrativeStatementWithoutSnomedCode() { var codeableConcept = createCodeableConcept(null, "not-a-snomed-system", CODING_DISPLAY); when(codeableConceptMapper.mapToCodeableConcept(any())).thenReturn(codeableConcept); @@ -166,19 +188,74 @@ public void mapNarrativeStatementWithoutSnomedCode() { List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), getEncounterList(), AUTHOR_ORG, createAttachmentList()); - var documentReference = documentReferences.get(0); + var documentReference = documentReferences.getFirst(); assertThat(documentReference.getType().getCodingFirstRep()) .isEqualTo(DegradedCodeableConcepts.DEGRADED_OTHER); } + @Test + void When_NarrativeStatement_With_ExternalDocumentAndNopatConfidentialityCode_Expect_MetaFromConfidentialityServiceWithSecurity() { + final RCMRMT030101UKEhrExtract ehrExtract = + unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_nopat.xml"); + + when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent( + eq(META_PROFILE), + confidentialityCodeCaptor.capture() + )).thenReturn(META_WITH_SECURITY_ADDED); + + final List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), + getEncounterList(), AUTHOR_ORG, createAttachmentList()); + + final CV externalDocumentConfidentialityCode = confidentialityCodeCaptor + .getValue() + .orElseThrow(TestUtility.NoConfidentialityCodePresentException::new); + + assertAll( + () -> documentReferences.forEach(this::assertMetaHasSecurity), + () -> assertThat(externalDocumentConfidentialityCode.getCode()).isEqualTo(NOPAT) + ); + } + + @Test + void When_NarrativeStatement_With_ExternalDocumentAndNoConfidentialityCode_Expect_MetaFromConfidentialityWithoutSecurity() { + final RCMRMT030101UKEhrExtract ehrExtract = + unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml"); + + when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent( + eq(META_PROFILE), + confidentialityCodeCaptor.capture() + )).thenReturn(META_WITHOUT_SECURITY_ADDED); + + final List documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(), + getEncounterList(), AUTHOR_ORG, createAttachmentList()); + + final Optional externalDocumentConfidentialityCode = confidentialityCodeCaptor + .getValue(); + + assertAll( + () -> documentReferences.forEach(this::assertMetaHasNoSecurity), + () -> assertThat(externalDocumentConfidentialityCode).isEmpty() + ); + } + + private void assertMetaHasSecurity(DocumentReference documentReference) { + final Meta meta = documentReference.getMeta(); + assertThat(meta).usingRecursiveComparison().isEqualTo(META_WITH_SECURITY_ADDED); + } + + private void assertMetaHasNoSecurity(DocumentReference documentReference) { + final Meta meta = documentReference.getMeta(); + assertThat(meta).usingRecursiveComparison().isEqualTo(META_WITHOUT_SECURITY_ADDED); + } + private void assertDocumentReferenceMappedFromNestedNarrativeStatement(DocumentReference documentReference) { assertThat(documentReference.getId()).isEqualTo(NARRATIVE_STATEMENT_ROOT_ID); - assertThat(documentReference.getMeta().getProfile().get(0).getValue()).isEqualTo(META_PROFILE); + assertThat(documentReference.getMeta().getProfile().getFirst().getValue()).isEqualTo(META_PROFILE); assertThat(documentReference.getStatus()).isEqualTo(DocumentReferenceStatus.CURRENT); assertThatIdentifierIsValid(documentReference.getIdentifierFirstRep(), documentReference.getId()); assertThat(documentReference.getType().getText()).isEqualTo(NARRATIVE_STATEMENT_TYPE); - assertThat(documentReference.getAuthor().get(0).getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); + assertThat(documentReference.getAuthor().getFirst().getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); assertThat(documentReference.getDescription()).isEqualTo("Some example text"); assertThat(documentReference.getIndexedElement().getValue()).isEqualTo("2010-01-14"); assertThat(documentReference.getCreatedElement().asStringValue()).isEqualTo("2019-07-08T13:35:00+00:00"); @@ -190,11 +267,11 @@ private void assertDocumentReferenceMappedFromNestedNarrativeStatement(DocumentR private void assertFullValidData(DocumentReference documentReference) { assertThat(documentReference.getId()).isEqualTo(NARRATIVE_STATEMENT_ROOT_ID); - assertThat(documentReference.getMeta().getProfile().get(0).getValue()).isEqualTo(META_PROFILE); + assertThat(documentReference.getMeta().getProfile().getFirst().getValue()).isEqualTo(META_PROFILE); assertThat(documentReference.getStatus()).isEqualTo(DocumentReferenceStatus.CURRENT); assertThatIdentifierIsValid(documentReference.getIdentifierFirstRep(), documentReference.getId()); assertThat(documentReference.getType().getText()).isEqualTo(NARRATIVE_STATEMENT_TYPE); - assertThat(documentReference.getAuthor().get(0).getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); + assertThat(documentReference.getAuthor().getFirst().getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); assertThat(documentReference.getDescription()).isEqualTo("Some example text"); assertThat(documentReference.getIndexedElement().getValue()).isEqualTo("2010-01-14"); assertThat(documentReference.getCreatedElement().asStringValue()).isEqualTo("2019-07-08T13:35:00+00:00"); @@ -206,34 +283,34 @@ private void assertFullValidData(DocumentReference documentReference) { private void assertOptionalValidData(DocumentReference documentReference) { assertThat(documentReference.getId()).isEqualTo(NARRATIVE_STATEMENT_ROOT_ID); - assertThat(documentReference.getMeta().getProfile().get(0).getValue()).isEqualTo(META_PROFILE); + assertThat(documentReference.getMeta().getProfile().getFirst().getValue()).isEqualTo(META_PROFILE); assertThat(documentReference.getStatus()).isEqualTo(DocumentReferenceStatus.CURRENT); assertThatIdentifierIsValid(documentReference.getIdentifierFirstRep(), documentReference.getId()); assertThat(documentReference.getType().getText()).isEqualTo(NARRATIVE_STATEMENT_TYPE); - assertThat(documentReference.getAuthor().get(0).getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); + assertThat(documentReference.getAuthor().getFirst().getReference()).isEqualTo("Practitioner/2D70F602-6BB1-47E0-B2EC-39912A59787D"); assertThat(documentReference.getDescription()).isEqualTo("31B75ED0-6E88-11EA-9384-E83935108FD5_patient-attachment.txt"); assertThat(documentReference.getCreatedElement().asStringValue()).isEqualTo("2019-07-08T13:35:00+00:00"); assertAttachmentData(documentReference); } private void assertAttachmentData(DocumentReference documentReference) { - assertThat(documentReference.getContent().get(0).getAttachment().getTitle()).isNull(); - assertThat(documentReference.getContent().get(0).getAttachment().getUrl()).isEqualTo(URL); - assertThat(documentReference.getContent().get(0).getAttachment().getContentType()).isEqualTo(CONTENT_TYPE); - assertThat(documentReference.getContent().get(0).getAttachment().getSize()).isEqualTo(ATTACHMENT_SIZE); + assertThat(documentReference.getContent().getFirst().getAttachment().getTitle()).isNull(); + assertThat(documentReference.getContent().getFirst().getAttachment().getUrl()).isEqualTo(URL); + assertThat(documentReference.getContent().getFirst().getAttachment().getContentType()).isEqualTo(CONTENT_TYPE); + assertThat(documentReference.getContent().getFirst().getAttachment().getSize()).isEqualTo(ATTACHMENT_SIZE); } private void assertDocumentReferenceWithAbsentAttachment(DocumentReference documentReference) { assertThat(documentReference.getId()).isEqualTo(NARRATIVE_STATEMENT_ROOT_ID); - assertThat(documentReference.getContent().get(0).getAttachment().getTitle()).isEqualTo(PLACEHOLDER); - assertThat(documentReference.getContent().get(0).getAttachment().getUrl()).isNotNull(); - assertThat(documentReference.getContent().get(0).getAttachment().hasSize()).isFalse(); - assertThat(documentReference.getContent().get(0).getAttachment().getContentType()).isEqualTo(CONTENT_TYPE); + assertThat(documentReference.getContent().getFirst().getAttachment().getTitle()).isEqualTo(PLACEHOLDER); + assertThat(documentReference.getContent().getFirst().getAttachment().getUrl()).isNotNull(); + assertThat(documentReference.getContent().getFirst().getAttachment().hasSize()).isFalse(); + assertThat(documentReference.getContent().getFirst().getAttachment().getContentType()).isEqualTo(CONTENT_TYPE); } private void assertDocumentReferenceWithInvalidEncounter(DocumentReference documentReference) { assertThat(documentReference.getId()).isEqualTo(NARRATIVE_STATEMENT_ROOT_ID); - assertThat(documentReference.getMeta().getProfile().get(0).getValue()).isEqualTo(META_PROFILE); + assertThat(documentReference.getMeta().getProfile().getFirst().getValue()).isEqualTo(META_PROFILE); assertThat(documentReference.getStatus()).isEqualTo(DocumentReferenceStatus.CURRENT); assertThatIdentifierIsValid(documentReference.getIdentifierFirstRep(), documentReference.getId()); assertThat(documentReference.getType().getText()).isEqualTo(NARRATIVE_STATEMENT_TYPE); @@ -260,11 +337,6 @@ private static List createAttachmentList() { .build()); } - private void setUpCodeableConceptMock() { - var codeableConcept = createCodeableConcept(null, SNOMED_SYSTEM, CODING_DISPLAY); - when(codeableConceptMapper.mapToCodeableConcept(any())).thenReturn(codeableConcept); - } - private List getEncounterList() { var encounter = new Encounter(); encounter.setId(ENCOUNTER_ID); @@ -273,6 +345,20 @@ private List getEncounterList() { @SneakyThrows private RCMRMT030101UKEhrExtract unmarshallEhrExtract(String fileName) { - return unmarshallFile(getFile("classpath:" + XML_RESOURCES_BASE + fileName), RCMRMT030101UKEhrExtract.class); + final File file = FileFactory.getXmlFileFor(TEST_FILES_DIRECTORY, fileName); + return unmarshallFile(file, RCMRMT030101UKEhrExtract.class); + } + + private void configureCommonStubs() { + final CodeableConcept concept = createCodeableConcept(null, SNOMED_SYSTEM, CODING_DISPLAY); + + Mockito.lenient().when(codeableConceptMapper.mapToCodeableConcept( + any(CD.class) + )).thenReturn(concept); + + Mockito.lenient().when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent( + eq(META_PROFILE), + confidentialityCodeCaptor.capture() + )).thenReturn(MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE)); } -} +} \ No newline at end of file diff --git a/gp2gp-translator/src/test/resources/xml/DocumentReference/narrative_statement_has_referred_to_external_document_with_nopat.xml b/gp2gp-translator/src/test/resources/xml/DocumentReference/narrative_statement_has_referred_to_external_document_with_nopat.xml new file mode 100644 index 000000000..c1cc80277 --- /dev/null +++ b/gp2gp-translator/src/test/resources/xml/DocumentReference/narrative_statement_has_referred_to_external_document_with_nopat.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + Some example text + + + + + + + Record Attachment + + + + + + + + + + + + + + \ No newline at end of file