Search in sources :

Example 1 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project beneficiary-fhir-data by CMSgov.

the class DiagnosisUtilV2 method addDiagnosisCode.

/**
 * @param eob the {@link ExplanationOfBenefit} to (possibly) modify
 * @param diagnosis the {@link Diagnosis} to add, if it's not already present
 * @return the {@link DiagnosisComponent#getSequence()} of the existing or newly-added entry
 */
static int addDiagnosisCode(ExplanationOfBenefit eob, Diagnosis diagnosis, ClaimTypeV2 claimType) {
    // Filter out if the diagnosis is already contained in the document
    Optional<DiagnosisComponent> existingDiagnosis = eob.getDiagnosis().stream().filter(d -> d.getDiagnosis() instanceof CodeableConcept).filter(d -> containedIn(diagnosis, (CodeableConcept) d.getDiagnosis())).findAny();
    // If we already have a match, we are done
    if (existingDiagnosis.isPresent()) {
        return existingDiagnosis.get().getSequenceElement().getValue();
    }
    // Set diagnosisCodeableConcept
    DiagnosisComponent diagnosisComponent = new DiagnosisComponent().setSequence(eob.getDiagnosis().size() + 1);
    diagnosisComponent.setDiagnosis(toCodeableConcept(diagnosis));
    // Set Type
    diagnosisComponent.addType(translateLabels(diagnosis.getLabels(), claimType));
    if (diagnosis.getPresentOnAdmission().isPresent() && diagnosis.getPresentOnAdmissionCode().isPresent()) {
        diagnosisComponent.addExtension(TransformerUtilsV2.createExtensionCoding(eob, diagnosis.getPresentOnAdmissionCode().get(), diagnosis.getPresentOnAdmission()));
    }
    eob.getDiagnosis().add(diagnosisComponent);
    return diagnosisComponent.getSequenceElement().getValue();
}
Also used : IntStream(java.util.stream.IntStream) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) LoggerFactory(org.slf4j.LoggerFactory) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) C4BBClaimProfessionalAndNonClinicianDiagnosisType(gov.cms.bfd.server.war.commons.carin.C4BBClaimProfessionalAndNonClinicianDiagnosisType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ItemComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent) ExDiagnosistype(org.hl7.fhir.r4.model.codesystems.ExDiagnosistype) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Map(java.util.Map) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) ReflectionUtils(gov.cms.bfd.server.war.commons.ReflectionUtils) Logger(org.slf4j.Logger) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) Set(java.util.Set) IOException(java.io.IOException) C4BBClaimInpatientInstitutionalDiagnosisType(gov.cms.bfd.server.war.commons.carin.C4BBClaimInpatientInstitutionalDiagnosisType) C4BBClaimOutpatientInstitutionalDiagnosisType(gov.cms.bfd.server.war.commons.carin.C4BBClaimOutpatientInstitutionalDiagnosisType) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) DiagnosisLabel(gov.cms.bfd.server.war.commons.Diagnosis.DiagnosisLabel) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Coding(org.hl7.fhir.r4.model.Coding) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) DiagnosisComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.DiagnosisComponent) InputStream(java.io.InputStream) DiagnosisComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.DiagnosisComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 2 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class Publisher method produceProfile.

private void produceProfile(ResourceDefn resource, Profile pack, ConstraintStructure profile, SectionTracker st, String intro, String notes, String prefix, ImplementationGuideDefn ig) throws Exception {
    File tmp = Utilities.createTempFile("tmp", ".tmp");
    String title = profile.getId();
    int level = (ig == null || ig.isCore()) ? 0 : 1;
    // you have to validate a profile, because it has to be merged with it's
    // base resource to fill out all the missing bits
    // validateProfile(profile);
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    XmlSpecGenerator gen = new XmlSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../");
    gen.generate(profile.getResource());
    gen.close();
    String xml = new String(bs.toByteArray());
    bs = new ByteArrayOutputStream();
    JsonSpecGenerator genJ = new JsonSpecGenerator(bs, title + "-definitions.html", "", page, ig.isCore() ? "" : "../", page.getVersion().toCode());
    genJ.generate(profile.getResource());
    genJ.close();
    String json = new String(bs.toByteArray());
    XmlParser comp = new XmlParser();
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.xml");
    comp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
    s.close();
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + prefix + title + ".profile.xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + title + ".profile.xml"));
    JsonParser jcomp = new JsonParser();
    s = new FileOutputStream(page.getFolders().dstDir + prefix + title + ".profile.json");
    jcomp.setOutputStyle(OutputStyle.PRETTY).compose(s, profile.getResource());
    s.close();
    // String shex = new ShExGenerator(page.getWorkerContext()).generate(HTMLLinkPolicy.NONE, profile.getResource());
    // TextFile.stringToFile(shex, Utilities.changeFileExt(page.getFolders().dstDir + prefix +title + ".profile.shex", ".shex"));
    // shexToXhtml(prefix +title + ".profile", "ShEx statement for " + prefix +title, shex, "profile-instance:type:" + title, "Type");
    TerminologyNotesGenerator tgen = new TerminologyNotesGenerator(new FileOutputStream(tmp), page);
    tgen.generate(level == 0 ? "" : "../", profile);
    tgen.close();
    String tx = TextFile.fileToString(tmp.getAbsolutePath());
    String src = TextFile.fileToString(page.getFolders().templateDir + "template-profile.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + ".html", level, null);
    else if (ig != null && !ig.isCore()) {
        src = addSectionNumbers(title + ".html", title, src, null, 1, null, ig);
        st = page.getSectionTrackerCache().get(ig.getCode() + "::" + title);
    }
    page.getHTMLChecker().registerFile(prefix + title + ".html", "StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, false);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + ".html");
    new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSchematrons(new FileOutputStream(page.getFolders().dstDir + prefix + title + ".sch"), profile.getResource());
    if (pack.getExamples().size() > 0) {
        src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-examples.html");
        src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
        page.getHTMLChecker().registerFile(prefix + title + "-examples.html", "Examples for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
        TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-examples.html");
    }
    src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-definitions.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + "-definitions.html", level, null);
    page.getHTMLChecker().registerFile(prefix + title + "-definitions.html", "Definitions for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-definitions.html");
    src = TextFile.fileToString(page.getFolders().templateDir + "template-profile-mappings.html");
    src = page.processProfileIncludes(profile.getId(), profile.getId(), pack, profile, xml, json, tx, src, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    if (st != null)
        src = insertSectionNumbers(src, st, title + "-mappings.html", level, null);
    page.getHTMLChecker().registerFile(prefix + title + "-mappings.html", "Mappings for StructureDefinition " + profile.getResource().getName(), HTMLLinkChecker.XHTML_TYPE, true);
    TextFile.stringToFile(src, page.getFolders().dstDir + prefix + title + "-mappings.html");
    try {
        processQuestionnaire(resource, profile.getResource(), st, false, prefix, ig);
    } catch (Exception e) {
        e.printStackTrace();
        page.log("Questionnaire Generation Failed: " + e.getMessage(), LogMessageType.Error);
    }
    new ReviewSpreadsheetGenerator().generate(page.getFolders().dstDir + prefix + Utilities.changeFileExt((String) profile.getResource().getUserData("filename"), "-review.xls"), "Health Level Seven International", page.getGenDate(), profile.getResource(), page);
    // xml to xhtml of xml
    // first pass is to strip the xsi: stuff. seems to need double
    // processing in order to delete namespace crap
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(page.getFolders().dstDir + prefix + title + ".profile.xml"));
    XmlGenerator xmlgen = new XmlGenerator();
    xmlgen.generate(xdoc.getDocumentElement(), tmp, "http://hl7.org/fhir", xdoc.getDocumentElement().getLocalName());
    // reload it now
    builder = factory.newDocumentBuilder();
    xdoc = builder.parse(new CSFileInputStream(tmp.getAbsolutePath()));
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(level)));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, "StructureDefinition", profile.getTitle(), 0, true, title + ".profile.xml.html");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-xml.html").replace("<%example%>", b.toString());
    html = page.processProfileIncludes(title + ".profile.xml.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, hasNarrative(xdoc));
    TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.xml.html");
    page.getHTMLChecker().registerFile(prefix + title + ".profile.xml.html", "StructureDefinition", HTMLLinkChecker.XHTML_TYPE, false);
    String n = prefix + title + ".profile";
    json = resource2Json(profile.getResource());
    json = "<div class=\"example\">\r\n<p>" + Utilities.escapeXml("StructureDefinition for " + profile.getResource().getDescription()) + "</p>\r\n<p><a href=\"" + title + ".profile.json\">Raw JSON</a></p>\r\n<pre class=\"json\">\r\n" + Utilities.escapeXml(json) + "\r\n</pre>\r\n</div>\r\n";
    html = TextFile.fileToString(page.getFolders().templateDir + "template-profile-example-json.html").replace("<%example%>", json);
    html = page.processProfileIncludes(title + ".profile.json.html", profile.getId(), pack, profile, "", "", "", html, title + ".html", (resource == null ? profile.getResource().getType() : resource.getName()) + "/" + pack.getId() + "/" + profile.getId(), intro, notes, ig, false, false);
    TextFile.stringToFile(html, page.getFolders().dstDir + prefix + title + ".profile.json.html");
    // page.getEpub().registerFile(n + ".json.html", description, EPubManager.XHTML_TYPE);
    page.getHTMLChecker().registerExternal(n + ".json.html");
    tmp.delete();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XmlSpecGenerator(org.hl7.fhir.definitions.generators.specification.XmlSpecGenerator) JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XmlGenerator(org.hl7.fhir.utilities.xml.XmlGenerator) TerminologyNotesGenerator(org.hl7.fhir.definitions.generators.specification.TerminologyNotesGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) 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) ReviewSpreadsheetGenerator(org.hl7.fhir.definitions.generators.specification.ReviewSpreadsheetGenerator) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileOutputStream(java.io.FileOutputStream) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 3 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class Publisher method checkFragment.

public void checkFragment(Fragment f) {
    try {
        // System.out.println("    "+f.page+"/"+f.id);
        String xml = f.getXml();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        Document doc = builder.parse(is);
        org.w3c.dom.Element base = doc.getDocumentElement();
        String type = base.getAttribute("fragment");
        if (!page.getDefinitions().hasPrimitiveType(type)) {
            if (f.isJson()) {
                org.hl7.fhir.r5.elementmodel.JsonParser p = new org.hl7.fhir.r5.elementmodel.JsonParser(page.getWorkerContext());
                p.setupValidation(ValidationPolicy.QUICK, null);
                p.parse(base.getTextContent(), type);
            } else {
                org.hl7.fhir.r5.elementmodel.XmlParser p = new org.hl7.fhir.r5.elementmodel.XmlParser(page.getWorkerContext());
                p.setupValidation(ValidationPolicy.QUICK, null);
                p.parse(XMLUtil.getFirstChild(base), type);
            }
        }
    } catch (Exception e) {
        page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.STRUCTURE, f.getPage(), "Fragment Error in page " + f.getPage() + (f.id != null ? "#" + f.id : "") + ": " + e.getMessage(), IssueSeverity.ERROR));
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Element(org.w3c.dom.Element) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 4 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class Publisher method stripXsd.

private InputStream stripXsd(InputStream source) throws Exception {
    byte[] src = IOUtils.toByteArray(source);
    try {
        byte[] xslt = IOUtils.toByteArray(new FileInputStream(Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "AnnotationStripper.xslt")));
        String scrs = new String(src);
        String xslts = new String(xslt);
        return new ByteArrayInputStream(XsltUtilities.transform(new HashMap<String, byte[]>(), src, xslt));
    } catch (Exception e) {
        if (web) {
            e.printStackTrace();
            throw e;
        } else
            return new ByteArrayInputStream(src);
    }
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware(false);
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document doc = builder.parse(source);
// stripElement(doc.getDocumentElement(), "annotation");
// TransformerFactory transformerFactory = TransformerFactory.newInstance();
// Transformer transformer = transformerFactory.newTransformer();
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
// DOMSource src = new DOMSource(doc);erent
// StreamResult streamResult =  new StreamResult(bo);
// transformer.transform(src, streamResult);
// bo.close();
// return new ByteArrayInputStream(bo.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) FileInputStream(java.io.FileInputStream) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project kindling by HL7.

the class Publisher method cloneToXhtml.

private void cloneToXhtml(String n, String description, boolean adorn, String pageType, String crumbTitle, ImplementationGuideDefn igd, ResourceDefn rd, WorkGroup wg) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document xdoc = builder.parse(new CSFileInputStream(new CSFile(page.getFolders().dstDir + n + ".xml")));
    XhtmlGenerator xhtml = new XhtmlGenerator(new ExampleAdorner(page.getDefinitions(), page.genlevel(Utilities.charCount(n, File.separatorChar))));
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    xhtml.generate(xdoc, b, n.toUpperCase().substring(0, 1) + n.substring(1), description, 0, adorn, n + ".xml.html");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example-xml.html").replace("<%example%>", b.toString());
    html = page.processPageIncludes(n + ".xml.html", html, pageType, null, n + ".xml.html", null, null, crumbTitle, (adorn && hasNarrative(xdoc)) ? new Boolean(true) : null, igd, rd, wg);
    TextFile.stringToFile(html, page.getFolders().dstDir + n + ".xml.html");
    // page.getEpub().registerFile(n + ".xml.html", description, EPubManager.XHTML_TYPE);
    page.getHTMLChecker().registerExternal(n + ".xml.html");
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CSFile(org.hl7.fhir.utilities.CSFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) XhtmlDocument(org.hl7.fhir.utilities.xhtml.XhtmlDocument) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) XhtmlGenerator(org.hl7.fhir.utilities.xml.XhtmlGenerator)

Aggregations

Document (org.w3c.dom.Document)48 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 DocumentBuilder (javax.xml.parsers.DocumentBuilder)36 IOException (java.io.IOException)33 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 ArrayList (java.util.ArrayList)28 Element (org.w3c.dom.Element)20 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 HashMap (java.util.HashMap)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 FileNotFoundException (java.io.FileNotFoundException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 List (java.util.List)11 CSFile (org.hl7.fhir.utilities.CSFile)11 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 XmlGenerator (org.hl7.fhir.utilities.xml.XmlGenerator)9 Identifier (org.hl7.fhir.r4.model.Identifier)8 TextFile (org.hl7.fhir.utilities.TextFile)8