Search in sources :

Example 1 with RCMRMT030101UK04MedicationStatement

use of org.hl7.v3.RCMRMT030101UK04MedicationStatement in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationRequestOrderMapper method mapToOrderMedicationRequest.

public MedicationRequest mapToOrderMedicationRequest(RCMRMT030101UK04EhrExtract ehrExtract, RCMRMT030101UK04MedicationStatement medicationStatement, RCMRMT030101UK04Prescribe supplyPrescribe, String practiseCode) {
    var ehrSupplyPrescribeIdExtract = extractEhrSupplyPrescribeId(supplyPrescribe);
    var inFulfillmentOfId = extractInFulfillmentOfId(supplyPrescribe);
    if (ehrSupplyPrescribeIdExtract.isPresent()) {
        var ehrSupplyPrescribeId = ehrSupplyPrescribeIdExtract.get();
        MedicationRequest medicationRequest = createMedicationRequestSkeleton(ehrSupplyPrescribeId);
        medicationRequest.addIdentifier(buildIdentifier(ehrSupplyPrescribeId, practiseCode));
        medicationRequest.setStatus(COMPLETED);
        medicationRequest.setIntent(ORDER);
        medicationRequest.addDosageInstruction(buildDosage(medicationStatement.getPertinentInformation()));
        medicationRequest.setDispenseRequest(buildDispenseRequestForPrescribe(supplyPrescribe));
        buildNotesForPrescribe(supplyPrescribe).forEach(medicationRequest::addNote);
        medicationMapper.extractMedicationReference(medicationStatement).ifPresent(medicationRequest::setMedication);
        inFulfillmentOfId.ifPresent(inFulfillmentId -> {
            var supplyAuthorise = extractSupplyAuthorise(ehrExtract, inFulfillmentId);
            buildPrescriptionTypeExtension(supplyAuthorise).ifPresent(medicationRequest::addExtension);
            medicationRequest.addBasedOn(buildMedicationRequestReference(inFulfillmentId));
        });
        return medicationRequest;
    }
    return null;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest)

Example 2 with RCMRMT030101UK04MedicationStatement

use of org.hl7.v3.RCMRMT030101UK04MedicationStatement 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 3 with RCMRMT030101UK04MedicationStatement

use of org.hl7.v3.RCMRMT030101UK04MedicationStatement 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)

Aggregations

Extension (org.hl7.fhir.dstu3.model.Extension)2 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 AllArgsConstructor (lombok.AllArgsConstructor)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)1 IdType (org.hl7.fhir.dstu3.model.IdType)1 MedicationStatement (org.hl7.fhir.dstu3.model.MedicationStatement)1 ACTIVE (org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.ACTIVE)1 COMPLETED (org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus.COMPLETED)1 UNK (org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementTaken.UNK)1 Reference (org.hl7.fhir.dstu3.model.Reference)1 ResourceType (org.hl7.fhir.dstu3.model.ResourceType)1 RCMRMT030101UK04Authorise (org.hl7.v3.RCMRMT030101UK04Authorise)1 RCMRMT030101UK04Component (org.hl7.v3.RCMRMT030101UK04Component)1