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);
}
}
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>();
}
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>();
}
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());
}
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;
}
Aggregations