Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
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.Encounter;
import org.hl7.fhir.dstu3.model.CodeableConcept;
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;
Expand Down Expand Up @@ -87,13 +87,9 @@ class DocumentReferenceMapperTest {
@Captor
private ArgumentCaptor<Optional<CV>> externalDocumentCaptor;

@BeforeEach
void setup() {
configureCommonStubs();
}

@Test
void mapNarrativeStatementToDocumentReferenceWithValidData() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand All @@ -104,11 +100,10 @@ void mapNarrativeStatementToDocumentReferenceWithValidData() {

@Test
void mapNarrativeStatementToDocumentReferenceWithNopatSecurity() {
registerDefaultDependencies(codeableConceptMapper);

final Meta stubbedMeta = MetaUtil.getMetaFor(META_WITH_SECURITY, META_PROFILE);
Mockito
.lenient()
.when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
any(String.class), any(Optional.class), any(Optional.class), any(Optional.class))).thenReturn(stubbedMeta);

var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_optional_data.xml");
Expand All @@ -127,7 +122,7 @@ void mapNarrativeStatementToDocumentReferenceWithNopatSecurity() {

@Test
void mapNarrativeStatementToDocumentReferenceWithOptionalData() {

registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_optional_data.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand All @@ -138,7 +133,7 @@ void mapNarrativeStatementToDocumentReferenceWithOptionalData() {

@Test
void mapMultipleNarrativeStatementToDocumentReference() {

registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("multiple_narrative_statements_has_referred_to_external_document.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand All @@ -148,6 +143,7 @@ void mapMultipleNarrativeStatementToDocumentReference() {

@Test
void mapNarrativeStatementToDocumentReferenceWithAttachments() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand All @@ -158,6 +154,7 @@ void mapNarrativeStatementToDocumentReferenceWithAttachments() {

@Test
void mapNarrativeStatementToDocumentReferenceWithAbsentAttachment() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_absent_attachment.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, new ArrayList<>());
Expand All @@ -168,6 +165,7 @@ void mapNarrativeStatementToDocumentReferenceWithAbsentAttachment() {

@Test
void mapNarrativeStatementToDocumentReferenceWithInvalidEncounterReference() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_with_invalid_encounter.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand All @@ -178,6 +176,7 @@ void mapNarrativeStatementToDocumentReferenceWithInvalidEncounterReference() {

@Test
void mapNestedNarrativeStatement() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("nested_narrative_statements.xml");

List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
Expand All @@ -189,6 +188,7 @@ void mapNestedNarrativeStatement() {

@Test
void mapNarrativeStatementToDocumentReferenceWithNullFlavors() {
registerDefaultDependencies(codeableConceptMapper, confidentialityService);
var ehrExtract = unmarshallEhrExtract("narrative_statement_null_flavors.xml");
List<DocumentReference> documentReferences = documentReferenceMapper.mapResources(ehrExtract, createPatient(),
getEncounterList(), AUTHOR_ORG, createAttachmentList());
Expand Down Expand Up @@ -228,6 +228,7 @@ void mapNarrativeStatementWithoutSnomedCode() {

@Test
void When_NarrativeStatement_With_ExternalDocumentAndNopatConfidentialityCode_Expect_MetaFromConfidentialityServiceWithSecurity() {
registerDefaultDependencies(codeableConceptMapper);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("narrative_statement_has_referred_to_external_document_with_nopat.xml");

Expand All @@ -253,6 +254,7 @@ void When_NarrativeStatement_With_ExternalDocumentAndNopatConfidentialityCode_Ex

@Test
void When_NarrativeStatement_With_ExternalDocumentAndNoConfidentialityCode_Expect_MetaFromConfidentialityWithoutSecurity() {
registerDefaultDependencies(codeableConceptMapper);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("narrative_statement_has_referred_to_external_document.xml");

Expand Down Expand Up @@ -384,18 +386,23 @@ private RCMRMT030101UKEhrExtract unmarshallEhrExtract(String 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),
ehrCompositionCaptor.capture(),
narrativeStatementCaptor.capture(),
externalDocumentCaptor.capture()
)).thenReturn(MetaUtil.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
public void registerDefaultDependencies(Object... dependencies) {
for (Object dependency : dependencies) {
if (dependency == codeableConceptMapper) {
final CodeableConcept concept = createCodeableConcept(null, SNOMED_SYSTEM, CODING_DISPLAY);

when(codeableConceptMapper.mapToCodeableConcept(
any(CD.class)
)).thenReturn(concept);
}
if (dependency == confidentialityService) {
when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
eq(META_PROFILE),
ehrCompositionCaptor.capture(),
narrativeStatementCaptor.capture(),
externalDocumentCaptor.capture()
)).thenReturn(MetaUtil.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE));
}
}
}
}
Loading
Loading