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;
}
Aggregations