Search in sources :

Example 26 with QuestionnaireResponse

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");
}
Also used : RCMRMT030101UK04CompoundStatement(org.hl7.v3.RCMRMT030101UK04CompoundStatement) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with QuestionnaireResponse

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;
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date)

Example 28 with QuestionnaireResponse

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;
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) Bundle(org.hl7.fhir.dstu3.model.Bundle) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Coding(org.hl7.fhir.dstu3.model.Coding) Observation(org.hl7.fhir.dstu3.model.Observation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 29 with QuestionnaireResponse

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;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) Bundle(org.hl7.fhir.r4.model.Bundle) BooleanType(org.hl7.fhir.r4.model.BooleanType) Extension(org.hl7.fhir.r4.model.Extension) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 30 with QuestionnaireResponse

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;
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Date(java.util.Date)

Aggregations

QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)15 ArrayList (java.util.ArrayList)14 Bundle (org.hl7.fhir.r4.model.Bundle)11 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)8 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)8 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)8 Test (org.junit.jupiter.api.Test)8 Reference (org.hl7.fhir.dstu3.model.Reference)7 Reference (org.hl7.fhir.r4.model.Reference)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 Map (java.util.Map)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)5 Coding (org.hl7.fhir.r4.model.Coding)4 Date (java.util.Date)3 Getter (lombok.Getter)3 Bundle (org.hl7.fhir.dstu3.model.Bundle)3