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));
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations