Search in sources :

Example 1 with FhirReference

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

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

the class FhirTaskDaoImplTest method searchForTasks_shouldHandleNullBasedOnRefs.

@Test
public void searchForTasks_shouldHandleNullBasedOnRefs() {
    FhirTask toUpdate = dao.get(TASK_UUID);
    FhirReference nullTypeRef = new FhirReference();
    nullTypeRef.setType(null);
    nullTypeRef.setReference(BASED_ON_ORDER_UUID);
    toUpdate.setOwnerReference(nullTypeRef);
    toUpdate.setBasedOnReferences(Collections.singleton(nullTypeRef));
    dao.createOrUpdate(toUpdate);
    FhirTask result = dao.get(TASK_UUID);
    assertThat(result.getBasedOnReferences(), notNullValue());
    assertThat(result.getBasedOnReferences().size(), greaterThan(0));
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirReference(org.openmrs.module.fhir2.model.FhirReference) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 3 with FhirReference

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

the class FhirTaskDaoImplTest method saveTask_shouldUpdateEncounterReference.

@Test
public void saveTask_shouldUpdateEncounterReference() {
    FhirTask toUpdate = dao.get(TASK_UUID);
    FhirReference forReference = new FhirReference();
    forReference.setType(FhirConstants.ENCOUNTER);
    forReference.setReference(ENCOUNTER_UUID);
    forReference.setName("TEMP");
    toUpdate.setEncounterReference(forReference);
    dao.createOrUpdate(toUpdate);
    FhirTask result = dao.get(TASK_UUID);
    assertThat(result.getEncounterReference(), notNullValue());
    assertThat(result.getEncounterReference().getId(), notNullValue());
    assertThat(result.getEncounterReference().getType(), equalTo(FhirConstants.ENCOUNTER));
    assertThat(result.getEncounterReference().getReference(), equalTo(ENCOUNTER_UUID));
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirReference(org.openmrs.module.fhir2.model.FhirReference) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with FhirReference

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

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

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceToFhir.

/**
 * Helpers for reference associations
 */
private Task shouldTranslateReferenceToFhir(FhirTask task, String refType, String refUuid, Consumer<FhirReference> setOpenmrsReference, Function<Task, Reference> getFhirReference) {
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setType(refType);
    openmrsReference.setReference(refUuid);
    setOpenmrsReference.accept(openmrsReference);
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
    Task result = taskTranslator.toFhirResource(task);
    Reference resultReference = getFhirReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference.getType(), equalTo(refType));
    assertThat(resultReference.getReference(), equalTo(refUuid));
    return result;
}
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)

Aggregations

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