Search in sources :

Example 36 with Medication

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

the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByDosageForm.

@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByDosageForm() {
    TokenAndListParam dosageFormCode = new TokenAndListParam();
    dosageFormCode.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
    when(fhirMedicationService.searchForMedications(isNull(), argThat(is(dosageFormCode)), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForMedication(null, dosageFormCode, null, 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)

Example 37 with Medication

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

the class MedicationFhirResourceProviderTest method getMedicationByUuid_shouldThrowResourceNotFoundException.

@Test(expected = ResourceNotFoundException.class)
public void getMedicationByUuid_shouldThrowResourceNotFoundException() {
    IdType id = new IdType();
    id.setValue(WRONG_MEDICATION_UUID);
    Medication medication = resourceProvider.getMedicationById(id);
    assertThat(medication, nullValue());
}
Also used : Medication(org.hl7.fhir.dstu3.model.Medication) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.Test)

Example 38 with Medication

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

the class MedicationFhirResourceProviderTest method createMedication_shouldCreateNewMedication.

@Test
public void createMedication_shouldCreateNewMedication() {
    when(fhirMedicationService.create(any(org.hl7.fhir.r4.model.Medication.class))).thenReturn(medication);
    MethodOutcome result = resourceProvider.createMedication(Medication30_40.convertMedication(medication));
    assertThat(result, notNullValue());
    assertThat(result.getCreated(), is(true));
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(medication.getId()));
}
Also used : Medication(org.hl7.fhir.dstu3.model.Medication) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.Test)

Example 39 with Medication

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

the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByCode.

@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByCode() {
    TokenAndListParam code = new TokenAndListParam();
    code.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
    when(fhirMedicationService.searchForMedications(argThat(is(code)), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForMedication(code, null, null, 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)

Example 40 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<Medication> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.get(0).fhirType(), equalTo(FhirConstants.MEDICATION));
}
Also used : 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