Search in sources :

Example 1 with FhirTaskOutput

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

the class FhirTaskDaoImplTest method saveTask_shouldUpdateOutput.

@Test
public void saveTask_shouldUpdateOutput() throws Exception {
    executeDataSet(CONCEPT_DATA_XML);
    HibernateConceptDAO cd = new HibernateConceptDAO();
    cd.setSessionFactory(sessionFactory);
    FhirTask toUpdate = dao.get(TASK_UUID);
    FhirReference outputReference = new FhirReference();
    outputReference.setType(FhirConstants.DIAGNOSTIC_REPORT);
    outputReference.setReference(DIAGNOSTIC_REPORT_UUID);
    outputReference.setName("TEMP");
    Concept type = cd.getConceptByUuid(CONCEPT_UUID);
    assertThat(type, notNullValue());
    FhirTaskOutput output = new FhirTaskOutput();
    output.setValueReference(outputReference);
    output.setType(type);
    output.setName("TEMP");
    // TODO: why is this not autogenerated?
    output.setId(23423);
    toUpdate.setOutput(Collections.singleton(output));
    FhirTask result = dao.get(TASK_UUID);
    assertThat(result.getOutput(), notNullValue());
    assertThat(result.getOutput(), not(empty()));
    assertThat(result.getOutput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID)))));
    assertThat(result.getOutput(), hasItem(hasProperty("valueReference", hasProperty("reference", equalTo(DIAGNOSTIC_REPORT_UUID)))));
}
Also used : Concept(org.openmrs.Concept) HibernateConceptDAO(org.openmrs.api.db.hibernate.HibernateConceptDAO) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirReference(org.openmrs.module.fhir2.model.FhirReference) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with FhirTaskOutput

use of org.openmrs.module.fhir2.model.FhirTaskOutput 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 3 with FhirTaskOutput

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

the class TaskTranslatorImpl method translateToOutputReference.

private FhirTaskOutput translateToOutputReference(Task.TaskOutputComponent taskOutputComponent) {
    FhirReference outputReference = referenceTranslator.toOpenmrsType((Reference) taskOutputComponent.getValue());
    Concept type = conceptTranslator.toOpenmrsType(taskOutputComponent.getType());
    FhirTaskOutput output = new FhirTaskOutput();
    output.setValueReference(outputReference);
    output.setType(type);
    output.setName("TaskOutputComponent/" + output.getUuid());
    return output;
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 4 with FhirTaskOutput

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

the class TaskTranslatorImpl method translateFromOutputReferences.

private Task.TaskOutputComponent translateFromOutputReferences(FhirTaskOutput openmrsOutput) {
    Reference ref = referenceTranslator.toFhirResource(openmrsOutput.getValueReference());
    CodeableConcept type = conceptTranslator.toFhirResource(openmrsOutput.getType());
    return new Task.TaskOutputComponent().setType(type).setValue(ref);
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 5 with FhirTaskOutput

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

the class FhirTaskTranslatorImplTest method toFhirResource_shouldTranslateOutputReference.

// Task.output
@Test
public void toFhirResource_shouldTranslateOutputReference() {
    FhirTask task = new FhirTask();
    FhirTaskOutput output = new FhirTaskOutput();
    FhirReference outputReference = new FhirReference();
    Concept outputType = new Concept();
    outputReference.setType(FhirConstants.DIAGNOSTIC_REPORT);
    outputReference.setReference(DIAGNOSTIC_REPORT_UUID);
    outputType.setUuid(CONCEPT_UUID);
    output.setType(outputType);
    output.setValueReference(outputReference);
    task.setOutput(Collections.singleton(output));
    when(conceptTranslator.toFhirResource(outputType)).thenReturn(new CodeableConcept().setCoding(Collections.singletonList(new Coding().setCode(CONCEPT_UUID))));
    Task result = shouldTranslateReferenceToFhir(task, FhirConstants.DIAGNOSTIC_REPORT, DIAGNOSTIC_REPORT_UUID, output::setValueReference, t -> (Reference) t.getOutput().iterator().next().getValue());
    assertThat(result.getOutput(), hasSize(1));
    assertThat(result.getOutput().iterator().next().getType().getCoding().iterator().next().getCode(), equalTo(CONCEPT_UUID));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) FhirTaskOutput(org.openmrs.module.fhir2.model.FhirTaskOutput) 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) FhirReference(org.openmrs.module.fhir2.model.FhirReference) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Aggregations

FhirReference (org.openmrs.module.fhir2.model.FhirReference)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 Concept (org.openmrs.Concept)4 FhirTaskOutput (org.openmrs.module.fhir2.model.FhirTaskOutput)4 Test (org.junit.Test)3 FhirTask (org.openmrs.module.fhir2.model.FhirTask)3 Reference (org.hl7.fhir.r4.model.Reference)2 Task (org.hl7.fhir.r4.model.Task)2 Coding (org.hl7.fhir.r4.model.Coding)1 HibernateConceptDAO (org.openmrs.api.db.hibernate.HibernateConceptDAO)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1