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.setRegEx(sheet.getColumn(row, "RegEx")); TypeRef td = new TypeRef(); td.setName(prim.getCode()); definitions.getKnownTypes().add(td); definitions.getPrimitives().put(prim.getCode(), prim); }
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.setBase(sheet.getColumn(row, "Base")); TypeRef td = new TypeRef(); td.setName(prim.getCode()); definitions.getKnownTypes().add(td); definitions.getPrimitives().put(prim.getCode(), prim); }
public void checkConditions(List<String> errors, Map<String, Long> dates) throws Exception { Utilities.checkFolder(srcDir, errors); Utilities.checkFolder(termDir, errors); Utilities.checkFolder(imgDir, errors); this.dates = dates; checkFile("required", termDir, "bindings.xml", errors, "all"); checkFile("required", dtDir, "primitives.xml", errors, "all"); for (String n : ini.getPropertyNames("types")) if (ini.getStringProperty("types", n).equals("")) { TypeRef t = new TypeParser().parse(n).get(0); checkFile("type definition", dtDir, t.getName().toLowerCase() + ".xml", errors, "all"); } for (String n : ini.getPropertyNames("structures")) checkFile("structure definition", dtDir, n.toLowerCase() + ".xml", errors, "all"); String[] shared = ini.getPropertyNames("shared"); if (shared != null) for (String n : shared) checkFile("shared structure definition", dtDir, n.toLowerCase() + ".xml", errors, "all"); for (String n : ini.getPropertyNames("infrastructure")) checkFile("infrastructure definition", dtDir, n.toLowerCase() + ".xml", errors, "all"); for (String n : ini.getPropertyNames("resources")) { if (!new File(srcDir + n).exists()) errors.add("unable to find folder for resource " + n); else { if (new CSFile(srcDir + n + File.separatorChar + n + "-spreadsheet.xml").exists()) { checkFile( "definition", srcDir + n + File.separatorChar, n + "-spreadsheet.xml", errors, n); } else checkFile("definition", srcDir + n + File.separatorChar, n + "-def.xml", errors, n); checkFile("example xml", srcDir + n + File.separatorChar, n + "-example.xml", errors, n); // now iterate all the files in the directory checking data for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n); } } for (String n : ini.getPropertyNames("special-resources")) { if (new CSFile(srcDir + n + File.separatorChar + n + "-spreadsheet.xml").exists()) checkFile("definition", srcDir + n + File.separatorChar, n + "-spreadsheet.xml", errors, n); else checkFile("definition", srcDir + n + File.separatorChar, n + "-def.xml", errors, n); // now iterate all the files in the directory checking data for (String fn : new File(srcDir + n + File.separatorChar).list()) checkFile("source", srcDir + n + File.separatorChar, fn, errors, n); } }
protected String getEmbeddedClassName(ElementDefn elementDefinition, TypeRef typeRef) { if (typeRef != null) return typeRef.getResolvedTypeName(); String typeName = generateTypeName(elementDefinition, null); String cname = elementDefinition.getDeclaredTypeName(); cname = (cname == null) ? typeName : cname; return Character.toUpperCase(cname.charAt(0)) + cname.substring(1); }
private String loadCompositeType(String n, Map<String, ElementDefn> map) throws Exception { TypeParser tp = new TypeParser(); List<TypeRef> ts = tp.parse(n); definitions.getKnownTypes().addAll(ts); try { TypeRef t = ts.get(0); File csv = new CSFile(dtDir + t.getName().toLowerCase() + ".xml"); if (csv.exists()) { SpreadsheetParser p = new SpreadsheetParser( new CSFileInputStream(csv), csv.getName(), definitions, srcDir, logger, registry); ElementDefn el = p.parseCompositeType(); map.put(t.getName(), el); el.getAcceptableGenericTypes().addAll(ts.get(0).getParams()); return el.getName(); } else { String p = ini.getStringProperty("types", n); csv = new CSFile(dtDir + p.toLowerCase() + ".xml"); if (!csv.exists()) throw new Exception("unable to find a definition for " + n + " in " + p); XLSXmlParser xls = new XLSXmlParser(new CSFileInputStream(csv), csv.getAbsolutePath()); Sheet sheet = xls.getSheets().get("Restrictions"); boolean found = false; for (int i = 0; i < sheet.rows.size(); i++) { if (sheet.getColumn(i, "Name").equals(n)) { found = true; Invariant inv = new Invariant(); inv.setId(n); inv.setEnglish(sheet.getColumn(i, "Rules")); inv.setOcl(sheet.getColumn(i, "OCL")); inv.setXpath(sheet.getColumn(i, "XPath")); definitions.getConstraints().put(n, new DefinedCode(n, sheet.getColumn(i, "Rules"), p)); definitions.getConstraintInvariants().put(n, inv); } } if (!found) throw new Exception("Unable to find definition for " + n); return n; } } catch (Exception e) { throw new Exception("Unable to load " + n + ": " + e.getMessage(), e); } }
protected void generateElement(GenBlock block, ElementDefn elementDefinition) { List<TypeRef> types = elementDefinition.getTypes(); boolean multipleCardinality = elementDefinition.getMaxCardinality() == null || elementDefinition.getMaxCardinality() > 1; if (types.size() > 0) { for (TypeRef typeRef : types) { String elementType = typeRef.getName(); if (elementType.startsWith("@")) { handleField(block, FieldType.EMBEDDED, multipleCardinality, elementDefinition, typeRef); } else { handleField( block, FieldType.getFieldType(elementType), multipleCardinality, elementDefinition, typeRef); dataTypes.add(elementType); } } } else if (types.size() == 0) { handleField(block, FieldType.EMBEDDED, multipleCardinality, elementDefinition, null); } }
protected String generateTypeName(ElementDefn elementDefinition, TypeRef type, boolean fixTypes) { String elementName = elementDefinition.getName().replace("[x]", ""); if (elementDefinition.getTypes().size() > 1) { String typeName = type.getName(); typeName = Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1); if (FieldType.QUANTITY == FieldType.getFieldType(typeName)) { elementName += "Quantity"; } else { elementName += typeName; } } if (!fixTypes) { return elementName; } else if (elementName.equals("type")) { elementName = "fhirType"; } else if (elementName.equals("collection")) { elementName = "fhirCollection"; } else if (elementName.equals("deleted")) { elementName = "fhirDeleted"; } else if (elementName.equals("version")) { elementName = "versionNum"; } else if (elementName.equals("class")) { elementName = "fhirClass"; } else if (elementName.equals("hash")) { elementName = "fhirHash"; } else if (elementName.equals("identity")) { elementName = "fhirIdentity"; } else if (elementName.equals("modifier")) { elementName = "fhirModifier"; } else if (elementName.equals("validated")) { elementName = "fhirValidated"; } return elementName; }
protected boolean isResource(ElementDefn elementDefinition) { for (TypeRef type : elementDefinition.getTypes()) { if (type.getName().endsWith(RESOURCE_TYPE)) return true; } return false; }