use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class SourceParser method processStringPattern.
private void processStringPattern(Sheet sheet, int row) throws Exception {
DefinedStringPattern prim = new DefinedStringPattern();
prim.setCode(sheet.getColumn(row, "Data Type"));
prim.setDefinition(sheet.getColumn(row, "Definition"));
prim.setComment(sheet.getColumn(row, "Comments"));
prim.setRegex(sheet.getColumn(row, "RegEx"));
prim.setSchema(sheet.getColumn(row, "Schema"));
prim.setJsonType(sheet.getColumn(row, "Json"));
prim.setBase(sheet.getColumn(row, "Base"));
TypeRef td = new TypeRef();
td.setName(prim.getCode());
definitions.getKnownTypes().add(td);
definitions.getPrimitives().put(prim.getCode(), prim);
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class SourceParser method processImport.
private void processImport(Sheet sheet, int row) throws Exception {
PrimitiveType prim = new PrimitiveType();
prim.setCode(sheet.getColumn(row, "Data Type"));
prim.setDefinition(sheet.getColumn(row, "Definition"));
prim.setComment(sheet.getColumn(row, "Comments"));
prim.setSchemaType(sheet.getColumn(row, "Schema"));
prim.setJsonType(sheet.getColumn(row, "Json"));
prim.setRegex(sheet.getColumn(row, "RegEx"));
prim.setV2(sheet.getColumn(row, "v2"));
prim.setV3(sheet.getColumn(row, "v3"));
TypeRef td = new TypeRef();
td.setName(prim.getCode());
definitions.getKnownTypes().add(td);
definitions.getPrimitives().put(prim.getCode(), prim);
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class TypeParser method parse.
public List<TypeRef> parse(String n, boolean inProfile, String profileExtensionBase, BaseWorkerContext resolver, boolean allowElement, String sheetName) throws Exception {
ArrayList<TypeRef> a = new ArrayList<TypeRef>();
String exceptionPrefix = sheetName == null ? "" : "Error parsing sheet " + sheetName + " - ";
if (n == null || n.equals("") || n.startsWith("!"))
return a;
// to allow splitting
if (n.indexOf("(") != -1 && n.indexOf("|") != -1) {
String[] typeParts = n.split("[\\(\\)]");
n = "";
for (int i = 0; i < typeParts.length; i++) {
n = n + typeParts[i++];
if (i < typeParts.length) {
n = n + "(" + typeParts[i].replace("|", ",") + ")";
}
}
}
String[] typeList = n.split("[\\|]");
for (int i = 0; i < typeList.length; i++) {
TypeRef t = new TypeRef();
String typeString = typeList[i].trim();
if (typeString.contains("<")) {
if (!inProfile) {
throw new Exception(exceptionPrefix + "Can't specify aggregation mode for types unless defining a profile: " + typeString);
}
int startPos = typeString.indexOf("<");
int endPos = typeString.indexOf(">");
if (endPos < startPos) {
throw new Exception(exceptionPrefix + "Missing '>' in data type definition: " + typeList[i]);
}
t.getAggregations().addAll(Arrays.asList(typeString.substring(startPos + 1, endPos).trim().split(",")));
typeString = typeString.substring(0, startPos);
}
if (typeString.contains("~")) {
String v = typeString.substring(typeString.indexOf("~"));
typeString = typeString.substring(0, typeString.indexOf("~") - 1);
t.setVersioning(org.hl7.fhir.r5.model.ElementDefinition.ReferenceVersionRules.fromCode(v));
}
if (typeString.contains("{")) {
if (!inProfile) {
throw new Exception(exceptionPrefix + "Can't specify profile for types unless defining a profile");
}
int startPos = typeString.indexOf("{");
int endPos = typeString.indexOf("}");
if (endPos < startPos) {
throw new Exception(exceptionPrefix + "Missing '}' in data type definition: " + typeList[i]);
}
String pt = typeString.substring(startPos + 1, endPos).trim();
typeString = typeString.substring(0, startPos);
if (pt.startsWith("#")) {
// what to do here depends on what it refers to
if (typeString.trim().equals("Extension"))
pt = profileExtensionBase + pt.substring(1);
else if (typeString.trim().startsWith("Reference") || typeString.trim().startsWith("Resource"))
pt = pt.substring(1).toLowerCase();
else
throw new Exception(exceptionPrefix + "Unhandled case");
}
t.setProfile(pt);
}
if (typeString.contains("(")) {
int startPos = typeString.indexOf("(");
int endPos = typeString.indexOf(")");
if (endPos < startPos) {
throw new Exception(exceptionPrefix + "Missing ')' in data type definition: " + typeList[i]);
}
String[] params = typeString.substring(startPos + 1, endPos).split(",");
for (int j = 0; j < params.length; j++) {
if (typeString.startsWith("Reference("))
if (inProfile && !resolver.getResourceNames().contains(params[j].trim()) && !"Any".equals(params[j].trim()))
throw new Exception(exceptionPrefix + "Unknown resource " + params[j].trim());
t.getParams().add(params[j].trim());
}
typeString = typeString.substring(0, startPos);
}
t.setName(typeString.trim());
if (t.getName().equals("Element") && !allowElement)
throw new Exception(exceptionPrefix + "The type 'Element' is illegal in this context");
a.add(t);
}
return a;
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class ElementDefn method resolvedTypeCode.
public String resolvedTypeCode(Definitions definitions) {
StringBuilder tn = new StringBuilder();
boolean first = true;
for (TypeRef t : types) {
if (!first)
tn.append("|");
first = false;
tn.append(t.getName());
if (t.hasParams()) {
tn.append("(");
boolean f = true;
for (String s : t.getParams()) {
if (definitions.hasLogicalModel(s)) {
for (String sn : definitions.getLogicalModel(s).getImplementations()) {
if (!f)
tn.append("|");
f = false;
tn.append(sn);
}
} else {
if (!f)
tn.append("|");
f = false;
tn.append(s);
}
}
tn.append(")");
}
}
return tn.toString();
}
use of org.hl7.fhir.definitions.model.TypeRef in project kindling by HL7.
the class ElementDefn method typeCodeNoParams.
public String typeCodeNoParams() {
StringBuilder tn = new StringBuilder();
boolean first = true;
for (TypeRef t : types) {
if (!first)
tn.append("|");
first = false;
tn.append(t.getName());
}
return tn.toString();
}
Aggregations