Search in sources :

Example 1 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project gpconnect-demonstrator by nhsconnect.

the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.

private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
    MedicationRequest medicationOrder = new MedicationRequest();
    String resourceId = String.valueOf(medicationOrderDetails.getId());
    String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
    String resourceType = medicationOrder.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    medicationOrder.setId(id);
    medicationOrder.getMeta().setVersionId(versionId);
    medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
    switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
        case "active":
            medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
            break;
        case "completed":
            medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
            break;
        case "draft":
            medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
            break;
        case "entered_in_error":
            medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
            break;
        case "on_hold":
            medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
            break;
        case "stopped":
            medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
            break;
    }
    if (medicationOrderDetails.getPatientId() != null) {
        medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
    } else {
        medicationOrder.setSubject(new Reference());
    }
    medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
    medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
    medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
    MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
    dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
    dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
    dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
    medicationOrder.setDispenseRequest(dispenseRequest);
    return medicationOrder;
}
Also used : DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) MedicationRequestDispenseRequestComponent(org.hl7.fhir.dstu3.model.MedicationRequest.MedicationRequestDispenseRequestComponent) StringDt(ca.uhn.fhir.model.primitive.StringDt)

Example 2 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project gpconnect-demonstrator by nhsconnect.

the class MedicationRequestResourceProvider method getMedicationRequestFromDetail.

private MedicationRequest getMedicationRequestFromDetail(MedicationRequestDetail requestDetail) {
    MedicationRequest medicationRequest = new MedicationRequest();
    medicationRequest.setId(requestDetail.getId().toString());
    List<Identifier> identifiers = new ArrayList<>();
    Identifier identifier = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(requestDetail.getGuid());
    identifiers.add(identifier);
    medicationRequest.setIdentifier(identifiers);
    medicationRequest.setMeta(new Meta().addProfile(SystemURL.SD_GPC_MEDICATION_REQUEST));
    setBasedOnReferences(medicationRequest, requestDetail);
    if (requestDetail.getPrescriptionTypeCode().contains("repeat")) {
        medicationRequest.setGroupIdentifier(new Identifier().setValue(requestDetail.getGroupIdentifier()));
    }
    try {
        medicationRequest.setStatus(MedicationRequestStatus.fromCode(requestDetail.getStatusCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    try {
        medicationRequest.setIntent(MedicationRequestIntent.fromCode(requestDetail.getIntentCode()));
    } catch (FHIRException e) {
        throw new UnprocessableEntityException(e.getMessage());
    }
    if (requestDetail.getMedicationId() != null) {
        medicationRequest.setMedication(new Reference(new IdType("Medication", requestDetail.getMedicationId())));
    }
    if (requestDetail.getPatientId() != null) {
        medicationRequest.setSubject(new Reference(new IdType("Patient", requestDetail.getPatientId())));
    }
    if (requestDetail.getAuthorisingPractitionerId() != null) {
        medicationRequest.setRecorder(new Reference(new IdType("Practitioner", requestDetail.getAuthorisingPractitionerId())));
    }
    if (requestDetail.getPriorMedicationRequestId() != null) {
        medicationRequest.setPriorPrescription(new Reference(new IdType("MedicationRequest", requestDetail.getPriorMedicationRequestId())));
    }
    medicationRequest.setAuthoredOn(requestDetail.getAuthoredOn());
    medicationRequest.setDispenseRequest(getDispenseRequestComponent(requestDetail));
    // medicationRequest.setRequester(getRequesterComponent(requestDetail)); //TODO - spec needs to clarify whether this should be populated or not
    setReasonCodes(medicationRequest, requestDetail);
    setNotes(medicationRequest, requestDetail);
    if (medicationRequest.getIntent() != MedicationRequestIntent.ORDER) {
        setRepeatInformation(medicationRequest, requestDetail);
    }
    setPrescriptionType(medicationRequest, requestDetail);
    setStatusReason(medicationRequest, requestDetail);
    String dosageInstructionText = requestDetail.getDosageText();
    medicationRequest.addDosageInstruction(new Dosage().setText(dosageInstructionText == null || dosageInstructionText.trim().isEmpty() ? NO_INFORMATION_AVAILABLE : dosageInstructionText).setPatientInstruction(requestDetail.getDosageInstructions()));
    return medicationRequest;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project gpconnect-demonstrator by nhsconnect.

the class PopulateMedicationBundle method getPractitionerIds.

private Set<String> getPractitionerIds(MedicationStatement medStatement, List<MedicationRequest> allMedReqs) {
    Set<String> practitionerIds = new HashSet<>();
    medStatement.getNote().forEach(note -> {
        try {
            if (note.getAuthorReference() != null && note.getAuthorReference().getReference() != null && note.getAuthorReference().getReference().startsWith("Practitioner")) {
                String[] split = note.getAuthorReference().getReference().split("/");
                practitionerIds.add(split[1]);
            }
        } catch (FHIRException e) {
            throw new UnprocessableEntityException(e.getMessage());
        }
    });
    allMedReqs.forEach(medReq -> {
        medReq.getNote().forEach(note -> {
            try {
                if (note.getAuthorReference() != null && note.getAuthorReference().getReference() != null && note.getAuthorReference().getReference().startsWith("Practitioner")) {
                    String[] split = note.getAuthorReference().getReference().split("/");
                    practitionerIds.add(split[1]);
                }
            } catch (FHIRException e) {
                throw new UnprocessableEntityException(e.getMessage());
            }
        });
        if (medReq.getRecorder() != null && medReq.getRecorder().getReference().startsWith("Practitioner")) {
            String[] split = medReq.getRecorder().getReference().split("/");
            practitionerIds.add(split[1]);
        }
    });
    return practitionerIds;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project bunsen by cerner.

the class TestData method newMedRequest.

/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {
    MedicationRequest medReq = new MedicationRequest();
    medReq.setId("test-med");
    // Medication code
    CodeableConcept med = new CodeableConcept();
    med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
    med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
    medReq.setMedication(med);
    Annotation annotation = new Annotation();
    annotation.setText("Test medication note.");
    annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
    medReq.addNote(annotation);
    return medReq;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Reference(org.hl7.fhir.dstu3.model.Reference) Annotation(org.hl7.fhir.dstu3.model.Annotation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 5 with MedicationRequest

use of org.hl7.fhir.r4.model.MedicationRequest in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7IdentifierFHIRConversionTest method medicationRequestIdentifierTest5.

@Test
void medicationRequestIdentifierTest5() throws IOException {
    // Test: Visit number from PV1-19, extID from RXE-2.1 and RXE-2.3
    String medicationRequest = "MSH|^~\\&|PROSLOV|MYHOSPITAL|WHIA|IBM|20170215080000||RDE^O11^RDE_O11|MSGID005520|T|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "PID|1||000054321^^^MRN|||||||||||||||78654\r" + "PV1||I|||||||||||||||||789789\r" + "ORC|NW|||||E|10^BID^D4^^^R||20170215080000\r" + "RXE|^^^20170923230000^^R|999^Ampicillin 250 MG TAB^NDC|100||mg|123^test^ABC||||10||5|";
    MedicationRequest medReq = ResourceUtils.getMedicationRequest(ftv, medicationRequest);
    // Expect 2 identifiers
    assertThat(medReq.hasIdentifier()).isTrue();
    assertThat(medReq.getIdentifier()).hasSize(2);
    List<Identifier> identifiers = medReq.getIdentifier();
    // Match the id's to position; we can't depend on an order.
    int posVN = getIdentifierPositionByValue("789789", identifiers);
    assertThat(posVN).isNotSameAs(-1);
    int posExtId = getIdentifierPositionByValue("999-NDC", identifiers);
    assertThat(posExtId).isNotSameAs(-1);
    // Identifier 1: Visit number
    Identifier identifier = medReq.getIdentifier().get(posVN);
    String value = identifier.getValue();
    String system = identifier.getSystem();
    // PV1.19
    assertThat(value).isEqualTo("789789");
    assertThat(system).isNull();
    CodeableConcept type = identifier.getType();
    DatatypeUtils.checkCommonCodeableConceptAssertions(type, "VN", "Visit number", "http://terminology.hl7.org/CodeSystem/v2-0203", null);
    // Identifier 2: extID based on RXE-2.1 and RXE-2.3
    identifier = medReq.getIdentifier().get(posExtId);
    value = identifier.getValue();
    system = identifier.getSystem();
    // RXE-2.1 and RXE-2.3
    assertThat(value).isEqualTo("999-NDC");
    assertThat(system).isEqualTo("urn:id:extID");
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Identifier(org.hl7.fhir.r4.model.Identifier) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)128 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)125 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)78 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)58 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)44 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)44 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)44 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)34 Resource (org.hl7.fhir.r4.model.Resource)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)29 Test (org.junit.jupiter.api.Test)29 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)23 TokenParam (ca.uhn.fhir.rest.param.TokenParam)23 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)21 Include (ca.uhn.fhir.model.api.Include)15 HashSet (java.util.HashSet)15 Reference (org.hl7.fhir.r4.model.Reference)13