Skip to content

Commit

Permalink
[NIAD-3029] Full PS Adaptor Compatibility with RCMR_IN030000UK07 Mess…
Browse files Browse the repository at this point in the history
…age Type (#666)
  • Loading branch information
martin-nhs authored Jun 28, 2024
1 parent 68c1a5d commit 0907119
Show file tree
Hide file tree
Showing 214 changed files with 45,498 additions and 29,835 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static Stream<Arguments> ehrExtractsWithObservationActualProblemCode() {
@MethodSource("ehrExtractsWithObservationActualProblemCode")
public void When_AddReferences_With_ObservationAsProblem_Expect_CodeAddedToCondition(String filename) {

final RCMRMT030101UK04EhrExtract ehrExtract = unmarshallEhrExtract(filename);
final RCMRMT030101UKEhrExtract ehrExtract = unmarshallEhrExtract(filename);
final List<Condition> conditions = conditionMapper.mapResources(ehrExtract, patient, List.of(), PRACTISE_CODE);

conditionMapper.addReferences(buildBundleWithNamedStatementObservation(), conditions, ehrExtract);
Expand All @@ -88,7 +88,7 @@ public static Stream<Arguments> ehrExtractsWithAllergyIntoleranceActualProblemCo
@MethodSource("ehrExtractsWithAllergyIntoleranceActualProblemCode")
public void When_AddReferences_With_AllergyIntoleranceAsProblem_Expect_CodeAddedToCondition(String filename) {

final RCMRMT030101UK04EhrExtract ehrExtract = unmarshallEhrExtract(filename);
final RCMRMT030101UKEhrExtract ehrExtract = unmarshallEhrExtract(filename);
final List<Condition> conditions = conditionMapper.mapResources(ehrExtract, patient, List.of(), PRACTISE_CODE);

conditionMapper.addReferences(buildBundleWithNamedStatementAllergy(), conditions, ehrExtract);
Expand All @@ -101,8 +101,8 @@ public void When_AddReferences_With_AllergyIntoleranceAsProblem_Expect_CodeAdded
}

@SneakyThrows
private RCMRMT030101UK04EhrExtract unmarshallEhrExtract(String filename) {
return unmarshallFile(getFile("classpath:" + CONDITION_RESOURCES_BASE + filename), RCMRMT030101UK04EhrExtract.class);
private RCMRMT030101UKEhrExtract unmarshallEhrExtract(String filename) {
return unmarshallFile(getFile("classpath:" + CONDITION_RESOURCES_BASE + filename), RCMRMT030101UKEhrExtract.class);
}

private Bundle buildBundleWithNamedStatementObservation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
import org.hl7.v3.CD;
import org.hl7.v3.RCMRMT030101UKAnnotation;
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UK04PertinentInformation02;
import org.hl7.v3.RCMRMT030101UKPertinentInformation02;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKNarrativeStatement;
import org.hl7.v3.RCMRMT030101UKObservationStatement;
import org.hl7.v3.RCMRMT030101UKPertinentInformation02;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -134,8 +133,8 @@ private String getComment(List<RCMRMT030101UKObservationStatement> observationSt
: observationStatements) {
var bloodPressureText = observationStatement.getPertinentInformation().stream()
.filter(this::pertinentInformationHasText)
.map(RCMRMT030101UK04PertinentInformation02.class::cast)
.map(RCMRMT030101UK04PertinentInformation02::getPertinentAnnotation)
.map(RCMRMT030101UKPertinentInformation02.class::cast)
.map(RCMRMT030101UKPertinentInformation02::getPertinentAnnotation)
.map(RCMRMT030101UKAnnotation::getText)
.map(text -> {

Expand Down Expand Up @@ -169,7 +168,7 @@ private String getComment(List<RCMRMT030101UKObservationStatement> observationSt
return stringBuilder.toString().trim();
}

private boolean pertinentInformationHasText(RCMRMT030101UKPertinentInformation02 pertinentInformation) {
private boolean pertinentInformationHasText(org.hl7.v3.RCMRMT030101UKPertinentInformation02 pertinentInformation) {
return pertinentInformation != null && pertinentInformation.getPertinentAnnotation() != null
&& StringUtils.isNotEmpty(pertinentInformation.getPertinentAnnotation().getText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@
import org.hl7.v3.RCMRMT030101UKComponent4;
import org.hl7.v3.RCMRMT030101UKComponent6;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrFolder;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrFolder;
import org.hl7.v3.RCMRMT030101UKLinkSet;
import org.hl7.v3.RCMRMT030101UKMedicationStatement;
import org.hl7.v3.RCMRMT030101UKObservationStatement;
Expand Down Expand Up @@ -143,7 +142,7 @@ private Condition getCondition(Patient patient, List<Encounter> encounters, RCMR
return condition;
}

public void addHierarchyReferencesToConditions(List<Condition> conditions, RCMRMT030101UK04EhrExtract ehrExtract) {
public void addHierarchyReferencesToConditions(List<Condition> conditions, RCMRMT030101UKEhrExtract ehrExtract) {
var allLinkSets = getCompositionsContainingLinkSets(ehrExtract).stream()
.flatMap(ehrComposition -> ehrComposition.getComponent().stream())
.map(RCMRMT030101UKComponent4::getLinkSet)
Expand Down Expand Up @@ -179,7 +178,7 @@ public void addHierarchyReferencesToConditions(List<Condition> conditions, RCMRM
});
}

public void addReferences(Bundle bundle, List<Condition> conditions, RCMRMT030101UK04EhrExtract ehrExtract) {
public void addReferences(Bundle bundle, List<Condition> conditions, RCMRMT030101UKEhrExtract ehrExtract) {
getCompositionsContainingLinkSets(ehrExtract).stream()
.flatMap(ehrComposition -> ehrComposition.getComponent().stream())
.map(RCMRMT030101UKComponent4::getLinkSet)
Expand Down Expand Up @@ -335,7 +334,7 @@ private CodeableConcept generateCategory() {
}

private List<Extension> buildRelatedClinicalContent(Bundle bundle, List<RCMRMT030101UKStatementRef> relatedClinicalStatementReferences,
RCMRMT030101UK04EhrExtract ehrExtract) {
RCMRMT030101UKEhrExtract ehrExtract) {

// Filter for bundle entries where entry ID exists in both streams
var bundleIds = bundle.getEntry()
Expand Down Expand Up @@ -366,7 +365,7 @@ private List<Extension> buildRelatedClinicalContent(Bundle bundle, List<RCMRMT03

}

private List<String> getMedicationRequestIds(RCMRMT030101UK04EhrExtract ehrExtract, List<RCMRMT030101UKStatementRef> statementRefs) {
private List<String> getMedicationRequestIds(RCMRMT030101UKEhrExtract ehrExtract, List<RCMRMT030101UKStatementRef> statementRefs) {

var medicationStatements = getMedicationStatements(ehrExtract);
Map<String, String> medicationStatementIdMapping = getMedicationStatementIdMapping(medicationStatements);
Expand Down Expand Up @@ -442,7 +441,7 @@ private List<Annotation> buildNotes(Optional<RCMRMT030101UKObservationStatement>
return annotationList;
}

private List<RCMRMT030101UKEhrComposition> getCompositionsContainingLinkSets(RCMRMT030101UK04EhrExtract ehrExtract) {
private List<RCMRMT030101UKEhrComposition> getCompositionsContainingLinkSets(RCMRMT030101UKEhrExtract ehrExtract) {

return ehrExtract.getComponent().stream()
.flatMap(component -> component.getEhrFolder().getComponent().stream())
Expand All @@ -454,7 +453,7 @@ private List<RCMRMT030101UKEhrComposition> getCompositionsContainingLinkSets(RCM
.toList();
}

private Optional<RCMRMT030101UKObservationStatement> getObservationStatementById(RCMRMT030101UK04EhrExtract ehrExtract, String id) {
private Optional<RCMRMT030101UKObservationStatement> getObservationStatementById(RCMRMT030101UKEhrExtract ehrExtract, String id) {

List<RCMRMT030101UKObservationStatement> observationStatements = ehrExtract.getComponent().stream()
.map(RCMRMT030101UKComponent::getEhrFolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.hl7.v3.II;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKAnnotation;
import org.hl7.v3.RCMRMT030101UKComponent;
import org.hl7.v3.RCMRMT030101UKComponent3;
Expand All @@ -28,7 +28,7 @@ public class DuplicateObservationStatementMapper {
public static final int CHAR_LIMIT_FOR_TRUNCATION = 50;
public static final String ELLIPSIS = "...";

public void mergeDuplicateObservationStatements(RCMRMT030101UK04EhrExtract ehrExtract) {
public void mergeDuplicateObservationStatements(RCMRMT030101UKEhrExtract ehrExtract) {
ehrExtract.getComponent()
.stream()
.map(RCMRMT030101UKComponent::getEhrFolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UKComponent3;
import org.hl7.v3.RCMRMT030101UKComponent4;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrFolder;
import org.hl7.v3.RCMRMT030101UKLinkSet;
import org.hl7.v3.RCMRMT030101UKAuthor;
Expand Down Expand Up @@ -80,7 +80,7 @@ public class EncounterMapper {
private final ResourceReferenceUtil resourceReferenceUtil;

public Map<String, List<? extends DomainResource>> mapEncounters(
RCMRMT030101UK04EhrExtract ehrExtract,
RCMRMT030101UKEhrExtract ehrExtract,
Patient patient,
String practiseCode,
List<Location> entryLocations
Expand Down Expand Up @@ -242,7 +242,7 @@ private boolean hasValidCategoryCompoundStatement(RCMRMT030101UKCompoundStatemen
return compoundStatement != null && CATEGORY_CLASS_CODE.equals(compoundStatement.getClassCode().get(0));
}

private List<RCMRMT030101UKEhrComposition> getEncounterEhrCompositions(RCMRMT030101UK04EhrExtract ehrExtract) {
private List<RCMRMT030101UKEhrComposition> getEncounterEhrCompositions(RCMRMT030101UKEhrExtract ehrExtract) {
return ehrExtract
.getComponent()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.hl7.fhir.dstu3.model.Identifier;
import org.hl7.fhir.dstu3.model.Location;
import org.hl7.fhir.dstu3.model.ContactPoint;
import org.hl7.v3.RCMRMT030101UK04Place;
import org.hl7.v3.RCMRMT030101UKPlace;
import org.hl7.v3.RCMRMT030101UKLocation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -42,12 +42,12 @@ public Location mapToLocation(RCMRMT030101UKLocation location, String practiseCo
return createLocation(id, identifier, null, null, null);
}

private String getName(RCMRMT030101UK04Place locatedPlace) {
private String getName(RCMRMT030101UKPlace locatedPlace) {
var name = locatedPlace.getName();
return name != null ? name : UNKNOWN_NAME;
}

private ContactPoint getLocationTelecom(RCMRMT030101UK04Place locatedPlace) {
private ContactPoint getLocationTelecom(RCMRMT030101UKPlace locatedPlace) {
var telecom = locatedPlace.getTelecom().stream().findFirst();
if (telecom.isPresent()) {
return TelecomUtil.mapTelecom(telecom.get());
Expand All @@ -56,7 +56,7 @@ private ContactPoint getLocationTelecom(RCMRMT030101UK04Place locatedPlace) {
return null;
}

private Address getLocationAddress(RCMRMT030101UK04Place locatedPlace) {
private Address getLocationAddress(RCMRMT030101UKPlace locatedPlace) {
var address = locatedPlace.getAddr();
if (address != null) {
return AddressUtil.mapAddress(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UK04ObservationStatement;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKObservationStatement;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -64,7 +63,7 @@ public List<DomainResource> mapResources(RCMRMT030101UKEhrExtract ehrExtract, Pa

}

public void addReferences(List<DomainResource> templates, List<Observation> observations, RCMRMT030101UK04EhrExtract ehrExtract) {
public void addReferences(List<DomainResource> templates, List<Observation> observations, RCMRMT030101UKEhrExtract ehrExtract) {
List<Observation> parentObservations = templates.stream()
.filter(Observation.class::isInstance)
.map(Observation.class::cast)
Expand All @@ -88,7 +87,7 @@ public void addReferences(List<DomainResource> templates, List<Observation> obse
.extractResourcesFromCompound(parentCompoundStatement,
RCMRMT030101UKComponent02::hasObservationStatement, RCMRMT030101UKComponent02::getObservationStatement)
.stream()
.map(RCMRMT030101UK04ObservationStatement.class::cast)
.map(RCMRMT030101UKObservationStatement.class::cast)
.map(observationStatement -> observationStatement.getId().getRoot())
.toList();

Expand Down Expand Up @@ -174,7 +173,7 @@ private InstantType getIssued(RCMRMT030101UKEhrComposition ehrComposition) {
return null;
}

private List<RCMRMT030101UKCompoundStatement> getCompoundStatementsByIds(RCMRMT030101UK04EhrExtract ehrExtract, List<String> ids) {
private List<RCMRMT030101UKCompoundStatement> getCompoundStatementsByIds(RCMRMT030101UKEhrExtract ehrExtract, List<String> ids) {

return ehrExtract.getComponent().get(0).getEhrFolder().getComponent()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.II;
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKNarrativeStatement;
import org.hl7.v3.RCMRMT030101UKAuthor;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -91,7 +90,7 @@ public List<DiagnosticReport> mapResources(RCMRMT030101UKEhrExtract ehrExtract,
)).toList();
}

public void handleChildObservationComments(RCMRMT030101UK04EhrExtract ehrExtract, List<Observation> observationComments) {
public void handleChildObservationComments(RCMRMT030101UKEhrExtract ehrExtract, List<Observation> observationComments) {

List<Observation> conclusionComments = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UK04ObservationStatement;
import org.hl7.v3.RCMRMT030101UKObservationStatement;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrComposition;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
Expand Down Expand Up @@ -275,7 +275,7 @@ private Stream<ObservationRelatedComponent> getObservationReferences(RCMRMT03010
return extractResourcesFromCompound(batteryCompoundStatement, RCMRMT030101UKComponent02::hasObservationStatement,
RCMRMT030101UKComponent02::getObservationStatement)
.stream()
.map(RCMRMT030101UK04ObservationStatement.class::cast)
.map(RCMRMT030101UKObservationStatement.class::cast)
.map(observationStatement -> new Reference(new IdType(ResourceType.Observation.name(), observationStatement.getId().getRoot())))
.map(reference -> new ObservationRelatedComponent().setTarget(reference)
.setType(ObservationRelationshipType.HASMEMBER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import org.hl7.fhir.dstu3.model.Specimen;
import org.hl7.fhir.dstu3.model.Specimen.SpecimenCollectionComponent;
import org.hl7.v3.RCMRMT030101UKComponent02;
import org.hl7.v3.RCMRMT030101UK04EhrExtract;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKEhrExtract;
import org.hl7.v3.RCMRMT030101UKCompoundStatement;
import org.hl7.v3.RCMRMT030101UKSpecimenRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -42,8 +41,8 @@ public class SpecimenMapper {

private final DateTimeMapper dateTimeMapper;

public List<Specimen> mapSpecimen(RCMRMT030101UK04EhrExtract ehrExtract, List<DiagnosticReport> diagnosticReports,
Patient patient, String practiceCode) {
public List<Specimen> mapSpecimen(RCMRMT030101UKEhrExtract ehrExtract, List<DiagnosticReport> diagnosticReports,
Patient patient, String practiceCode) {

return diagnosticReports.stream()
.flatMap(diagnosticReport -> diagnosticReport.getSpecimen().stream())
Expand All @@ -58,7 +57,7 @@ public List<Specimen> mapSpecimen(RCMRMT030101UK04EhrExtract ehrExtract, List<Di
.toList();
}

public List<Observation> removeSurplusObservationComments(RCMRMT030101UK04EhrExtract ehrExtract,
public List<Observation> removeSurplusObservationComments(RCMRMT030101UKEhrExtract ehrExtract,
List<Observation> observationComments) {

var specimenCompoundStatements = findAllSpecimenCompoundStatements(ehrExtract);
Expand Down Expand Up @@ -153,7 +152,7 @@ private Optional<RCMRMT030101UKSpecimenRole> getSpecimenRole(RCMRMT030101UKCompo
}

private Optional<RCMRMT030101UKCompoundStatement> getParentCompoundStatementByChildId(
RCMRMT030101UK04EhrExtract ehrExtract, String id) {
RCMRMT030101UKEhrExtract ehrExtract, String id) {

return ehrExtract.getComponent().get(0).getEhrFolder().getComponent().stream()
.flatMap(component3 -> component3.getEhrComposition().getComponent().stream())
Expand Down
Loading

0 comments on commit 0907119

Please sign in to comment.