Search in sources :

Example 31 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderTest method updateMedication_shouldUpdateRequestedMedication.

@Test
public void updateMedication_shouldUpdateRequestedMedication() {
    Medication med = medication;
    med.setStatus(Medication.MedicationStatus.INACTIVE);
    when(fhirMedicationService.update(MEDICATION_UUID, medication)).thenReturn(med);
    MethodOutcome result = resourceProvider.updateMedication(new IdType().setValue(MEDICATION_UUID), medication);
    assertThat(result, notNullValue());
    assertThat(result.getResource(), equalTo(med));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 32 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByUUID.

@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByUUID() {
    TokenAndListParam uuid = new TokenAndListParam();
    uuid.addAnd(new TokenParam().setValue(MEDICATION_UUID));
    when(fhirMedicationService.searchForMedications(isNull(), isNull(), isNull(), argThat(is(uuid)), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForMedication(null, null, null, uuid, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.iterator().next().fhirType(), equalTo(FhirConstants.MEDICATION));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Test(org.junit.Test)

Example 33 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderTest method searchForMedication_shouldNotAddResourcesForEmptyRevInclude.

@Test
public void searchForMedication_shouldNotAddResourcesForEmptyRevInclude() {
    when(fhirMedicationService.searchForMedications(any(), any(), any(), any(), any(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    HashSet<Include> revIncludes = new HashSet<>();
    IBundleProvider results = resourceProvider.searchForMedication(null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.MEDICATION));
    assertThat(((Medication) resultList.iterator().next()).getId(), equalTo(MEDICATION_UUID));
}
Also used : Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderTest method getMedicationByUuid_shouldReturnMatchingMedication.

@Test
public void getMedicationByUuid_shouldReturnMatchingMedication() {
    when(fhirMedicationService.get(MEDICATION_UUID)).thenReturn(medication);
    IdType id = new IdType();
    id.setValue(MEDICATION_UUID);
    Medication medication = resourceProvider.getMedicationById(id);
    assertThat(medication, notNullValue());
    assertThat(medication.getId(), notNullValue());
    assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
Also used : Medication(org.hl7.fhir.dstu3.model.Medication) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 35 with Medication

use of org.hl7.fhir.r4.model.Medication in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByIngredientCode.

@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByIngredientCode() {
    TokenAndListParam ingredientCode = new TokenAndListParam();
    ingredientCode.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
    when(fhirMedicationService.searchForMedications(isNull(), isNull(), argThat(is(ingredientCode)), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForMedication(null, null, ingredientCode, null, null, null);
    List<Medication> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.MEDICATION));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Medication(org.hl7.fhir.dstu3.model.Medication) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)112 Medication (org.hl7.fhir.r4.model.Medication)62 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)43 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)34 Medication (org.hl7.fhir.dstu3.model.Medication)33 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)30 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)24 TokenParam (ca.uhn.fhir.rest.param.TokenParam)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)20 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)19 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)18 InputStream (java.io.InputStream)17 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)14 Coding (org.hl7.fhir.r4.model.Coding)14 Date (java.util.Date)13 ArrayList (java.util.ArrayList)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)11