Search in sources :

Example 26 with WorkGroup

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

the class ResourceParser method convertPack.

private Profile convertPack(ImplementationGuide ig, String id, WorkGroup wg) throws Exception {
    Profile p = new Profile(id.substring(id.indexOf("-") + 1));
    p.setTitle(ig.getTitle());
    p.forceMetadata("id", ig.getId());
    if (ig.hasName()) {
        p.forceMetadata("name", ig.getName());
    }
    if (ig.hasPublisher()) {
        p.forceMetadata("author.name", ig.getPublisher());
    }
    if (ig.hasExtension(BuildExtensions.EXT_CODE)) {
        p.forceMetadata("code", BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_CODE));
    }
    if (ig.hasExtension(BuildExtensions.EXT_FMM_LEVEL)) {
        p.forceMetadata("fmm", BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_FMM_LEVEL));
    }
    if (ig.hasDescription()) {
        p.forceMetadata("description", ig.getDescription());
    }
    if (ig.hasStatus()) {
        p.forceMetadata("status", ig.getStatus().toCode());
    }
    if (ig.hasVersion()) {
        p.forceMetadata("version", ig.getVersion());
    }
    if (ig.hasTitle()) {
        p.forceMetadata("display", ig.getTitle());
    }
    if (ig.hasExtension(BuildExtensions.EXT_WORKGROUP)) {
        p.forceMetadata("workgroup", BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_WORKGROUP));
    }
    if (ig.hasDate()) {
        p.forceMetadata("date", ig.getDateElement().primitiveValue());
    }
    if (ig.hasExperimental()) {
        p.forceMetadata("Experimental", ig.getExperimentalElement().primitiveValue());
    }
    if (ig.hasExtension(BuildExtensions.EXT_INTRODUCTION)) {
        p.setIntroduction(Utilities.path(folder, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_INTRODUCTION)));
    }
    if (ig.hasExtension(BuildExtensions.EXT_NOTES)) {
        p.setNotes(Utilities.path(folder, BuildExtensions.readStringExtension(ig, BuildExtensions.EXT_NOTES)));
    }
    for (ImplementationGuideDefinitionResourceComponent res : ig.getDefinition().getResource()) {
        String ref = res.getReference().getReference();
        String type = ref.substring(0, ref.indexOf("/"));
        String rid = ref.substring(ref.indexOf("/") + 1);
        if ("StructureDefinition".equals(type)) {
            StructureDefinition sd;
            if (new File(Utilities.path(folder, "structuredefinition-extension-" + rid + ".xml")).exists()) {
                sd = (StructureDefinition) parseXml("structuredefinition-extension-" + rid + ".xml");
                sd.setUserData("path", "extension-" + sd.getId() + ".html");
                p.getExtensions().add(sd);
                context.cacheResource(sd);
            } else {
                ConstraintStructure tp = processProfile(rid, ig.getId().substring(ig.getId().indexOf("-") + 1), res, wg);
                sd = tp.getResource();
                sd.setUserData("path", sd.getId() + ".html");
                p.getProfiles().add(tp);
            }
            sd.setUserData(ToolResourceUtilities.NAME_RES_IG, id);
            sd.setVersion(version);
            for (ElementDefinition ed : sd.getDifferential().getElement()) {
                if (ed.hasBinding() && ed.getBinding().hasValueSet()) {
                    loadValueSet(ed.getBinding().getValueSet(), true);
                }
            }
        } else if ("SearchParameter".equals(type)) {
            SearchParameter sp = processSearchParameter(rid);
            p.getSearchParameters().add(sp);
        } else {
            // example
            p.getExamples().add(makeExample(res, ref, type, rid));
        }
    }
    return p;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) Profile(org.hl7.fhir.definitions.model.Profile)

Example 27 with WorkGroup

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

the class Publisher method producePage.

// private void validateProfile(ProfileDefn profile) throws FileNotFoundException, Exception {
// for (ResourceDefn c : profile.getResources()) {
// StructureDefinition resource = loadResourceProfile(c.getName());
// ProfileValidator v = new ProfileValidator();
// v.setCandidate(c);
// v.setProfile(resource);
// v.setTypes(typeFeed);
// List<String> errors = v.evaluate();
// if (errors.size() > 0)
// throw new Exception("Error validating " + profile.metadata("name") + ": " + errors.toString());
// }
// }
// private void produceFutureReference(String n) throws Exception {
// ElementDefn e = new ElementDefn();
// e.setName(page.getIni().getStringProperty("future-resources", n));
// }
/*
  private StructureDefinition loadResourceProfile(String name) throws FileNotFoundException, Exception {
    XmlParser xml = new XmlParser();
    try {
      return (StructureDefinition) xml.parse(new CSFileInputStream(page.getFolders().dstDir + name.toLowerCase() + ".profile.xml"));
    } catch (Exception e) {
      throw new Exception("error parsing " + name, e);
    }
  }
  */
// private void produceIgPage(String source, String file, String logicalName, ImplementationGuideDefn ig) throws Exception {
// String src = TextFile.fileToString(source);
// src = page.processPageIncludes(file, src, "page", null, null, null, logicalName, null);
// // before we save this page out, we're going to figure out what it's index
// // is, and number the headers if we can
// 
// if (Utilities.noString(logicalName))
// logicalName = Utilities.fileTitle(file);
// 
// TextFile.stringToFile(src, page.getFolders().dstDir + file);
// src = addSectionNumbers(file, logicalName, src, null, 0, null, ig);
// 
// TextFile.stringToFile(src, page.getFolders().dstDir + file);
// 
// src = TextFile.fileToString(source).replace("<body>", "<body style=\"margin: 10px\">");
// src = page.processPageIncludesForBook(file, src, "page", null, null);
// cachePage(file, src, logicalName);
// }
// 
private void producePage(String file, String logicalName) throws Exception {
    String src = TextFile.fileToString(page.getFolders().srcDir + file);
    src = page.processPageIncludes(file, src, "page", null, null, null, logicalName, null, null, null);
    if (Utilities.noString(logicalName))
        logicalName = Utilities.fileTitle(file);
    TextFile.stringToFile(src, page.getFolders().dstDir + file);
    DocumentHolder doch = new DocumentHolder();
    src = addSectionNumbers(file, logicalName, src, null, 0, doch, null);
    if (!page.getDefinitions().getStructuralPages().contains(file)) {
        XhtmlNode fmm = findId(doch.doc, "fmm");
        XhtmlNode wg = findId(doch.doc, "wg");
        if (fmm == null)
            page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, file, "Page has no fmm level", IssueSeverity.ERROR));
        else
            page.getDefinitions().page(file).setFmm(get2ndPart(fmm.allText()));
        if (wg == null)
            page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, -1, -1, file, "Page has no workgroup", IssueSeverity.ERROR));
        else
            page.getDefinitions().page(file).setWg(wg.getChildNodes().get(0).allText());
    }
    TextFile.stringToFile(src, page.getFolders().dstDir + file);
    src = TextFile.fileToString(page.getFolders().srcDir + file).replace("<body>", "<body style=\"margin: 10px\">");
    src = page.processPageIncludesForBook(file, src, "page", null, null, null);
    cachePage(file, src, logicalName, true);
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)13 FileNotFoundException (java.io.FileNotFoundException)9 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 CSFile (org.hl7.fhir.utilities.CSFile)9 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)8 WorkGroup (org.hl7.fhir.definitions.model.WorkGroup)8 File (java.io.File)7 ArrayList (java.util.ArrayList)6 TransformerException (javax.xml.transform.TransformerException)6 TextFile (org.hl7.fhir.utilities.TextFile)6 URISyntaxException (java.net.URISyntaxException)5 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)5 IniFile (org.hl7.fhir.utilities.IniFile)5 Date (java.util.Date)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 UcumException (org.fhir.ucum.UcumException)4 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)4 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4