use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MedicationStatementMapperTest method When_MappingPrescribeResourceWithNoLastIssueDate_Expect_AllFieldsToBeMappedCorrectly.
@Test
public void When_MappingPrescribeResourceWithNoLastIssueDate_Expect_AllFieldsToBeMappedCorrectly() {
var medicationStatement = unmarshallMedicationStatement("medicationStatementAuthoriseNoOptionals_MedicationStatement.xml");
var authorise = medicationStatement.getComponent().stream().filter(RCMRMT030101UK04Component2::hasEhrSupplyAuthorise).map(RCMRMT030101UK04Component2::getEhrSupplyAuthorise).findFirst();
when(medicationMapper.extractMedicationReference(any())).thenReturn(Optional.of(new Reference(new IdType(ResourceType.Medication.name(), MEDICATION_ID))));
assertThat(authorise.isPresent()).isTrue();
var medicationStatement1 = medicationStatementMapper.mapToMedicationStatement(new RCMRMT030101UK04EhrExtract(), medicationStatement, authorise.get(), PRACTISE_CODE, new DateTimeType());
var lastIssuedDate = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1");
assertThat(lastIssuedDate.size()).isEqualTo(0);
var prescribingAgency = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescribingAgency-1");
assertThat(prescribingAgency.size()).isEqualTo(1);
assertThat(medicationStatement1.getBasedOnFirstRep().getReferenceElement().getIdPart()).isEqualTo(TEST_ID);
assertThat(medicationStatement1.getStatus()).isEqualTo(ACTIVE);
assertThat(medicationStatement1.getMedicationReference().getReferenceElement().getIdPart()).isEqualTo(MEDICATION_ID);
assertThat(medicationStatement1.getTaken()).isEqualTo(UNK);
assertThat(medicationStatement1.getDosageFirstRep().getText()).isEqualTo(TAKE_ONE_DAILY);
}
use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MedicationRequestPlanMapper method mapToPlanMedicationRequest.
public MedicationRequest mapToPlanMedicationRequest(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Authorise supplyAuthorise, String practiseCode) {
var ehrSupplyAuthoriseIdExtract = extractEhrSupplyAuthoriseId(supplyAuthorise);
if (ehrSupplyAuthoriseIdExtract.isPresent()) {
var ehrSupplyAuthoriseId = ehrSupplyAuthoriseIdExtract.get();
var discontinue = extractMatchingDiscontinue(ehrSupplyAuthoriseId, ehrExtract);
MedicationRequest medicationRequest = createMedicationRequestSkeleton(ehrSupplyAuthoriseId);
medicationRequest.addIdentifier(buildIdentifier(ehrSupplyAuthoriseId, practiseCode));
medicationRequest.setStatus(buildMedicationRequestStatus(supplyAuthorise));
medicationRequest.setIntent(PLAN);
medicationRequest.addDosageInstruction(buildDosage(medicationStatement.getPertinentInformation()));
medicationRequest.setDispenseRequest(buildDispenseRequestForAuthorise(supplyAuthorise, medicationStatement));
List<Extension> repeatInformationExtensions = new ArrayList<>();
extractSupplyAuthoriseRepeatInformation(supplyAuthorise).ifPresent(repeatInformationExtensions::add);
extractRepeatInformationIssued(ehrExtract, supplyAuthorise, ehrSupplyAuthoriseId).ifPresent(repeatInformationExtensions::add);
extractAuthorisationExpiryDate(supplyAuthorise).ifPresent(repeatInformationExtensions::add);
buildCondensedExtensions(REPEAT_INFORMATION_URL, repeatInformationExtensions).ifPresent(medicationRequest::addExtension);
List<Extension> statusChangeExtensions = new ArrayList<>();
discontinue.map(this::buildStatusChangeDateExtension).ifPresent(statusChangeExtensions::add);
discontinue.map(this::extractTermText).map(this::buildStatusReasonCodeableConceptExtension).ifPresent(statusChangeExtensions::add);
buildCondensedExtensions(STATUS_CHANGE_URL, statusChangeExtensions).ifPresent(medicationRequest::addExtension);
buildPrescriptionTypeExtension(supplyAuthorise).ifPresent(medicationRequest::addExtension);
buildNotesForAuthorise(supplyAuthorise).forEach(medicationRequest::addNote);
extractPriorPrescription(supplyAuthorise).ifPresent(medicationRequest::setPriorPrescription);
medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationRequest::setMedication);
return medicationRequest;
}
return null;
}
use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MedicationStatementMapper method mapToMedicationStatement.
public MedicationStatement mapToMedicationStatement(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Authorise supplyAuthorise, String practiseCode, DateTimeType authoredOn) {
var ehrSupplyAuthoriseIdExtract = extractEhrSupplyAuthoriseId(supplyAuthorise);
if (ehrSupplyAuthoriseIdExtract.isPresent()) {
String ehrSupplyAuthoriseId = ehrSupplyAuthoriseIdExtract.get();
MedicationStatement medicationStatement1 = new MedicationStatement();
medicationStatement1.setId(ehrSupplyAuthoriseId + MS_SUFFIX);
medicationStatement1.setMeta(generateMeta(MEDICATION_STATEMENT_URL));
medicationStatement1.addIdentifier(buildIdentifier(ehrSupplyAuthoriseId + MS_SUFFIX, practiseCode));
medicationStatement1.setTaken(UNK);
medicationStatement1.addBasedOn(new Reference(new IdType(ResourceType.MedicationRequest.name(), ehrSupplyAuthoriseId)));
medicationStatement1.addExtension(generatePrescribingAgencyExtension());
medicationStatement1.setStatus(buildMedicationStatementStatus(supplyAuthorise));
medicationStatement1.addDosage(buildDosage(medicationStatement.getPertinentInformation()));
extractHighestSupplyPrescribeTime(ehrExtract, ehrSupplyAuthoriseId).map(dateTime -> new Extension(MS_LAST_ISSUE_DATE, dateTime)).ifPresent(medicationStatement1::addExtension);
medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationStatement1::setMedication);
MedicationMapperUtils.extractDispenseRequestPeriodStart(supplyAuthorise).ifPresentOrElse(dateTimeType -> {
medicationStatement1.setEffective(buildDispenseRequestPeriodEnd(supplyAuthorise, medicationStatement).setStartElement(dateTimeType));
}, () -> {
medicationStatement1.setEffective(buildDispenseRequestPeriodEnd(supplyAuthorise, medicationStatement).setStartElement(authoredOn));
});
return medicationStatement1;
}
return null;
}
use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.
the class DiagnosticReportMapper method mapResources.
@Override
public List<DiagnosticReport> mapResources(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient, List<Encounter> encounters, String practiseCode) {
return mapEhrExtractToFhirResource(ehrExtract, (extract, composition, component) -> extractAllCompoundStatements(component).filter(Objects::nonNull).filter(ResourceFilterUtil::isDiagnosticReport).map(compoundStatement -> {
DiagnosticReport diagnosticReport = createDiagnosticReport(compoundStatement, patient, composition, encounters, practiseCode);
getIssued(ehrExtract, compoundStatement, composition).ifPresent(diagnosticReport::setIssuedElement);
return diagnosticReport;
})).toList();
}
use of org.hl7.v3.RCMRMT030101UK04EhrExtract in project nia-patient-switching-standard-adaptor by NHSDigital.
the class ConditionMapper method getCondition.
private Condition getCondition(RCMRMT030101UK04EhrExtract ehrExtract, Patient patient, List<Encounter> encounters, RCMRMT030101UK04EhrComposition composition, RCMRMT030101UK04LinkSet linkSet, String practiseCode) {
String id = linkSet.getId().getRoot();
Condition condition = (Condition) new Condition().addIdentifier(buildIdentifier(id, practiseCode)).addCategory(generateCategory()).setId(id).setMeta(generateMeta(META_PROFILE));
buildClinicalStatus(linkSet.getCode()).ifPresentOrElse(condition::setClinicalStatus, () -> {
condition.setClinicalStatus(ACTIVE);
condition.addNote(new Annotation(new StringType(DEFAULT_CLINICAL_STATUS)));
});
condition.setSubject(new Reference(patient));
condition.addExtension(buildProblemSignificance(linkSet.getCode()));
generateAnnotationToMinor(linkSet.getCode()).ifPresent(condition::addNote);
buildContext(composition, encounters).ifPresent(condition::setContext);
buildOnsetDateTimeType(linkSet).ifPresent(condition::setOnset);
buildAbatementDateTimeType(linkSet.getEffectiveTime()).ifPresent(condition::setAbatement);
buildAssertedDateTimeType(composition).ifPresentOrElse(condition::setAssertedDateElement, () -> condition.setAssertedDateElement(parseToDateTimeType(ehrExtract.getAvailabilityTime().getValue())));
composition.getParticipant2().stream().findFirst().ifPresent(participant2 -> condition.setAsserter(new Reference(new IdType(ResourceType.Practitioner.name(), participant2.getAgentRef().getId().getRoot()))));
return condition;
}
Aggregations