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))));
}
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))));
}
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));
}
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;
}
Aggregations