Search in sources :

Example 11 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldSetOpenmrsTaskUUIDWhenNull.

@Test
public void toOpenmrsType_shouldSetOpenmrsTaskUUIDWhenNull() {
    FhirTask task = new FhirTask();
    task.setUuid(null);
    Task fhirTask = taskTranslator.toFhirResource(task);
    fhirTask.setId(TASK_UUID);
    FhirTask result = taskTranslator.toOpenmrsType(task, fhirTask);
    assertThat(result, notNullValue());
    assertThat(result.getUuid(), 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) Test(org.junit.Test)

Example 12 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldUpdateOwner.

@Test
public void toOpenmrsType_shouldUpdateOwner() {
    Task task = new Task();
    shouldUpdateReferenceInOpenmrs(task, FhirConstants.ORGANIZATION, OPENELIS_ID, task::setOwner, FhirTask::getOwnerReference);
}
Also used : 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 13 with Task

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

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceListToFhir.

private void shouldTranslateReferenceListToFhir(FhirTask task, String refType, String refUuid, Consumer<Set<FhirReference>> setOpenmrsReference, Function<Task, List<Reference>> getFhirReference) {
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setType(refType);
    openmrsReference.setReference(refUuid);
    setOpenmrsReference.accept(Collections.singleton(openmrsReference));
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
    Task result = taskTranslator.toFhirResource(task);
    Collection<Reference> resultReference = getFhirReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference, hasSize(1));
    assertThat(resultReference.iterator().next(), notNullValue());
    assertThat(resultReference.iterator().next().getType(), equalTo(refType));
    assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
}
Also used : Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 14 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldUpdateInputTextValue.

@Test
public void toOpenmrsType_shouldUpdateInputTextValue() {
    Task task = new Task();
    Task.ParameterComponent input = new Task.ParameterComponent();
    CodeableConcept inputType = new CodeableConcept().setText("some text");
    String inputVal = "some input value";
    input.setType(inputType).setValue(new StringType(inputVal));
    Concept openmrsInputType = new Concept();
    openmrsInputType.setUuid(CONCEPT_UUID);
    task.setInput(Collections.singletonList(input));
    FhirTask openmrsTask = new FhirTask();
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setInput(Collections.singleton(new FhirTaskInput()));
    when(conceptTranslator.toOpenmrsType(inputType)).thenReturn(openmrsInputType);
    FhirTask result = taskTranslator.toOpenmrsType(openmrsTask, task);
    assertThat(result.getInput(), not(empty()));
    assertThat(result.getInput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID)))));
    assertThat(result.getInput(), hasItem(hasProperty("valueText", equalTo(inputVal))));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Task(org.hl7.fhir.r4.model.Task) FhirTask(org.openmrs.module.fhir2.model.FhirTask) StringType(org.hl7.fhir.r4.model.StringType) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 15 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldUpdateStatusOnExistingTask.

@Test
public void toOpenmrsType_shouldUpdateStatusOnExistingTask() {
    FhirTask task = new FhirTask();
    task.setStatus(OPENMRS_TASK_STATUS);
    task.setUuid(TASK_UUID);
    Task fhirTask = taskTranslator.toFhirResource(task);
    fhirTask.setStatus(FHIR_NEW_TASK_STATUS);
    FhirTask result = taskTranslator.toOpenmrsType(task, fhirTask);
    assertThat(result, notNullValue());
    assertThat(result.getStatus(), equalTo(OPENMRS_NEW_TASK_STATUS));
}
Also used : 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.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