Search in sources :

Example 6 with Medication

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

the class EncounterSearchQueryTest method searchForEncounters_shouldHandleMultipleReverseIncludes.

@Test
public void searchForEncounters_shouldHandleMultipleReverseIncludes() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(ENCOUNTER_UUID));
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("ServiceRequest:encounter"));
    revIncludes.add(new Include("MedicationRequest:encounter"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    // reverse included resources (8 medication request + 3 service request) added as part of the result list
    assertThat(resultList.size(), equalTo(12));
    assertThat(resultList.subList(1, 12), everyItem(allOf(anyOf(is(instanceOf(MedicationRequest.class)), is(instanceOf(ServiceRequest.class))), hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID)))))));
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 7 with Medication

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

the class FhirMedicationServiceImplTest method setup.

@Before
public void setup() {
    fhirMedicationService = new FhirMedicationServiceImpl() {

        @Override
        protected void validateObject(Drug object) {
        }
    };
    fhirMedicationService.setTranslator(medicationTranslator);
    fhirMedicationService.setDao(medicationDao);
    fhirMedicationService.setSearchQuery(searchQuery);
    fhirMedicationService.setSearchQueryInclude(searchQueryInclude);
    medication = new Medication();
    medication.setId(MEDICATION_UUID);
    drug = new Drug();
    drug.setUuid(MEDICATION_UUID);
}
Also used : Drug(org.openmrs.Drug) Medication(org.hl7.fhir.r4.model.Medication) Before(org.junit.Before)

Example 8 with Medication

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

the class FhirMedicationServiceImplTest method updateMedication_shouldThrowInvalidRequestException.

@Test(expected = InvalidRequestException.class)
public void updateMedication_shouldThrowInvalidRequestException() {
    Medication medication = new Medication();
    medication.setId(MEDICATION_UUID);
    fhirMedicationService.update(WRONG_MEDICATION_UUID, medication);
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) Test(org.junit.Test)

Example 9 with Medication

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

the class FhirMedicationServiceImplTest method searchForMedications_shouldSearchMedicationsByDosageForm.

@Test
public void searchForMedications_shouldSearchMedicationsByDosageForm() {
    List<Drug> medications = new ArrayList<>();
    medications.add(drug);
    TokenAndListParam dosageForm = new TokenAndListParam();
    dosageForm.addAnd(new TokenOrListParam().addOr(new TokenParam().setValue(CODE)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DOSAGE_FORM_SEARCH_HANDLER, dosageForm);
    when(medicationDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(MEDICATION_UUID));
    when(medicationDao.getSearchResults(any(), any())).thenReturn(medications);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, medicationDao, medicationTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
    IBundleProvider result = fhirMedicationService.searchForMedications(null, dosageForm, null, null, null, null);
    List<IBaseResource> resultList = get(result);
    assertThat(result, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : Drug(org.openmrs.Drug) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 10 with Medication

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

the class FhirMedicationServiceImplTest method getMedicationByUuid_shouldGetMedicationByUuid.

@Test
public void getMedicationByUuid_shouldGetMedicationByUuid() {
    when(medicationDao.get(MEDICATION_UUID)).thenReturn(drug);
    when(medicationTranslator.toFhirResource(drug)).thenReturn(medication);
    Medication medication = fhirMedicationService.get(MEDICATION_UUID);
    assertThat(medication, notNullValue());
    assertThat(medication.getId(), notNullValue());
    assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) 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