Search in sources :

Example 56 with DataType

use of org.hl7.fhir.r4b.model.DataType in project kindling by HL7.

the class PageProcessor method describeValueSetByRef.

private String describeValueSetByRef(DataType reft) {
    String ref = reft.primitiveValue();
    ValueSet vs = definitions.getValuesets().get(ref);
    if (vs == null) {
        if (ref.equals("http://snomed.info/id"))
            return "Snomed CT";
        else
            return ref;
    } else
        return vs.present();
}
Also used : ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 57 with DataType

use of org.hl7.fhir.r4b.model.DataType in project kindling by HL7.

the class OldSpreadsheetParser method processValue.

private DataType processValue(Sheet sheet, int row, String column, String source, ElementDefn e) throws Exception {
    if (Utilities.noString(source))
        return null;
    if (e.getTypes().size() != 1)
        throw new Exception("Unable to process " + column + " unless a single type is specified (types = " + e.typeCode() + ") " + getLocation(row) + ", column = " + column);
    String type = e.typeCode();
    if (definitions != null) {
        if (definitions.getConstraints().containsKey(type))
            type = definitions.getConstraints().get(type).getBaseType();
    } else {
        StructureDefinition sd = context.fetchTypeDefinition(type);
        if (// not loaded yet?
        sd != null)
            type = sd.getType();
        if (type.equals("SimpleQuantity"))
            type = "Quantity";
    }
    if (source.startsWith("{")) {
        JsonParser json = new JsonParser();
        return json.parseType(source, type);
    } else if (source.startsWith("<")) {
        XmlParser xml = new XmlParser();
        return xml.parseType(source, type);
    } else {
        if (source.startsWith("\"") && source.endsWith("\""))
            source = source.substring(1, source.length() - 1);
        if (type.equals("string"))
            return new StringType(source);
        if (type.equals("boolean"))
            return new BooleanType(Boolean.valueOf(source));
        if (type.equals("integer"))
            return new IntegerType(Integer.valueOf(source));
        if (type.equals("integer64"))
            return new Integer64Type(Long.valueOf(source));
        if (type.equals("unsignedInt"))
            return new UnsignedIntType(Integer.valueOf(source));
        if (type.equals("positiveInt"))
            return new PositiveIntType(Integer.valueOf(source));
        if (type.equals("decimal"))
            return new DecimalType(new BigDecimal(source));
        if (type.equals("base64Binary"))
            return new Base64BinaryType(Base64.decode(source.toCharArray()));
        if (type.equals("instant"))
            return new InstantType(source);
        if (type.equals("uri"))
            return new UriType(source);
        if (type.equals("url"))
            return new UrlType(source);
        if (type.equals("canonical"))
            return new CanonicalType(source);
        if (type.equals("date"))
            return new DateType(source);
        if (type.equals("dateTime"))
            return new DateTimeType(source);
        if (type.equals("time"))
            return new TimeType(source);
        if (type.equals("code"))
            return new CodeType(source);
        if (type.equals("oid"))
            return new OidType(source);
        if (type.equals("uuid"))
            return new UuidType(source);
        if (type.equals("id"))
            return new IdType(source);
        if (type.startsWith("Reference(")) {
            Reference r = new Reference();
            r.setReference(source);
            return r;
        }
        if (type.equals("Period")) {
            if (source.contains("->")) {
                String[] parts = source.split("\\-\\>");
                Period p = new Period();
                p.setStartElement(new DateTimeType(parts[0].trim()));
                if (parts.length > 1)
                    p.setEndElement(new DateTimeType(parts[1].trim()));
                return p;
            } else
                throw new Exception("format not understood parsing " + source + " into a period");
        }
        if (type.equals("CodeableConcept")) {
            CodeableConcept cc = new CodeableConcept();
            if (source.contains(":")) {
                String[] parts = source.split("\\:");
                String system = "";
                if (parts[0].equalsIgnoreCase("SCT"))
                    system = "http://snomed.info/sct";
                else if (parts[0].equalsIgnoreCase("LOINC"))
                    system = "http://loinc.org";
                else if (parts[0].equalsIgnoreCase("AMTv2"))
                    system = "http://nehta.gov.au/amtv2";
                else
                    system = "http://hl7.org/fhir/" + parts[0];
                String code = parts[1];
                String display = parts.length > 2 ? parts[2] : null;
                cc.addCoding().setSystem(system).setCode(code).setDisplay(display);
            } else
                throw new Exception("format not understood parsing " + source + " into a codeable concept");
            return cc;
        }
        if (type.equals("Identifier")) {
            Identifier id = new Identifier();
            id.setSystem("urn:ietf:rfc:3986");
            id.setValue(source);
            return id;
        }
        if (type.equals("Quantity")) {
            int s = 0;
            if (source.startsWith("<=") || source.startsWith("=>"))
                s = 2;
            else if (source.startsWith("<") || source.startsWith(">"))
                s = 1;
            int i = s;
            while (i < source.length() && Character.isDigit(source.charAt(i))) i++;
            Quantity q = new Quantity();
            if (s > 0)
                q.setComparator(QuantityComparator.fromCode(source.substring(0, s)));
            if (i > s)
                q.setValue(new BigDecimal(source.substring(s, i)));
            if (i < source.length())
                q.setUnit(source.substring(i).trim());
            return q;
        }
        throw new Exception("Unable to process primitive value '" + source + "' provided for " + column + " - unhandled type " + type + " @ " + getLocation(row));
    }
}
Also used : StringType(org.hl7.fhir.r5.model.StringType) PositiveIntType(org.hl7.fhir.r5.model.PositiveIntType) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) UriType(org.hl7.fhir.r5.model.UriType) TimeType(org.hl7.fhir.r5.model.TimeType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Identifier(org.hl7.fhir.r5.model.Identifier) InstantType(org.hl7.fhir.r5.model.InstantType) DateType(org.hl7.fhir.r5.model.DateType) JsonParser(org.hl7.fhir.r5.formats.JsonParser) XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) OidType(org.hl7.fhir.r5.model.OidType) UuidType(org.hl7.fhir.r5.model.UuidType) Reference(org.hl7.fhir.r5.model.Reference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Period(org.hl7.fhir.r5.model.Period) Quantity(org.hl7.fhir.r5.model.Quantity) Integer64Type(org.hl7.fhir.r5.model.Integer64Type) FHIRException(org.hl7.fhir.exceptions.FHIRException) BigDecimal(java.math.BigDecimal) IdType(org.hl7.fhir.r5.model.IdType) IntegerType(org.hl7.fhir.r5.model.IntegerType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) DecimalType(org.hl7.fhir.r5.model.DecimalType) CodeType(org.hl7.fhir.r5.model.CodeType) UnsignedIntType(org.hl7.fhir.r5.model.UnsignedIntType) Base64BinaryType(org.hl7.fhir.r5.model.Base64BinaryType) UrlType(org.hl7.fhir.r5.model.UrlType) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 58 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class TurtleParser method parseResource.

private void parseResource(Turtle src, String npath, TTLComplex object, Element context, Property property, String name, TTLObject e) throws FHIRException {
    TTLComplex obj;
    if (e instanceof TTLComplex)
        obj = (TTLComplex) e;
    else if (e instanceof TTLURL) {
        String url = ((TTLURL) e).getUri();
        obj = src.getObject(url);
        if (obj == null) {
            logError(e.getLine(), e.getCol(), npath, IssueType.INVALID, "reference to " + url + " cannot be resolved", IssueSeverity.FATAL);
            return;
        }
    } else
        throw new FHIRFormatError("Wrong type for resource");
    TTLObject type = obj.getPredicates().get("http://www.w3.org/2000/01/rdf-schema#type");
    if (type == null) {
        logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "Unknown resource type (missing rdfs:type)", IssueSeverity.FATAL);
        return;
    }
    if (type instanceof TTLList) {
        // this is actually broken - really we have to look through the structure definitions at this point
        for (TTLObject tobj : ((TTLList) type).getList()) {
            if (tobj instanceof TTLURL && ((TTLURL) tobj).getUri().startsWith(FHIR_URI_BASE)) {
                type = tobj;
                break;
            }
        }
    }
    if (!(type instanceof TTLURL)) {
        logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, "Unexpected datatype for rdfs:type)", IssueSeverity.FATAL);
        return;
    }
    String rt = ((TTLURL) type).getUri();
    String ns = rt.substring(0, rt.lastIndexOf("/"));
    rt = rt.substring(rt.lastIndexOf("/") + 1);
    StructureDefinition sd = getDefinition(object.getLine(), object.getCol(), ns, rt);
    if (sd == null)
        return;
    Element n = new Element(tail(name), property).markLocation(object.getLine(), object.getCol());
    context.getChildren().add(n);
    n.updateProperty(new Property(this.context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(n.getProperty()), property);
    n.setType(rt);
    parseChildren(src, npath, obj, n, false);
}
Also used : TTLComplex(org.hl7.fhir.r4.utils.formats.Turtle.TTLComplex) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) SpecialElement(org.hl7.fhir.r4.elementmodel.Element.SpecialElement) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TTLURL(org.hl7.fhir.r4.utils.formats.Turtle.TTLURL) TTLObject(org.hl7.fhir.r4.utils.formats.Turtle.TTLObject) TTLList(org.hl7.fhir.r4.utils.formats.Turtle.TTLList)

Example 59 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method buildFixedExpression.

private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
    DataType fixed = criteriaElement.getFixed();
    if (fixed instanceof CodeableConcept) {
        CodeableConcept cc = (CodeableConcept) fixed;
        expression.append(" and ");
        buildCodeableConceptExpression(ed, expression, discriminator, cc);
    } else if (fixed instanceof Identifier) {
        Identifier ii = (Identifier) fixed;
        expression.append(" and ");
        buildIdentifierExpression(ed, expression, discriminator, ii);
    } else if (fixed instanceof Coding) {
        Coding c = (Coding) fixed;
        expression.append(" and ");
        buildCodingExpression(ed, expression, discriminator, c);
    } else {
        expression.append(" and (");
        if (fixed instanceof StringType) {
            Gson gson = new Gson();
            String json = gson.toJson((StringType) fixed);
            String escapedString = json.substring(json.indexOf(":") + 2);
            escapedString = escapedString.substring(0, escapedString.indexOf(",\"myStringValue") - 1);
            expression.append("'" + escapedString + "'");
        } else if (fixed instanceof UriType) {
            expression.append("'" + ((UriType) fixed).asStringValue() + "'");
        } else if (fixed instanceof IntegerType) {
            expression.append(((IntegerType) fixed).asStringValue());
        } else if (fixed instanceof DecimalType) {
            expression.append(((IntegerType) fixed).asStringValue());
        } else if (fixed instanceof BooleanType) {
            expression.append(((BooleanType) fixed).asStringValue());
        } else
            throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_VALUE_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), fixed.getClass().getName()));
        expression.append(" in " + discriminator + ")");
    }
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) StringType(org.hl7.fhir.r5.model.StringType) BooleanType(org.hl7.fhir.r5.model.BooleanType) DataType(org.hl7.fhir.r5.model.DataType) Gson(com.google.gson.Gson) DecimalType(org.hl7.fhir.r5.model.DecimalType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) UriType(org.hl7.fhir.r5.model.UriType)

Example 60 with DataType

use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method buildPattternExpression.

private void buildPattternExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
    DataType pattern = criteriaElement.getPattern();
    if (pattern instanceof CodeableConcept) {
        CodeableConcept cc = (CodeableConcept) pattern;
        expression.append(" and ");
        buildCodeableConceptExpression(ed, expression, discriminator, cc);
    } else if (pattern instanceof Coding) {
        Coding c = (Coding) pattern;
        expression.append(" and ");
        buildCodingExpression(ed, expression, discriminator, c);
    } else if (pattern instanceof BooleanType || pattern instanceof IntegerType || pattern instanceof DecimalType) {
        expression.append(" and ");
        buildPrimitiveExpression(ed, expression, discriminator, pattern, false);
    } else if (pattern instanceof PrimitiveType) {
        expression.append(" and ");
        buildPrimitiveExpression(ed, expression, discriminator, pattern, true);
    } else if (pattern instanceof Identifier) {
        Identifier ii = (Identifier) pattern;
        expression.append(" and ");
        buildIdentifierExpression(ed, expression, discriminator, ii);
    } else if (pattern instanceof HumanName) {
        HumanName name = (HumanName) pattern;
        expression.append(" and ");
        buildHumanNameExpression(ed, expression, discriminator, name);
    } else if (pattern instanceof Address) {
        Address add = (Address) pattern;
        expression.append(" and ");
        buildAddressExpression(ed, expression, discriminator, add);
    } else {
        throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_PATTERN_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), pattern.fhirType()));
    }
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) HumanName(org.hl7.fhir.r5.model.HumanName) Identifier(org.hl7.fhir.r5.model.Identifier) Address(org.hl7.fhir.r5.model.Address) Coding(org.hl7.fhir.r5.model.Coding) BooleanType(org.hl7.fhir.r5.model.BooleanType) DataType(org.hl7.fhir.r5.model.DataType) DecimalType(org.hl7.fhir.r5.model.DecimalType) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Aggregations

DataType (org.hl7.fhir.r5.model.DataType)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 Collectors (java.util.stream.Collectors)6 DataType (org.hl7.cql.model.DataType)6 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 ArrayList (java.util.ArrayList)5 StructType (org.apache.spark.sql.types.StructType)5 BooleanType (org.hl7.fhir.r5.model.BooleanType)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 DataType (org.hl7.fhir.r4b.model.DataType)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3