Search in sources :

Example 26 with Ratio

use of org.hl7.fhir.r5.model.Ratio in project org.hl7.fhir.core by hapifhir.

the class MeasureValidator method validateMeasureReport.

// ---------------------------------------------------------------------------------------------------------------------------------------------------------
public void validateMeasureReport(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element element, NodeStack stack) throws FHIRException {
    Element m = element.getNamedChild("measure");
    String measure = null;
    if (m != null) {
        /*
       * q.getValue() is correct for R4 content, but we'll also accept the second
       * option just in case we're validating raw STU3 content. Being lenient here
       * isn't the end of the world since if someone is actually doing the reference
       * wrong in R4 content it'll get flagged elsewhere by the validator too
       */
        if (isNotBlank(m.getValue())) {
            measure = m.getValue();
        } else if (isNotBlank(m.getChildValue("reference"))) {
            measure = m.getChildValue("reference");
        }
    }
    if (hint(errors, IssueType.REQUIRED, element.line(), element.col(), stack.getLiteralPath(), measure != null, I18nConstants.MEASURE_MR_M_NONE)) {
        long t = System.nanoTime();
        Measure msrc = measure.startsWith("#") ? loadMeasure(element, measure.substring(1)) : context.fetchResource(Measure.class, measure);
        timeTracker.sd(t);
        if (warning(errors, IssueType.REQUIRED, m.line(), m.col(), stack.getLiteralPath(), msrc != null, I18nConstants.MEASURE_MR_M_NOTFOUND, measure)) {
            boolean inComplete = !"complete".equals(element.getNamedChildValue("status"));
            MeasureContext mc = new MeasureContext(msrc, element);
            NodeStack ns = stack.push(m, -1, m.getProperty().getDefinition(), m.getProperty().getDefinition());
            hint(errors, IssueType.BUSINESSRULE, m.line(), m.col(), ns.getLiteralPath(), Utilities.existsInList(mc.scoring(), "proportion", "ratio", "continuous-variable", "cohort"), I18nConstants.MEASURE_MR_M_SCORING_UNK);
            validateMeasureReportGroups(hostContext, mc, errors, element, stack, inComplete);
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) Measure(org.hl7.fhir.r5.model.Measure) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack)

Example 27 with Ratio

use of org.hl7.fhir.r5.model.Ratio 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 28 with Ratio

use of org.hl7.fhir.r5.model.Ratio in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent, ResourceContext rc) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        return;
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType) {
        if (e.hasPrimitiveValue())
            x.addText(((DateTimeType) e).toHumanDisplay());
    } else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.r4.model.DateType)
        x.addText(((org.hl7.fhir.r4.model.DateType) e).toHumanDisplay());
    else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType)
        x.addText(((BooleanType) e).getValue().toString());
    else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.r4.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.r4.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.r4.model.DecimalType) {
        x.addText(((org.hl7.fhir.r4.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x, defn.getPath(), rc != null && rc.resourceResource != null ? rc.resourceResource.getId() : null);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.tx("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference(), rc);
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.ah(tr.getReference());
                else
                    c = x.ah(r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null && tr.getResource() != null) {
                c.tx(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"), rc);
            }
        } else if (tr != null && tr.getResource() != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"), rc);
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
        if (sd == null)
            throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
        else
            generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails, indent + 1, rc);
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) Enumeration(org.hl7.fhir.r4.model.Enumeration) EventTiming(org.hl7.fhir.r4.model.Timing.EventTiming)

Example 29 with Ratio

use of org.hl7.fhir.r5.model.Ratio in project org.hl7.fhir.core by hapifhir.

the class JsonParser method composeType.

protected void composeType(String prefix, DataType type) throws IOException {
    if (type == null) {
        ;
    } else if (type instanceof Address) {
        composeAddress(prefix + "Address", (Address) type);
    } else if (type instanceof Age) {
        composeAge(prefix + "Age", (Age) type);
    } else if (type instanceof Annotation) {
        composeAnnotation(prefix + "Annotation", (Annotation) type);
    } else if (type instanceof Attachment) {
        composeAttachment(prefix + "Attachment", (Attachment) type);
    } else if (type instanceof CodeableConcept) {
        composeCodeableConcept(prefix + "CodeableConcept", (CodeableConcept) type);
    } else if (type instanceof CodeableReference) {
        composeCodeableReference(prefix + "CodeableReference", (CodeableReference) type);
    } else if (type instanceof Coding) {
        composeCoding(prefix + "Coding", (Coding) type);
    } else if (type instanceof ContactDetail) {
        composeContactDetail(prefix + "ContactDetail", (ContactDetail) type);
    } else if (type instanceof ContactPoint) {
        composeContactPoint(prefix + "ContactPoint", (ContactPoint) type);
    } else if (type instanceof Contributor) {
        composeContributor(prefix + "Contributor", (Contributor) type);
    } else if (type instanceof Count) {
        composeCount(prefix + "Count", (Count) type);
    } else if (type instanceof DataRequirement) {
        composeDataRequirement(prefix + "DataRequirement", (DataRequirement) type);
    } else if (type instanceof Distance) {
        composeDistance(prefix + "Distance", (Distance) type);
    } else if (type instanceof Dosage) {
        composeDosage(prefix + "Dosage", (Dosage) type);
    } else if (type instanceof Duration) {
        composeDuration(prefix + "Duration", (Duration) type);
    } else if (type instanceof ElementDefinition) {
        composeElementDefinition(prefix + "ElementDefinition", (ElementDefinition) type);
    } else if (type instanceof Expression) {
        composeExpression(prefix + "Expression", (Expression) type);
    } else if (type instanceof Extension) {
        composeExtension(prefix + "Extension", (Extension) type);
    } else if (type instanceof HumanName) {
        composeHumanName(prefix + "HumanName", (HumanName) type);
    } else if (type instanceof Identifier) {
        composeIdentifier(prefix + "Identifier", (Identifier) type);
    } else if (type instanceof MarketingStatus) {
        composeMarketingStatus(prefix + "MarketingStatus", (MarketingStatus) type);
    } else if (type instanceof Meta) {
        composeMeta(prefix + "Meta", (Meta) type);
    } else if (type instanceof Money) {
        composeMoney(prefix + "Money", (Money) type);
    } else if (type instanceof Narrative) {
        composeNarrative(prefix + "Narrative", (Narrative) type);
    } else if (type instanceof ParameterDefinition) {
        composeParameterDefinition(prefix + "ParameterDefinition", (ParameterDefinition) type);
    } else if (type instanceof Period) {
        composePeriod(prefix + "Period", (Period) type);
    } else if (type instanceof Population) {
        composePopulation(prefix + "Population", (Population) type);
    } else if (type instanceof ProdCharacteristic) {
        composeProdCharacteristic(prefix + "ProdCharacteristic", (ProdCharacteristic) type);
    } else if (type instanceof ProductShelfLife) {
        composeProductShelfLife(prefix + "ProductShelfLife", (ProductShelfLife) type);
    } else if (type instanceof Quantity) {
        composeQuantity(prefix + "Quantity", (Quantity) type);
    } else if (type instanceof Range) {
        composeRange(prefix + "Range", (Range) type);
    } else if (type instanceof Ratio) {
        composeRatio(prefix + "Ratio", (Ratio) type);
    } else if (type instanceof RatioRange) {
        composeRatioRange(prefix + "RatioRange", (RatioRange) type);
    } else if (type instanceof Reference) {
        composeReference(prefix + "Reference", (Reference) type);
    } else if (type instanceof RelatedArtifact) {
        composeRelatedArtifact(prefix + "RelatedArtifact", (RelatedArtifact) type);
    } else if (type instanceof SampledData) {
        composeSampledData(prefix + "SampledData", (SampledData) type);
    } else if (type instanceof Signature) {
        composeSignature(prefix + "Signature", (Signature) type);
    } else if (type instanceof Timing) {
        composeTiming(prefix + "Timing", (Timing) type);
    } else if (type instanceof TriggerDefinition) {
        composeTriggerDefinition(prefix + "TriggerDefinition", (TriggerDefinition) type);
    } else if (type instanceof UsageContext) {
        composeUsageContext(prefix + "UsageContext", (UsageContext) type);
    } else if (type instanceof CodeType) {
        composeCodeCore(prefix + "Code", (CodeType) type, false);
        composeCodeExtras(prefix + "Code", (CodeType) type, false);
    } else if (type instanceof OidType) {
        composeOidCore(prefix + "Oid", (OidType) type, false);
        composeOidExtras(prefix + "Oid", (OidType) type, false);
    } else if (type instanceof CanonicalType) {
        composeCanonicalCore(prefix + "Canonical", (CanonicalType) type, false);
        composeCanonicalExtras(prefix + "Canonical", (CanonicalType) type, false);
    } else if (type instanceof UuidType) {
        composeUuidCore(prefix + "Uuid", (UuidType) type, false);
        composeUuidExtras(prefix + "Uuid", (UuidType) type, false);
    } else if (type instanceof UrlType) {
        composeUrlCore(prefix + "Url", (UrlType) type, false);
        composeUrlExtras(prefix + "Url", (UrlType) type, false);
    } else if (type instanceof UnsignedIntType) {
        composeUnsignedIntCore(prefix + "UnsignedInt", (UnsignedIntType) type, false);
        composeUnsignedIntExtras(prefix + "UnsignedInt", (UnsignedIntType) type, false);
    } else if (type instanceof MarkdownType) {
        composeMarkdownCore(prefix + "Markdown", (MarkdownType) type, false);
        composeMarkdownExtras(prefix + "Markdown", (MarkdownType) type, false);
    } else if (type instanceof IdType) {
        composeIdCore(prefix + "Id", (IdType) type, false);
        composeIdExtras(prefix + "Id", (IdType) type, false);
    } else if (type instanceof PositiveIntType) {
        composePositiveIntCore(prefix + "PositiveInt", (PositiveIntType) type, false);
        composePositiveIntExtras(prefix + "PositiveInt", (PositiveIntType) type, false);
    } else if (type instanceof DateType) {
        composeDateCore(prefix + "Date", (DateType) type, false);
        composeDateExtras(prefix + "Date", (DateType) type, false);
    } else if (type instanceof DateTimeType) {
        composeDateTimeCore(prefix + "DateTime", (DateTimeType) type, false);
        composeDateTimeExtras(prefix + "DateTime", (DateTimeType) type, false);
    } else if (type instanceof StringType) {
        composeStringCore(prefix + "String", (StringType) type, false);
        composeStringExtras(prefix + "String", (StringType) type, false);
    } else if (type instanceof IntegerType) {
        composeIntegerCore(prefix + "Integer", (IntegerType) type, false);
        composeIntegerExtras(prefix + "Integer", (IntegerType) type, false);
    } else if (type instanceof Integer64Type) {
        composeInteger64Core(prefix + "Integer64", (Integer64Type) type, false);
        composeInteger64Extras(prefix + "Integer64", (Integer64Type) type, false);
    } else if (type instanceof UriType) {
        composeUriCore(prefix + "Uri", (UriType) type, false);
        composeUriExtras(prefix + "Uri", (UriType) type, false);
    } else if (type instanceof InstantType) {
        composeInstantCore(prefix + "Instant", (InstantType) type, false);
        composeInstantExtras(prefix + "Instant", (InstantType) type, false);
    } else if (type instanceof BooleanType) {
        composeBooleanCore(prefix + "Boolean", (BooleanType) type, false);
        composeBooleanExtras(prefix + "Boolean", (BooleanType) type, false);
    } else if (type instanceof Base64BinaryType) {
        composeBase64BinaryCore(prefix + "Base64Binary", (Base64BinaryType) type, false);
        composeBase64BinaryExtras(prefix + "Base64Binary", (Base64BinaryType) type, false);
    } else if (type instanceof TimeType) {
        composeTimeCore(prefix + "Time", (TimeType) type, false);
        composeTimeExtras(prefix + "Time", (TimeType) type, false);
    } else if (type instanceof DecimalType) {
        composeDecimalCore(prefix + "Decimal", (DecimalType) type, false);
        composeDecimalExtras(prefix + "Decimal", (DecimalType) type, false);
    } else
        throw new Error("Unhandled type");
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 30 with Ratio

use of org.hl7.fhir.r5.model.Ratio in project org.hl7.fhir.core by hapifhir.

the class JavaResourceGenerator method generateChildrenRegister.

private void generateChildrenRegister(Analysis analysis, TypeInfo ti, String indent) throws Exception {
    String rn = analysis.getName();
    boolean isInterface = analysis.isInterface();
    List<ElementDefinition> children = ti.getChildren();
    write(indent + "  protected void listChildren(List<Property> children) {\r\n");
    write(indent + "    super.listChildren(children);\r\n");
    for (ElementDefinition e : children) {
        if (!isInterface && !e.typeSummary().equals("xhtml")) {
            write(indent + "    children.add(new Property(\"" + e.getName() + "\", \"" + resolvedTypeCode(e) + "\", \"" + Utilities.escapeJava(replaceTitle(rn, e.getDefinition())) + "\", 0, " + (e.unbounded() ? "java.lang.Integer.MAX_VALUE" : e.getMax()) + ", " + getElementName(e.getName(), true) + "));\r\n");
        }
    }
    write(indent + "  }\r\n\r\n");
    write(indent + "  @Override\r\n");
    write(indent + "  public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {\r\n");
    write(indent + "    switch (_hash) {\r\n");
    for (ElementDefinition e : children) {
        if (!isInterface && !e.typeSummary().equals("xhtml")) {
            write(indent + "    case " + propId(e.getName()) + ": /*" + e.getName() + "*/ ");
            write(" return new Property(\"" + e.getName() + "\", \"" + resolvedTypeCode(e) + "\", \"" + Utilities.escapeJava(replaceTitle(rn, e.getDefinition())) + "\", 0, " + (e.unbounded() ? "java.lang.Integer.MAX_VALUE" : e.getMax()) + ", " + getElementName(e.getName(), true) + ");\r\n");
            if (e.getName().endsWith("[x]")) {
                String n = e.getName().substring(0, e.getName().length() - 3);
                write(indent + "    case " + propId(n) + ": /*" + n + "*/ ");
                write(" return new Property(\"" + e.getName() + "\", \"" + resolvedTypeCode(e) + "\", \"" + Utilities.escapeJava(replaceTitle(rn, e.getDefinition())) + "\", 0, " + (e.unbounded() ? "java.lang.Integer.MAX_VALUE" : e.getMax()) + ", " + getElementName(e.getName(), true) + ");\r\n");
                if (e.typeSummary().equals("*")) {
                    // master list in datatypes.html
                    for (String t : new String[] { "base64Binary", "boolean", "canonical", "code", "date", "dateTime", "decimal", "id", "instant", "integer", "integer64", "markdown", "oid", "positiveInt", "string", "time", "unsignedInt", "uri", "url", "uuid", "Address", "Annotation", "Attachment", "CodeableConcept", "Coding", "ContactPoint", "HumanName", "Identifier", "Period", "Quantity", "Range", "Ratio", "Reference", "SampledData", "Signature", "Timing", "Dosage" }) {
                        String tn = n + Utilities.capitalize(t);
                        write(indent + "    case " + propId(tn) + ": /*" + tn + "*/ ");
                        write(" return new Property(\"" + e.getName() + "\", \"" + resolvedTypeCode(e, t) + "\", \"" + Utilities.escapeJava(replaceTitle(rn, e.getDefinition())) + "\", 0, " + (e.unbounded() ? "java.lang.Integer.MAX_VALUE" : e.getMax()) + ", " + getElementName(e.getName(), true) + ");\r\n");
                    }
                } else
                    for (TypeRefComponent tr : e.getType()) {
                        String tn = n + Utilities.capitalize(checkConstraint(tr.getCode()));
                        write(indent + "    case " + propId(tn) + ": /*" + tn + "*/ ");
                        write(" return new Property(\"" + e.getName() + "\", \"" + resolvedTypeCode(e, tr.getCode()) + "\", \"" + Utilities.escapeJava(replaceTitle(rn, e.getDefinition())) + "\", 0, " + (e.unbounded() ? "java.lang.Integer.MAX_VALUE" : e.getMax()) + ", " + getElementName(e.getName(), true) + ");\r\n");
                    }
            }
        }
    }
    write(indent + "    default: return super.getNamedProperty(_hash, _name, _checkValid);\r\n");
    write(indent + "    }\r\n\r\n");
    write(indent + "  }\r\n\r\n");
}
Also used : TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Ratio (org.hl7.fhir.r4.model.Ratio)8 Resource (org.hl7.fhir.r4.model.Resource)7 Base64 (org.apache.commons.codec.binary.Base64)6 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)2 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2 ListResource (org.hl7.fhir.r4.model.ListResource)2 Measure (org.hl7.fhir.r4.model.Measure)2 MeasureReport (org.hl7.fhir.r4.model.MeasureReport)2 Patient (org.hl7.fhir.r4.model.Patient)2