use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project nia-patient-switching-standard-adaptor by NHSDigital.
the class ResourceReferenceUtilTest method testTemplateResourcesReferencedAtCompoundStatementLevel.
@Test
public void testTemplateResourcesReferencedAtCompoundStatementLevel() {
final RCMRMT030101UK04CompoundStatement compoundStatement = unmarshallCompoundStatementElement("compound_statement_template.xml");
List<Reference> references = new ArrayList<>();
resourceReferenceUtil.extractChildReferencesFromCompoundStatement(compoundStatement, references);
assertThat(references.size()).isEqualTo(FOUR);
assertThat(references.get(0).getReference()).isEqualTo("QuestionnaireResponse/7334D39A-BBB3-424A-B5D3-E841BCA39BF7-QRSP");
assertThat(references.get(1).getReference()).isEqualTo("Observation/7334D39A-BBB3-424A-B5D3-E841BCA39BF7");
assertThat(references.get(2).getReference()).isEqualTo("Observation/3DCC9FC9-1873-4004-9789-C4E5C52B02B9");
assertThat(references.get(THREE).getReference()).isEqualTo("Observation/278ADD5F-2AC7-48DC-966A-0BA7C029C793");
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationBundle.
private Bundle createObservationBundle(QuestionnaireResponse questionnaireResponse) {
Bundle newBundle = new Bundle();
Date authored = questionnaireResponse.getAuthored();
Identifier bundleId = new Identifier();
bundleId.setValue("QuestionnaireResponse/" + questionnaireResponse.getIdElement().getIdPart());
newBundle.setType(Bundle.BundleType.TRANSACTION);
newBundle.setIdentifier(bundleId);
Map<String, Coding> questionnaireCodeMap = getQuestionnaireCodeMap(questionnaireResponse.getQuestionnaire().getReference());
questionnaireResponse.getItem().stream().forEach(item -> {
processItems(item, authored, questionnaireResponse, newBundle, questionnaireCodeMap);
});
return newBundle;
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationFromItemAnswer.
private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, String linkId, Date authored, QuestionnaireResponse questionnaireResponse, Map<String, Coding> questionnaireCodeMap) {
Observation obs = new Observation();
obs.setEffective(new DateTimeType(authored));
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setSubject(questionnaireResponse.getSubject());
Coding qrCategoryCoding = new Coding();
qrCategoryCoding.setCode("survey");
qrCategoryCoding.setSystem("http://hl7.org/fhir/observation-category");
obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding)));
obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId)));
obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId);
switch(answer.getValue().fhirType()) {
case "string":
obs.setValue(new StringType(answer.getValueStringType().getValue()));
break;
case "Coding":
obs.setValue(new CodeableConcept().addCoding(answer.getValueCoding()));
break;
case "boolean":
obs.setValue(new BooleanType(answer.getValueBooleanType().booleanValue()));
break;
}
Reference questionnaireResponseReference = new Reference();
questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart());
Observation.ObservationRelatedComponent related = new Observation.ObservationRelatedComponent().setType(Observation.ObservationRelationshipType.DERIVEDFROM).setTarget(questionnaireResponseReference);
obs.setRelated(Collections.singletonList(related));
Extension linkIdExtension = new Extension();
linkIdExtension.setUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/derivedFromLinkId");
Extension innerLinkIdExtension = new Extension();
innerLinkIdExtension.setUrl("text");
innerLinkIdExtension.setValue(new StringType(linkId));
linkIdExtension.setExtension(Collections.singletonList(innerLinkIdExtension));
obs.addExtension(linkIdExtension);
Bundle.BundleEntryRequestComponent berc = new Bundle.BundleEntryRequestComponent();
berc.setMethod(Bundle.HTTPVerb.PUT);
berc.setUrl("Observation/" + obs.getId());
Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
bec.setResource(obs);
bec.setRequest(berc);
return bec;
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationFromItemAnswer.
private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, String linkId, Date authored, QuestionnaireResponse questionnaireResponse, Map<String, Coding> questionnaireCodeMap) {
Observation obs = new Observation();
obs.setEffective(new DateTimeType(authored));
obs.setStatus(Observation.ObservationStatus.FINAL);
obs.setSubject(questionnaireResponse.getSubject());
Coding qrCategoryCoding = new Coding();
qrCategoryCoding.setCode("survey");
qrCategoryCoding.setSystem("http://hl7.org/fhir/observation-category");
obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding)));
obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId)));
obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId);
switch(answer.getValue().fhirType()) {
case "string":
obs.setValue(new StringType(answer.getValueStringType().getValue()));
break;
case "Coding":
obs.setValue(new CodeableConcept().addCoding(answer.getValueCoding()));
break;
case "boolean":
obs.setValue(new BooleanType(answer.getValueBooleanType().booleanValue()));
break;
}
Reference questionnaireResponseReference = new Reference();
questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart());
obs.setDerivedFrom(Collections.singletonList(questionnaireResponseReference));
Extension linkIdExtension = new Extension();
linkIdExtension.setUrl("http://hl7.org/fhir/uv/sdc/StructureDefinition/derivedFromLinkId");
Extension innerLinkIdExtension = new Extension();
innerLinkIdExtension.setUrl("text");
innerLinkIdExtension.setValue(new StringType(linkId));
linkIdExtension.setExtension(Collections.singletonList(innerLinkIdExtension));
obs.addExtension(linkIdExtension);
Bundle.BundleEntryRequestComponent berc = new Bundle.BundleEntryRequestComponent();
berc.setMethod(Bundle.HTTPVerb.PUT);
berc.setUrl("Observation/" + obs.getId());
Bundle.BundleEntryComponent bec = new Bundle.BundleEntryComponent();
bec.setResource(obs);
bec.setRequest(berc);
return bec;
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project cqf-ruler by DBCG.
the class ExtractProvider method createObservationBundle.
private Bundle createObservationBundle(QuestionnaireResponse questionnaireResponse) {
Bundle newBundle = new Bundle();
Date authored = questionnaireResponse.getAuthored();
Identifier bundleId = new Identifier();
bundleId.setValue("QuestionnaireResponse/" + questionnaireResponse.getIdElement().getIdPart());
newBundle.setType(Bundle.BundleType.TRANSACTION);
newBundle.setIdentifier(bundleId);
String questionnaireCanonical = questionnaireResponse.getQuestionnaire();
if (questionnaireCanonical == null || questionnaireCanonical.isEmpty()) {
throw new IllegalArgumentException("The QuestionnaireResponse must have the source Questionnaire specified to do extraction");
}
Map<String, Coding> questionnaireCodeMap = getQuestionnaireCodeMap(questionnaireCanonical);
questionnaireResponse.getItem().stream().forEach(item -> {
processItems(item, authored, questionnaireResponse, newBundle, questionnaireCodeMap);
});
return newBundle;
}
Aggregations