Search in sources :

Example 51 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnConditionByOnsetDate.

@Test
public void searchForObsConditions_shouldReturnConditionByOnsetDate() {
    DateRangeParam onsetDate = new DateRangeParam(new DateParam("eq" + ONSET_DATE_TIME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "obsDatetime", onsetDate);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getOnsetDateTimeType().getValue().toString(), containsString(ONSET_DATE));
    assertThat(resultList.size(), equalTo(2));
}
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) DateParam(ca.uhn.fhir.rest.param.DateParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 52 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated.

@Test
public void searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(EXISTING_OBS_CONDITION_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Condition(org.hl7.fhir.r4.model.Condition) 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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 53 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnConditionByCode.

@Test
public void searchForObsConditions_shouldReturnConditionByCode() {
    TokenAndListParam listParam = new TokenAndListParam();
    listParam.addValue(new TokenOrListParam().add(new TokenParam(CODE_SYSTEM_1, CODE_VALUE_1)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getCode().getCodingFirstRep().getCode(), equalTo(CONCEPT_ID_1));
    assertThat(resultList.size(), equalTo(2));
}
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) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 54 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method getTask_shouldRetrieveTaskByUuid.

@Test
public void getTask_shouldRetrieveTaskByUuid() {
    FhirTask task = new FhirTask();
    org.hl7.fhir.r4.model.Task translatedTask = new org.hl7.fhir.r4.model.Task();
    task.setUuid(TASK_UUID);
    translatedTask.setId(TASK_UUID);
    when(dao.get(TASK_UUID)).thenReturn(task);
    when(translator.toFhirResource(task)).thenReturn(translatedTask);
    org.hl7.fhir.r4.model.Task result = fhirTaskService.get(TASK_UUID);
    assertThat(result, notNullValue());
    assertThat(result, equalTo(translatedTask));
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Example 55 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method updateTask_shouldUpdateExistingTask.

@Test
public void updateTask_shouldUpdateExistingTask() {
    org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
    FhirTask openmrsTask = new FhirTask();
    FhirTask updatedOpenmrsTask = new FhirTask();
    fhirTask.setId(TASK_UUID);
    fhirTask.setStatus(FHIR_NEW_TASK_STATUS);
    fhirTask.setIntent(FHIR_TASK_INTENT);
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setStatus(OPENMRS_TASK_STATUS);
    openmrsTask.setIntent(OPENMRS_TASK_INTENT);
    updatedOpenmrsTask.setUuid(TASK_UUID);
    updatedOpenmrsTask.setStatus(OPENMRS_NEW_TASK_STATUS);
    openmrsTask.setIntent(OPENMRS_TASK_INTENT);
    when(translator.toOpenmrsType(openmrsTask, fhirTask)).thenReturn(updatedOpenmrsTask);
    when(dao.createOrUpdate(updatedOpenmrsTask)).thenReturn(updatedOpenmrsTask);
    when(dao.get(TASK_UUID)).thenReturn(openmrsTask);
    when(translator.toFhirResource(updatedOpenmrsTask)).thenReturn(fhirTask);
    org.hl7.fhir.r4.model.Task result = fhirTaskService.update(TASK_UUID, fhirTask);
    assertThat(result, notNullValue());
    assertThat(result, equalTo(fhirTask));
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)427 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)104 ArrayList (java.util.ArrayList)101 IOException (java.io.IOException)78 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)65 List (java.util.List)64 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 FileOutputStream (java.io.FileOutputStream)59 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 File (java.io.File)57 InputStream (java.io.InputStream)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Bundle (org.hl7.fhir.dstu3.model.Bundle)48 MethodSource (org.junit.jupiter.params.provider.MethodSource)46 Arrays (java.util.Arrays)45 Collectors (java.util.stream.Collectors)45