Skip to content

Commit

Permalink
Niad-3005: Code optimization (AllergyIntollerance) (#740)
Browse files Browse the repository at this point in the history
* [NIAD-3130] Add failing unit test for ReferralRequestMapperTest.java

* [NIAD-3130] Address test discrepancies

* [NIAD-3130] Address test discrepancies

* [NIAD-3130] Modified production ReferralRequestMapper to make unit tests pass

* [NIAD-3130] Add test to verify behavior of NOPAT at ehrComposition level to ReferralRequestMapperTest

* [NIAD-3130] Add test to verify behavior of NOSCRUB confidentiality code within ReferralRequestMapperTest

* [NIAD-3130] Update CHANGELOG.md

* small code optimization

---------

Co-authored-by: martin-nhs <[email protected]>
  • Loading branch information
ole4ryb and martin-nhs authored Aug 2, 2024
1 parent 9ec6c88 commit 2c8e21a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,27 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrComposition eh

var allergyIntolerance = new AllergyIntolerance();
var observationStatement = extractObservationStatement(compoundStatement);

var id = observationStatement
.getId()
.getRoot();
var id = observationStatement.getId().getRoot();

final Meta meta = confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
META_PROFILE,
ehrComposition.getConfidentialityCode(),
observationStatement.getConfidentialityCode()
);
observationStatement.getConfidentialityCode());

initializeAllergyIntolerance(allergyIntolerance, compoundStatement, ehrComposition, patient, practiseCode, id, meta);
buildAdditionalFields(allergyIntolerance, compoundStatement, ehrComposition, encounters, observationStatement);

return allergyIntolerance;
}

private void initializeAllergyIntolerance(
AllergyIntolerance allergyIntolerance,
RCMRMT030101UKCompoundStatement compoundStatement,
RCMRMT030101UKEhrComposition ehrComposition,
Patient patient,
String practiseCode,
String id,
Meta meta) {

allergyIntolerance
.addCategory(getCategory(compoundStatement))
Expand All @@ -105,6 +116,14 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrComposition eh
.addIdentifier(buildIdentifier(id, practiseCode))
.setMeta(meta)
.setId(id);
}

private void buildAdditionalFields(
AllergyIntolerance allergyIntolerance,
RCMRMT030101UKCompoundStatement compoundStatement,
RCMRMT030101UKEhrComposition ehrComposition,
List<Encounter> encounters,
RCMRMT030101UKObservationStatement observationStatement) {

buildOnset(compoundStatement, allergyIntolerance);
buildParticipantReferences(ehrComposition, compoundStatement, allergyIntolerance);
Expand All @@ -114,19 +133,8 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrComposition eh
var codeableConceptFromValue = getCodeableConceptFromNonEgtonCodeValue(observationStatement);
var compoundCode = compoundStatement.getCode().getCode();

buildCode(allergyIntolerance,
observationStatement,
compoundCode,
codeableConceptFromCode,
codeableConceptFromValue);

buildNote(allergyIntolerance,
observationStatement,
compoundCode,
codeableConceptFromCode,
codeableConceptFromValue);

return allergyIntolerance;
buildCode(allergyIntolerance, observationStatement, compoundCode, codeableConceptFromCode, codeableConceptFromValue);
buildNote(allergyIntolerance, observationStatement, compoundCode, codeableConceptFromCode, codeableConceptFromValue);
}

private void buildParticipantReferences(RCMRMT030101UKEhrComposition ehrComposition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceVerificationStatus.UNCONFIRMED;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -326,9 +327,9 @@ void testGivenAllergyWithNoOptionalData() {
assertThat(allergyIntolerance.getCode().getCodingFirstRep()).isEqualTo(DegradedCodeableConcepts.DEGRADED_DRUG_ALLERGY);
assertThat(allergyIntolerance.getCode().getCoding().get(1).getDisplay()).isEqualTo(CODING_DISPLAY_1);
assertThat(allergyIntolerance.getAssertedDateElement().asStringValue()).isEqualTo("2019-07-08T13:35:00+00:00");
assertThat(allergyIntolerance.getRecorder().getReference()).isNull(); // this is added later in the UnknownPractitionerHandler
assertThat(allergyIntolerance.getAsserter().getReference()).isNull();
assertThat(allergyIntolerance.getOnset()).isNull();
assertNull(allergyIntolerance.getRecorder().getReference()); // this is added later in the UnknownPractitionerHandler
assertNull(allergyIntolerance.getAsserter().getReference());
assertNull(allergyIntolerance.getOnset());
assertThat(allergyIntolerance.getNote()).isEmpty();
verifyConfidentialityServiceCalled(1, Optional.empty(), Optional.empty());
}
Expand Down Expand Up @@ -389,28 +390,6 @@ void testGivenAllergyIntoleranceWithNopatConfidentialityCodePresentWithinEhrComp
verifyConfidentialityServiceCalled(1, ehrComposition.getConfidentialityCode(), Optional.empty());
}

@Test
void testGivenAllergyIntoleranceWithNoscrubConfidentialityCodePresentWithinEhrCompositionExpectMetaSecurityAdded() {
final Meta stubbedMeta = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtract("allergy-structure-with-ehr-composition-nopat-confidentiality-code.xml");

Mockito
.lenient()
.when(confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
any(String.class), any(Optional.class), any(Optional.class)
)).thenReturn(stubbedMeta);

final RCMRMT030101UKEhrComposition ehrComposition = TestUtility.GET_EHR_COMPOSITION.apply(ehrExtract);
final List<AllergyIntolerance> allergyIntolerance = allergyIntoleranceMapper
.mapResources(ehrExtract, getPatient(), getEncounterList(), PRACTISE_CODE);

final Meta meta = allergyIntolerance.get(0).getMeta();

assertMetaSecurityPresent(meta);
verifyConfidentialityServiceCalled(1, ehrComposition.getConfidentialityCode(), Optional.empty());
}

@Test
void testGivenAllergyIntoleranceWithNopatConfidentialityCodePresentWithinObservationStatementExpectMetaSecurityAdded() {
final Meta stubbedMeta = MetaFactory.getMetaFor(META_WITH_SECURITY, META_PROFILE);
Expand Down Expand Up @@ -442,7 +421,7 @@ void testGivenAllergyIntoleranceWithNoscrubConfidentialityCodePresentWithinObser
final List<AllergyIntolerance> allergyIntolerance = allergyIntoleranceMapper
.mapResources(ehrExtract, getPatient(), getEncounterList(), PRACTISE_CODE);

assertThat(allergyIntolerance.get(0).getMeta().getSecurity()).hasSize(0);
assertThat(allergyIntolerance.get(0).getMeta().getSecurity()).isEmpty();
verifyConfidentialityServiceCalled(1, Optional.empty(), observationStatement.getConfidentialityCode());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class ReferralRequestMapperTest {
private static final String UNEXPECTED_PRIORITY_DISPLAY = "Delayed priority";
private static final String PRIORITY_NOTE_PREPENDAGE = "Priority: ";
private static final String NOPAT = "NOPAT";

private static final String NOSCRUB = "NOSCRUB";

private static final String TEST_DIRECTORY_NAME = "RequestStatement";

@Mock
Expand Down Expand Up @@ -477,7 +480,7 @@ void When_MapToReferralRequest_With_NopatConfidentialityCode_Expect_MetaFromConf

final CV confidentialityCode = confidentialityCodeCaptor
.getAllValues()
.get(0) // requestStatement.getConfidentialityCode()
.get(0) // First value
.orElseThrow();

assertAll(
Expand Down Expand Up @@ -505,7 +508,7 @@ void When_MapToReferralRequest_With_NopatConfidentialityCodeWithinEhrComposition

final CV confidentialityCode = confidentialityCodeCaptor
.getAllValues()
.get(1) // ehrComposition.getConfidentialityCode()
.get(1) // Second value (i.e. ehrComposition.getConfidentialityCode())
.orElseThrow();

assertAll(
Expand All @@ -515,6 +518,27 @@ void When_MapToReferralRequest_With_NopatConfidentialityCodeWithinEhrComposition
);
}

@Test
void When_MapToReferralRequest_With_NoscrubConfidentialityCode_Expect_MetaFromConfidentialityServiceWithoutSecurity() {
final Meta metaWithoutSecurity = MetaFactory.getMetaFor(META_WITHOUT_SECURITY, META_PROFILE);
final RCMRMT030101UKEhrExtract ehrExtract =
unmarshallEhrExtractElement("full_valid_data_example_with_noscrub_confidentiality_code.xml");
final RCMRMT030101UKEhrComposition ehrComposition = GET_EHR_COMPOSITION.apply(ehrExtract);

final ReferralRequest result = mapReferralRequest(ehrExtract, ehrComposition,
composition -> composition.getComponent().get(0).getRequestStatement());

final CV confidentialityCode = confidentialityCodeCaptor
.getAllValues()
.get(0) // First value
.orElseThrow();

assertAll(
() -> assertThat(result.getMeta()).usingRecursiveComparison().isEqualTo(metaWithoutSecurity),
() -> assertThat(confidentialityCode.getCode()).isEqualTo(NOSCRUB)
);
}

private RCMRMT030101UKRequestStatement getNestedRequestStatement(RCMRMT030101UKEhrComposition ehrComposition) {
return ehrComposition.getComponent()
.get(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<EhrExtract xmlns="urn:hl7-org:v3" classCode="EXTRACT" moodCode="EVN">
<availabilityTime value="20200101010101" />
<component typeCode="COMP">
<ehrFolder classCode="FOLDER" moodCode="EVN">
<component typeCode="COMP">
<ehrComposition xmlns="urn:hl7-org:v3" classCode="COMPOSITION" moodCode="EVN">
<id root="72A39454-299F-432E-993E-5A6232B4E099" />
<availabilityTime value="20190708143500"/>
<Participant2 typeCode="PRF" contextControlCode="OP">
<agentRef classCode="AGNT">
<id root="B1AF3701-4D1C-11E3-9E6B-010000001205"/>
</agentRef>
</Participant2>
<component typeCode="COMP" >
<RequestStatement classCode="OBS" moodCode="RQO">
<id root="B4303C92-4D1C-11E3-A2DD-010000000161"/>
<code code="8HV6." codeSystem="2.16.840.1.113883.2.1.3.2.4.14" displayName="Reason Code">
<translation code="183885007" codeSystem="2.16.840.1.113883.2.1.3.2.4.15" displayName="Reason Code 1"/>
<translation code="8HV6.00" codeSystem="2.16.840.1.113883.2.1.6.2" displayName="Reason Code 2"/>
</code>
<text>Test request statement text New line</text>
<statusCode code="COMPLETE"/>
<effectiveTime>
<center value="20050406" nullFlavor="NI"/>
</effectiveTime>
<availabilityTime value="20100101123000"/>
<priorityCode code="394848005" displayName="Normal" codeSystem="2.16.840.1.113883.2.1.3.2.4.15">
<originalText>Routine</originalText>
</priorityCode>
<confidentialityCode
code="NOSCRUB"
codeSystem="2.16.840.1.113883.4.642.3.47"
displayName="no scrubbing of the patient, family or caregivers without attending provider's authorization" />
<responsibleParty typeCode="RESP">
<agentRef classCode="AGNT">
<id root="B8CA3710-4D1C-11E3-9E6B-010000001205"/>
</agentRef>
</responsibleParty>
<Participant typeCode="PPRF" contextControlCode="OP">
<agentRef classCode="AGNT">
<id root="58341512-03F3-4C8E-B41C-A8FCA3886BBB"/>
</agentRef>
</Participant>
</RequestStatement>
</component>
</ehrComposition>
</component>
</ehrFolder>
</component>
</EhrExtract>

0 comments on commit 2c8e21a

Please sign in to comment.