Search in sources :

Example 51 with TypeRef

use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.

the class SourceParser method processStringPattern.

private void processStringPattern(Sheet sheet, int row) throws Exception {
    DefinedStringPattern prim = new DefinedStringPattern();
    prim.setCode(sheet.getColumn(row, "Data Type"));
    prim.setDefinition(sheet.getColumn(row, "Definition"));
    prim.setComment(sheet.getColumn(row, "Comments"));
    prim.setRegex(sheet.getColumn(row, "RegEx"));
    prim.setSchema(sheet.getColumn(row, "Schema"));
    prim.setJsonType(sheet.getColumn(row, "Json"));
    prim.setBase(sheet.getColumn(row, "Base"));
    TypeRef td = new TypeRef();
    td.setName(prim.getCode());
    definitions.getKnownTypes().add(td);
    definitions.getPrimitives().put(prim.getCode(), prim);
}
Also used : DefinedStringPattern(org.hl7.fhir.definitions.model.DefinedStringPattern) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Example 52 with TypeRef

use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.

the class SourceParser method processImport.

private void processImport(Sheet sheet, int row) throws Exception {
    PrimitiveType prim = new PrimitiveType();
    prim.setCode(sheet.getColumn(row, "Data Type"));
    prim.setDefinition(sheet.getColumn(row, "Definition"));
    prim.setComment(sheet.getColumn(row, "Comments"));
    prim.setSchemaType(sheet.getColumn(row, "Schema"));
    prim.setJsonType(sheet.getColumn(row, "Json"));
    prim.setRegex(sheet.getColumn(row, "RegEx"));
    prim.setV2(sheet.getColumn(row, "v2"));
    prim.setV3(sheet.getColumn(row, "v3"));
    TypeRef td = new TypeRef();
    td.setName(prim.getCode());
    definitions.getKnownTypes().add(td);
    definitions.getPrimitives().put(prim.getCode(), prim);
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) PrimitiveType(org.hl7.fhir.definitions.model.PrimitiveType)

Example 53 with TypeRef

use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.

the class TypeParser method parse.

public List<TypeRef> parse(String n, boolean inProfile, String profileExtensionBase, BaseWorkerContext resolver, boolean allowElement, String sheetName) throws Exception {
    ArrayList<TypeRef> a = new ArrayList<TypeRef>();
    String exceptionPrefix = sheetName == null ? "" : "Error parsing sheet " + sheetName + " - ";
    if (n == null || n.equals("") || n.startsWith("!"))
        return a;
    // to allow splitting
    if (n.indexOf("(") != -1 && n.indexOf("|") != -1) {
        String[] typeParts = n.split("[\\(\\)]");
        n = "";
        for (int i = 0; i < typeParts.length; i++) {
            n = n + typeParts[i++];
            if (i < typeParts.length) {
                n = n + "(" + typeParts[i].replace("|", ",") + ")";
            }
        }
    }
    String[] typeList = n.split("[\\|]");
    for (int i = 0; i < typeList.length; i++) {
        TypeRef t = new TypeRef();
        String typeString = typeList[i].trim();
        if (typeString.contains("<")) {
            if (!inProfile) {
                throw new Exception(exceptionPrefix + "Can't specify aggregation mode for types unless defining a profile: " + typeString);
            }
            int startPos = typeString.indexOf("<");
            int endPos = typeString.indexOf(">");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing '>' in data type definition: " + typeList[i]);
            }
            t.getAggregations().addAll(Arrays.asList(typeString.substring(startPos + 1, endPos).trim().split(",")));
            typeString = typeString.substring(0, startPos);
        }
        if (typeString.contains("~")) {
            String v = typeString.substring(typeString.indexOf("~"));
            typeString = typeString.substring(0, typeString.indexOf("~") - 1);
            t.setVersioning(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.fromCode(v));
        }
        if (typeString.contains("{")) {
            if (!inProfile) {
                throw new Exception(exceptionPrefix + "Can't specify profile for types unless defining a profile");
            }
            int startPos = typeString.indexOf("{");
            int endPos = typeString.indexOf("}");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing '}' in data type definition: " + typeList[i]);
            }
            String pt = typeString.substring(startPos + 1, endPos).trim();
            typeString = typeString.substring(0, startPos);
            if (pt.startsWith("#")) {
                // what to do here depends on what it refers to
                if (typeString.trim().equals("Extension"))
                    pt = profileExtensionBase + pt.substring(1);
                else if (typeString.trim().startsWith("Reference") || typeString.trim().startsWith("Resource"))
                    pt = pt.substring(1).toLowerCase();
                else
                    throw new Exception(exceptionPrefix + "Unhandled case");
            }
            t.setProfile(pt);
        }
        if (typeString.contains("(")) {
            int startPos = typeString.indexOf("(");
            int endPos = typeString.indexOf(")");
            if (endPos < startPos) {
                throw new Exception(exceptionPrefix + "Missing ')' in data type definition: " + typeList[i]);
            }
            String[] params = typeString.substring(startPos + 1, endPos).split(",");
            for (int j = 0; j < params.length; j++) {
                if (typeString.startsWith("Reference("))
                    if (inProfile && !resolver.getResourceNames().contains(params[j].trim()) && !"Any".equals(params[j].trim()))
                        throw new Exception(exceptionPrefix + "Unknown resource " + params[j].trim());
                t.getParams().add(params[j].trim());
            }
            typeString = typeString.substring(0, startPos);
        }
        t.setName(typeString.trim());
        if (t.getName().equals("Element") && !allowElement)
            throw new Exception(exceptionPrefix + "The type 'Element' is illegal in this context");
        a.add(t);
    }
    return a;
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 54 with TypeRef

use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.

the class ElementDefn method resolvedTypeCode.

public String resolvedTypeCode(Definitions definitions) {
    StringBuilder tn = new StringBuilder();
    boolean first = true;
    for (TypeRef t : types) {
        if (!first)
            tn.append("|");
        first = false;
        tn.append(t.getName());
        if (t.hasParams()) {
            tn.append("(");
            boolean f = true;
            for (String s : t.getParams()) {
                if (definitions.hasLogicalModel(s)) {
                    for (String sn : definitions.getLogicalModel(s).getImplementations()) {
                        if (!f)
                            tn.append("|");
                        f = false;
                        tn.append(sn);
                    }
                } else {
                    if (!f)
                        tn.append("|");
                    f = false;
                    tn.append(s);
                }
            }
            tn.append(")");
        }
    }
    return tn.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Example 55 with TypeRef

use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.

the class ElementDefn method typeCodeNoParams.

public String typeCodeNoParams() {
    StringBuilder tn = new StringBuilder();
    boolean first = true;
    for (TypeRef t : types) {
        if (!first)
            tn.append("|");
        first = false;
        tn.append(t.getName());
    }
    return tn.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRef(org.hl7.fhir.definitions.model.TypeRef)

Aggregations

TypeRef (org.hl7.fhir.definitions.model.TypeRef)51 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)26 ArrayList (java.util.ArrayList)18 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 IOException (java.io.IOException)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 URISyntaxException (java.net.URISyntaxException)8 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)8 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 Invariant (org.hl7.fhir.definitions.model.Invariant)6 CSFile (org.hl7.fhir.utilities.CSFile)6 IniFile (org.hl7.fhir.utilities.IniFile)6 TextFile (org.hl7.fhir.utilities.TextFile)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 UcumException (org.fhir.ucum.UcumException)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5