use of org.hl7.fhir.dstu2016may.model.Base64BinaryType in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.
public static Parameter toCohortParameter(Extension extension) {
Parameter parameter;
Type extensionValue = extension.getValue();
if (extensionValue instanceof Base64BinaryType) {
parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
} else if (extensionValue instanceof BooleanType) {
parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
} else if (extensionValue instanceof DateType) {
parameter = new DateParameter(((DateType) extensionValue).asStringValue());
} else if (extensionValue instanceof DateTimeType) {
parameter = convertDateTimeType((DateTimeType) extensionValue);
} else if (extensionValue instanceof DecimalType) {
parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
} else if (extensionValue instanceof InstantType) {
parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
} else if (extensionValue instanceof IntegerType) {
parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
} else if (extensionValue instanceof StringType) {
parameter = new StringParameter(((StringType) extensionValue).getValue());
} else if (extensionValue instanceof TimeType) {
parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
} else if (extensionValue instanceof UriType) {
parameter = new StringParameter(((UriType) extensionValue).getValue());
} else if (extensionValue instanceof Coding) {
parameter = convertCoding((Coding) extensionValue);
} else if (extensionValue instanceof CodeableConcept) {
parameter = convertCodeableConcept((CodeableConcept) extensionValue);
} else if (extensionValue instanceof Period) {
Period castValue = (Period) extensionValue;
parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
} else if (extensionValue instanceof Quantity) {
parameter = convertQuantity((Quantity) extensionValue);
} else if (extensionValue instanceof Range) {
Range castValue = (Range) extensionValue;
parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
} else if (extensionValue instanceof Ratio) {
Ratio castValue = (Ratio) extensionValue;
parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
} else {
throw new UnsupportedFhirTypeException(extensionValue);
}
return parameter;
}
use of org.hl7.fhir.dstu2016may.model.Base64BinaryType in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testBase64Binary__shouldReturnStringParameter.
@Test
public void testBase64Binary__shouldReturnStringParameter() {
ParameterDefinition parameterDefinition = getBaseParameterDefinition("base64Binary");
String base64String = "AAA";
Base64BinaryType fhirValue = new Base64BinaryType(base64String);
parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
assertEquals(new StringParameter(base64String), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
use of org.hl7.fhir.dstu2016may.model.Base64BinaryType 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));
}
}
use of org.hl7.fhir.dstu2016may.model.Base64BinaryType in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent, ResourceContext rc) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType) {
if (e.hasPrimitiveValue())
x.addText(((DateTimeType) e).toHumanDisplay());
} else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.r4.model.DateType)
x.addText(((org.hl7.fhir.r4.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType)
x.addText(((BooleanType) e).getValue().toString());
else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x);
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
} else if (e instanceof org.hl7.fhir.r4.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.r4.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.r4.model.DecimalType) {
x.addText(((org.hl7.fhir.r4.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
} else if (e instanceof Address) {
renderAddress((Address) e, x);
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
} else if (e instanceof UriType) {
renderUri((UriType) e, x, defn.getPath(), rc != null && rc.resourceResource != null ? rc.resourceResource.getId() : null);
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
} else if (e instanceof Range) {
renderRange((Range) e, x);
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.tx("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.tx(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
} else if (e instanceof Reference) {
Reference r = (Reference) e;
XhtmlNode c = x;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
tr = resolveReference(res, r.getReference(), rc);
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.ah(tr.getReference());
else
c = x.ah(r.getReference());
}
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
c.addText(r.getDisplay());
if (tr != null && tr.getResource() != null) {
c.tx(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"), rc);
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"), rc);
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
if (sd == null)
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
else
generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails, indent + 1, rc);
}
}
use of org.hl7.fhir.dstu2016may.model.Base64BinaryType in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeType.
protected void composeType(String prefix, DataType type) throws IOException {
if (type == null) {
;
} else if (type instanceof Address) {
composeAddress(prefix + "Address", (Address) type);
} else if (type instanceof Age) {
composeAge(prefix + "Age", (Age) type);
} else if (type instanceof Annotation) {
composeAnnotation(prefix + "Annotation", (Annotation) type);
} else if (type instanceof Attachment) {
composeAttachment(prefix + "Attachment", (Attachment) type);
} else if (type instanceof CodeableConcept) {
composeCodeableConcept(prefix + "CodeableConcept", (CodeableConcept) type);
} else if (type instanceof CodeableReference) {
composeCodeableReference(prefix + "CodeableReference", (CodeableReference) type);
} else if (type instanceof Coding) {
composeCoding(prefix + "Coding", (Coding) type);
} else if (type instanceof ContactDetail) {
composeContactDetail(prefix + "ContactDetail", (ContactDetail) type);
} else if (type instanceof ContactPoint) {
composeContactPoint(prefix + "ContactPoint", (ContactPoint) type);
} else if (type instanceof Contributor) {
composeContributor(prefix + "Contributor", (Contributor) type);
} else if (type instanceof Count) {
composeCount(prefix + "Count", (Count) type);
} else if (type instanceof DataRequirement) {
composeDataRequirement(prefix + "DataRequirement", (DataRequirement) type);
} else if (type instanceof Distance) {
composeDistance(prefix + "Distance", (Distance) type);
} else if (type instanceof Dosage) {
composeDosage(prefix + "Dosage", (Dosage) type);
} else if (type instanceof Duration) {
composeDuration(prefix + "Duration", (Duration) type);
} else if (type instanceof ElementDefinition) {
composeElementDefinition(prefix + "ElementDefinition", (ElementDefinition) type);
} else if (type instanceof Expression) {
composeExpression(prefix + "Expression", (Expression) type);
} else if (type instanceof Extension) {
composeExtension(prefix + "Extension", (Extension) type);
} else if (type instanceof HumanName) {
composeHumanName(prefix + "HumanName", (HumanName) type);
} else if (type instanceof Identifier) {
composeIdentifier(prefix + "Identifier", (Identifier) type);
} else if (type instanceof MarketingStatus) {
composeMarketingStatus(prefix + "MarketingStatus", (MarketingStatus) type);
} else if (type instanceof Meta) {
composeMeta(prefix + "Meta", (Meta) type);
} else if (type instanceof Money) {
composeMoney(prefix + "Money", (Money) type);
} else if (type instanceof Narrative) {
composeNarrative(prefix + "Narrative", (Narrative) type);
} else if (type instanceof ParameterDefinition) {
composeParameterDefinition(prefix + "ParameterDefinition", (ParameterDefinition) type);
} else if (type instanceof Period) {
composePeriod(prefix + "Period", (Period) type);
} else if (type instanceof Population) {
composePopulation(prefix + "Population", (Population) type);
} else if (type instanceof ProdCharacteristic) {
composeProdCharacteristic(prefix + "ProdCharacteristic", (ProdCharacteristic) type);
} else if (type instanceof ProductShelfLife) {
composeProductShelfLife(prefix + "ProductShelfLife", (ProductShelfLife) type);
} else if (type instanceof Quantity) {
composeQuantity(prefix + "Quantity", (Quantity) type);
} else if (type instanceof Range) {
composeRange(prefix + "Range", (Range) type);
} else if (type instanceof Ratio) {
composeRatio(prefix + "Ratio", (Ratio) type);
} else if (type instanceof RatioRange) {
composeRatioRange(prefix + "RatioRange", (RatioRange) type);
} else if (type instanceof Reference) {
composeReference(prefix + "Reference", (Reference) type);
} else if (type instanceof RelatedArtifact) {
composeRelatedArtifact(prefix + "RelatedArtifact", (RelatedArtifact) type);
} else if (type instanceof SampledData) {
composeSampledData(prefix + "SampledData", (SampledData) type);
} else if (type instanceof Signature) {
composeSignature(prefix + "Signature", (Signature) type);
} else if (type instanceof Timing) {
composeTiming(prefix + "Timing", (Timing) type);
} else if (type instanceof TriggerDefinition) {
composeTriggerDefinition(prefix + "TriggerDefinition", (TriggerDefinition) type);
} else if (type instanceof UsageContext) {
composeUsageContext(prefix + "UsageContext", (UsageContext) type);
} else if (type instanceof CodeType) {
composeCodeCore(prefix + "Code", (CodeType) type, false);
composeCodeExtras(prefix + "Code", (CodeType) type, false);
} else if (type instanceof OidType) {
composeOidCore(prefix + "Oid", (OidType) type, false);
composeOidExtras(prefix + "Oid", (OidType) type, false);
} else if (type instanceof CanonicalType) {
composeCanonicalCore(prefix + "Canonical", (CanonicalType) type, false);
composeCanonicalExtras(prefix + "Canonical", (CanonicalType) type, false);
} else if (type instanceof UuidType) {
composeUuidCore(prefix + "Uuid", (UuidType) type, false);
composeUuidExtras(prefix + "Uuid", (UuidType) type, false);
} else if (type instanceof UrlType) {
composeUrlCore(prefix + "Url", (UrlType) type, false);
composeUrlExtras(prefix + "Url", (UrlType) type, false);
} else if (type instanceof UnsignedIntType) {
composeUnsignedIntCore(prefix + "UnsignedInt", (UnsignedIntType) type, false);
composeUnsignedIntExtras(prefix + "UnsignedInt", (UnsignedIntType) type, false);
} else if (type instanceof MarkdownType) {
composeMarkdownCore(prefix + "Markdown", (MarkdownType) type, false);
composeMarkdownExtras(prefix + "Markdown", (MarkdownType) type, false);
} else if (type instanceof IdType) {
composeIdCore(prefix + "Id", (IdType) type, false);
composeIdExtras(prefix + "Id", (IdType) type, false);
} else if (type instanceof PositiveIntType) {
composePositiveIntCore(prefix + "PositiveInt", (PositiveIntType) type, false);
composePositiveIntExtras(prefix + "PositiveInt", (PositiveIntType) type, false);
} else if (type instanceof DateType) {
composeDateCore(prefix + "Date", (DateType) type, false);
composeDateExtras(prefix + "Date", (DateType) type, false);
} else if (type instanceof DateTimeType) {
composeDateTimeCore(prefix + "DateTime", (DateTimeType) type, false);
composeDateTimeExtras(prefix + "DateTime", (DateTimeType) type, false);
} else if (type instanceof StringType) {
composeStringCore(prefix + "String", (StringType) type, false);
composeStringExtras(prefix + "String", (StringType) type, false);
} else if (type instanceof IntegerType) {
composeIntegerCore(prefix + "Integer", (IntegerType) type, false);
composeIntegerExtras(prefix + "Integer", (IntegerType) type, false);
} else if (type instanceof Integer64Type) {
composeInteger64Core(prefix + "Integer64", (Integer64Type) type, false);
composeInteger64Extras(prefix + "Integer64", (Integer64Type) type, false);
} else if (type instanceof UriType) {
composeUriCore(prefix + "Uri", (UriType) type, false);
composeUriExtras(prefix + "Uri", (UriType) type, false);
} else if (type instanceof InstantType) {
composeInstantCore(prefix + "Instant", (InstantType) type, false);
composeInstantExtras(prefix + "Instant", (InstantType) type, false);
} else if (type instanceof BooleanType) {
composeBooleanCore(prefix + "Boolean", (BooleanType) type, false);
composeBooleanExtras(prefix + "Boolean", (BooleanType) type, false);
} else if (type instanceof Base64BinaryType) {
composeBase64BinaryCore(prefix + "Base64Binary", (Base64BinaryType) type, false);
composeBase64BinaryExtras(prefix + "Base64Binary", (Base64BinaryType) type, false);
} else if (type instanceof TimeType) {
composeTimeCore(prefix + "Time", (TimeType) type, false);
composeTimeExtras(prefix + "Time", (TimeType) type, false);
} else if (type instanceof DecimalType) {
composeDecimalCore(prefix + "Decimal", (DecimalType) type, false);
composeDecimalExtras(prefix + "Decimal", (DecimalType) type, false);
} else
throw new Error("Unhandled type");
}
Aggregations