Search in sources :

Example 41 with Task

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

the class ProvenanceTranslatorImplTest method shouldGetCreateProvenanceForOpenmrsMetadata.

@Test
public void shouldGetCreateProvenanceForOpenmrsMetadata() {
    Provenance provenance = taskProvenanceTranslator.getCreateProvenance(task);
    assertThat(provenance, notNullValue());
    assertThat(provenance.getId(), notNullValue());
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Test(org.junit.Test)

Example 42 with Task

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

the class ServiceRequestTranslatorImplTest method toFhirResource_shouldTranslateToFhirResourceWithReplacesFieldGivenRevisedOrder.

@Test
public void toFhirResource_shouldTranslateToFhirResourceWithReplacesFieldGivenRevisedOrder() {
    discontinuedTestOrder.setAction(Order.Action.REVISE);
    List<Task> tasks = setUpBasedOnScenario(Task.TaskStatus.ACCEPTED);
    when(taskService.searchForTasks(any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(tasks, PREFERRED_PAGE_SIZE, COUNT));
    ServiceRequest result = translator.toFhirResource(discontinuedTestOrder);
    assertThat(result, notNullValue());
    assertThat(result.getId(), notNullValue());
    assertThat(result.getId(), equalTo(DISCONTINUED_TEST_ORDER_UUID));
    assertThat(result.getReplaces().get(0).getReference(), equalTo(PRIOR_SERVICE_REQUEST_REFERENCE));
    assertThat(result.getReplaces().get(0).getIdentifier().getValue(), equalTo(TEST_ORDER_NUMBER));
}
Also used : Task(org.hl7.fhir.r4.model.Task) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.Test) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 43 with Task

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

the class ServiceRequestTranslatorImplTest method setUpBasedOnScenario.

private List<Task> setUpBasedOnScenario(Task.TaskStatus status) {
    Reference basedOnRef = new Reference();
    Task task = new Task();
    task.setStatus(status);
    basedOnRef.setReference("ServiceRequest/" + SERVICE_REQUEST_UUID);
    basedOnRef.setType("ServiceRequest");
    task.addBasedOn(basedOnRef);
    return Collections.singletonList(task);
}
Also used : Task(org.hl7.fhir.r4.model.Task) Reference(org.hl7.fhir.r4.model.Reference)

Example 44 with Task

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

the class ServiceRequestTranslatorImplTest method toFhirResource_shouldTranslateToFhirResourceWithReplacesFieldGivenDiscontinuedOrder.

@Test
public void toFhirResource_shouldTranslateToFhirResourceWithReplacesFieldGivenDiscontinuedOrder() {
    discontinuedTestOrder.setAction(Order.Action.DISCONTINUE);
    List<Task> tasks = setUpBasedOnScenario(Task.TaskStatus.REJECTED);
    when(taskService.searchForTasks(any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(tasks, PREFERRED_PAGE_SIZE, COUNT));
    ServiceRequest result = translator.toFhirResource(discontinuedTestOrder);
    assertThat(result, notNullValue());
    assertThat(result.getId(), notNullValue());
    assertThat(result.getId(), equalTo(DISCONTINUED_TEST_ORDER_UUID));
    assertThat(result.getReplaces().get(0).getReference(), equalTo(PRIOR_SERVICE_REQUEST_REFERENCE));
    assertThat(result.getReplaces().get(0).getIdentifier().getValue(), equalTo(TEST_ORDER_NUMBER));
}
Also used : Task(org.hl7.fhir.r4.model.Task) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.Test) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 45 with Task

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

the class ServiceRequestTranslatorImpl method determineServiceRequestPerformer.

private 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 : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Setter(lombok.Setter) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) Reference(org.hl7.fhir.r4.model.Reference) OrderIdentifierTranslator(org.openmrs.module.fhir2.api.translators.OrderIdentifierTranslator) Task(org.hl7.fhir.r4.model.Task) AccessLevel(lombok.AccessLevel) ServiceRequestTranslator(org.openmrs.module.fhir2.api.translators.ServiceRequestTranslator) FhirTaskService(org.openmrs.module.fhir2.api.FhirTaskService) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Nonnull(javax.annotation.Nonnull) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) PractitionerReferenceTranslator(org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator) TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) EncounterReferenceTranslator(org.openmrs.module.fhir2.api.translators.EncounterReferenceTranslator) ConceptTranslator(org.openmrs.module.fhir2.api.translators.ConceptTranslator) Collection(java.util.Collection) Period(org.hl7.fhir.r4.model.Period) Order(org.openmrs.Order) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) Provider(org.openmrs.Provider) PatientReferenceTranslator(org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator) Validate.notNull(org.apache.commons.lang3.Validate.notNull) Collections(java.util.Collections) 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)

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