Search in sources :

Example 46 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskTranslatorImpl method toFhirResource.

@Override
public Task toFhirResource(@Nonnull FhirTask openmrsTask) {
    notNull(openmrsTask, "The openmrsTask object should not be null");
    Task fhirTask = new Task();
    setFhirTaskFields(openmrsTask, fhirTask);
    fhirTask.addContained(provenanceTranslator.getCreateProvenance(openmrsTask));
    fhirTask.addContained(provenanceTranslator.getUpdateProvenance(openmrsTask));
    return fhirTask;
}
Also used : Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask)

Example 47 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class BaseServiceRequestTranslator method determineServiceRequestPerformer.

protected Reference determineServiceRequestPerformer(String orderUuid) {
    IBundleProvider results = taskService.searchForTasks(new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("ServiceRequest", null, orderUuid))), null, null, null, null, null, null);
    Collection<Task> serviceRequestTasks = results.getResources(START_INDEX, END_INDEX).stream().map(p -> (Task) p).collect(Collectors.toList());
    if (serviceRequestTasks.size() != 1) {
        return null;
    }
    return serviceRequestTasks.iterator().next().getOwner();
}
Also used : ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Setter(lombok.Setter) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Reference(org.hl7.fhir.r4.model.Reference) Collectors(java.util.stream.Collectors) Task(org.hl7.fhir.r4.model.Task) AccessLevel(lombok.AccessLevel) FhirTaskService(org.openmrs.module.fhir2.api.FhirTaskService) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Task(org.hl7.fhir.r4.model.Task) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam)

Example 48 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceProviderWebTest method updateTask_shouldErrorForNonexistentTask.

@Test
public void updateTask_shouldErrorForNonexistentTask() throws Exception {
    String jsonTask;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_TASK_WRONG_ID_PATH)) {
        Objects.requireNonNull(is);
        jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    when(service.update(eq(WRONG_TASK_UUID), any(org.hl7.fhir.r4.model.Task.class))).thenThrow(new MethodNotAllowedException("Can't find Task"));
    MockHttpServletResponse response = put("/Task/" + WRONG_TASK_UUID).jsonContent(jsonTask).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isMethodNotAllowed());
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) MethodNotAllowedException(ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 49 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceProviderWebTest method updateTask_shouldUpdateExistingTask.

@Test
public void updateTask_shouldUpdateExistingTask() throws Exception {
    String jsonTask;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_TASK_PATH)) {
        Objects.requireNonNull(is);
        jsonTask = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    when(service.update(anyString(), any(org.hl7.fhir.r4.model.Task.class))).thenReturn(task);
    MockHttpServletResponse response = put("/Task/" + TASK_UUID).jsonContent(jsonTask).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 50 with Task

use of org.hl7.fhir.r5.model.Task in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceProviderWebTest method deleteTask_shouldDeleteTask.

@Test
public void deleteTask_shouldDeleteTask() throws Exception {
    Task task = new Task();
    task.setId(TASK_UUID);
    task.setStatus(Task.TaskStatus.ACCEPTED);
    when(service.delete(any(String.class))).thenReturn(TaskVersionConverter.convertTask(task));
    MockHttpServletResponse response = delete("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)127 Task (org.hl7.fhir.r4.model.Task)120 FhirTask (org.openmrs.module.fhir2.model.FhirTask)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Bundle (org.hl7.fhir.r4.model.Bundle)40 Reference (org.hl7.fhir.r4.model.Reference)28 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)24 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)23 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)22 Task (org.hl7.fhir.dstu3.model.Task)21 IdType (org.hl7.fhir.r4.model.IdType)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 Date (java.util.Date)16 ArrayList (java.util.ArrayList)13 List (java.util.List)13 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)13 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)11 Collectors (java.util.stream.Collectors)11