private Type readConstant(String s, FHIRLexer lexer) throws FHIRLexerException { if (Utilities.isInteger(s)) return new IntegerType(s); else if (Utilities.isDecimal(s)) return new DecimalType(s); else if (Utilities.existsInList(s, "true", "false")) return new BooleanType(s.equals("true")); else return new StringType(lexer.processConstant(s)); }
private void setValueScientific(String value) throws UcumException { int i = value.indexOf("e"); String s = value.substring(0, i); String e = value.substring(i+1); if (Utilities.noString(s) || s.equals("-") || !Utilities.isDecimal(s)) throw new UcumException("'"+value+"' is not a valid decimal (numeric)"); if (Utilities.noString(e) || e.equals("-") || !Utilities.isInteger(e)) throw new UcumException("'"+value+"' is not a valid decimal (exponent)"); setValueDecimal(s); scientific = true; // now adjust for exponent if (e.charAt(0) == '-') i = 1; else i = 0; while (i < e.length()) { if (!Character.isDigit(e.charAt(i))) throw new UcumException(""+value+"' is not a valid decimal"); i++; } i = Integer.parseInt(e); decimal = decimal + i; }
public String makelink() { if (link == null) return predicate; else return "<a href=\""+link+"\">"+Utilities.escapeXml(predicate)+"</a>"; }
public static String sdNs(String type, String overrideVersionNs) { if (Utilities.isAbsoluteUrl(type)) return type; else if (overrideVersionNs != null) return Utilities.pathURL(overrideVersionNs, type); else return "http://hl7.org/fhir/StructureDefinition/"+type; }
private String getSystemType(String url) { if (url.startsWith("http://hl7.org/fhir/StructureDefinition/")) { String code = url.substring(40); if (Utilities.existsInList(code, "string", "boolean", "integer", "decimal", "dateTime", "time", "Quantity")) return FP_NS+Utilities.capitalize(code); } return null; }
private String readConstantType(ExecutionTypeContext context, String constant) throws PathEngineException { if (constant.equals("true")) return "boolean"; else if (constant.equals("false")) return "boolean"; else if (Utilities.isInteger(constant)) return "integer"; else if (Utilities.isDecimal(constant)) return "decimal"; else if (constant.startsWith("%")) return resolveConstantType(context, constant); else return "string"; }
type = ei.name.substring(prefix.length() - 3); if (isPrimitiveType(type)) type = Utilities.uncapitalize(type); } else if (ei.definition.getType().size() > 1) { if ((prefix + Utilities.capitalize(t.getCode())).equals(ei.name)) type = t.getCode(); if (type == null) {
public DateType makeDateFromTS(Element ts) throws Exception { if (ts == null) return null; String v = ts.getAttribute("value"); if (Utilities.noString(v)) return null; DateType d = DateType.parseV3(v); return d; }
private boolean doEquivalent(Base left, Base right) throws PathEngineException { if (left.hasType("integer") && right.hasType("integer")) return doEquals(left, right); if (left.hasType("boolean") && right.hasType("boolean")) return doEquals(left, right); if (left.hasType("integer", "decimal") && right.hasType("integer", "decimal")) return Utilities.equivalentNumber(left.primitiveValue(), right.primitiveValue()); if (left.hasType("date", "dateTime", "time", "instant") && right.hasType("date", "dateTime", "time", "instant")) return Utilities.equivalentNumber(left.primitiveValue(), right.primitiveValue()); if (left.hasType("string", "id", "code", "uri") && right.hasType("string", "id", "code", "uri")) return Utilities.equivalent(convertToString(left), convertToString(right)); throw new PathEngineException(String.format("Unable to determine equivalence between %s and %s", left.fhirType(), right.fhirType())); }
public boolean isPrimitive(String code) { return Utilities.existsInList(code, "boolean", "integer", "string", "decimal", "uri", "base64Binary", "instant", "date", "dateTime", "time", "code", "oid", "id", "markdown", "unsignedInt", "positiveInt", "xhtml", "url", "canonical"); // StructureDefinition sd = context.fetchTypeDefinition(code); // return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE; }
protected int parseIntegerPrimitive(String value) { if (value.startsWith("+") && Utilities.isInteger(value.substring(1))) value = value.substring(1); return java.lang.Integer.parseInt(value); } protected int parseIntegerPrimitive(java.lang.Long value) {
public static String ns(String n) { return Utilities.isAbsoluteUrl(n) ? n : FHIR_NS+n; }
private String generateInnerType(List<StringBuilder> list, StructureDefinition sd, String name, ElementDefinition child, String mode) throws IOException { if (child.hasUserData(INNER_TYPE_NAME+"."+mode)) return child.getUserString(INNER_TYPE_NAME+"."+mode); String typeName = name+Utilities.capitalize(tail(child.getPath(), false)); child.setUserData(INNER_TYPE_NAME+"."+mode, typeName); StringBuilder b = new StringBuilder(); list.add(b); b.append(mode); b.append(" "); b.append(typeName); b.append(" {\r\n"); generateProperties(list, b, typeName, sd, child, mode); b.append("}"); b.append("\r\n"); b.append("\r\n"); return typeName; }
private void copyToDest(String base, String folder, String dest, List<String> res) throws IOException { for (File f : new File(folder).listFiles()) { if (f.isDirectory()) { copyToDest(base, f.getAbsolutePath(), Utilities.path(dest, f.getName()), res); } else { String dst = Utilities.path(dest, f.getName()); FileUtils.copyFile(f, new File(dst), true); res.add(f.getAbsolutePath().substring(base.length()+1)); } } }
public QName getQN(StructureDefinition sd, ElementDefinition edc, String t, boolean chase) throws FHIRException { QName qn = new QName(); qn.type = Utilities.isAbsoluteUrl(t) ? tail(t) : t; if (Utilities.isAbsoluteUrl(t)) { String ns = root(t); if (ns.equals(root(sd.getUrl()))) qn.typeNs = namespaces.get(ns); StructureDefinition lib = library.get(t); if (lib == null && !Utilities.existsInList(t, "http://hl7.org/fhir/cda/StructureDefinition/StrucDoc.Text", "http://hl7.org/fhir/StructureDefinition/Element")) throw new FHIRException("Unable to resolve "+t+" for "+edc.getPath()); if (lib != null)
public void addFolder(String actualDir, String statedDir, boolean omitIfExists) throws IOException { File fd = new CSFile(actualDir); String files[] = fd.list(); for (String f : files) { if (new CSFile(Utilities.path(actualDir, f)).isDirectory()) addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists); else addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists); } }
private String getExtensionType(Element element) { for (Element e : element.getChildren()) { if (e.getName().startsWith("value")) { String tn = e.getName().substring(5); String ltn = Utilities.uncapitalize(tn); if (isPrimitiveType(ltn)) return ltn; else return tn; } } return null; }
private List<Base> funcToDecimal(ExecutionContext context, List<Base> focus, ExpressionNode exp) { String s = convertToString(focus); List<Base> result = new ArrayList<Base>(); if (Utilities.isDecimal(s)) result.add(new DecimalType(s)); return result; }
private void produceAttribute(StructureDefinition sd, ElementDefinition ed, ElementDefinition edc, String lang) throws IOException, FHIRException { TypeRefComponent t = edc.getTypeFirstRep(); String name = tailDot(edc.getPath()); String min = String.valueOf(edc.getMin()); String max = edc.getMax(); // todo: check it's a code... // if (!max.equals("1")) // throw new FHIRException("Illegal cardinality \""+max+"\" for attribute "+edc.getPath()); if (Utilities.isAbsoluteUrl(t.getCode())) throw new FHIRException("Only FHIR primitive types are supported for attributes ("+t.getCode()+")"); String typeNs = namespaces.get("http://hl7.org/fhir"); String type = t.getCode(); w(" <xs:attribute name=\""+name+"\" use=\""+(min.equals("0") || edc.hasFixed() || edc.hasDefaultValue() ? "optional" : "required")+"\" type=\""+typeNs+":"+type+(typeNs.equals("fhir") ? "-primitive" : "")+"\""+ (edc.hasFixed() ? " fixed=\""+edc.getFixed().primitiveValue()+"\"" : "")+(edc.hasDefaultValue() && !edc.hasFixed() ? " default=\""+edc.getDefaultValue().primitiveValue()+"\"" : "")+""); if (annotations && edc.hasDefinition()) { ln(">"); ln(" <xs:annotation>"); ln(" <xs:documentation xml:lang=\""+lang+"\">"+Utilities.escapeXml(edc.getDefinition())+"</xs:documentation>"); ln(" </xs:annotation>"); ln(" </xs:attribute>"); } else ln("/>"); }