use of org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse in project Gravity-SDOH-Exchange-RI by FHIR.
the class AssessmentResponseToDtoConverter2 method convert.
@Override
public List<AssessmentResponse> convert(AseessmentInfoBundleExtractor.AssessmentInfoHolder infoHolder) {
return infoHolder.getQuestionnaireResponse().getItem().stream().map(qr -> {
AssessmentResponse assessmentResponse = new AssessmentResponse();
assessmentResponse.setQuestion(new StringTypeDto(qr.getText()));
Type itemAnswer = qr.getAnswerFirstRep().getValue();
if (itemAnswer instanceof StringType) {
assessmentResponse.setAnswer(new StringTypeDto(((StringType) itemAnswer).getValue()));
} else if (itemAnswer instanceof Coding) {
assessmentResponse.setAnswer(new StringTypeDto(((Coding) itemAnswer).getDisplay()));
} else {
assessmentResponse.getErrors().add(String.format("Answer cannot be resolved. %s type is not expected.", itemAnswer.getClass().getSimpleName()));
assessmentResponse.setAnswer(new StringTypeDto("Answer cannot be parsed."));
}
return assessmentResponse;
}).collect(Collectors.toList());
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse in project Gravity-SDOH-Exchange-RI by FHIR.
the class AssessmentResponseToDtoConverter method convert.
@Override
public List<AssessmentResponse> convert(AseessmentInfoBundleExtractor.AssessmentInfoHolder infoHolder) {
Map<String, String> items = new HashMap<>();
infoHolder.getQuestionnaireResponse().getItem().forEach(i -> items.put(i.getLinkId(), i.getText()));
return infoHolder.getObservations().stream().filter(Observation::hasValue).map(o -> {
AssessmentDto.AssessmentResponse assessmentResponse = new AssessmentDto.AssessmentResponse();
String code = o.getCode().getCodingFirstRep().getCode();
String question = items.get("/" + code);
if (question == null) {
question = code;
assessmentResponse.getErrors().add("No question text found. Using a code instead.");
}
assessmentResponse.setQuestion(new StringTypeDto(question));
assessmentResponse.setAnswer(typeToDtoConverter.convert(o.getValue()));
return assessmentResponse;
}).collect(Collectors.toList());
}
Aggregations