Search in sources :

Example 76 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType 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 77 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class SpreadSheetCreator method summary.

private String summary(TypeRefComponent tr) {
    String res = tr.getWorkingCode();
    if (Utilities.existsInList(res, "Element", "BackboneElement")) {
        return null;
    }
    if (tr.hasProfile()) {
        if (tr.getProfile().size() == 1) {
            res = tr.getProfile().get(0).primitiveValue().substring(40);
        } else {
            throw new Error("Not supported yet");
        }
    }
    if (tr.hasTargetProfile()) {
        List<String> tl = new ArrayList<>();
        for (CanonicalType tp : tr.getTargetProfile()) {
            tl.add(tp.primitiveValue().substring(40));
        }
        res = res + "(" + String.join("|", tl) + ")";
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 78 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class Publisher method buildConceptMap.

private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
    ConceptMap cm = new ConceptMap();
    cm.setUserData("path", "sc-" + vs.getUserString("path"));
    cm.setUserData("resource-definition", rd);
    cm.setId("sc-" + vs.getId());
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setVersion(page.getVersion().toCode());
    cm.setName(vs.getName() + "CanonicalMap");
    cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setDate(vs.getDate());
    cm.setPublisher(vs.getPublisher());
    cm.addContact(vs.getContactFirstRep());
    cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
    cm.setSource(new CanonicalType(vs.getUrl()));
    cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
    List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
    List<String> self = page.getDefinitions().getStatusCodes().get(path);
    ConceptMapGroupComponent grp = cm.addGroup();
    grp.setTarget("http://hl7.org/fhir/resource-status");
    grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
    for (int i = 0; i < self.size(); i++) {
        if (!Utilities.noString(self.get(i))) {
            String cc = canonical.get(i);
            String sc = self.get(i);
            SourceElementComponent e = grp.addElement();
            e.setCode(sc);
            TargetElementComponent t = e.addTarget();
            t.setCode(cc);
            t.setRelationship(ConceptMapRelationship.EQUIVALENT);
        }
    }
    if (!grp.hasElement())
        return null;
    page.getConceptMaps().see(cm, page.packageInfo());
    statusCodeConceptMaps.add(cm);
    return cm;
}
Also used : TargetElementComponent(org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) SourceElementComponent(org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent)

Example 79 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class Canonical10_40 method convertCanonicalToReference.

public static Reference convertCanonicalToReference(CanonicalType src) throws FHIRException {
    Reference dst = new Reference(src.getValueAsString());
    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, dst);
    return dst;
}
Also used : Reference(org.hl7.fhir.dstu2.model.Reference)

Example 80 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method makeChoiceRows.

private void makeChoiceRows(List<Row> subRows, ElementDefinition element, HierarchicalTableGenerator gen, String corePath, String profileBaseFileName) {
    // create a child for each choice
    for (TypeRefComponent tr : element.getType()) {
        Row choicerow = gen.new Row();
        String t = tr.getWorkingCode();
        if (isReference(t)) {
            choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), null, null));
            choicerow.getCells().add(gen.new Cell());
            choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
            choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
            Cell c = gen.new Cell();
            choicerow.getCells().add(c);
            if (ADD_REFERENCE_TO_TABLE) {
                if (tr.getWorkingCode().equals("canonical"))
                    c.getPieces().add(gen.new Piece(corePath + "datatypes.html#canonical", "canonical", null));
                else
                    c.getPieces().add(gen.new Piece(corePath + "references.html#Reference", "Reference", null));
                c.getPieces().add(gen.new Piece(null, "(", null));
            }
            boolean first = true;
            for (CanonicalType rt : tr.getTargetProfile()) {
                if (!first)
                    c.getPieces().add(gen.new Piece(null, " | ", null));
                genTargetLink(gen, profileBaseFileName, corePath, c, tr, rt.getValue());
                first = false;
            }
            if (ADD_REFERENCE_TO_TABLE)
                c.getPieces().add(gen.new Piece(null, ")", null));
        } else {
            StructureDefinition sd = context.fetchTypeDefinition(t);
            if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
                choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), sd.getDescription(), null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
                choicerow.getCells().add(gen.new Cell(null, corePath + "datatypes.html#" + t, t, null, null));
            // } else if (definitions.getConstraints().contthnsKey(t)) {
            // ProfiledType pt = definitions.getConstraints().get(t);
            // choicerow.getCells().add(gen.new Cell(null, null, e.getName().replace("[x]", Utilities.capitalize(pt.getBaseType())), definitions.getTypes().containsKey(t) ? definitions.getTypes().get(t).getDefinition() : null, null));
            // choicerow.getCells().add(gen.new Cell());
            // choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
            // choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
            // choicerow.getCells().add(gen.new Cell(null, definitions.getSrcFile(t)+".html#"+t.replace("*", "open"), t, null, null));
            } else {
                choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), sd.getDescription(), null));
                choicerow.getCells().add(gen.new Cell());
                choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
                choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
                choicerow.getCells().add(gen.new Cell(null, pkp.getLinkFor(corePath, t), t, null, null));
            }
        }
        choicerow.getCells().add(gen.new Cell());
        subRows.add(choicerow);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) CanonicalType(org.hl7.fhir.r4.model.CanonicalType)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5