Search in sources :

Example 26 with Medication

use of org.hl7.fhir.r4.model.Medication in project elexis-server by elexis.

the class MedicationTest method loadArticleMedicationById.

@Test
public void loadArticleMedicationById() {
    Medication customArticle = client.read().resource(Medication.class).withId(ArticleTyp.EIGENARTIKEL + "." + AllTests.getTestDatabaseInitializer().getArticle().getId()).execute();
    assertNotNull(customArticle);
    System.out.println(FhirUtil.serializeToString(customArticle));
    Map<String, Coding> codeMap = parseCodeMap(customArticle);
    assertEquals("test article", codeMap.get(MedicamentCoding.NAME.getUrl()).getCode());
    assertEquals("0000001111111", codeMap.get(MedicamentCoding.GTIN.getOid()).getCode());
}
Also used : MedicamentCoding(ch.elexis.core.findings.util.fhir.MedicamentCoding) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.hl7.fhir.r4.model.Medication) Test(org.junit.Test)

Example 27 with Medication

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

the class MedicationFhirResourceProviderTest method searchForMedication_shouldReturnMatchingBundleOfMedicationByLastUpdated.

@Test
public void searchForMedication_shouldReturnMatchingBundleOfMedicationByLastUpdated() {
    DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE);
    when(fhirMedicationService.searchForMedications(isNull(), isNull(), isNull(), isNull(), argThat(is(lastUpdated)), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(medication), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForMedication(null, null, null, null, lastUpdated, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.iterator().next().fhirType(), equalTo(FhirConstants.MEDICATION));
}
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 28 with Medication

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

the class MedicationFhirResourceProviderTest method updateMedication_shouldThrowMethodNotAllowedIfDoesNotExist.

@Test(expected = MethodNotAllowedException.class)
public void updateMedication_shouldThrowMethodNotAllowedIfDoesNotExist() {
    Medication wrongMedication = new Medication();
    wrongMedication.setId(WRONG_MEDICATION_UUID);
    when(fhirMedicationService.update(WRONG_MEDICATION_UUID, wrongMedication)).thenThrow(MethodNotAllowedException.class);
    resourceProvider.updateMedication(new IdType().setValue(WRONG_MEDICATION_UUID), wrongMedication);
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 29 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.getMedicationByUuid(id);
    assertThat(medication, notNullValue());
    assertThat(medication.getId(), notNullValue());
    assertThat(medication.getId(), equalTo(MEDICATION_UUID));
}
Also used : Medication(org.hl7.fhir.r4.model.Medication) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 30 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<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.iterator().next().fhirType(), equalTo(FhirConstants.MEDICATION));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) 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)

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