org.hl7.fhir.r4.model.Type Java Examples
The following examples show how to use
org.hl7.fhir.r4.model.Type.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSVWriter.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private String renderType(Type value) throws Exception { String s = null; ByteArrayOutputStream bs = new ByteArrayOutputStream(); if (asXml) { xml.setOutputStyle(OutputStyle.PRETTY); xml.compose(bs, "", value); bs.close(); s = bs.toString(); s = s.substring(s.indexOf("\n")+2); } else { json.setOutputStyle(OutputStyle.PRETTY); json.compose(bs, value, ""); bs.close(); s = bs.toString(); } return s; }
Example #2
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private boolean ruleCompares(ElementDefinition ed, Type vLeft, Type vRight, String path, int nullStatus) throws IOException { if (vLeft == null && vRight == null && nullStatus == BOTH_NULL) return true; if (vLeft == null && vRight == null) { messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Must be the same and not null (null/null)", ValidationMessage.IssueSeverity.ERROR)); status(ed, ProfileUtilities.STATUS_ERROR); } if (vLeft == null && nullStatus == EITHER_NULL) return true; if (vRight == null && nullStatus == EITHER_NULL) return true; if (vLeft == null || vRight == null || !Base.compareDeep(vLeft, vRight, false)) { messages.add(new ValidationMessage(Source.ProfileComparer, ValidationMessage.IssueType.STRUCTURE, path, "Must be the same ("+toString(vLeft)+"/"+toString(vRight)+")", ValidationMessage.IssueSeverity.ERROR)); status(ed, ProfileUtilities.STATUS_ERROR); } return true; }
Example #3
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException { if (tgt.getParameter().size() < 2) return null; Type p1 = tgt.getParameter().get(0).getValue(); Type p2 = tgt.getParameter().get(1).getValue(); if (p1 instanceof IdType || p2 instanceof IdType) return null; if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType)) return null; String uri = ((PrimitiveType) p1).asStringValue(); String code = ((PrimitiveType) p2).asStringValue(); if (Utilities.noString(uri)) throw new FHIRException("Describe Transform, but the uri is blank"); if (Utilities.noString(code)) throw new FHIRException("Describe Transform, but the code is blank"); Coding c = buildCoding(uri, code); return NarrativeGenerator.describeSystem(c.getSystem())+"#"+c.getCode()+(c.hasDisplay() ? "("+c.getDisplay()+")" : ""); }
Example #4
Source File: XLSXWriter.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private String renderType(Type value) throws Exception { if (value == null) return ""; if (value.isPrimitive()) return value.primitiveValue(); String s = null; ByteArrayOutputStream bs = new ByteArrayOutputStream(); if (asXml) { xml.setOutputStyle(OutputStyle.PRETTY); xml.compose(bs, "", value); bs.close(); s = bs.toString(); s = s.substring(s.indexOf("\n")+2); } else { json.setOutputStyle(OutputStyle.PRETTY); json.compose(bs, value, ""); bs.close(); s = bs.toString(); } return s; }
Example #5
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
static Type mapValueToFHIRType(Object value, String unit) { if (value == null) { return null; } else if (value instanceof Condition) { Code conditionCode = ((HealthRecord.Entry) value).codes.get(0); return mapCodeToCodeableConcept(conditionCode, SNOMED_URI); } else if (value instanceof Code) { return mapCodeToCodeableConcept((Code) value, SNOMED_URI); } else if (value instanceof String) { return new StringType((String) value); } else if (value instanceof Number) { double dblVal = ((Number) value).doubleValue(); PlainBigDecimal bigVal = new PlainBigDecimal(dblVal); return new Quantity().setValue(bigVal) .setCode(unit).setSystem(UNITSOFMEASURE_URI) .setUnit(unit); } else if (value instanceof Components.SampledData) { return mapValueToSampledData((Components.SampledData) value, unit); } else { throw new IllegalArgumentException("unexpected observation value class: " + value.getClass().toString() + "; " + value); } }
Example #6
Source File: OperationDefinition14_40.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu2016may.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent(); VersionConvertor_14_40.copyElement(src, tgt); if (src.hasStrength()) tgt.setStrengthElement(VersionConvertor_14_40.convertBindingStrength(src.getStrengthElement())); Type t = VersionConvertor_14_40.convertType(src.getValueSet()); if (t != null) { if (t instanceof org.hl7.fhir.r4.model.Reference) tgt.setValueSet(((org.hl7.fhir.r4.model.Reference) t).getReference()); else tgt.setValueSet(t.primitiveValue()); tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet())); } return tgt; }
Example #7
Source File: ImplementationGuide14_40.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent(); VersionConvertor_14_40.copyElement(src, tgt); if (src.hasExampleFor()) { Type t = VersionConvertor_14_40.convertType(src.getExampleFor()); tgt.setExample(t instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) t).getReference()) : t); } else if (src.hasExample()) tgt.setExample(new org.hl7.fhir.r4.model.BooleanType(src.getExample())); if (src.hasName()) tgt.setNameElement(VersionConvertor_14_40.convertString(src.getNameElement())); if (src.hasDescription()) tgt.setDescriptionElement(VersionConvertor_14_40.convertString(src.getDescriptionElement())); if (src.hasSourceReference()) tgt.setReference(VersionConvertor_14_40.convertReference(src.getSourceReference())); else if (src.hasSourceUriType()) tgt.setReference(new org.hl7.fhir.r4.model.Reference(src.getSourceUriType().getValue())); return tgt; }
Example #8
Source File: OperationDefinition30_40.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException { if (src == null) return null; org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent(); VersionConvertor_30_40.copyElement(src, tgt); if (src.hasStrength()) tgt.setStrengthElement(VersionConvertor_30_40.convertBindingStrength(src.getStrengthElement())); if (src.hasValueSet()) { Type t = VersionConvertor_30_40.convertType(src.getValueSet()); if (t instanceof org.hl7.fhir.r4.model.Reference) tgt.setValueSet(((org.hl7.fhir.r4.model.Reference) t).getReference()); else tgt.setValueSet(t.primitiveValue()); tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet())); } return tgt; }
Example #9
Source File: OperationDefinition10_40.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu2.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r4.model.OperationDefinition.OperationDefinitionParameterBindingComponent(); VersionConvertor_10_40.copyElement(src, tgt); if (src.hasStrength()) tgt.setStrengthElement(VersionConvertor_10_40.convertBindingStrength(src.getStrengthElement())); Type t = VersionConvertor_10_40.convertType(src.getValueSet()); if (t != null) { if (t instanceof org.hl7.fhir.r4.model.Reference) tgt.setValueSet(((org.hl7.fhir.r4.model.Reference) t).getReference()); else tgt.setValueSet(t.primitiveValue()); tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet())); } return tgt; }
Example #10
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public Type parseType(InputStream input, String knownType) throws IOException, FHIRFormatError { try { XmlPullParser xml = loadXml(input); return parseType(xml, knownType); } catch (XmlPullParserException e) { throw new FHIRFormatError(e.getMessage(), e); } }
Example #11
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private Type generateFixedValue(StructureMapGroupRuleTargetComponent tgt) { if (!allParametersFixed(tgt)) return null; if (!tgt.hasTransform()) return null; switch (tgt.getTransform()) { case COPY: return tgt.getParameter().get(0).getValue(); case TRUNCATE: return null; //case ESCAPE: //case CAST: //case APPEND: case TRANSLATE: return null; //case DATEOP, //case UUID, //case POINTER, //case EVALUATE, case CC: CodeableConcept cc = new CodeableConcept(); cc.addCoding(buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue())); return cc; case C: return buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue()); case QTY: return null; //case ID, //case CP, default: return null; } }
Example #12
Source File: ObjectConverter.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public Type convertToType(Element element) throws FHIRException { Type b = new Factory().create(element.fhirType()); if (b instanceof PrimitiveType) { ((PrimitiveType) b).setValueAsString(element.primitiveValue()); } else { for (Element child : element.getChildren()) { b.setProperty(child.getName(), convertToType(child)); } } return b; }
Example #13
Source File: FhirR4.java From synthea with Apache License 2.0 | 5 votes |
/** * Convert the timestamp into a FHIR DateType or DateTimeType. * * @param datetime Timestamp * @param time If true, return a DateTime; if false, return a Date. * @return a DateType or DateTimeType representing the given timestamp */ private static Type convertFhirDateTime(long datetime, boolean time) { Date date = new Date(datetime); if (time) { return new DateTimeType(date); } else { return new DateType(date); } }
Example #14
Source File: ValueSetExpanderSimple.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean existsInParams(List<ValueSetExpansionParameterComponent> params, String name, Type value) { for (ValueSetExpansionParameterComponent p : params) { if (p.getName().equals(name) && PrimitiveType.compareDeep(p.getValue(), value, false)) return true; } return false; }
Example #15
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String toString(Type val) throws IOException { if (val instanceof PrimitiveType) return "\"" + ((PrimitiveType) val).getValueAsString()+"\""; IParser jp = context.newJsonParser(); return jp.composeString(val, "value"); }
Example #16
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public Type parseAnyType(InputStream input, String knownType) throws IOException, FHIRFormatError { try { XmlPullParser xml = loadXml(input); return parseAnyType(xml, knownType); } catch (XmlPullParserException e) { throw new FHIRFormatError(e.getMessage(), e); } }
Example #17
Source File: ResourceUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private static String renderDEUnits(Type units) { if (units == null || units.isEmpty()) return ""; if (units instanceof CodeableConcept) return renderCodeable((CodeableConcept) units); else return "<a href=\""+Utilities.escapeXml(((Reference) units).getReference())+"\">"+Utilities.escapeXml(((Reference) units).getReference())+"</a>"; }
Example #18
Source File: ToolingExtensions.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static PrimitiveType<Type> readPrimitiveExtension(DomainResource c, String uri) { Extension ex = getExtension(c, uri); if (ex == null) return null; return (PrimitiveType<Type>) ex.getValue(); }
Example #19
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
/** * Compose a type to a stream (used in the spec, for example, but not normally in production) * @ */ public void compose(OutputStream stream, String rootName, Type type) throws IOException { xml = new XMLWriter(stream, "UTF-8", version == XmlVersion.V1_1); xml.setPretty(style == OutputStyle.PRETTY); xml.start(); xml.setDefaultNamespace(FHIR_NS); composeType(Utilities.noString(rootName) ? "value" : rootName, type); xml.end(); }
Example #20
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public void compose(OutputStream stream, Type type, String rootName) throws IOException { xml = new XMLWriter(stream, "UTF-8", version == XmlVersion.V1_1); xml.setPretty(style == OutputStyle.PRETTY); xml.start(); xml.setDefaultNamespace(FHIR_NS); composeType(Utilities.noString(rootName) ? "value" : rootName, type); xml.end(); }
Example #21
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException { Type p = parameter.getValue(); if (!(p instanceof IdType)) return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs())); else { String n = ((IdType) p).asStringValue(); VariableForProfiling b = vars.get(VariableMode.INPUT, n); if (b == null) b = vars.get(VariableMode.OUTPUT, n); if (b == null) throw new DefinitionException("Variable "+n+" not found ("+vars.summary()+")"); return b.getProperty().getTypes(); } }
Example #22
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private Type readConstant(String s, FHIRLexer lexer) throws FHIRLexerException { if (Utilities.isInteger(s)) return new IntegerType(s); else if (Utilities.isDecimal(s, false)) return new DecimalType(s); else if (Utilities.existsInList(s, "true", "false")) return new BooleanType(s.equals("true")); else return new StringType(lexer.processConstant(s)); }
Example #23
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException { Type p = parameter.getValue(); if (!(p instanceof IdType)) return p; else { String n = ((IdType) p).asStringValue(); Base b = vars.get(VariableMode.INPUT, n); if (b == null) b = vars.get(VariableMode.OUTPUT, n); if (b == null) throw new DefinitionException("Variable "+n+" not found ("+vars.summary()+")"); return b; } }
Example #24
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String getParamString(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) { Type p = parameter.getValue(); if (p == null || p instanceof IdType) return null; if (!p.hasPrimitiveValue()) return null; return p.primitiveValue(); }
Example #25
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean allParametersFixed(StructureMapGroupRuleTargetComponent tgt) { for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) { Type pr = p.getValue(); if (pr instanceof IdType) return false; } return true; }
Example #26
Source File: JsonParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public void compose(OutputStream stream, Type type, String rootName) throws IOException { OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8"); if (style == OutputStyle.CANONICAL) json = new JsonCreatorCanonical(osw); else json = new JsonCreatorDirect(osw);// use this instead of Gson because this preserves decimal formatting json.setIndent(style == OutputStyle.PRETTY ? " " : ""); json.beginObject(); composeTypeInner(type); json.endObject(); json.finish(); osw.flush(); }
Example #27
Source File: RdfParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
@Override public void compose(OutputStream stream, Type type, String rootName) throws IOException { throw new Error("Not supported in RDF"); }
Example #28
Source File: RdfParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
@Override public Type parseAnyType(InputStream input, String knownType) throws IOException, FHIRFormatError { throw new Error("Parsing not implemented yet"); }
Example #29
Source File: ParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
public Type parseAnyType(byte[] bytes, String typeName) throws FHIRFormatError, IOException { ByteArrayInputStream bi = new ByteArrayInputStream(bytes); return parseAnyType(bi, typeName); }
Example #30
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws FHIRException { VariableForProfiling var = null; if (tgt.hasContext()) { var = vars.get(VariableMode.OUTPUT, tgt.getContext()); if (var == null) throw new FHIRException("Rule \""+ruleId+"\": target context not known: "+tgt.getContext()); if (!tgt.hasElement()) throw new FHIRException("Rule \""+ruleId+"\": Not supported yet"); } TypeDetails type = null; if (tgt.hasTransform()) { type = analyseTransform(context, map, tgt, var, vars); // profiling: dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v); } else { Property vp = var.property.baseProperty.getChild(tgt.getElement(), tgt.getElement()); if (vp == null) throw new FHIRException("Unknown Property "+tgt.getElement()+" on "+var.property.path); type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement())); } if (tgt.getTransform() == StructureMapTransform.CREATE) { String s = getParamString(vars, tgt.getParameter().get(0)); if (worker.getResourceNames().contains(s)) tw.newResource(tgt.getVariable(), s); } else { boolean mapsSrc = false; for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) { Type pr = p.getValue(); if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv)) mapsSrc = true; } if (mapsSrc) { if (var == null) throw new Error("Rule \""+ruleId+"\": Attempt to assign with no context"); tw.valueAssignment(tgt.getContext(), var.property.getPath()+"."+tgt.getElement()+getTransformSuffix(tgt.getTransform())); } else if (tgt.hasContext()) { if (isSignificantElement(var.property, tgt.getElement())) { String td = describeTransform(tgt); if (td != null) tw.keyAssignment(tgt.getContext(), var.property.getPath()+"."+tgt.getElement()+" = "+td); } } } Type fixed = generateFixedValue(tgt); PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt); if (tgt.hasVariable()) if (tgt.hasElement()) vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop); else vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop); }