Search in sources :

Example 1 with FhirTaskInput

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

the class FhirTaskDaoImplTest method saveTask_shouldUpdateInput.

@Test
public void saveTask_shouldUpdateInput() throws Exception {
    executeDataSet(CONCEPT_DATA_XML);
    HibernateConceptDAO cd = new HibernateConceptDAO();
    cd.setSessionFactory(sessionFactory);
    FhirTask toUpdate = dao.get(TASK_UUID);
    Double someNumericVal = 123123.11;
    Concept type = cd.getConceptByUuid(CONCEPT_UUID);
    assertThat(type, notNullValue());
    FhirTaskInput input = new FhirTaskInput();
    input.setValueNumeric(someNumericVal);
    input.setType(type);
    input.setName("TEMP");
    // TODO: why is this not autogenerated?
    input.setId(23423);
    toUpdate.setInput(Collections.singleton(input));
    FhirTask result = dao.get(TASK_UUID);
    assertThat(result.getInput(), notNullValue());
    assertThat(result.getInput(), not(empty()));
    assertThat(result.getInput(), hasItem(hasProperty("type", hasProperty("uuid", equalTo(CONCEPT_UUID)))));
    assertThat(result.getInput(), hasItem(hasProperty("valueNumeric", equalTo(someNumericVal))));
}
Also used : Concept(org.openmrs.Concept) HibernateConceptDAO(org.openmrs.api.db.hibernate.HibernateConceptDAO) FhirTask(org.openmrs.module.fhir2.model.FhirTask) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 2 with FhirTaskInput

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

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

Example 4 with FhirTaskInput

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

the class TaskTranslatorImpl method translateToInputText.

private FhirTaskInput translateToInputText(Task.ParameterComponent parameterComponent) {
    Concept type = conceptTranslator.toOpenmrsType(parameterComponent.getType());
    FhirTaskInput input = new FhirTaskInput();
    input.setType(type);
    input.setValueText(parameterComponent.getValue().toString());
    input.setName("ParameterComponent/" + input.getUuid());
    return input;
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) FhirTaskInput(org.openmrs.module.fhir2.model.FhirTaskInput)

Aggregations

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