Search in sources :

Example 1 with BindingMethod

use of org.hl7.fhir.definitions.model.BindingSpecification.BindingMethod in project kindling by HL7.

the class BindingsFixer method processSheet.

private static void processSheet(XLSXmlParser xls, Sheet sheet, String dir, String sfx) throws Exception {
    for (int row = 0; row < sheet.rows.size(); row++) {
        String bindingName = sheet.getColumn(row, "Binding Name");
        if (Utilities.noString(bindingName) || bindingName.startsWith("!"))
            continue;
        BindingMethod method = BindingsParser.readBinding(sheet.getColumn(row, "Binding"), "??");
        String ref = sheet.getColumn(row, "Reference");
        if (method == BindingMethod.CodeList) {
            if (ref.startsWith("#valueset-"))
                throw new Exception("don't start code list references with #valueset-");
            String vfn = Utilities.path(dir, "valueset-" + sfx + ref.substring(1) + ".xml");
            String cfn = Utilities.path(dir, "codesystem-" + sfx + ref.substring(1) + ".xml");
            File vf = new File(vfn);
            File cf = new File(cfn);
            if (!vf.exists()) {
                System.out.println("Produce " + vfn);
                ValueSet vs = ValueSetUtilities.makeShareable(new ValueSet());
                vs.setVersion(Constants.VERSION);
                vs.setId(sfx + ref.substring(1));
                vs.setUrl("http://hl7.org/fhir/ValueSet/" + sfx + ref.substring(1));
                vs.setDescription(sheet.getColumn(row, "Description"));
                vs.setName(bindingName);
                vs.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
                vs.setCopyright(sheet.getColumn(row, "Copyright"));
                Sheet css = xls.getSheets().get(ref.substring(1));
                if (css == null) {
                    throw new Exception("Error parsing binding " + bindingName + ": code list reference '" + ref + "' not resolved");
                }
                CodeSystem cs = CodeSystemUtilities.makeShareable(new CodeSystem());
                cs.setVersion(Constants.VERSION);
                cs.setId(sfx + ref.substring(1));
                cs.setUrl("http://hl7.org/fhir/" + sfx + ref.substring(1));
                cs.setDescription(sheet.getColumn(row, "Description"));
                cs.setName(bindingName);
                cs.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
                cs.setCopyright(sheet.getColumn(row, "Copyright"));
                vs.getCompose().addInclude().setSystem(cs.getUrl());
                processCodes(cs, css);
                new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(vf), vs);
                new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(cf), cs);
            }
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ValueSet(org.hl7.fhir.r5.model.ValueSet) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) BindingMethod(org.hl7.fhir.definitions.model.BindingSpecification.BindingMethod)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 BindingMethod (org.hl7.fhir.definitions.model.BindingSpecification.BindingMethod)1 XmlParser (org.hl7.fhir.r5.formats.XmlParser)1 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)1 ValueSet (org.hl7.fhir.r5.model.ValueSet)1 XLSXmlParser (org.hl7.fhir.utilities.xls.XLSXmlParser)1 Sheet (org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet)1