Skip to content

Commit

Permalink
NIAD-2935: Remove EhrExtract / availabilityTime as a fallback (#465)
Browse files Browse the repository at this point in the history
This time field would always be the current (as of the GP2GP transfer being started) time, which would never be an appropriate value to use for an entry within the medical record.


---------

Co-authored-by: Steven McCullagh <[email protected]>
  • Loading branch information
Alex-Nita and stevenmccullaghmadetech authored Feb 27, 2024
1 parent 704e500 commit ce2213f
Show file tree
Hide file tree
Showing 22 changed files with 433 additions and 69 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Changed
* `AllergyIntoleranceMapper` - Changed `assertedDate` field fallback value from `EhrExtract.AvailiabiltyTime` to `EhrComposition.Author.Time`
* `BloodPressureMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`
* `ConditionMapper` - Removed `assertedDate` field fallback value of `EhrExtract.AvailiabiltyTime`
* `ConsultationListMapper` - Removed `date` field fallback value of `EhrExtract.AvailiabiltyTime`
* `DiagnosticReportMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`
* `MedicationRequestMapper` - Changed `authoredOn` field fallback value from `EhrExtract.AvailiabiltyTime` to `EhrComposition.Author.Time`
* `ObservationCommentMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`
* `ObservationMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`
* `SpecimenBatteryMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`
* `TemplateMapper` - Removed `issued` field fallback value of `EhrExtract.AvailiabiltyTime`

### Fixed
* Fixed an issue where Plan Statements (Recalls) used a fixed value for Status instead of taking a provided text value into account.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private AllergyIntolerance mapAllergyIntolerance(RCMRMT030101UKEhrExtract ehrExt

allergyIntolerance
.addCategory(getCategory(compoundStatement))
.setAssertedDateElement(getAssertedDateElement(compoundStatement.getAvailabilityTime(), ehrExtract, ehrComposition))
.setAssertedDateElement(getAssertedDateElement(compoundStatement.getAvailabilityTime(), ehrComposition))
.setPatient(new Reference(patient))
.setClinicalStatus(ACTIVE)
.setVerificationStatus(UNCONFIRMED)
Expand Down Expand Up @@ -239,16 +239,18 @@ private void buildOnset(RCMRMT030101UKCompoundStatement compoundStatement, Aller
}
}

private DateTimeType getAssertedDateElement(TS availabilityTime, RCMRMT030101UKEhrExtract ehrExtract,
private DateTimeType getAssertedDateElement(TS availabilityTime,
RCMRMT030101UKEhrComposition ehrComposition) {

if (availabilityTime != null && availabilityTime.hasValue()) {
return parseToDateTimeType(availabilityTime.getValue());
} else {
if (ehrComposition.getAvailabilityTime() != null && ehrComposition.getAvailabilityTime().hasValue()) {
return parseToDateTimeType(ehrComposition.getAvailabilityTime().getValue());
} else if (ehrExtract.getAvailabilityTime() != null && ehrExtract.getAvailabilityTime().hasValue()) {
return parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue());
} else if (ehrComposition.getAuthor() != null
&& ehrComposition.getAuthor().getTime() != null
&& ehrComposition.getAuthor().getTime().hasValue()) {
return parseToDateTimeType(ehrComposition.getAuthor().getTime().getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private Observation mapObservation(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT03
getComment(observationStatements, getNarrativeStatementsFromCompoundStatement(compoundStatement)))
.setSubject(new Reference(patient))
.setIssuedElement(getIssued(
ehrExtract,
ehrComposition))
.addPerformer(getParticipantReference(
compoundStatement.getParticipant(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import static uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.getMedicationStatements;
import static uk.nhs.adaptors.pss.translator.util.CompoundStatementResourceExtractors.extractAllLinkSets;
import static uk.nhs.adaptors.pss.translator.util.DateFormatUtil.parseToDateTimeType;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildReferenceExtension;
import static uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta;
Expand Down Expand Up @@ -133,9 +132,7 @@ private Condition getCondition(RCMRMT030101UKEhrExtract ehrExtract, Patient pati
buildOnsetDateTimeType(linkSet).ifPresent(condition::setOnset);
buildAbatementDateTimeType(linkSet.getEffectiveTime()).ifPresent(condition::setAbatement);

buildAssertedDateTimeType(composition).ifPresentOrElse(
condition::setAssertedDateElement,
() -> condition.setAssertedDateElement(parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue())));
buildAssertedDateTimeType(composition).ifPresent(condition::setAssertedDateElement);

composition.getParticipant2()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ListResource mapToConsultation(RCMRMT030101UK04EhrExtract ehrExtract, Enc
.setTitle(getConsultationTitle(encounter.getType()))
.setCode(CodeableConceptUtils.createCodeableConcept(CONSULTATION_CODE_CODE, LIST_CODE_SYSTEM, CONSULTATION_CODE_DISPLAY, null))
.setSubject(encounter.getSubject())
.setDateElement(getConsultationDate(encounter.getPeriod(), ehrExtract))
.setDateElement(getConsultationDate(encounter.getPeriod()))
.setOrderedBy(CodeableConceptUtils.createCodeableConcept(LIST_ORDERED_BY_CODE, LIST_ORDERED_BY_SYSTEM,
LIST_ORDERED_BY_DISPLAY, null))
.setEncounter(new Reference(encounter))
Expand All @@ -77,12 +77,12 @@ private String getConsultationTitle(List<CodeableConcept> codeableConceptList) {
return null;
}

private DateTimeType getConsultationDate(Period period, RCMRMT030101UK04EhrExtract ehrExtract) {
private DateTimeType getConsultationDate(Period period) {
if (period != null && period.hasStart()) {
return period.getStartElement();
} else {
return DateFormatUtil.parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue());
}

return null;
}

public ListResource mapToTopic(ListResource consultation, RCMRMT030101UKCompoundStatement compoundStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private Observation mapObservation(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT03
observation.setMeta(generateMeta(META_URL));
observation.setStatus(FINAL);
observation.setSubject(new Reference(patient));
observation.setIssuedElement(createIssued(ehrExtract, ehrComposition));
observation.setIssuedElement(createIssued(ehrComposition));
observation.setCode(createCodeableConcept());
observation.addPerformer(createPerformer(ehrComposition, narrativeStatement));
observation.addIdentifier(buildIdentifier(narrativeStatementId.getRoot(), practiseCode));
Expand All @@ -83,13 +83,13 @@ private void setObservationComment(Observation observation, String text) {
}
}

private InstantType createIssued(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT030101UKEhrComposition composition) {
private InstantType createIssued(RCMRMT030101UKEhrComposition composition) {

if (!composition.getAuthor().getTime().hasNullFlavor()) {
return DateFormatUtil.parseToInstantType(composition.getAuthor().getTime().getValue());
}

return DateFormatUtil.parseToInstantType(ehrExtract.getAvailabilityTime().getValue());
return null;
}

private Reference createPerformer(RCMRMT030101UKEhrComposition composition, RCMRMT030101UKNarrativeStatement narrativeStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private Observation mapObservation(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT03
.setStatus(FINAL)
.addIdentifier(buildIdentifier(id, practiseCode))
.setCode(getCode(observationStatement.getCode()))
.setIssuedElement(getIssued(ehrExtract, ehrComposition))
.setIssuedElement(getIssued(ehrComposition))
.addPerformer(getParticipantReference(observationStatement.getParticipant(), ehrComposition))
.setInterpretation(getInterpretation(observationStatement.getInterpretationCode()))
.setComment(getComment(
Expand Down Expand Up @@ -137,7 +137,7 @@ private Observation mapObservationFromRequestStatement(RCMRMT030101UKEhrExtract
.setStatus(FINAL)
.addIdentifier(buildIdentifier(id, practiseCode))
.setCode(getCode(requestStatement.getCode()))
.setIssuedElement(getIssued(ehrExtract, ehrComposition))
.setIssuedElement(getIssued(ehrComposition))
.addPerformer(getParticipantReference(requestStatement.getParticipant(), ehrComposition))
.setComment(SELF_REFERRAL)
.setSubject(new Reference(patient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private Observation createParentObservation(RCMRMT030101UKCompoundStatement comp

parentObservation
.setSubject(new Reference(patient))
.setIssuedElement(getIssued(ehrComposition, ehrExtract))
.setIssuedElement(getIssued(ehrComposition))
.addPerformer(getParticipantReference(compoundStatement.getParticipant(), ehrComposition))
.setCode(codeableConcept)
.setStatus(FINAL)
Expand All @@ -165,12 +165,12 @@ private void addEffective(Observation observation, Object effective) {
}
}

private InstantType getIssued(RCMRMT030101UKEhrComposition ehrComposition, RCMRMT030101UKEhrExtract ehrExtract) {
private InstantType getIssued(RCMRMT030101UKEhrComposition ehrComposition) {
if (ehrComposition.getAuthor().getTime().hasValue()) {

return parseToInstantType(ehrComposition.getAuthor().getTime().getValue());
}
return parseToInstantType(ehrExtract.getAvailabilityTime().getValue());
return null;
}

private List<RCMRMT030101UKCompoundStatement> getCompoundStatementsByIds(RCMRMT030101UK04EhrExtract ehrExtract, List<String> ids) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<DiagnosticReport> mapResources(RCMRMT030101UKEhrExtract ehrExtract,
DiagnosticReport diagnosticReport = createDiagnosticReport(
compoundStatement, patient, composition, encounters, practiseCode
);
getIssued(ehrExtract, compoundStatement, composition).ifPresent(diagnosticReport::setIssuedElement);
getIssued(compoundStatement, composition).ifPresent(diagnosticReport::setIssuedElement);
return diagnosticReport;
}
)).toList();
Expand Down Expand Up @@ -195,8 +195,8 @@ private Optional<Reference> buildContext(RCMRMT030101UKEhrComposition ehrComposi
.map(Reference::new);
}

private Optional<InstantType> getIssued(RCMRMT030101UKEhrExtract ehrExtract,
RCMRMT030101UKCompoundStatement compoundStatement, RCMRMT030101UKEhrComposition ehrComposition) {
private Optional<InstantType> getIssued(RCMRMT030101UKCompoundStatement compoundStatement,
RCMRMT030101UKEhrComposition ehrComposition) {

if (compoundStatementHasValidAvailabilityTime(compoundStatement)) {
return Optional.of(parseToInstantType(compoundStatement.getAvailabilityTime().getValue()));
Expand All @@ -206,10 +206,6 @@ private Optional<InstantType> getIssued(RCMRMT030101UKEhrExtract ehrExtract,
return Optional.of(parseToInstantType(ehrComposition.getAuthor().getTime().getValue()));
}

if (availabilityTimeHasValue(ehrExtract.getAvailabilityTime())) {
return Optional.of(parseToInstantType(ehrExtract.getAvailabilityTime().getValue()));
}

return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class SpecimenBatteryMapper {
public Observation mapBatteryObservation(SpecimenBatteryParameters batteryParameters) {
final var batteryCompoundStatement = batteryParameters.getBatteryCompoundStatement();
final var ehrComposition = batteryParameters.getEhrComposition();
final var ehrExtract = batteryParameters.getEhrExtract();

final Observation observation = new Observation();
final String id = batteryParameters.getBatteryCompoundStatement().getId().get(0).getRoot();
Expand All @@ -84,7 +83,7 @@ public Observation mapBatteryObservation(SpecimenBatteryParameters batteryParame
batteryParameters.getBatteryCompoundStatement(), batteryParameters.getObservationComments()));
getContext(batteryParameters.getEncounters(), ehrComposition).ifPresent(observation::setContext);
addEffective(batteryCompoundStatement, observation);
getIssued(ehrExtract, ehrComposition).ifPresent(observation::setIssuedElement);
getIssued(ehrComposition).ifPresent(observation::setIssuedElement);
getPerformer(batteryCompoundStatement, ehrComposition).ifPresent(observation::addPerformer);
getRelated(batteryCompoundStatement).forEach(observation::addRelated);
handleDirectChildNarrativeStatementUserComments(batteryCompoundStatement, observation, batteryParameters.getObservationComments());
Expand Down Expand Up @@ -210,16 +209,12 @@ private Reference createSpecimenReference(RCMRMT030101UKCompoundStatement specim
return new Reference(new IdType(Specimen.name(), specimenCompoundStatement.getId().get(0).getRoot()));
}

private Optional<InstantType> getIssued(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT030101UKEhrComposition ehrComposition) {
private Optional<InstantType> getIssued(RCMRMT030101UKEhrComposition ehrComposition) {

if (hasValidTimeValue(ehrComposition.getAuthor())) {
return Optional.of(parseToInstantType(ehrComposition.getAuthor().getTime().getValue()));
}

if (availabilityTimeHasValue(ehrExtract.getAvailabilityTime())) {
return Optional.of(parseToInstantType(ehrExtract.getAvailabilityTime().getValue()));
}

return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Stream<DomainResource> mapMedicationStatement(RCMRMT030101UKEhrExtract e

var context = encounters.stream()
.filter(encounter1 -> encounter1.getId().equals(ehrComposition.getId().getRoot())).findFirst();
var authoredOn = getAuthoredOn(medicationStatement.getAvailabilityTime(), ehrExtract, ehrComposition);
var authoredOn = getAuthoredOn(medicationStatement.getAvailabilityTime(), ehrComposition);
var dateAsserted = extractDateAsserted(ehrComposition, ehrExtract);
var requester = extractRequester(ehrComposition, medicationStatement);
var recorder = extractRecorder(ehrComposition, medicationStatement);
Expand Down Expand Up @@ -98,16 +98,17 @@ private DomainResource setCommonFields(DomainResource resource, Optional<Referen
return resource;
}

private DateTimeType getAuthoredOn(TS availabilityTime, RCMRMT030101UKEhrExtract ehrExtract,
RCMRMT030101UKEhrComposition ehrComposition) {

private DateTimeType getAuthoredOn(TS availabilityTime,
RCMRMT030101UKEhrComposition ehrComposition) {
if (availabilityTime != null && availabilityTime.hasValue()) {
return DateFormatUtil.parseToDateTimeType(availabilityTime.getValue());
} else {
if (ehrComposition.getAvailabilityTime() != null && ehrComposition.getAvailabilityTime().hasValue()) {
return DateFormatUtil.parseToDateTimeType(ehrComposition.getAvailabilityTime().getValue());
} else if (ehrExtract.getAvailabilityTime() != null && ehrExtract.getAvailabilityTime().hasValue()) {
return DateFormatUtil.parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue());
}
if (ehrComposition.hasAuthor() && ehrComposition.getAuthor().hasTime() && ehrComposition.getAuthor().getTime().hasValue()) {
return DateFormatUtil.parseToDateTimeType(ehrComposition.getAuthor().getTime().getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hl7.v3.PQ;
import org.hl7.v3.RCMRMT030101UKAuthor;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKInterpretationRange;
import org.hl7.v3.RCMRMT030101UKReferenceRange;
import org.hl7.v3.TS;
Expand Down Expand Up @@ -110,16 +109,12 @@ public static List<Observation.ObservationReferenceRangeComponent> getReferenceR
return outputReferenceRanges;
}

public static InstantType getIssued(RCMRMT030101UKEhrExtract ehrExtract, RCMRMT030101UKEhrComposition matchingEhrComposition) {
public static InstantType getIssued(RCMRMT030101UKEhrComposition matchingEhrComposition) {

if (authorHasValidTimeValue(matchingEhrComposition.getAuthor())) {
return DateFormatUtil.parseToInstantType(matchingEhrComposition.getAuthor().getTime().getValue());
}

if (availabilityTimeHasValue(ehrExtract.getAvailabilityTime())) {
return DateFormatUtil.parseToInstantType(ehrExtract.getAvailabilityTime().getValue());
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ public void testMapAllergyWithNoOptionalData() {
assertThat(allergyIntolerance.getNote()).isEmpty();
}

@Test
public void testMapAllergyAssertedDateFallbackData() {
when(codeableConceptMapper.mapToCodeableConcept(any(CD.class))).thenReturn(defaultCodeableConcept());
var ehrExtract = unmarshallEhrExtract("allergy-structure-with-asserted-date-fallback.xml");
List<AllergyIntolerance> allergyIntolerances = allergyIntoleranceMapper.mapResources(ehrExtract, getPatient(),
getEncounterList(), PRACTISE_CODE);

assertThat(allergyIntolerances.size()).isEqualTo(1);
var allergyIntolerance = allergyIntolerances.get(0);

assertFixedValues(allergyIntolerance);

assertThat(allergyIntolerance.getAssertedDateElement().asStringValue()).isEqualTo("2010-02-09T12:31:51+00:00");
}

@Test
public void testMapMultipleAllergies() {
when(codeableConceptMapper.mapToCodeableConcept(any(CD.class))).thenReturn(defaultCodeableConcept());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testConditionIsMappedCorrectlyNoReferences() {

assertThat(condition.getOnsetDateTimeType()).isEqualTo(EHR_EXTRACT_AVAILABILITY_DATETIME);
assertThat(condition.getAbatementDateTimeType()).isEqualTo(EHR_EXTRACT_AVAILABILITY_DATETIME);
assertThat(condition.getAssertedDateElement().getValue()).isEqualTo(EHR_EXTRACT_AVAILABILITY_DATETIME.getValue());
assertThat(condition.getAssertedDateElement().getValue()).isNull();

assertThat(condition.getNote().size()).isEqualTo(0);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public void testLinkSetWithNoDatesIsMappedCorrectly() {
assertThat(conditions.get(0).getClinicalStatus().getDisplay()).isEqualTo("Inactive");

assertThat(conditions.get(0).getAbatementDateTimeType()).isNull();
assertThat(conditions.get(0).getAssertedDateElement().getValue()).isEqualTo(EHR_EXTRACT_AVAILABILITY_DATETIME.getValue());
assertThat(conditions.get(0).getAssertedDateElement().getValue()).isNull();
}

@Test
Expand Down
Loading

0 comments on commit ce2213f

Please sign in to comment.