Search in sources :

Example 1 with Expression

use of com.walmartlabs.concord.runtime.v2.model.Expression in project quality-measure-and-cohort-service by Alvearie.

the class FhirTestBase method createSupplementalDataComponent.

protected MeasureSupplementalDataComponent createSupplementalDataComponent(String defineName, String text) {
    MeasureSupplementalDataComponent supplementalDataComponent = new MeasureSupplementalDataComponent();
    CodeableConcept supplementalCC = new CodeableConcept();
    Coding supplementalCoding = new Coding();
    supplementalCoding.setCode("supplemental-data-coding");
    supplementalCC.setCoding(Arrays.asList(supplementalCoding));
    supplementalCC.setText(text);
    supplementalDataComponent.setCode(supplementalCC);
    CodeableConcept usage = new CodeableConcept();
    Coding usageCoding = new Coding();
    usageCoding.setCode("supplemental-data");
    usage.setCoding(Arrays.asList(usageCoding));
    supplementalDataComponent.setUsage(Arrays.asList(usage));
    Expression supplementalExpression = new Expression();
    supplementalExpression.setExpression(defineName);
    supplementalExpression.setLanguage("text/cql.identifier");
    supplementalDataComponent.setCriteria(supplementalExpression);
    return supplementalDataComponent;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) Expression(org.hl7.fhir.r4.model.Expression) MeasureSupplementalDataComponent(org.hl7.fhir.r4.model.Measure.MeasureSupplementalDataComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 2 with Expression

use of com.walmartlabs.concord.runtime.v2.model.Expression in project org.hl7.fhir.core by hapifhir.

the class ExpressionAdvisor50 method handleExtension.

public void handleExtension(@Nonnull String path, @Nonnull org.hl7.fhir.r5.model.Extension src, @Nonnull org.hl7.fhir.dstu2.model.Extension tgt) {
    if (src.getValue() instanceof org.hl7.fhir.r5.model.Expression) {
        StringType type = new StringType();
        if (src.getValue() == null) {
            throw new NullPointerException("null cannot be cast to non-null type org.hl7.fhir.r5.model.Expression");
        } else {
            type.setValueAsString(((Expression) src.getValue()).getExpression());
            tgt.setValue(type);
            if (src.hasUrlElement()) {
                tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
            }
        }
    } else {
        throw new FHIRException("Unknown extension type passed in to custom convertor method.");
    }
}
Also used : Expression(org.hl7.fhir.r5.model.Expression) StringType(org.hl7.fhir.dstu2.model.StringType) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with Expression

use of com.walmartlabs.concord.runtime.v2.model.Expression in project org.hl7.fhir.core by hapifhir.

the class Expression40Test method testBaseAdvisorExpressionIgore.

@Test
@DisplayName("Ensure base advisor ignores Expression types and doesn't explode.")
public void testBaseAdvisorExpressionIgore() throws IOException {
    Expression exp = new Expression();
    exp.setExpression("x + y = z");
    Extension ext = new Extension();
    ext.setValue(exp);
    BaseAdvisor_10_40 baseAdvisor1040 = new BaseAdvisor_10_40();
    Assertions.assertTrue(baseAdvisor1040.ignoreExtension("", ext));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Expression(org.hl7.fhir.r4.model.Expression) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Expression

use of com.walmartlabs.concord.runtime.v2.model.Expression in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
    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) {
        renderDateTime(x, e);
    } else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.r5.model.DateType) {
        org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e);
        renderDate(x, dt);
    } 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(x, (CodeableConcept) e, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding(x, (Coding) e, showCodeDetails);
    } else if (e instanceof CodeableReference) {
        renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation(x, (Annotation) e);
    } else if (e instanceof Identifier) {
        renderIdentifier(x, (Identifier) e);
    } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
        if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) {
            x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) {
        if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) {
            x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
        x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName(x, (HumanName) e);
    } else if (e instanceof SampledData) {
        renderSampledData(x, (SampledData) e);
    } else if (e instanceof Address) {
        renderAddress(x, (Address) e);
    } else if (e instanceof ContactPoint) {
        renderContactPoint(x, (ContactPoint) e);
    } else if (e instanceof Expression) {
        renderExpression(x, (Expression) e);
    } else if (e instanceof Money) {
        renderMoney(x, (Money) e);
    } else if (e instanceof ContactDetail) {
        ContactDetail cd = (ContactDetail) e;
        if (cd.hasName()) {
            x.tx(cd.getName() + ": ");
        }
        boolean first = true;
        for (ContactPoint c : cd.getTelecom()) {
            if (first)
                first = false;
            else
                x.tx(",");
            renderContactPoint(x, c);
        }
    } else if (e instanceof UriType) {
        renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
    } else if (e instanceof Timing) {
        renderTiming(x, (Timing) e);
    } else if (e instanceof Range) {
        renderRange(x, (Range) e);
    } else if (e instanceof Quantity) {
        renderQuantity(x, (Quantity) e, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
        x.tx("/");
        renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        renderPeriod(x, p);
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.getReference() != null && r.getReference().contains("#")) {
            if (containedIds.contains(r.getReference().substring(1))) {
                x.ah(r.getReference()).tx("See " + r.getReference());
            } else {
                // in this case, we render the resource in line
                ResourceWrapper rw = null;
                for (ResourceWrapper t : res.getContained()) {
                    if (r.getReference().substring(1).equals(t.getId())) {
                        rw = t;
                    }
                }
                if (rw == null) {
                    renderReference(res, x, r);
                } else {
                    x.an(rw.getId());
                    ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
                    rr.render(parent.blockquote(), rw);
                }
            }
        } else {
            renderReference(res, x, r);
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof DataRequirement) {
        DataRequirement p = (DataRequirement) e;
        renderDataRequirement(x, p);
    } else if (e instanceof PrimitiveType) {
        x.tx(((PrimitiveType) e).primitiveValue());
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
    }
}
Also used : ResourceWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper) Meta(org.hl7.fhir.r5.model.Meta) Address(org.hl7.fhir.r5.model.Address) StringType(org.hl7.fhir.r5.model.StringType) Attachment(org.hl7.fhir.r5.model.Attachment) DataRequirement(org.hl7.fhir.r5.model.DataRequirement) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) Narrative(org.hl7.fhir.r5.model.Narrative) SampledData(org.hl7.fhir.r5.model.SampledData) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) InstantType(org.hl7.fhir.r5.model.InstantType) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Period(org.hl7.fhir.r5.model.Period) Range(org.hl7.fhir.r5.model.Range) IdType(org.hl7.fhir.r5.model.IdType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) Timing(org.hl7.fhir.r5.model.Timing) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r5.model.UriType) HumanName(org.hl7.fhir.r5.model.HumanName) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Money(org.hl7.fhir.r5.model.Money) Ratio(org.hl7.fhir.r5.model.Ratio) Enumeration(org.hl7.fhir.r5.model.Enumeration) Reference(org.hl7.fhir.r5.model.Reference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Quantity(org.hl7.fhir.r5.model.Quantity) Base(org.hl7.fhir.r5.model.Base) Annotation(org.hl7.fhir.r5.model.Annotation) Extension(org.hl7.fhir.r5.model.Extension) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) Expression(org.hl7.fhir.r5.model.Expression) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) CodeType(org.hl7.fhir.r5.model.CodeType) Base64BinaryType(org.hl7.fhir.r5.model.Base64BinaryType)

Example 5 with Expression

use of com.walmartlabs.concord.runtime.v2.model.Expression in project CRD by HL7-DaVinci.

the class QuestionnaireEmbeddedCQLProcessor method findAndReplaceEmbeddedCql.

private void findAndReplaceEmbeddedCql(List<QuestionnaireItemComponent> itemComponents) {
    for (QuestionnaireItemComponent itemComponent : itemComponents) {
        if (hasEmbeddedCql(itemComponent)) {
            List<Extension> extensionList = itemComponent.getExtension();
            for (int i = 0; i < extensionList.size(); i++) {
                Extension extension = extensionList.get(i);
                if (extension.getUrl().equals("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression")) {
                    Expression expression = (Expression) extension.getValue();
                    if (expression.getLanguage().equals("text/cql")) {
                        String expressionString = expression.getExpression();
                        // regex for \"library\".statement
                        final String libraryRefRegex = "^\"[a-zA-Z0-9]+\".[a-zA-Z0-9]+$";
                        final Pattern pattern = Pattern.compile(libraryRefRegex, Pattern.MULTILINE);
                        // cql-execution library to throw error if it is invalid
                        if (!pattern.matcher(expressionString).find()) {
                            String cqlExpression = String.format(CQL_DEFINE_LINKID_PATTERN, itemComponent.getLinkId(), expressionString);
                            String elm = null;
                            try {
                                elm = CqlExecution.translateToElm(cqlExpression, this);
                            // logger.info("converted elm: " + elm);
                            } catch (Exception e) {
                                logger.error("Failed to convert inline CQL to elm. For linkId " + itemComponent.getLinkId());
                            }
                            if (elm != null) {
                                expression.setExpression(elm);
                                expression.setLanguage("application/elm+json");
                            }
                        }
                    }
                }
            }
        }
        if (itemComponent.hasItem()) {
            findAndReplaceEmbeddedCql(itemComponent.getItem());
        }
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Pattern(java.util.regex.Pattern) QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent) Expression(org.hl7.fhir.r4.model.Expression)

Aggregations

Expression (org.hl7.fhir.r4.model.Expression)8 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 Coding (org.hl7.fhir.r4.model.Coding)4 Extension (org.hl7.fhir.r4.model.Extension)3 Measure (org.hl7.fhir.r4.model.Measure)3 Expression (org.hl7.fhir.r5.model.Expression)3 Expression (com.walmartlabs.concord.runtime.v2.model.Expression)2 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)2 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)2 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 StringType (org.hl7.fhir.dstu2.model.StringType)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 ApiException (com.walmartlabs.concord.ApiException)1 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 ExpressionOptions (com.walmartlabs.concord.runtime.v2.model.ExpressionOptions)1 ProcessDefinition (com.walmartlabs.concord.runtime.v2.model.ProcessDefinition)1 Step (com.walmartlabs.concord.runtime.v2.model.Step)1 SynchronizationService (com.walmartlabs.concord.runtime.v2.runner.SynchronizationService)1 CheckpointService (com.walmartlabs.concord.runtime.v2.runner.checkpoints.CheckpointService)1