use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project nia-patient-switching-standard-adaptor by NHSDigital.
the class MedicationRequestOrderMapperTest method When_MappingPrescribeResourceWithAllOptionals_Expect_AllFieldsToBeMappedCorrectly.
@Test
public void When_MappingPrescribeResourceWithAllOptionals_Expect_AllFieldsToBeMappedCorrectly() {
var medicationStatement = unmarshallMedicationStatement("medicationStatementPrescribeAllOptionals.xml");
var prescribe = medicationStatement.getComponent().stream().filter(RCMRMT030101UK04Component2::hasEhrSupplyPrescribe).map(RCMRMT030101UK04Component2::getEhrSupplyPrescribe).findFirst();
when(medicationMapper.extractMedicationReference(any())).thenReturn(Optional.of(new Reference(new IdType(ResourceType.Medication.name(), MEDICATION_ID))));
assertThat(prescribe.isPresent()).isTrue();
var medicationRequest = medicationRequestOrderMapper.mapToOrderMedicationRequest(new RCMRMT030101UK04EhrExtract(), medicationStatement, prescribe.get(), PRACTISE_CODE);
assertCommonValues(medicationRequest);
medicationRequest.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescriptionType-1").forEach(extension -> assertPrescriptionType(extension, "Repeat"));
assertThat(medicationRequest.getBasedOnFirstRep().getReferenceElement().getIdPart()).isEqualTo(TEST_ID);
assertThat(medicationRequest.getNote().size()).isEqualTo(THREE);
assertThat(medicationRequest.getDosageInstructionFirstRep().getText()).isEqualTo(TAKE_ONE_DAILY);
assertThat(medicationRequest.getDispenseRequest().getQuantity().getValue().intValue()).isEqualTo(SEVEN);
assertThat(medicationRequest.getDispenseRequest().getValidityPeriod().getStartElement().getValue()).isEqualTo(DateFormatUtil.parseToDateTimeType(AVAILABILITY_TIME).getValue());
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT 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.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT 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.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT 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.fhir.r4.model.codesystems.ResourceTypes.MEDICATIONSTATEMENT in project nia-patient-switching-standard-adaptor by NHSDigital.
the class ResourceReferenceUtilTest method testMedicationResourcesReferencedAtEhrCompositionLevel.
@Test
public void testMedicationResourcesReferencedAtEhrCompositionLevel() {
final RCMRMT030101UK04EhrComposition ehrComposition = unmarshallEhrCompositionElement("ehr_composition_medication.xml");
List<Reference> references = new ArrayList<>();
resourceReferenceUtil.extractChildReferencesFromEhrComposition(ehrComposition, references);
assertThat(references.size()).isEqualTo(THREE);
assertThat(references.get(0).getReference()).isEqualTo("MedicationStatement/A0A70B62-2649-4C8F-B3AB-618B8257C942-MS");
assertThat(references.get(1).getReference()).isEqualTo("MedicationRequest/A0A70B62-2649-4C8F-B3AB-618B8257C942");
assertThat(references.get(2).getReference()).isEqualTo("MedicationRequest/9B4B797A-D674-4362-B666-2ADC8551EEDA");
}
Aggregations