use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMedicationParamIsSpecified.
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenMedicationParamIsSpecified() {
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
ReferenceAndListParam medicationParam = new ReferenceAndListParam();
medicationParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Medication.SP_RES_ID)));
IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, medicationParam, null, null, null);
List<MedicationRequest> resources = get(results, 1, 5);
assertThat(results, notNullValue());
assertThat(resources, hasSize(equalTo(1)));
assertThat(resources.get(0), notNullValue());
assertThat(resources.get(0).fhirType(), equalTo(FhirConstants.MEDICATION_REQUEST));
assertThat(resources.get(0).getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderTest method updateMedicationRequest_shouldUpdateMedicationRequest.
@Test
public void updateMedicationRequest_shouldUpdateMedicationRequest() {
when(fhirMedicationRequestService.update(eq(MEDICATION_REQUEST_UUID), any(org.hl7.fhir.r4.model.MedicationRequest.class))).thenReturn(medicationRequest);
MethodOutcome result = resourceProvider.updateMedicationRequest(new IdType().setValue(MEDICATION_REQUEST_UUID), MedicationRequest30_40.convertMedicationRequest(medicationRequest));
assertThat(result, notNullValue());
assertThat(result.getResource(), notNullValue());
assertThat(result.getResource().getIdElement().getIdPart(), equalTo(medicationRequest.getId()));
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestTranslatorImpl method toFhirResource.
@Override
public MedicationRequest toFhirResource(@Nonnull DrugOrder drugOrder) {
notNull(drugOrder, "The DrugOrder object should not be null");
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setId(drugOrder.getUuid());
medicationRequest.setStatus(statusTranslator.toFhirResource(drugOrder));
medicationRequest.setMedication(medicationReferenceTranslator.toFhirResource(drugOrder.getDrug()));
medicationRequest.setPriority(medicationRequestPriorityTranslator.toFhirResource(drugOrder.getUrgency()));
medicationRequest.setRequester(practitionerReferenceTranslator.toFhirResource(drugOrder.getOrderer()));
medicationRequest.setEncounter(encounterReferenceTranslator.toFhirResource(drugOrder.getEncounter()));
medicationRequest.setSubject(patientReferenceTranslator.toFhirResource(drugOrder.getPatient()));
medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
medicationRequest.addNote(new Annotation().setText(drugOrder.getCommentToFulfiller()));
medicationRequest.addReasonCode(conceptTranslator.toFhirResource(drugOrder.getOrderReason()));
medicationRequest.addDosageInstruction(dosageTranslator.toFhirResource(drugOrder));
if (drugOrder.getPreviousOrder() != null && (drugOrder.getAction() == Order.Action.DISCONTINUE || drugOrder.getAction() == Order.Action.REVISE)) {
medicationRequest.setPriorPrescription(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder())));
} else if (drugOrder.getPreviousOrder() != null && drugOrder.getAction() == Order.Action.RENEW) {
medicationRequest.setBasedOn(Collections.singletonList(createOrderReference(drugOrder.getPreviousOrder()).setIdentifier(orderIdentifierTranslator.toFhirResource(drugOrder.getPreviousOrder()))));
}
return medicationRequest;
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderWebTest method verifyUri.
private void verifyUri(String uri) throws Exception {
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setId(MEDICATION_REQUEST_UUID);
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
Bundle results = readBundleResponse(response);
assertThat(results.getEntry(), notNullValue());
assertThat(results.getEntry(), not(empty()));
assertThat(results.getEntry().get(0).getResource(), notNullValue());
assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderWebTest method verifyUri.
private void verifyUri(String uri) throws Exception {
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
Bundle results = readBundleResponse(response);
assertThat(results.getEntry(), notNullValue());
assertThat(results.getEntry(), not(empty()));
assertThat(results.getEntry().get(0).getResource(), notNullValue());
assertThat(results.getEntry().get(0).getResource().getIdElement().getIdPart(), equalTo(MEDICATION_REQUEST_UUID));
}
Aggregations