Search in sources :

Example 36 with MEDICATIONSTATEMENT

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());
}
Also used : RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) Reference(org.hl7.fhir.dstu3.model.Reference) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Example 37 with MEDICATIONSTATEMENT

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);
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) Reference(org.hl7.fhir.dstu3.model.Reference) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Example 38 with MEDICATIONSTATEMENT

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;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) MedicationMapperUtils.buildPrescriptionTypeExtension(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildPrescriptionTypeExtension) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) ArrayList(java.util.ArrayList)

Example 39 with MEDICATIONSTATEMENT

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;
}
Also used : RCMRMT030101UK04Component3(org.hl7.v3.RCMRMT030101UK04Component3) RCMRMT030101UK04EhrFolder(org.hl7.v3.RCMRMT030101UK04EhrFolder) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) RCMRMT030101UK04Prescribe(org.hl7.v3.RCMRMT030101UK04Prescribe) DateFormatUtil(uk.nhs.adaptors.pss.translator.util.DateFormatUtil) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) UNK(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementTaken.UNK) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) MedicationMapperUtils.extractEhrSupplyAuthoriseId(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.extractEhrSupplyAuthoriseId) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) Service(org.springframework.stereotype.Service) RCMRMT030101UK04EhrExtract(org.hl7.v3.RCMRMT030101UK04EhrExtract) MedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement) COMPLETED(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.COMPLETED) MedicationMapperUtils.buildDispenseRequestPeriodEnd(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildDispenseRequestPeriodEnd) ACTIVE(org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.ACTIVE) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Reference(org.hl7.fhir.dstu3.model.Reference) MedicationMapperUtils.buildDosage(uk.nhs.adaptors.pss.translator.mapper.medication.MedicationMapperUtils.buildDosage) RCMRMT030101UK04EhrComposition(org.hl7.v3.RCMRMT030101UK04EhrComposition) RCMRMT030101UK04MedicationStatement(org.hl7.v3.RCMRMT030101UK04MedicationStatement) RCMRMT030101UK04Authorise(org.hl7.v3.RCMRMT030101UK04Authorise) Objects(java.util.Objects) TS(org.hl7.v3.TS) List(java.util.List) RCMRMT030101UK04Component(org.hl7.v3.RCMRMT030101UK04Component) Optional(java.util.Optional) ResourceUtil.generateMeta(uk.nhs.adaptors.pss.translator.util.ResourceUtil.generateMeta) Comparator(java.util.Comparator) AllArgsConstructor(lombok.AllArgsConstructor) ResourceUtil.buildIdentifier(uk.nhs.adaptors.pss.translator.util.ResourceUtil.buildIdentifier) Extension(org.hl7.fhir.dstu3.model.Extension) Reference(org.hl7.fhir.dstu3.model.Reference) MedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement) RCMRMT030101UK04MedicationStatement(org.hl7.v3.RCMRMT030101UK04MedicationStatement) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 40 with MEDICATIONSTATEMENT

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");
}
Also used : RCMRMT030101UK04EhrComposition(org.hl7.v3.RCMRMT030101UK04EhrComposition) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ArrayList (java.util.ArrayList)11 MedicationStatement (org.hl7.fhir.r4.model.MedicationStatement)9 Test (org.junit.jupiter.api.Test)9 Coding (org.hl7.fhir.r4.model.Coding)8 Reference (org.hl7.fhir.dstu3.model.Reference)6 IdType (org.hl7.fhir.dstu3.model.IdType)5 Date (java.util.Date)4 RCMRMT030101UK04Component2 (org.hl7.v3.RCMRMT030101UK04Component2)4 RCMRMT030101UK04EhrExtract (org.hl7.v3.RCMRMT030101UK04EhrExtract)4 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)3 Extension (org.hl7.fhir.dstu3.model.Extension)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)2 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 Condition (org.hl7.fhir.r4.model.Condition)2