Search in sources :

Example 36 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project kindling by HL7.

the class PageProcessor method generateToc.

private String generateToc() throws Exception {
    // return breadCrumbManager.makeToc();
    List<String> entries = new ArrayList<String>();
    entries.addAll(toc.keySet());
    Collections.sort(entries, new SectionSorter());
    Set<String> pages = new HashSet<String>();
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(folders.dstDir, false, true);
    TableModel model = gen.new TableModel("toc", true);
    model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Table of Contents", "Table of Contents", null, 0));
    Deque<TocItem> stack = new ArrayDeque<TocItem>();
    for (String s : entries) {
        TocEntry t = toc.get(s);
        if (!t.isIg() && !s.startsWith("?")) {
            String nd = s;
            while (nd.endsWith(".0")) nd = nd.substring(0, nd.length() - 2);
            int d = Utilities.charCount(nd, '.');
            if (d < 4 && !pages.contains(t.getLink())) {
                String np = getNormativePackageForPage(t.getLink());
                pages.add(t.getLink());
                while (!stack.isEmpty() && stack.getFirst().depth >= d) stack.pop();
                Row row = gen.new Row();
                row.setIcon("icon_page.gif", null);
                String td = t.getText();
                if (!stack.isEmpty()) {
                    if (td.startsWith(stack.getFirst().entry.getText() + " - "))
                        td = td.substring(stack.getFirst().entry.getText().length() + 3);
                    else if (td.startsWith(stack.getFirst().entry.getText()))
                        td = td.substring(stack.getFirst().entry.getText().length());
                }
                Cell cell = gen.new Cell(null, t.getLink(), nd + " " + td, t.getText() + " ", null);
                row.getCells().add(cell);
                if (np != null) {
                    cell.addPiece(gen.new Piece(null, " ", null));
                    cell.addPiece(gen.new Piece("versions.html#std-process", "basic".equals(np) ? "(Normative)" : "(Normative / " + Utilities.capitalize(np) + ")", null).addStyle("color: #008000"));
                    if (np.equals("infrastructure"))
                        row.setIcon("icon_page_n_i.gif", null);
                    else if (np.equals("conformance"))
                        row.setIcon("icon_page_n_c.gif", null);
                    else if (np.equals("patient"))
                        row.setIcon("icon_page_n_p.gif", null);
                    else if (np.equals("observation"))
                        row.setIcon("icon_page_n_o.gif", null);
                    else
                        row.setIcon("icon_page_n.gif", null);
                } else {
                    cell.addPiece(gen.new Piece(null, " ", null));
                    cell.addPiece(gen.new Piece("versions.html#std-process", "(Trial Use)", null).addStyle("color: #b3b3b3"));
                }
                if (stack.isEmpty())
                    model.getRows().add(row);
                else
                    stack.getFirst().row.getSubRows().add(row);
                stack.push(new TocItem(t, row, d));
            }
        }
    }
    return new XhtmlComposer(XhtmlComposer.HTML).compose(gen.generate(model, "", 0, null));
}
Also used : ArrayList(java.util.ArrayList) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) ArrayDeque(java.util.ArrayDeque) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel) HashSet(java.util.HashSet)

Example 37 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project kindling by HL7.

the class Publisher method produceArchive.

private void produceArchive() throws Exception {
    String target = page.getFolders().archiveDir + "v" + page.getVersion() + ".zip";
    File tf = new CSFile(target);
    if (tf.exists())
        tf.delete();
    ZipGenerator zip = new ZipGenerator(target);
    int c = 0;
    String[] files = new CSFile(page.getFolders().dstDir).list();
    for (String f : files) {
        File fn = new CSFile(page.getFolders().dstDir + f);
        if (!fn.isDirectory()) {
            if (f.endsWith(".html")) {
                String src = TextFile.fileToString(fn.getAbsolutePath());
                String srcn = src.replace("<!-- achive note -->", "This is an old version of FHIR retained for archive purposes. Do not use for anything else");
                if (!srcn.equals(src))
                    c++;
                srcn = srcn.replace("<body>", "<body><div class=\"watermark\"/>").replace("<body class=\"book\">", "<body class=\"book\"><div class=\"watermark\"/>");
                zip.addFileSource(f, srcn, false);
            // Utilities.stringToFile(srcn, target+File.separator+f);
            } else if (f.endsWith(".css")) {
                String src = TextFile.fileToString(fn.getAbsolutePath());
                src = src.replace("#fff", "lightcyan");
                zip.addFileSource(f, src, false);
            // Utilities.stringToFile(srcn, target+File.separator+f);
            } else
                zip.addFileName(f, fn.getAbsolutePath(), false);
        } else if (!fn.getAbsolutePath().endsWith("v2") && !fn.getAbsolutePath().endsWith("v3")) {
        // used to put stuff in sub-directories. clean them out if they
        // still exist
        // Utilities.clearDirectory(fn.getAbsolutePath());
        // fn.delete();
        }
    }
    if (c < 3)
        // so
        throw new Exception("header note replacement in archive failed");
    // check
    // the
    // syntax
    // of
    // the
    // string
    // constant
    // above
    zip.close();
}
Also used : CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project kindling by HL7.

the class ExampleInspector method validateRDF.

private void validateRDF(String fttl, String fjld, String rt) throws FileNotFoundException, IOException {
    if (VALIDATE_RDF && new File(fjld).exists()) {
        FileInputStream f = new FileInputStream(fjld);
        int size = f.available();
        f.close();
        if (size > 1000000)
            return;
        // replace @context with the contents of the right context file
        JsonObject json = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.fileToString(fjld));
        json.remove("@context");
        json.add("@context", jsonLdDefns.get("@context"));
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jcnt = gson.toJson(json);
        // TextFile.stringToFile(jcnt, "c:\\temp\\jsonld\\"+rt+".jsonld");
        // parse to a model
        Model mj = ModelFactory.createDefaultModel();
        mj.read(new StringReader(jcnt), null, "JSON-LD");
        // read turtle file into Jena
        Model mt = RDFDataMgr.loadModel(fttl);
        // use ShEx to validate turtle file - TODO
        shex.validate(mt);
    // List<String> diffs = new ModelComparer().setModel1(mt, "ttl").setModel2(mj, "json").compare();
    // if (!diffs.isEmpty()) {
    // System.out.println("not isomorphic");
    // for (String s : diffs) {
    // System.out.println("  "+s);
    // }
    // RDFDataMgr.write(new FileOutputStream("c:\\temp\\json.nt"), mj, RDFFormat.NTRIPLES_UTF8);
    // RDFDataMgr.write(new FileOutputStream("c:\\temp\\ttl.nt"), mt, RDFFormat.NTRIPLES_UTF8);
    // }
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) FileInputStream(java.io.FileInputStream)

Example 39 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project kindling by HL7.

the class OldSpreadsheetParser method readOperations.

private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
    Map<String, Operation> ops = new HashMap<String, Operation>();
    Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            String use = sheet.getColumn(row, "Use");
            String doco = sheet.getColumn(row, "Documentation");
            String type = sheet.getColumn(row, "Type");
            List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
            List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                if (!name.contains(".")) {
                    if (!type.equals("operation"))
                        throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
                    if (!name.toLowerCase().equals(name))
                        throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
                    params.clear();
                    boolean system = false;
                    boolean istype = false;
                    boolean instance = false;
                    for (String c : use.split("\\|")) {
                        c = c.trim();
                        if ("system".equalsIgnoreCase(c))
                            system = true;
                        else if ("resource".equalsIgnoreCase(c))
                            istype = true;
                        else if ("instance".equalsIgnoreCase(c))
                            instance = true;
                        else
                            throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
                    }
                    Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
                    op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
                    op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
                    op.setFooter2(sheet.getColumn(row, "Footer2"));
                    op.setFmm(sheet.getColumn(row, "fmm"));
                    op.getExamples2().addAll(examples2);
                    oplist.add(op);
                    ops.put(name, op);
                } else {
                    String context = name.substring(0, name.lastIndexOf('.'));
                    String pname = name.substring(name.lastIndexOf('.') + 1);
                    Operation operation;
                    List<OperationParameter> plist;
                    if (context.contains(".")) {
                        String opname = name.substring(0, name.indexOf('.'));
                        // inside of a tuple
                        if (!Utilities.noString(use))
                            throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
                        operation = ops.get(opname);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
                        OperationParameter param = params.get(context);
                        if (param == null)
                            throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
                        if (!param.getFhirType().equals("Tuple"))
                            throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
                        plist = param.getParts();
                    } else {
                        if (!use.equals("in") && !use.equals("out"))
                            throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
                        operation = ops.get(context);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
                        plist = operation.getParameters();
                    }
                    String profile = sheet.getColumn(row, "Profile");
                    String min = sheet.getColumn(row, "Min");
                    String max = sheet.getColumn(row, "Max");
                    OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
                    String bs = sheet.getColumn(row, "Binding");
                    if (!Utilities.noString(bs))
                        p.setBs(bindings.get(bs));
                    plist.add(p);
                    params.put(name, p);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) Operation(org.hl7.fhir.definitions.model.Operation) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 40 with Use

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.Use in project kindling by HL7.

the class OldSpreadsheetParser method scanNestedTypes.

private void scanNestedTypes(ResourceDefn parent, ElementDefn root, String parentName) throws Exception {
    for (ElementDefn element : root.getElements()) {
        if (element.hasNestedElements()) {
            String nestedTypeName;
            ElementDefn newCompositeType = new ElementDefn();
            // generated name for this nested type
            if (element.typeCode().startsWith("=")) {
                if (isProfile)
                    throw new Exception("Cannot use '=' types in profiles on " + parentName);
                element.setStatedType(element.typeCode().substring(1));
                nestedTypeName = element.typeCode().substring(1);
            } else {
                nestedTypeName = parentName + Utilities.capitalize(element.getName());
            }
            newCompositeType.setAnonymousTypedGroup(true);
            // Add Component to the actually generated name to avoid
            // confusing between the element name and the element's type
            newCompositeType.setName(nestedTypeName + "Component");
            newCompositeType.setDefinition("A nested type in " + parent.getName() + ": " + element.getDefinition());
            newCompositeType.getElements().addAll(element.getElements());
            if (parent.getRoot().getNestedTypes().containsKey(nestedTypeName))
                throw new Exception("Nested type " + nestedTypeName + " already exist in resource " + parent.getName());
            parent.getRoot().getNestedTypes().put(nestedTypeName, newCompositeType);
            // Clear out the name of the local type, so old code
            // will not see a change.
            element.getTypes().clear();
            element.setDeclaredTypeName(newCompositeType.getName());
            scanNestedTypes(parent, element, nestedTypeName);
        }
    }
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ArrayList (java.util.ArrayList)82 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)43 List (java.util.List)41 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 Date (java.util.Date)39 IOException (java.io.IOException)38 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)35 Test (org.junit.jupiter.api.Test)35 Resource (org.hl7.fhir.r4.model.Resource)34 Collectors (java.util.stream.Collectors)29 Coding (org.hl7.fhir.r4.model.Coding)27 Reference (org.hl7.fhir.r4.model.Reference)27 Timer (com.codahale.metrics.Timer)26 HashMap (java.util.HashMap)25 Bundle (org.hl7.fhir.r4.model.Bundle)25 Reference (org.hl7.fhir.dstu3.model.Reference)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)21 JsonObject (com.google.gson.JsonObject)20