Search in sources :

Example 1 with OrderSelectContext

use of org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext in project CRD by HL7-DaVinci.

the class CrdRequestCreator method createOrderSelectRequest.

/**
 * Generate a order select request that contains a DeviceRequest.
 *
 * @param patientGender Desired gender of the patient in the request
 * @param patientBirthdate Desired birth date of the patient in the request
 * @return Fully populated CdsRequest
 */
public static OrderSelectRequest createOrderSelectRequest(Enumerations.AdministrativeGender patientGender, Date patientBirthdate, String patientAddressState, String providerAddressState, Coding requestCoding, Coding statementCoding) {
    OrderSelectRequest request = new OrderSelectRequest();
    request.setHook(Hook.ORDER_SELECT);
    request.setHookInstance(UUID.randomUUID().toString());
    OrderSelectContext context = new OrderSelectContext();
    request.setContext(context);
    context.setUserId("Practitioner/1234");
    Patient patient = createPatient(patientGender, patientBirthdate, patientAddressState);
    context.setPatientId(patient.getId());
    // create and build MedicationRequest
    MedicationRequest mr = new MedicationRequest();
    mr.setStatus(MedicationRequest.MedicationRequestStatus.DRAFT);
    mr.setId("MedicationRequest/123");
    mr.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
    PrefetchCallback callback = (p, c) -> {
        mr.setPerformer(new Reference(p));
        mr.addInsurance(new Reference(c));
    };
    mr.setSubject(new Reference(patient));
    Practitioner provider = createPractitioner();
    Bundle prefetchBundle = createPrefetchBundle(patient, provider, callback, providerAddressState);
    mr.setMedication(new CodeableConcept().addCoding(requestCoding));
    Bundle orderBundle = new Bundle();
    Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
    bec.setResource(mr);
    orderBundle.addEntry(bec);
    Bundle.BundleEntryComponent pfDrBec = new Bundle.BundleEntryComponent();
    pfDrBec.setResource(mr);
    prefetchBundle.addEntry(pfDrBec);
    context.setDraftOrders(orderBundle);
    context.setSelections(new String[] { "123" });
    Bundle prefetchMedicationStatementBundle = new Bundle();
    bec = new Bundle.BundleEntryComponent();
    bec.setResource(patient);
    prefetchMedicationStatementBundle.addEntry(bec);
    bec = new Bundle.BundleEntryComponent();
    MedicationStatement ms = new MedicationStatement();
    ms.setId("MedciationStatement/12345");
    ms.setMedication(new CodeableConcept().addCoding(statementCoding));
    bec.setResource(ms);
    prefetchMedicationStatementBundle.addEntry(bec);
    // add the prefetch into the request
    CrdPrefetch prefetch = new CrdPrefetch();
    prefetch.setMedicationRequestBundle(prefetchBundle);
    prefetch.setMedicationStatementBundle(prefetchMedicationStatementBundle);
    request.setPrefetch(prefetch);
    return request;
}
Also used : CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch) Logger(org.slf4j.Logger) OrderSignContext(org.hl7.davinci.r4.crdhook.ordersign.OrderSignContext) Date(java.util.Date) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) LoggerFactory(org.slf4j.LoggerFactory) UUID(java.util.UUID) OrderSignRequest(org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest) OrderSelectContext(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext) AddressUse(org.hl7.fhir.r4.model.Address.AddressUse) ArrayList(java.util.ArrayList) List(java.util.List) OrderSelectRequest(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest) Hook(org.cdshooks.Hook) AddressType(org.hl7.fhir.r4.model.Address.AddressType) OrderSelectRequest(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest) OrderSelectContext(org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext) CrdPrefetch(org.hl7.davinci.r4.crdhook.CrdPrefetch)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 UUID (java.util.UUID)1 Hook (org.cdshooks.Hook)1 CrdPrefetch (org.hl7.davinci.r4.crdhook.CrdPrefetch)1 OrderSelectContext (org.hl7.davinci.r4.crdhook.orderselect.OrderSelectContext)1 OrderSelectRequest (org.hl7.davinci.r4.crdhook.orderselect.OrderSelectRequest)1 OrderSignContext (org.hl7.davinci.r4.crdhook.ordersign.OrderSignContext)1 OrderSignRequest (org.hl7.davinci.r4.crdhook.ordersign.OrderSignRequest)1 org.hl7.fhir.r4.model (org.hl7.fhir.r4.model)1 AddressType (org.hl7.fhir.r4.model.Address.AddressType)1 AddressUse (org.hl7.fhir.r4.model.Address.AddressUse)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1