Skip to content

Commit

Permalink
NAID-3122 - Add confidentialityCode support to `AllergyIntoleranceM…
Browse files Browse the repository at this point in the history
…apper.java` (#684)

* [NIAD-3122] Add Predicate to ObservationUtil.java

* [NIAD-3122] Add initial mapping logic

* [NIAD-3122] Add initial mapping logic

* [NIAD-3122] Add CodingFactory.java

* [NIAD-3122] Add comment

* [NIAD-3122] Refactor ResourceUtil.java

* [NIAD-3122] Refactor ResourceUtil.java

* [NIAD-3122] Refactor ResourceUtil.java

* [NIAD-3122] Refactor ResourceUtil.java

* [NIAD-3122] Add unit tests

* [NIAD-3122] Refactor unit tests

* [NIAD-3122] Refactor unit tests

* [NIAD-3122] Update CHANGELOG.md
  • Loading branch information
martin-nhs authored Jul 3, 2024
1 parent eb19e1d commit 8c5ce1f
Show file tree
Hide file tree
Showing 8 changed files with 477 additions and 98 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added
* The AllergyIntoleranceMapper has been enhanced to support the redaction fix. If an Allergy Intolerance record includes a confidentialityCode, the meta.security field of the corresponding FHIR resource will now be appropriately populated.

## [3.0.0] - 2024-07-02

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.Encounter;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.v3.CD;
Expand All @@ -40,6 +41,7 @@
import lombok.RequiredArgsConstructor;
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 Down Expand Up @@ -88,14 +90,21 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrComposition eh
.getId()
.getRoot();

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

allergyIntolerance
.addCategory(getCategory(compoundStatement))
.setAssertedDateElement(getAssertedDateElement(compoundStatement.getAvailabilityTime(), ehrComposition))
.setPatient(new Reference(patient))
.setClinicalStatus(ACTIVE)
.setVerificationStatus(UNCONFIRMED)
.addIdentifier(buildIdentifier(id, practiseCode))
.setMeta(generateMeta(META_PROFILE))
.setMeta(meta)
.setId(id);

buildOnset(compoundStatement, allergyIntolerance);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package uk.nhs.adaptors.pss.translator.util;

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

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

public final class ConfidentialityUtil {

private ConfidentialityUtil() { }

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");

public static Meta addSecurityToMetaIfConfidentialityCodesPresent(Collection<Optional<CV>> confidentialityCodes, Meta meta) {
final boolean isCodePresent = confidentialityCodes.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.anyMatch(ConfidentialityUtil::isNopat);

if (isCodePresent) {
return ConfidentialityUtil.addConfidentialityToMeta(meta);
}

return meta;
}

private static Meta addConfidentialityToMeta(final Meta meta) {
return meta.setSecurity(
Collections.singletonList(
CONFIDENTIALITY_CODING
)
);
}

private static boolean isNopat(CV coding) {
return coding.getCode().equals("NOPAT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.nhs.adaptors.pss.translator.util.builder;

import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.v3.CV;
import uk.nhs.adaptors.pss.translator.util.ConfidentialityUtil;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;

public final class MetaBuilder {
private Meta meta;

public MetaBuilder withInitialMeta(final Supplier<Meta> metaSupplier) {
this.meta = Objects.requireNonNull(metaSupplier.get());
return this;
}

@SafeVarargs
public final MetaBuilder withSecurityIfConfidentialityCodesPresent(Optional<CV>... confidentialityCodes) {
this.meta = ConfidentialityUtil.addSecurityToMetaIfConfidentialityCodesPresent(
Arrays.asList(confidentialityCodes),
this.meta
);

return this;
}

public Meta build() {
return this.meta.copy();
}
}
Loading

0 comments on commit 8c5ce1f

Please sign in to comment.