Search in sources :

Example 86 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class MeasureValidator method validateScore.

private void validateScore(ValidatorHostContext hostContext, MeasureContext m, List<ValidationMessage> errors, Element mrg, NodeStack stack, boolean inProgress) {
    Element ms = mrg.getNamedChild("measureScore");
    // first, we check MeasureReport.type
    if ("data-collection".equals(m.reportType())) {
        banned(errors, stack, ms, I18nConstants.MEASURE_MR_SCORE_PROHIBITED_RT);
    } else if ("cohort".equals(m.scoring())) {
        // cohort - there is no measure score
        banned(errors, stack, ms, I18nConstants.MEASURE_MR_SCORE_PROHIBITED_MS);
    } else if (Utilities.existsInList(m.scoring(), "proportion", "ratio", "continuous-variable")) {
        if (rule(errors, IssueType.REQUIRED, mrg.line(), mrg.col(), stack.getLiteralPath(), ms != null, I18nConstants.MEASURE_MR_SCORE_REQUIRED, m.scoring())) {
            NodeStack ns = stack.push(ms, -1, ms.getProperty().getDefinition(), ms.getProperty().getDefinition());
            Element v = ms.getNamedChild("value");
            // TODO: this is a DEQM special and should be handled differently
            if (v == null) {
                if (ms.hasExtension("http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-alternateScoreType")) {
                    v = ms.getExtension("http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-alternateScoreType").getNamedChild("value");
                }
            }
            if ("proportion".equals(m.scoring())) {
                // proportion - score is a unitless number from 0 ... 1
                banned(errors, ns, ms, "unit", I18nConstants.MEASURE_MR_SCORE_UNIT_PROHIBITED, "proportion");
                banned(errors, ns, ms, "system", I18nConstants.MEASURE_MR_SCORE_UNIT_PROHIBITED, "proportion");
                banned(errors, ns, ms, "code", I18nConstants.MEASURE_MR_SCORE_UNIT_PROHIBITED, "proportion");
                if (rule(errors, IssueType.REQUIRED, ms.line(), ms.col(), ns.getLiteralPath(), v != null, I18nConstants.MEASURE_MR_SCORE_VALUE_REQUIRED, "proportion")) {
                    try {
                        BigDecimal dec = new BigDecimal(v.primitiveValue());
                        NodeStack nsv = ns.push(v, -1, v.getProperty().getDefinition(), v.getProperty().getDefinition());
                        rule(errors, IssueType.REQUIRED, v.line(), v.col(), nsv.getLiteralPath(), dec.compareTo(new BigDecimal(0)) >= 0 && dec.compareTo(new BigDecimal(1)) <= 0, I18nConstants.MEASURE_MR_SCORE_VALUE_INVALID_01);
                    } catch (Exception e) {
                    // nothing - will have caused an error elsewhere
                    }
                }
            } else if ("ratio".equals(m.scoring())) {
                // ratio -  score is a number with no value constraints, and maybe with a unit (perhaps constrained by extension)
                if (rule(errors, IssueType.REQUIRED, ms.line(), ms.col(), ns.getLiteralPath(), v != null, I18nConstants.MEASURE_MR_SCORE_VALUE_REQUIRED, "ratio")) {
                    Element unit = ms.getNamedChild("code");
                    Coding c = m.measure().hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-unit") ? (Coding) m.measure().getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-unit").getValue() : null;
                    if (unit != null) {
                        if (c != null) {
                            NodeStack nsc = ns.push(unit, -1, unit.getProperty().getDefinition(), unit.getProperty().getDefinition());
                            rule(errors, IssueType.CODEINVALID, unit.line(), unit.col(), nsc.getLiteralPath(), c.getCode().equals(unit.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getCode());
                            Element system = ms.getNamedChild("system");
                            if (system == null) {
                                NodeStack nss = system == null ? ns : ns.push(system, -1, system.getProperty().getDefinition(), system.getProperty().getDefinition());
                                rule(errors, IssueType.CODEINVALID, system.line(), system.col(), nss.getLiteralPath(), c.getSystem().equals(system.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getSystem());
                            } else {
                                rule(errors, IssueType.CODEINVALID, ms.line(), ms.col(), ns.getLiteralPath(), c.getSystem().equals(system.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getSystem());
                            }
                        }
                    } else if (c != null) {
                        rule(errors, IssueType.NOTFOUND, ms.line(), ms.col(), ns.getLiteralPath(), false, I18nConstants.MEASURE_MR_SCORE_FIXED, DataRenderer.display(context, c));
                    } else {
                        warning(errors, IssueType.NOTFOUND, ms.line(), ms.col(), ns.getLiteralPath(), false, I18nConstants.MEASURE_MR_SCORE_UNIT_REQUIRED, "ratio");
                    }
                }
            } else if ("continuous-variable".equals(m.scoring())) {
                // continuous-variable - score is a quantity with a unit per the extension
                if (rule(errors, IssueType.REQUIRED, ms.line(), ms.col(), ns.getLiteralPath(), v != null, I18nConstants.MEASURE_MR_SCORE_VALUE_REQUIRED, "continuous-variable")) {
                    Element unit = ms.getNamedChild("code");
                    Coding c = m.measure().hasExtension("http://hl7.org/fhir/StructureDefinition/questionnaire-unit") ? (Coding) m.measure().getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/questionnaire-unit").getValue() : null;
                    if (unit != null) {
                        if (c != null) {
                            NodeStack nsc = ns.push(unit, -1, unit.getProperty().getDefinition(), unit.getProperty().getDefinition());
                            rule(errors, IssueType.CODEINVALID, unit.line(), unit.col(), nsc.getLiteralPath(), c.getCode().equals(unit.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getCode());
                            Element system = ms.getNamedChild("system");
                            if (system == null) {
                                NodeStack nss = system == null ? ns : ns.push(system, -1, system.getProperty().getDefinition(), system.getProperty().getDefinition());
                                rule(errors, IssueType.CODEINVALID, system.line(), system.col(), nss.getLiteralPath(), c.getSystem().equals(system.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getSystem());
                            } else {
                                rule(errors, IssueType.CODEINVALID, ms.line(), ms.col(), ns.getLiteralPath(), c.getSystem().equals(system.primitiveValue()), I18nConstants.MEASURE_MR_SCORE_FIXED, c.getSystem());
                            }
                        }
                    } else if (c != null) {
                        rule(errors, IssueType.NOTFOUND, ms.line(), ms.col(), ns.getLiteralPath(), false, I18nConstants.MEASURE_MR_SCORE_FIXED, DataRenderer.display(context, c));
                    }
                }
            }
        }
    // else do nothing - there's a hint elsewhere
    }
}
Also used : Coding(org.hl7.fhir.r5.model.Coding) Element(org.hl7.fhir.r5.elementmodel.Element) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 87 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class Tester method main.

public static void main(String[] args) throws Exception {
    IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
    int t = 0;
    int ok = 0;
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
        if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
            // if (f.equals("account-questionnaire.xml")) {
            System.out.print("convert " + f);
            // Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
            // new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
            // String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
            // String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
            Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
            Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
            Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
            String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
            String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
            t++;
            if (src.equals(tgt)) {
                System.out.println(".. ok");
                ok++;
            } else
                System.out.println(".. fail");
        }
    // }
    }
    System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
Also used : IWorkerContext(org.hl7.fhir.dstu3.context.IWorkerContext) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream)

Example 88 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeQuestionnaireQuestionnaireItemInitialComponent.

protected void composeQuestionnaireQuestionnaireItemInitialComponent(Complex parent, String parentType, String name, Questionnaire.QuestionnaireItemInitialComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "initial", name, element, index);
    if (element.hasValue())
        composeType(t, "Questionnaire", "value", element.getValue(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 89 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeQuestionnaireResponse.

protected void composeQuestionnaireResponse(Complex parent, String parentType, String name, QuestionnaireResponse element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "QuestionnaireResponse", name, element, index);
    if (element.hasIdentifier())
        composeIdentifier(t, "QuestionnaireResponse", "identifier", element.getIdentifier(), -1);
    for (int i = 0; i < element.getBasedOn().size(); i++) composeReference(t, "QuestionnaireResponse", "basedOn", element.getBasedOn().get(i), i);
    for (int i = 0; i < element.getPartOf().size(); i++) composeReference(t, "QuestionnaireResponse", "partOf", element.getPartOf().get(i), i);
    if (element.hasQuestionnaireElement())
        composeCanonical(t, "QuestionnaireResponse", "questionnaire", element.getQuestionnaireElement(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "QuestionnaireResponse", "status", element.getStatusElement(), -1);
    if (element.hasSubject())
        composeReference(t, "QuestionnaireResponse", "subject", element.getSubject(), -1);
    if (element.hasEncounter())
        composeReference(t, "QuestionnaireResponse", "encounter", element.getEncounter(), -1);
    if (element.hasAuthoredElement())
        composeDateTime(t, "QuestionnaireResponse", "authored", element.getAuthoredElement(), -1);
    if (element.hasAuthor())
        composeReference(t, "QuestionnaireResponse", "author", element.getAuthor(), -1);
    if (element.hasSource())
        composeReference(t, "QuestionnaireResponse", "source", element.getSource(), -1);
    for (int i = 0; i < element.getItem().size(); i++) composeQuestionnaireResponseQuestionnaireResponseItemComponent(t, "QuestionnaireResponse", "item", element.getItem().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 90 with Questionnaire

use of org.hl7.fhir.r4.model.Questionnaire in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeQuestionnaire.

protected void composeQuestionnaire(Complex parent, String parentType, String name, Questionnaire element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Questionnaire", name, element, index);
    if (element.hasUrlElement())
        composeUri(t, "Questionnaire", "url", element.getUrlElement(), -1);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "Questionnaire", "identifier", element.getIdentifier().get(i), i);
    if (element.hasVersionElement())
        composeString(t, "Questionnaire", "version", element.getVersionElement(), -1);
    if (element.hasNameElement())
        composeString(t, "Questionnaire", "name", element.getNameElement(), -1);
    if (element.hasTitleElement())
        composeString(t, "Questionnaire", "title", element.getTitleElement(), -1);
    for (int i = 0; i < element.getDerivedFrom().size(); i++) composeCanonical(t, "Questionnaire", "derivedFrom", element.getDerivedFrom().get(i), i);
    if (element.hasStatusElement())
        composeEnum(t, "Questionnaire", "status", element.getStatusElement(), -1);
    if (element.hasExperimentalElement())
        composeBoolean(t, "Questionnaire", "experimental", element.getExperimentalElement(), -1);
    for (int i = 0; i < element.getSubjectType().size(); i++) composeCode(t, "Questionnaire", "subjectType", element.getSubjectType().get(i), i);
    if (element.hasDateElement())
        composeDateTime(t, "Questionnaire", "date", element.getDateElement(), -1);
    if (element.hasPublisherElement())
        composeString(t, "Questionnaire", "publisher", element.getPublisherElement(), -1);
    for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "Questionnaire", "contact", element.getContact().get(i), i);
    if (element.hasDescriptionElement())
        composeMarkdown(t, "Questionnaire", "description", element.getDescriptionElement(), -1);
    for (int i = 0; i < element.getUseContext().size(); i++) composeUsageContext(t, "Questionnaire", "useContext", element.getUseContext().get(i), i);
    for (int i = 0; i < element.getJurisdiction().size(); i++) composeCodeableConcept(t, "Questionnaire", "jurisdiction", element.getJurisdiction().get(i), i);
    if (element.hasPurposeElement())
        composeMarkdown(t, "Questionnaire", "purpose", element.getPurposeElement(), -1);
    if (element.hasCopyrightElement())
        composeMarkdown(t, "Questionnaire", "copyright", element.getCopyrightElement(), -1);
    if (element.hasApprovalDateElement())
        composeDate(t, "Questionnaire", "approvalDate", element.getApprovalDateElement(), -1);
    if (element.hasLastReviewDateElement())
        composeDate(t, "Questionnaire", "lastReviewDate", element.getLastReviewDateElement(), -1);
    if (element.hasEffectivePeriod())
        composePeriod(t, "Questionnaire", "effectivePeriod", element.getEffectivePeriod(), -1);
    for (int i = 0; i < element.getCode().size(); i++) composeCoding(t, "Questionnaire", "code", element.getCode().get(i), i);
    for (int i = 0; i < element.getItem().size(); i++) composeQuestionnaireQuestionnaireItemComponent(t, "Questionnaire", "item", element.getItem().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)18 ArrayList (java.util.ArrayList)15 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)12 QuestionnaireItemComponent (org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)11 QuestionnaireItemComponent (org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemComponent)11 File (java.io.File)10 TextFile (org.hl7.fhir.utilities.TextFile)10 Test (org.junit.jupiter.api.Test)10 FileOutputStream (java.io.FileOutputStream)9 Questionnaire (org.hl7.fhir.dstu3.model.Questionnaire)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)8 QuestionnaireItemComponent (org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)8 IOException (java.io.IOException)7 Bundle (org.hl7.fhir.r4.model.Bundle)7 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)7 ValueSet (org.hl7.fhir.r5.model.ValueSet)7 FileNotFoundException (java.io.FileNotFoundException)6 Extension (org.hl7.fhir.r4.model.Extension)6