Search in sources :

Example 76 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testIntegerType.

@Test
public void testIntegerType() {
    Integer expected = 1;
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(expected);
    assertTrue(fhirTypeValue instanceof IntegerType);
    assertEquals(expected, ((IntegerType) fhirTypeValue).getValue());
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) Test(org.junit.Test)

Example 77 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project kindling by HL7.

the class SpreadSheetReloader method parseStatus.

private void parseStatus(Element ed, String value) {
    ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
    ed.removeExtension(BuildExtensions.EXT_STANDARDS_STATUS);
    ed.removeExtension(BuildExtensions.EXT_NORMATIVE_VERSION);
    if (!Utilities.noString(value) && value.contains("/")) {
        String[] p = value.split("\\/");
        if (Utilities.noString(p[0].trim())) {
            ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
        } else {
            ed.addExtension(BuildExtensions.EXT_FMM_LEVEL, new IntegerType(p[0]));
        }
        if (p[1].contains(";")) {
            ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1].substring(0, p[1].indexOf(";"))));
            ed.addExtension(BuildExtensions.EXT_NORMATIVE_VERSION, new CodeType(p[1].substring(p[1].indexOf("from=") + 5)));
        } else {
            ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1]));
        }
    }
    sortExtensions(ed);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) CodeType(org.hl7.fhir.r5.model.CodeType)

Example 78 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType 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 79 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeCardinality.

private String describeCardinality(ElementDefinition definition, ElementDefinition fallback, UnusedTracker tracker) {
    IntegerType min = definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
    StringType max = definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
    if (min.isEmpty() && fallback != null)
        min = fallback.getMinElement();
    if (max.isEmpty() && fallback != null)
        max = fallback.getMaxElement();
    tracker.used = !max.isEmpty() && !max.getValue().equals("0");
    if (min.isEmpty() && max.isEmpty())
        return null;
    else
        return (!min.hasValue() ? "" : Integer.toString(min.getValue())) + ".." + (!max.hasValue() ? "" : max.getValue());
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) StringType(org.hl7.fhir.r4.model.StringType)

Example 80 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method genCardinality.

private void genCardinality(HierarchicalTableGenerator gen, ElementDefinition definition, Row row, boolean hasDef, UnusedTracker tracker, ElementDefinition fallback) {
    IntegerType min = !hasDef ? new IntegerType() : definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
    StringType max = !hasDef ? new StringType() : definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
    if (min.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
        ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
        if (base.hasMinElement()) {
            min = base.getMinElement().copy();
            min.setUserData(DERIVATION_EQUALS, true);
        }
    }
    if (max.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
        ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
        if (base.hasMaxElement()) {
            max = base.getMaxElement().copy();
            max.setUserData(DERIVATION_EQUALS, true);
        }
    }
    if (min.isEmpty() && fallback != null)
        min = fallback.getMinElement();
    if (max.isEmpty() && fallback != null)
        max = fallback.getMaxElement();
    if (!max.isEmpty())
        tracker.used = !max.getValue().equals("0");
    Cell cell = gen.new Cell(null, null, null, null, null);
    row.getCells().add(cell);
    if (!min.isEmpty() || !max.isEmpty()) {
        cell.addPiece(checkForNoChange(min, gen.new Piece(null, !min.hasValue() ? "" : Integer.toString(min.getValue()), null)));
        cell.addPiece(checkForNoChange(min, max, gen.new Piece(null, "..", null)));
        cell.addPiece(checkForNoChange(min, gen.new Piece(null, !max.hasValue() ? "" : max.getValue(), null)));
    }
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) StringType(org.hl7.fhir.r4.model.StringType) Piece(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)

Aggregations

ArrayList (java.util.ArrayList)51 BigDecimal (java.math.BigDecimal)34 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)28 IntegerType (org.hl7.fhir.r5.model.IntegerType)26 IntegerType (org.hl7.fhir.r4.model.IntegerType)23 IntegerType (org.hl7.fhir.r4b.model.IntegerType)23 UcumException (org.fhir.ucum.UcumException)19 Test (org.junit.jupiter.api.Test)13 Decimal (org.fhir.ucum.Decimal)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 Base (org.hl7.fhir.r4b.model.Base)11 Base (org.hl7.fhir.r5.model.Base)11 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)10 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)10 StringType (org.hl7.fhir.r4.model.StringType)10 Patient (org.hl7.fhir.r4.model.Patient)9 Map (java.util.Map)7 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)7 DecimalType (org.hl7.fhir.r5.model.DecimalType)7 List (java.util.List)6