Search in sources :

Example 36 with FhirTask

use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method saveTask_shouldCreateNewTask.

@Test
public void saveTask_shouldCreateNewTask() {
    org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
    FhirTask openmrsTask = new FhirTask();
    fhirTask.setStatus(FHIR_TASK_STATUS);
    fhirTask.setIntent(FHIR_TASK_INTENT);
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setStatus(OPENMRS_TASK_STATUS);
    openmrsTask.setIntent(OPENMRS_TASK_INTENT);
    when(translator.toOpenmrsType(fhirTask)).thenReturn(openmrsTask);
    when(dao.createOrUpdate(openmrsTask)).thenReturn(openmrsTask);
    when(translator.toFhirResource(openmrsTask)).thenReturn(fhirTask);
    org.hl7.fhir.r4.model.Task result = fhirTaskService.create(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)

Example 37 with FhirTask

use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method updateTask_shouldThrowResourceNotFoundIfTaskDoesNotExist.

@Test(expected = ResourceNotFoundException.class)
public void updateTask_shouldThrowResourceNotFoundIfTaskDoesNotExist() {
    org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
    fhirTask.setId(WRONG_TASK_UUID);
    when(dao.get(WRONG_TASK_UUID)).thenReturn(null);
    fhirTaskService.update(WRONG_TASK_UUID, fhirTask);
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Example 38 with FhirTask

use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method searchForTasks_shouldReturnTasksByParameters.

@Test
public void searchForTasks_shouldReturnTasksByParameters() {
    List<FhirTask> openmrsTasks = new ArrayList<>();
    FhirTask openmrsTask = new FhirTask();
    openmrsTask.setUuid(TASK_UUID);
    openmrsTasks.add(openmrsTask);
    Task task = new Task();
    task.setId(TASK_UUID);
    SearchParameterMap theParams = new SearchParameterMap();
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(TASK_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(openmrsTasks);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, fhirGlobalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(openmrsTask)).thenReturn(task);
    IBundleProvider results = fhirTaskService.searchForTasks(null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(TASK_UUID))));
}
Also used : Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTask(org.openmrs.module.fhir2.model.FhirTask) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 39 with FhirTask

use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method updateTask_shouldThrowInvalidRequestForUuidMismatch.

@Test(expected = InvalidRequestException.class)
public void updateTask_shouldThrowInvalidRequestForUuidMismatch() {
    org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
    fhirTask.setId(TASK_UUID);
    fhirTaskService.update(WRONG_TASK_UUID, fhirTask);
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Example 40 with FhirTask

use of org.openmrs.module.fhir2.model.FhirTask in project openmrs-module-fhir2 by openmrs.

the class FhirTaskServiceImplTest method updateTask_shouldThrowInvalidRequestForMissingUuid.

@Test(expected = InvalidRequestException.class)
public void updateTask_shouldThrowInvalidRequestForMissingUuid() {
    org.hl7.fhir.r4.model.Task fhirTask = new org.hl7.fhir.r4.model.Task();
    fhirTaskService.update(TASK_UUID, fhirTask);
}
Also used : Task(org.hl7.fhir.r4.model.Task) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Test(org.junit.Test)

Aggregations

FhirTask (org.openmrs.module.fhir2.model.FhirTask)66 Test (org.junit.Test)57 Task (org.hl7.fhir.r4.model.Task)47 FhirReference (org.openmrs.module.fhir2.model.FhirReference)16 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)10 Reference (org.hl7.fhir.r4.model.Reference)9 Concept (org.openmrs.Concept)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)7 Date (java.util.Date)5 FhirTaskInput (org.openmrs.module.fhir2.model.FhirTaskInput)4 FhirTaskOutput (org.openmrs.module.fhir2.model.FhirTaskOutput)4 Coding (org.hl7.fhir.r4.model.Coding)3 StringType (org.hl7.fhir.r4.model.StringType)3 ArrayList (java.util.ArrayList)2 Identifier (org.hl7.fhir.r4.model.Identifier)2 Provenance (org.hl7.fhir.r4.model.Provenance)2 Before (org.junit.Before)2 HibernateConceptDAO (org.openmrs.api.db.hibernate.HibernateConceptDAO)2 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)1 Collection (java.util.Collection)1