Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIAD-3132 Populate the "no disclosure to patient" label for Encounter #695

Merged
merged 29 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8ea91f4
[NIAD-3132] Added initial tests for ConfidentialityService.java
martin-nhs Jul 11, 2024
fdc90e8
[NIAD-3132] Added initial tests for ConfidentialityService.java
martin-nhs Jul 11, 2024
c087f62
[NIAD-3132] Updated AllergyIntoleranceMapper.java and EncounterMapper…
martin-nhs Jul 11, 2024
6ca34bd
[NIAD-3132] Removed old logic
martin-nhs Jul 11, 2024
ed490e7
[NIAD-3132] Addressed failing tests
martin-nhs Jul 11, 2024
c013de5
[NIAD-3132] Refactor failing tests
martin-nhs Jul 11, 2024
9b21d81
[NIAD-3132] Removed old tests
martin-nhs Jul 11, 2024
e13d44a
[NIAD-3132] Updated CHANGELOG.md
martin-nhs Jul 11, 2024
d4f8291
[NIAD-3132] Updated CHANGELOG.md
martin-nhs Jul 11, 2024
5c816a9
[NIAD-3132] Delegate generation of META to ConfidentialityService.java
martin-nhs Jul 11, 2024
b9d3c01
[NIAD-3132] Delegate generation of META to ConfidentialityService.java
martin-nhs Jul 11, 2024
e918d6f
[NIAD-3132] Converted to unit test, away from integration test.
martin-nhs Jul 11, 2024
0bc1db3
[NIAD-3132] Further enhancements to ConfidentialityServiceTest.java
martin-nhs Jul 11, 2024
4bce13a
Merge branch 'main' into NIAD-3132
MartinWheelerMT Jul 12, 2024
5566b56
[NIAD-3132] Address failing tests within AllergyIntoleranceMapperTest…
martin-nhs Jul 12, 2024
a041f82
[NIAD-3132] Address failing tests within AllergyIntoleranceMapperTest…
martin-nhs Jul 12, 2024
6a5a71d
[NIAD-3132] Tidy EncounterMapperTest.java imports
martin-nhs Jul 12, 2024
3fea402
[NIAD-3132] Addressed PR Comment https://github.com/NHSDigital/nia-pa…
martin-nhs Jul 12, 2024
be0ea9f
[NIAD-3132] Moved from using Collection to utilising variable arguments
martin-nhs Jul 12, 2024
ec268ce
[NIAD-3132] Updated AllergyIntoleranceMapperTest.java for https://git…
martin-nhs Jul 12, 2024
2fd7ab1
[NIAD-3132] Updated EncounterMapperTest.java.java for https://github.…
martin-nhs Jul 12, 2024
989202d
[NIAD-3132] Address checkstyle violations
martin-nhs Jul 12, 2024
ce75db9
Merge branch 'main' into NIAD-3132
martin-nhs Jul 12, 2024
8f35126
Refactor ConfidentialityService
MartinWheelerMT Jul 15, 2024
82b7703
[NIAD-3132] Added further test coverage
martin-nhs Jul 15, 2024
211d7bb
[NIAD-3132] Dried test code up
martin-nhs Jul 15, 2024
d38005c
[NIAD-3132] Enhancements to unit tests
martin-nhs Jul 15, 2024
24ea7f9
[NIAD-3132] Enhancements to unit tests
martin-nhs Jul 15, 2024
2c0a6e8
[NIAD-3132] Addressed checkstyle violations
martin-nhs Jul 15, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## Added
* The EncounterMapper has been enhanced to support the redaction fix. If an Encounter record includes a confidentialityCode,
the meta.security field of the corresponding FHIR resource will now be [appropriately populated][nopat-docs].

## [3.0.1] - 2024-07-12

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static uk.nhs.adaptors.pss.translator.util.ParticipantReferenceUtil.fetchRecorderAndAsserter;
import static uk.nhs.adaptors.pss.translator.util.ParticipantReferenceUtil.getParticipantReference;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -39,9 +38,9 @@
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
import uk.nhs.adaptors.pss.translator.service.ConfidentialityService;
import uk.nhs.adaptors.pss.translator.util.DegradedCodeableConcepts;
import uk.nhs.adaptors.pss.translator.util.ResourceFilterUtil;
import uk.nhs.adaptors.pss.translator.util.builder.MetaBuilder;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
Expand All @@ -59,6 +58,7 @@ public class AllergyIntoleranceMapper extends AbstractMapper<AllergyIntolerance>
public static final String RECORDER = "recorder";

private final CodeableConceptMapper codeableConceptMapper;
private final ConfidentialityService confidentialityService;

@Override
public List<AllergyIntolerance> mapResources(RCMRMT030101UKEhrExtract ehrExtract, Patient patient, List<Encounter> encounters,
Expand Down Expand Up @@ -90,12 +90,11 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrComposition eh
.getId()
.getRoot();

final Meta meta = new MetaBuilder()
.withInitialMeta(() -> generateMeta(META_PROFILE))
.withSecurityIfConfidentialityCodesPresent(
ehrComposition.getConfidentialityCode(),
observationStatement.getConfidentialityCode()
).build();
final Meta meta = confidentialityService.createMetaAndAddSecurityIfConfidentialityCodesPresent(
META_PROFILE,
ehrComposition.getConfidentialityCode(),
observationStatement.getConfidentialityCode()
);

allergyIntolerance
.addCategory(getCategory(compoundStatement))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.nhs.adaptors.pss.translator.mapper;

import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -22,6 +21,7 @@
import org.hl7.fhir.dstu3.model.ListResource;
import org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent;
import org.hl7.fhir.dstu3.model.Location;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Period;
import org.hl7.fhir.dstu3.model.Reference;
Expand All @@ -46,9 +46,11 @@
import org.springframework.util.CollectionUtils;

import lombok.RequiredArgsConstructor;
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.ResourceReferenceUtil;

import static uk.nhs.adaptors.common.util.CodeableConceptUtils.createCodeableConcept;

@Service
Expand Down Expand Up @@ -78,6 +80,7 @@ public class EncounterMapper {
private final CodeableConceptMapper codeableConceptMapper;
private final ConsultationListMapper consultationListMapper;
private final ResourceReferenceUtil resourceReferenceUtil;
private final ConfidentialityService confidentialityService;

public Map<String, List<? extends DomainResource>> mapEncounters(
RCMRMT030101UKEhrExtract ehrExtract,
Expand Down Expand Up @@ -287,14 +290,20 @@ private Encounter mapToEncounter(
var id = ehrComposition.getId().getRoot();

var encounter = new Encounter();

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

encounter
.setParticipant(getParticipants(ehrComposition.getAuthor(), ehrComposition.getParticipant2()))
.setStatus(EncounterStatus.FINISHED)
.setSubject(new Reference(patient))
.setType(getType(ehrComposition.getCode()))
.setPeriod(getPeriod(ehrComposition))
.addIdentifier(buildIdentifier(id, practiseCode))
.setMeta(generateMeta(ENCOUNTER_META_PROFILE))
.setMeta(meta)
.setId(id);

setEncounterLocation(encounter, ehrComposition, entryLocations);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.nhs.adaptors.pss.translator.service;

import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.v3.CV;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta;

@Service
public class ConfidentialityService {
private static final Coding CONFIDENTIALITY_CODING = new Coding()
.setSystem("http://hl7.org/fhir/v3/ActCode")
.setCode("NOPAT")
.setDisplay("no disclosure to patient, family or caregivers without attending provider's authorization");

@SafeVarargs
public final Meta createMetaAndAddSecurityIfConfidentialityCodesPresent(String metaProfile, Optional<CV>... cvs) {
return Arrays.stream(cvs).flatMap(Optional::stream).anyMatch(this::isNopat)
? generateMeta(metaProfile).setSecurity(Collections.singletonList(CONFIDENTIALITY_CODING))
: generateMeta(metaProfile);
}

private boolean isNopat(CV coding) {
return coding.getCode().equals("NOPAT");
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package uk.nhs.adaptors.pss.translator;

import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.UriType;

import java.util.Collections;

public final class MetaFactory {
private MetaFactory() { }
private static final Coding NOPAT_CODING = new Coding()
.setSystem("http://hl7.org/fhir/v3/ActCode")
.setCode("NOPAT")
.setDisplay("no disclosure to patient, family or caregivers without attending provider's authorization");

public static Meta getMetaFor(final MetaType metaType, final String profile) {
return switch (metaType) {
case META_WITHOUT_SECURITY -> getBaseMeta(profile);
case META_WITH_SECURITY -> getMetaWithSecurity(profile);
};
}

private static Meta getBaseMeta(final String profile) {
return new Meta().setProfile(
Collections.singletonList(
new UriType(profile)
)
);
}

private static Meta getMetaWithSecurity(final String profile) {
return getBaseMeta(profile).addSecurity(NOPAT_CODING);
}

public enum MetaType {
META_WITH_SECURITY,
META_WITHOUT_SECURITY
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.nhs.adaptors.pss.translator;

import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;

import java.util.function.Function;

public final class TestUtility {
private TestUtility() { }

public static final Function<RCMRMT030101UKEhrExtract, RCMRMT030101UKEhrComposition> GET_EHR_COMPOSITION =
extract -> extract
.getComponent().get(0)
.getEhrFolder()
.getComponent().get(0)
.getEhrComposition();
}
Loading