Search in sources :

Example 26 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method processDataType.

private void processDataType(StructureDefinition profile, QuestionnaireItemComponent group, ElementDefinition element, String path, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups, List<ElementDefinition> parents) throws FHIRException {
    String tc = t.getWorkingCode();
    if (tc.equals("code"))
        addCodeQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "string", "id", "oid", "uuid", "markdown"))
        addStringQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "uri", "url", "canonical"))
        addUriQuestions(group, element, path, answerGroups);
    else if (tc.equals("boolean"))
        addBooleanQuestions(group, element, path, answerGroups);
    else if (tc.equals("decimal"))
        addDecimalQuestions(group, element, path, answerGroups);
    else if (tc.equals("dateTime") || tc.equals("date"))
        addDateTimeQuestions(group, element, path, answerGroups);
    else if (tc.equals("instant"))
        addInstantQuestions(group, element, path, answerGroups);
    else if (tc.equals("time"))
        addTimeQuestions(group, element, path, answerGroups);
    else if (tc.equals("CodeableConcept"))
        addCodeableConceptQuestions(group, element, path, answerGroups);
    else if (tc.equals("Period"))
        addPeriodQuestions(group, element, path, answerGroups);
    else if (tc.equals("Ratio"))
        addRatioQuestions(group, element, path, answerGroups);
    else if (tc.equals("HumanName"))
        addHumanNameQuestions(group, element, path, answerGroups);
    else if (tc.equals("Address"))
        addAddressQuestions(group, element, path, answerGroups);
    else if (tc.equals("ContactPoint"))
        addContactPointQuestions(group, element, path, answerGroups);
    else if (tc.equals("Identifier"))
        addIdentifierQuestions(group, element, path, answerGroups);
    else if (tc.equals("integer") || tc.equals("positiveInt") || tc.equals("unsignedInt"))
        addIntegerQuestions(group, element, path, answerGroups);
    else if (tc.equals("Coding"))
        addCodingQuestions(group, element, path, answerGroups);
    else if (Utilities.existsInList(tc, "Quantity", "Count", "Age", "Duration", "Distance", "Money"))
        addQuantityQuestions(group, element, path, answerGroups);
    else if (tc.equals("Money"))
        addMoneyQuestions(group, element, path, answerGroups);
    else if (tc.equals("Reference"))
        addReferenceQuestions(group, element, path, t.getTargetProfile(), answerGroups);
    else if (tc.equals("Duration"))
        addDurationQuestions(group, element, path, answerGroups);
    else if (tc.equals("base64Binary"))
        addBinaryQuestions(group, element, path, answerGroups);
    else if (tc.equals("Attachment"))
        addAttachmentQuestions(group, element, path, answerGroups);
    else if (tc.equals("Age"))
        addAgeQuestions(group, element, path, answerGroups);
    else if (tc.equals("Range"))
        addRangeQuestions(group, element, path, answerGroups);
    else if (tc.equals("Timing"))
        addTimingQuestions(group, element, path, answerGroups);
    else if (tc.equals("Annotation"))
        addAnnotationQuestions(group, element, path, answerGroups);
    else if (tc.equals("SampledData"))
        addSampledDataQuestions(group, element, path, answerGroups);
    else if (tc.equals("Extension")) {
        if (t.hasProfile())
            addExtensionQuestions(profile, group, element, path, t.getProfile().get(0).getValue(), answerGroups, parents);
    } else if (tc.equals("SampledData"))
        addSampledDataQuestions(group, element, path, answerGroups);
    else if (!tc.equals("Narrative") && !tc.equals("Resource") && !tc.equals("Meta") && !tc.equals("Signature")) {
        StructureDefinition sd = context.fetchTypeDefinition(tc);
        if (sd == null)
            throw new NotImplementedException("Unhandled Data Type: " + tc + " on element " + element.getPath());
        buildGroup(group, sd, sd.getSnapshot().getElementFirstRep(), parents, answerGroups);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 27 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opLessOrEqual.

private List<Base> opLessOrEqual(List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
    if (left.size() == 0 || right.size() == 0) {
        return new ArrayList<Base>();
    }
    if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
        Base l = left.get(0);
        Base r = right.get(0);
        if (l.hasType(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING)) {
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) <= 0);
        } else if ((l.hasType("integer", "decimal", "unsignedInt", "positiveInt")) && (r.hasType("integer", "decimal", "unsignedInt", "positiveInt"))) {
            return makeBoolean(new Double(l.primitiveValue()) <= new Double(r.primitiveValue()));
        } else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant"))) {
            Integer i = compareDateTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i <= 0);
            }
        } else if ((l.hasType("time")) && (r.hasType("time"))) {
            Integer i = compareTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i <= 0);
            }
        } else {
            throw makeException(expr, I18nConstants.FHIRPATH_CANT_COMPARE, l.fhirType(), r.fhirType());
        }
    } else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
        List<Base> lUnits = left.get(0).listChildrenByName("unit");
        String lunit = lUnits.size() == 1 ? lUnits.get(0).primitiveValue() : null;
        List<Base> rUnits = right.get(0).listChildrenByName("unit");
        String runit = rUnits.size() == 1 ? rUnits.get(0).primitiveValue() : null;
        if ((lunit == null && runit == null) || lunit.equals(runit)) {
            return opLessOrEqual(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"), expr);
        } else {
            if (worker.getUcumService() == null) {
                return makeBoolean(false);
            } else {
                List<Base> dl = new ArrayList<Base>();
                dl.add(qtyToCanonicalDecimal((Quantity) left.get(0)));
                List<Base> dr = new ArrayList<Base>();
                dr.add(qtyToCanonicalDecimal((Quantity) right.get(0)));
                return opLessOrEqual(dl, dr, expr);
            }
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) MergedList(org.hl7.fhir.utilities.MergedList) List(java.util.List) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r4b.model.Base)

Example 28 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opGreater.

private List<Base> opGreater(List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
    if (left.size() == 0 || right.size() == 0)
        return new ArrayList<Base>();
    if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
        Base l = left.get(0);
        Base r = right.get(0);
        if (l.hasType(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING)) {
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
        } else if ((l.hasType("integer", "decimal", "unsignedInt", "positiveInt")) && (r.hasType("integer", "decimal", "unsignedInt", "positiveInt"))) {
            return makeBoolean(new Double(l.primitiveValue()) > new Double(r.primitiveValue()));
        } else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant"))) {
            Integer i = compareDateTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i > 0);
            }
        } else if ((l.hasType("time")) && (r.hasType("time"))) {
            Integer i = compareTimeElements(l, r, false);
            if (i == null) {
                return makeNull();
            } else {
                return makeBoolean(i > 0);
            }
        } else {
            throw makeException(expr, I18nConstants.FHIRPATH_CANT_COMPARE, l.fhirType(), r.fhirType());
        }
    } else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
        List<Base> lUnit = left.get(0).listChildrenByName("unit");
        List<Base> rUnit = right.get(0).listChildrenByName("unit");
        if (Base.compareDeep(lUnit, rUnit, true)) {
            return opGreater(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"), expr);
        } else {
            if (worker.getUcumService() == null) {
                return makeBoolean(false);
            } else {
                List<Base> dl = new ArrayList<Base>();
                dl.add(qtyToCanonicalDecimal((Quantity) left.get(0)));
                List<Base> dr = new ArrayList<Base>();
                dr.add(qtyToCanonicalDecimal((Quantity) right.get(0)));
                return opGreater(dl, dr, expr);
            }
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) MergedList(org.hl7.fhir.utilities.MergedList) List(java.util.List) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r4b.model.Base)

Example 29 with DateTime

use of org.hl7.elm.r1.DateTime in project org.hl7.fhir.core by hapifhir.

the class XLSXmlParser method readData.

private String readData(Element cell, int col, String s) throws DOMException, FHIRException {
    List<Element> data = new ArrayList<Element>();
    // cell.getElementsByTagNameNS(XLS_NS, "Data");
    XMLUtil.getNamedChildren(cell, "Data", data);
    if (data.size() == 0)
        return "";
    check(data.size() == 1, "Multiple Data encountered (" + Integer.toString(data.size()) + " @ col " + Integer.toString(col) + " - " + cell.getTextContent() + " (" + s + "))");
    Element d = data.get(0);
    String type = d.getAttributeNS(XLS_NS, "Type");
    if ("Boolean".equals(type)) {
        if (d.getTextContent().equals("1"))
            return "True";
        else
            return "False";
    } else if ("String".equals(type)) {
        return d.getTextContent();
    } else if ("Number".equals(type)) {
        return d.getTextContent();
    } else if ("DateTime".equals(type)) {
        return d.getTextContent();
    } else if ("Error".equals(type)) {
        return null;
    } else
        throw new FHIRException("Cell Type is not known (" + d.getAttributeNodeNS(XLS_NS, "Type") + ") in " + getLocation());
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 30 with DateTime

use of org.hl7.elm.r1.DateTime in project odm2fhir by num-codex.

the class StageAtDiagnosis method createCondition.

private Condition createCondition(ItemData generalCoding, ItemData answerCoding) {
    var condition = (Condition) new Condition().addIdentifier(createIdentifier(CONDITION, generalCoding)).setRecordedDateElement(// TODO Set actual DateTime value
    UNKNOWN_DATE_TIME).addCategory(createCodeableConcept(createCoding(SNOMED_CT, "394807007", "Infectious diseases (specialty) (qualifier value)"))).setClinicalStatus(ACTIVE).setCode(createCodeableConcept(createCoding(SNOMED_CT, "840539006", "Disease caused by Severe acute respiratory syndrome coronavirus 2 (disorder)"))).setVerificationStatus(CONFIRMED).setMeta(createMeta(DIAGNOSIS_COVID_19));
    var summaryCodeableConcept = createCodeableConcept(answerCoding);
    var typeCodeableConcept = createCodeableConcept(generalCoding);
    if (!summaryCodeableConcept.getCoding().isEmpty() && !typeCodeableConcept.getCoding().isEmpty()) {
        condition.addStage(new ConditionStageComponent().setSummary(summaryCodeableConcept).setType(typeCodeableConcept));
    }
    return condition;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) ConditionStageComponent(org.hl7.fhir.r4.model.Condition.ConditionStageComponent)

Aggregations

ArrayList (java.util.ArrayList)30 List (java.util.List)21 LinkedHashSet (java.util.LinkedHashSet)20 Test (org.junit.Test)18 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)16 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 Before (org.junit.Before)11 Set (java.util.Set)10 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 Condition (org.hl7.fhir.r4.model.Condition)8 MergedList (org.hl7.fhir.utilities.MergedList)8 Date (java.util.Date)5 HashMap (java.util.HashMap)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 Period (org.hl7.fhir.r4.model.Period)4 Procedure (org.hl7.fhir.r4.model.Procedure)4 CodeType (org.hl7.fhir.r5.model.CodeType)4 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)4