use of org.hl7.fhir.r4.model.Questionnaire in project fhir-bridge by ehrbase.
the class FindQuestionnaireResponseTransactionIT method findQuestionnaireResponseSearch.
@Test
void findQuestionnaireResponseSearch() throws IOException {
for (int i = 0; i < 3; i++) {
create("QuestionnaireResponse/transactions/find-questionnaire-response-search.json");
}
Bundle bundle = search("QuestionnaireResponse?patient.identifier=" + PATIENT_ID + "&status=entered-in-error");
Assertions.assertEquals(3, bundle.getTotal());
bundle.getEntry().forEach(entry -> {
var questionnaireResponse = (QuestionnaireResponse) entry.getResource();
Assertions.assertEquals(PATIENT_ID, questionnaireResponse.getSubject().getIdentifier().getValue());
Assertions.assertEquals(QuestionnaireResponse.QuestionnaireResponseStatus.ENTEREDINERROR, questionnaireResponse.getStatus());
});
}
use of org.hl7.fhir.r4.model.Questionnaire in project Gravity-SDOH-Exchange-RI by FHIR.
the class PatientTaskItemInfoHolderToItemDtoConverter method convert.
@Override
public PatientTaskItemDto convert(T taskInfoHolder) {
Task task = taskInfoHolder.getTask();
Questionnaire questionnaire = taskInfoHolder.getQuestionnaire();
PatientTaskItemDto taskDto = createDto();
taskDto.setId(task.getIdElement().getIdPart());
taskDto.setName(task.getDescription());
taskDto.setPriority(task.getPriority().getDisplay());
taskDto.setLastModified(FhirUtil.toLocalDateTime(task.getLastModifiedElement()));
taskDto.setStatus(task.getStatus().getDisplay());
taskDto.setStatusReason(task.getStatusReason().getText());
setReferralTask(task, taskDto);
List<Coding> codings = task.getCode().getCoding();
PatientTaskCode code = getCode(taskDto, codings);
if (code != null) {
Coding coding = code.toCoding();
taskDto.setCode(new CodingDto(coding.getCode(), coding.getDisplay()));
}
setTaskType(task, taskDto, code);
if (questionnaire != null) {
taskDto.setAssessment(new ReferenceDto(questionnaire.getIdElement().getIdPart(), questionnaire.getTitle()));
}
for (TaskOutputComponent outputComponent : task.getOutput()) {
Type componentValue = outputComponent.getValue();
Coding coding = FhirUtil.findCoding(Lists.newArrayList(outputComponent.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
if (coding != null) {
Reference qrRef = (Reference) componentValue;
if (QuestionnaireResponse.class.getSimpleName().equals(qrRef.getReferenceElement().getResourceType())) {
taskDto.setAssessmentResponse(new ReferenceDto(qrRef.getReferenceElement().getIdPart(), coding.getDisplay()));
}
}
if (componentValue instanceof CodeableConcept) {
CodeableConcept outcome = (CodeableConcept) componentValue;
taskDto.setOutcome(outcome.getText());
}
}
return taskDto;
}
use of org.hl7.fhir.r4.model.Questionnaire in project Gravity-SDOH-Exchange-RI by FHIR.
the class QuestionnaireRepository method findByCanonnicalUri.
public Optional<Questionnaire> findByCanonnicalUri(String uri) {
Assert.notNull(uri, "CannonnicalUri should be specified");
Bundle bundle = getClient().search().forResource(Questionnaire.class).where(Questionnaire.URL.matches().value(uri)).returnBundle(Bundle.class).execute();
return Optional.ofNullable(FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().findFirst().orElse(null));
}
use of org.hl7.fhir.r4.model.Questionnaire in project Gravity-SDOH-Exchange-RI by FHIR.
the class AseessmentInfoBundleExtractor method extract.
@Override
public List<AssessmentInfoHolder> extract(Bundle bundle) {
Map<String, Questionnaire> questionnaires = new HashMap<>();
FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().forEach(q -> questionnaires.put(q.getUrl(), q));
return FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().map(questionnaireResponse -> {
List<Observation> observations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsQuestionnaireReference(observation, questionnaireResponse.getIdElement().getIdPart())).collect(Collectors.toList());
// Observations might be derived not only from the Questionnaire, but also from other Observations.
// If we do not include these "intermediate" observations - the link between the QuestionnaireResponse and
// Condition will not be found.
List<Observation> derivedObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsObservationReference(observation, observations)).collect(Collectors.toList());
observations.addAll(derivedObservations);
List<Condition> conditions = FhirUtil.getFromBundle(bundle, Condition.class).stream().filter(condition -> containsObservationReference(condition, observations)).collect(Collectors.toList());
Questionnaire questionnaire = questionnaires.get(questionnaireResponse.getQuestionnaire());
return new AssessmentInfoHolder(questionnaireResponse, questionnaire, observations, conditions);
}).collect(Collectors.toList());
}
use of org.hl7.fhir.r4.model.Questionnaire in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConditionInfoBundleExtractor method extract.
@Override
public List<? extends ConditionInfoHolder> extract(Bundle bundle) {
Map<String, Observation> allObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().collect(Collectors.toMap(observation -> observation.getIdElement().getIdPart(), Function.identity()));
Map<String, QuestionnaireResponse> allQuestionnaireResponses = FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().collect(Collectors.toMap(qr -> qr.getIdElement().getIdPart(), Function.identity()));
Map<String, Questionnaire> allQuestionnaires = FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().collect(Collectors.toMap(q -> q.getUrl(), Function.identity()));
return FhirUtil.getFromBundle(bundle, Condition.class).stream().map(condition -> {
Reference evidenceReference = condition.getEvidence().stream().map(ConditionEvidenceComponent::getDetail).flatMap(Collection::stream).findFirst().orElse(null);
QuestionnaireResponse questionnaireResponse = null;
Questionnaire questionnaire = null;
List<Observation> observations = new ArrayList<>();
if (evidenceReference != null) {
Observation evidenceObservation = allObservations.remove(evidenceReference.getReferenceElement().getIdPart());
observations.add(evidenceObservation);
questionnaireResponse = allQuestionnaireResponses.get(findQuestionnaireResponseId(evidenceObservation));
String questionnaireResponseId = questionnaireResponse.getIdElement().getIdPart();
Iterator<Entry<String, Observation>> iterator = allObservations.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, Observation> observationEntry = iterator.next();
Observation value = observationEntry.getValue();
if (containsQuestionnaireReference(value, questionnaireResponseId)) {
observations.add(value);
iterator.remove();
}
}
questionnaire = allQuestionnaires.get(questionnaireResponse.getQuestionnaire());
}
return new ConditionInfoHolder(condition, questionnaire, questionnaireResponse, observations);
}).collect(Collectors.toList());
}
Aggregations