Search in sources :

Example 26 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldTranslateUnsupportedStatusToUnknown.

@Test
public void toOpenmrsType_shouldTranslateUnsupportedStatusToUnknown() {
    Task task = new Task();
    task.setStatus(Task.TaskStatus.ENTEREDINERROR);
    FhirTask result = taskTranslator.toOpenmrsType(task);
    assertThat(result, notNullValue());
    assertThat(result.getStatus(), equalTo(FhirTask.TaskStatus.UNKNOWN));
}
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 27 with Task

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

the class FhirTaskTranslatorImplTest method toFhirResource_shouldAddProvenanceResources.

@Test
public void toFhirResource_shouldAddProvenanceResources() {
    FhirTask task = new FhirTask();
    task.setUuid(TASK_UUID);
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    when(provenanceTranslator.getCreateProvenance(task)).thenReturn(provenance);
    when(provenanceTranslator.getUpdateProvenance(task)).thenReturn(provenance);
    org.hl7.fhir.r4.model.Task result = taskTranslator.toFhirResource(task);
    assertThat(result, notNullValue());
    assertThat(result.getContained(), not(empty()));
    assertThat(result.getContained().size(), greaterThanOrEqualTo(2));
    assertThat(result.getContained().stream().anyMatch(resource -> resource.getResourceType().name().equals(Provenance.class.getSimpleName())), is(true));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Date(java.util.Date) Mock(org.mockito.Mock) Matchers.not(org.hamcrest.Matchers.not) Identifier(org.hl7.fhir.r4.model.Identifier) RunWith(org.junit.runner.RunWith) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FhirReference(org.openmrs.module.fhir2.model.FhirReference) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Task(org.hl7.fhir.r4.model.Task) FhirUtils(org.openmrs.module.fhir2.api.util.FhirUtils) StringType(org.hl7.fhir.r4.model.StringType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FhirConstants(org.openmrs.module.fhir2.FhirConstants) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Before(org.junit.Before) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) Collection(java.util.Collection) Set(java.util.Set) Provenance(org.hl7.fhir.r4.model.Provenance) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IdType(org.hl7.fhir.r4.model.IdType) Consumer(java.util.function.Consumer) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) Task(org.hl7.fhir.r4.model.Task) Provenance(org.hl7.fhir.r4.model.Provenance) FhirTask(org.openmrs.module.fhir2.model.FhirTask) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 28 with Task

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

the class FhirTaskTranslatorImplTest method toOpenmrsType_shouldUpdateOutputReference.

@Test
public void toOpenmrsType_shouldUpdateOutputReference() {
    Task task = new Task();
    Task.TaskOutputComponent output = new Task.TaskOutputComponent();
    Reference outputReference = new Reference().setReference(DIAGNOSTIC_REPORT_UUID).setType(FhirConstants.DIAGNOSTIC_REPORT);
    CodeableConcept outputType = new CodeableConcept().setText("some text");
    output.setType(outputType).setValue(outputReference);
    Concept openmrsOutputType = new Concept();
    openmrsOutputType.setUuid(CONCEPT_UUID);
    task.setOutput(Collections.singletonList(output));
    FhirTask openmrsTask = new FhirTask();
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setOutput(Collections.singleton(new FhirTaskOutput()));
    when(conceptTranslator.toOpenmrsType(outputType)).thenReturn(openmrsOutputType);
    FhirTask result = shouldUpdateReferenceInOpenmrs(task, FhirConstants.DIAGNOSTIC_REPORT, DIAGNOSTIC_REPORT_UUID, output::setValue, t -> t.getOutput().iterator().next().getValueReference());
    assertThat(result.getOutput(), hasSize(1));
    assertThat(result.getOutput().iterator().next().getType().getUuid(), equalTo(CONCEPT_UUID));
}
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) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 29 with Task

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

the class FhirTaskTranslatorImplTest method shouldUpdateReferenceListInOpenmrs.

private void shouldUpdateReferenceListInOpenmrs(Task task, String refType, String refUuid, Consumer<List<Reference>> setFhirReference, Function<FhirTask, Set<FhirReference>> getOpenmrsReference) {
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    setFhirReference.accept(Collections.singletonList(fhirReference));
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setReference(refUuid);
    openmrsReference.setType(refType);
    FhirTask openmrsTask = new FhirTask();
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setEncounterReference(new FhirReference());
    when(referenceTranslator.toOpenmrsType(any(Reference.class))).thenReturn(openmrsReference);
    FhirTask result = taskTranslator.toOpenmrsType(openmrsTask, task);
    Collection<FhirReference> resultReference = getOpenmrsReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference, hasSize(1));
    assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
    assertThat(resultReference.iterator().next().getType(), equalTo(refType));
}
Also used : 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 30 with Task

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

the class FhirTaskTranslatorImplTest method toFhirResource_shouldTranslateInputTextValue.

// Task.input
@Test
public void toFhirResource_shouldTranslateInputTextValue() {
    FhirTask task = new FhirTask();
    FhirTaskInput input = new FhirTaskInput();
    String inputVal = "some input value";
    Concept inputType = new Concept();
    inputType.setUuid(CONCEPT_UUID);
    input.setType(inputType);
    input.setValueText(inputVal);
    task.setInput(Collections.singleton(input));
    when(conceptTranslator.toFhirResource(inputType)).thenReturn(new CodeableConcept().setCoding(Collections.singletonList(new Coding().setCode(CONCEPT_UUID))));
    Task result = taskTranslator.toFhirResource(task);
    assertThat(result, notNullValue());
    assertThat(result.getInput(), hasSize(1));
    assertThat(result.getInput().iterator().next().getType().getCoding().iterator().next().getCode(), equalTo(CONCEPT_UUID));
    assertThat(result.getInput().iterator().next().getValue().toString(), 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) FhirTask(org.openmrs.module.fhir2.model.FhirTask) Coding(org.hl7.fhir.r4.model.Coding) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) 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