use of org.hl7.fhir.r4.model.MedicationRequest in project elexis-server by elexis.
the class MedicationRequestTest method updateMedicationRequest.
@Test
public void updateMedicationRequest() {
// load existing order
Bundle results = client.search().forResource(MedicationRequest.class).where(MedicationRequest.PATIENT.hasId(patient.getId())).returnBundle(Bundle.class).execute();
assertNotNull(results);
List<BundleEntryComponent> entries = results.getEntry();
assertFalse(entries.isEmpty());
Optional<MedicationRequest> activeOrder = getActiveOrderWithDosage(entries);
assertTrue(activeOrder.isPresent());
MedicationRequest updateOrder = activeOrder.get();
updateOrder.getDosageInstruction().get(0).setText("test");
List<Extension> entryTypes = updateOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
assertEquals(EntryType.FIXED_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
entryTypes.get(0).setValue(new CodeType(EntryType.SYMPTOMATIC_MEDICATION.name()));
// update the medication
MethodOutcome outcome = client.update().resource(updateOrder).execute();
// read and validate change
MedicationRequest oldOrder = client.read().resource(MedicationRequest.class).withId(activeOrder.get().getId()).execute();
assertNotNull(oldOrder);
MedicationRequest newOrder = client.read().resource(MedicationRequest.class).withId(outcome.getId()).execute();
assertNotNull(newOrder);
assertEquals(MedicationRequestStatus.COMPLETED, oldOrder.getStatus());
assertEquals(MedicationRequestStatus.ACTIVE, newOrder.getStatus());
assertEquals("test", newOrder.getDosageInstruction().get(0).getText());
entryTypes = newOrder.getExtensionsByUrl("www.elexis.info/extensions/prescription/entrytype");
assertEquals(EntryType.SYMPTOMATIC_MEDICATION.name(), ((CodeType) entryTypes.get(0).getValue()).getValue());
}
use of org.hl7.fhir.r4.model.MedicationRequest in project elexis-server by elexis.
the class MedicationRequestTest method getMedicationRequest.
@Test
public void getMedicationRequest() {
// test with full id url
Bundle results = client.search().forResource(MedicationRequest.class).where(MedicationRequest.PATIENT.hasId(patient.getId())).returnBundle(Bundle.class).execute();
assertNotNull(results);
List<BundleEntryComponent> entries = results.getEntry();
assertFalse(entries.isEmpty());
MedicationRequest order = (MedicationRequest) entries.get(0).getResource();
// read
MedicationRequest readOrder = client.read().resource(MedicationRequest.class).withId(order.getId()).execute();
assertNotNull(readOrder);
assertEquals(order.getId(), readOrder.getId());
// test with id part only
results = client.search().forResource(MedicationRequest.class).where(MedicationRequest.PATIENT.hasId(patient.getIdElement().getIdPart())).returnBundle(Bundle.class).execute();
assertNotNull(results);
entries = results.getEntry();
assertFalse(entries.isEmpty());
MedicationRequest foundOrder = (MedicationRequest) entries.get(0).getResource();
assertEquals(order.getId(), foundOrder.getId());
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLastUpdatedIsSpecified.
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenLastUpdatedIsSpecified() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
IBundleProvider results = resourceProvider.searchForMedicationRequests(null, null, null, null, null, null, null, lastUpdated, null);
List<IBaseResource> resources = getResources(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 getMedicationRequestByUuid_shouldReturnMatchingMedicationRequest.
@Test
public void getMedicationRequestByUuid_shouldReturnMatchingMedicationRequest() {
when(fhirMedicationRequestService.get(MEDICATION_REQUEST_UUID)).thenReturn(medicationRequest);
IdType id = new IdType();
id.setValue(MEDICATION_REQUEST_UUID);
MedicationRequest medicationRequest = resourceProvider.getMedicationRequestByUuid(id);
assertThat(medicationRequest, notNullValue());
assertThat(medicationRequest.getId(), notNullValue());
assertThat(medicationRequest.getId(), equalTo(MEDICATION_REQUEST_UUID));
}
use of org.hl7.fhir.r4.model.MedicationRequest in project openmrs-module-fhir2 by openmrs.
the class MedicationRequestFhirResourceProviderTest method searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPatientParamIsSpecified.
@Test
public void searchMedicationRequest_shouldReturnMatchingMedicationRequestWhenPatientParamIsSpecified() {
when(fhirMedicationRequestService.searchForMedicationRequests(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medicationRequest), 10, 1));
ReferenceAndListParam patientParam = new ReferenceAndListParam();
patientParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)));
IBundleProvider results = resourceProvider.searchForMedicationRequests(patientParam, null, null, null, null, null, null, null, null);
List<IBaseResource> resources = getResources(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));
}
Aggregations