Search in sources :

Example 66 with MedicationRequest

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());
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) CodeType(org.hl7.fhir.r4.model.CodeType) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.Test)

Example 67 with MedicationRequest

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());
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Test(org.junit.Test)

Example 68 with MedicationRequest

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));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.Test)

Example 69 with MedicationRequest

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));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 70 with MedicationRequest

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));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Test(org.junit.Test)

Aggregations

MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)128 Test (org.junit.Test)128 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)36 Test (org.junit.jupiter.api.Test)35 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 Resource (org.hl7.fhir.r4.model.Resource)31 MedicationRequest (org.hl7.fhir.dstu3.model.MedicationRequest)26 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)23 TokenParam (ca.uhn.fhir.rest.param.TokenParam)23 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)23 ArrayList (java.util.ArrayList)19 Include (ca.uhn.fhir.model.api.Include)15 HashSet (java.util.HashSet)15