コード例 #1
0
        def resolve_placeholders(self, definition):
            """Assemble the definition using our name and replacements.

            Pass:
                definition - definition with placeholders to be resolved

            Return:
                marked-up definition row
            """

            if definition.langcode == "en":
                name = deepcopy(self.english_name)
            elif self.spanish_name is None:
                name = deepcopy(self.english_name)
                self.__append_en_ingles(name)
            else:
                name = deepcopy(self.spanish_name)
            root = etree.Element("GlossaryTermDef")
            root.append(name)
            root.append(self.__make_capped_name(name))
            root.append(deepcopy(definition.node.find("DefinitionText")))
            if self.replacements:
                node = etree.Element("GlossaryTermPlaceHolder")
                for replacement in self.replacements.values():
                    node.append(deepcopy(replacement))
                root.append(node)
            if definition.replacements:
                node = etree.Element("GlossaryConceptPlaceHolder")
                for replacement in definition.replacements.values():
                    node.append(deepcopy(replacement))
                root.append(node)
            doc = Doc(Concept.GUEST, xml=etree.tostring(root))
            result = doc.filter(Concept.FILTER)
            return html.fromstring(str(result.result_tree))
コード例 #2
0
    def _person_locations_picklist(self):
        """
        Support picking a Person address to link to

        Parameters:
          DocId - unique identifier of the Person document to link to
                  (required)
          PrivatePracticeOnly - if "no" (the default) picklist includes
                                other practice locations (in addition to
                                private practice locations); otherwise
                                only private practice locations are included

        Return:
          XML document node with the following structure:
            ReportBody
              ReportName
              ReportRow*
                Link
                Data
        """

        doc_id = self.__opts.get("DocId")
        if not doc_id:
            raise Exception("Missing required 'DocId' parameter")
        doc = Doc(self.session, id=doc_id)
        private_practice_only = self.__opts.get("PrivatePracticeOnly", "no")
        parms = dict(
            docId=etree.XSLT.strparam(str(doc.id)),
            privatePracticeOnly=etree.XSLT.strparam(private_practice_only),
            repName=etree.XSLT.strparam(self.name))
        filter_name = "Person Locations Picklist"
        result = doc.filter("name:" + filter_name, parms=parms)
        return result.result_tree.getroot()
コード例 #3
0
    def _person_address_fragment(self):
        """
        Fetch the details for an address identified by fragment ID

        Parameters:
          Link - string in the form CDR0000999999#XXX, representing
                 the unique ID of a CDR document, and the ID for
                 a node withing that document's subtree (required)

        Return:
          XML document node with the following structure:
            ReportBody
              [sequence of contact information elements]
        """

        link = self.__opts.get("Link")
        if not link:
            raise Exception("Missing required 'Link' parameter")
        try:
            doc_id, frag_id = link.split("#", 1)
        except:
            raise Exception("Link parameter must include fragment ID")
        parms = dict(fragId=etree.XSLT.strparam(frag_id))
        doc = Doc(self.session, id=doc_id)
        result = doc.filter("name:Person Address Fragment", parms=parms)
        return result.result_tree.getroot()
コード例 #4
0
        def markup_for_name(name):
            """Highlight insertion/deletion markup for the term name.

            Pass:
                name - parsed XML node for the term name string
            """

            doc = Doc(Concept.GUEST, xml=etree.tostring(name))
            result = doc.filter(Concept.FILTER)
            return html.fromstring(str(result.result_tree).strip())
コード例 #5
0
            def row(self):
                """HTML markup for this comment."""

                if not hasattr(self, "_row"):
                    wrapper = etree.Element("GlossaryTermDef")
                    wrapper.append(self.__node)
                    doc = Doc(Concept.GUEST, xml=etree.tostring(wrapper))
                    result = doc.filter(Concept.FILTER)
                    self._row = html.fromstring(str(result.result_tree))
                return self._row
コード例 #6
0
    def nodes(self):
        """Sequence of HTML elements to be added to the report.

        We use XSL/T filtering to generate the HTML fragments
        for the report for this summary, which we then parse
        so they can be added to the page object.
        """

        if not hasattr(self, "_nodes"):
            opts = dict(id=self.id, version=self.version)
            doc = Doc(self.control.session, **opts)
            result = doc.filter(*self.FILTERS, parms=self.parms)
            html = str(result.result_tree).strip()
            self._nodes = self.H.fragments_fromstring(html)
        return self._nodes
コード例 #7
0
ファイル: SummaryChanges.py プロジェクト: NCIOCPL/cdr-admin
    def sections(self):
        """Sequence of sections of the report, one for each change."""

        if not hasattr(self, "_sections"):
            last_section = None
            sections = []
            for version, date in self.versions:
                display_date = date.strftime("%m/%d/%Y")
                doc = Doc(self.session, id=self.id, version=version)
                response = doc.filter(self.FILTER)
                html = str(response.result_tree).strip()
                if html != last_section:
                    last_section = html
                    html = html.replace("@@PubVerDate@@", display_date)
                    sections.append(lxml.html.fragments_fromstring(html))
            self._sections = reversed(sections)
        return self._sections
コード例 #8
0
    def customize_report(self, page):
        """Create a custom version of the report with address information."""

        # Styling for the custom portion of the table.
        rule = ".person-addresses td { padding: 0 50px; }"
        page.head.append(page.B.STYLE(rule))

        # Housekeeping before we get into the loop for the search results.
        table = page.body.find("table")
        table.set("class", "person-loc-search-results")
        session_parm = f"&{SESSION}={self.session.name}"
        filter_parms = dict(repName="dummy", includeHomeAddresses="yes")

        # Walk through each row in the results set.
        for i, row in enumerate(self.rows):
            doc = Doc(self.session, id=row[0])
            title = row[1]
            url = f"{BASE}/QcReport.py?DocId={doc.cdr_id}{session_parm}"
            link = page.B.A(doc.cdr_id, href=url)

            # Create the first table row for this result.
            tr = page.B.TR(page.B.CLASS("row-item"))
            tr.append(page.B.TD(f"{i+1}.", page.B.CLASS("row-number")))
            tr.append(page.B.TD(link, page.B.CLASS("doc-link")))
            tr.append(page.B.TD(title, page.B.CLASS("doc-title")))
            table.append(tr)

            # Add a second row to the table if there are any addresses.
            filter_parms["docId"] = doc.cdr_id
            response = doc.filter(self.ADDRESS_FILTER, parms=filter_parms)
            root = response.result_tree.getroot()
            addresses = [node for node in root.iter("Data")]
            if addresses:
                ul = page.B.UL()
                td = page.B.TD(ul, colspan="3")
                tr = page.B.TR(td, page.B.CLASS("person-addresses"))
                for node in addresses:
                    ul.append(page.B.LI(Doc.get_text(node, default="")))
                table.append(tr)
コード例 #9
0
    def _term_sets(self):
        """
        Collect named sets of CDR terms

        Parameters:
          SetType - optional string restricting report to term sets
                    whose type name matches the pattern passed
                    (any wildcards in the pattern must be included,
                    the report code does not wrap the string in a
                    pair of wildcards); as of this writing, this
                    parameter is of limited use, as all of the
                    existing term sets have the set type of
                    "diagnosis macro"

        Return:
          XML document node with the following structure:
            ReportBody
              ReportName
              TermSet*
                Name
                Members [string of CDR term IDs]
        """

        query = Query("doc_version v", "v.id", "MAX(v.num) AS num")
        query.join("query_term_pub t", "t.doc_id = v.id")
        query.where("t.path = '/TermSet/TermSetType'")
        query.where("v.publishable = 'Y'")
        query.group("v.id")
        pattern = self.__opts.get("SetType")
        if pattern:
            query.where(query.Condition("t.value", pattern, "LIKE"))
        body = self.__start_body()
        for id, num in query.execute(self.cursor).fetchall():
            doc = Doc(self.session, id=id, version=num)
            result = doc.filter("name:Get TermSet Name and Members")
            body.append(result.result_tree.getroot())
        return body