def __get_definitions(self, root):
        """Assemble the term's definitions.

        Only get the ones matching the user's language and audience.
        If any contain matches for any of the user's terms, highlight
        the match and set `self.matched` to `True`.

        Pass:
            root - parsed export document

        Return:
            sequence of term definition strings
        """

        if self.control.language == "English":
            paths = ["TermDefinition"]
        elif self.control.language == "Spanish":
            paths = ["SpanishTermDefinition"]
        else:
            paths = ["TermDefinition", "SpanishTermDefinition"]
        definitions = []
        for path in paths:
            for node in root.findall(path):
                if self.control.audience in self.AUDIENCES:
                    audience = Doc.get_text(node.find("Audience"), "").strip()
                    if audience != self.control.audience:
                        continue
                text = Doc.get_text(node.find("DefinitionText"), "").strip()
                if text:
                    text = self.normalize(text)
                    definition = self.__add_highlights(text)
                    if definition != text:
                        self.matched = True
                        definitions.append(definition)
        return definitions
Esempio n. 2
0
 def parameters(self):
     if not hasattr(self, "_parameters"):
         self._parameters = dict()
         for node in self.__node.findall("SubsetFilterParm"):
             name = Doc.get_text(node.find("ParmName"))
             value = Doc.get_text(node.find("ParmValue"), "")
             self._parameters[name] = value
     return self._parameters
Esempio n. 3
0
        def aliases(self):
            """Sequence of other names for this drug term."""

            if not hasattr(self, "_aliases"):
                self._aliases = []
                for node in self.doc.findall("OtherName"):
                    self._aliases.append([
                        self.id,
                        Doc.get_text(node.find("OtherTermName", "")).strip(),
                        Doc.get_text(node.find("OtherNameType", "")).strip(),
                        self.LANGUAGE,
                    ])
            return self._aliases
Esempio n. 4
0
        def text(self):
            """String describing the video, displayed at the top."""

            if not hasattr(self, "_text"):
                self._text = None
                node = self.node.find("SpecificMediaTitle")
                if node is not None:
                    self._text = Doc.get_text(node, "").strip()
                if not self._text:
                    node = self.node.find("VideoID")
                    if node is not None:
                        self._text = Doc.get_text(node, "").strip()
            return self._text
Esempio n. 5
0
 def __init__(self, control, node):
     self.control = control
     self.date = self.type = None
     self.comments = []
     for child in node:
         if child.tag == "TypeOfDISChangeValue":
             self.type = Doc.get_text(child)
         elif child.tag == "Date":
             self.date = Doc.get_text(child)
         elif child.tag == "Comment":
             if control.comments:
                 comment = Doc.get_text(child)
                 if comment:
                     self.comments.append(comment)
Esempio n. 6
0
        def options(self):
            """
            Dictionary of fixed settings for this job type
            """

            if not hasattr(self, "_options"):
                self._options = dict(AbortOnError="Yes",
                                     PublishIfWarnings="No")
                path = "SubsetOptions/SubsetOption"
                for child in self.__node.findall(path):
                    name = Doc.get_text(child.find("OptionName"))
                    value = Doc.get_text(child.find("OptionValue"))
                    self._options[name] = value
            return self._options
Esempio n. 7
0
        def parms(self):
            """
            Dictionary of user-controllable settings with defaults
            """

            if not hasattr(self, "_parms"):
                self._parms = {}
                path = "SubsetParameters/SubsetParameter"
                for child in self.__node.findall(path):
                    name = Doc.get_text(child.find("ParmName"))
                    value = Doc.get_text(child.find("ParmValue"))
                    if name in self._parms:
                        raise Exception("Duplicate parm {!r}".format(name))
                    self._parms[name] = value
            return self._parms
    def english_request(self):
        """Request for use of English media content."""

        if not hasattr(self, "_english_request"):
            path = "PermissionInformation/PermissionRequested"
            self._english_request = Doc.get_text(self.doc.root.find(path))
        return self._english_request
Esempio n. 9
0
            def title(self):
                """String for the embedded video's title."""

                if not hasattr(self, "_title"):
                    node = self.__node.find("VideoTitle")
                    self._title = Doc.get_text(node, "").strip()
                return self._title
Esempio n. 10
0
    def subsystem(self):
        """
        Reference to the `Job.Subsystem` object controlling this job
        """

        if not hasattr(self, "_subsystem"):
            self._subsystem = None
            if self.system:
                if self.system.root is None:
                    doc = self.system
                    args = doc.cdr_id, doc.version, doc.title
                    doc = "{}V{} ({})".format(*args)
                    message = "{} can't be parsed".format(doc)
                    raise Exception(message)
                name = self.__opts.get("subsystem")
                if not name and self.id:
                    query = Query("pub_proc", "pub_subset")
                    query.where(query.Condition("id", self.id))
                    row = query.execute(self.cursor).fetchone()
                    if not row:
                        raise Exception("Job {} not found".format(self.id))
                    name = row.pub_subset
                if name:
                    path = "SystemSubset/SubsetName"
                    for node in self.system.root.findall(path):
                        if Doc.get_text(node) == name:
                            parent = node.getparent()
                            self._subsystem = Job.Subsystem(parent, name)
                            break
        return self._subsystem
Esempio n. 11
0
        def pattern(self):
            """String for the regular expression used for validation."""

            if not hasattr(self, "_pattern"):
                node = self.__node.find("ParmInfoPattern")
                self._pattern = Doc.get_text(node)
            return self._pattern
Esempio n. 12
0
        def help(self):
            """String for the explanation of the parameter."""

            if not hasattr(self, "_help"):
                help = Doc.get_text(self.__node.find("ParmInfoHelp"))
                self._help = help.replace("\r", "")
            return self._help
Esempio n. 13
0
    def description(self):
        """String containing the description of this system's usage."""

        if not hasattr(self, "_description"):
            node = self.doc.root.find("SystemDescription")
            self._description = Doc.get_text(node, "").strip()
        return self._description
Esempio n. 14
0
    def response_date(self):
        """Date the response to the request was received."""

        if not hasattr(self, "_response_date"):
            path = "PermissionInformation/PermissionResponseDate"
            self._response_date = Doc.get_text(self.doc.root.find(path))
        return self._response_date
Esempio n. 15
0
        def string(self):
            """Plain text string for this term name."""

            if not hasattr(self, "_string"):
                node = self.__node.find("TermNameString")
                self._string = Doc.get_text(node, "").strip() or None
            return self._string
Esempio n. 16
0
        def pronunciation(self):
            """Crude representation of the way the term name is spoken."""

            if not hasattr(self, "_pronunciation"):
                node = self.__node.find("TermPronunciation")
                self._pronunciation = Doc.get_text(node, "").strip() or None
            return self._pronunciation
Esempio n. 17
0
        def node(self):
            """Personal name information block."""

            if not hasattr(self, "_node"):
                node = self.doc.root.find("PersonNameInformation")
                self._node = etree.Element("Name")
                for incoming, outgoing in self.NAME_TAGS:
                    value = Doc.get_text(node.find(incoming))
                    if value:
                        etree.SubElement(self._node, outgoing).text = value
                for child in node.findall("ProfessionalSuffix/*"):
                    if child.tag in self.SUFFIX_TAGS:
                        value = Doc.get_text(child)
                        if value:
                            etree.SubElement(self._node, "Suffix").text = value
            return self._node
Esempio n. 18
0
        def name(self):
            """String for the drug's preferred name."""

            if not hasattr(self, "_name"):
                name = Doc.get_text(self.doc.find("PreferredName", ""))
                self._name = name.strip()
            return self._name
Esempio n. 19
0
    def expiration_date(self):
        """Date on which the permission expires."""

        if not hasattr(self, "_expiration_date"):
            path = "PermissionInformation/PermissionExpirationDate"
            self._expiration_date = Doc.get_text(self.doc.root.find(path))
        return self._expiration_date
Esempio n. 20
0
    def matches(self):
        """Assemble the sequence of matches for the caller's phrases."""

        if not hasattr(self, "_matches"):
            matches = []
            regex = self.__control.regex
            for section in self.root.findall("SummarySection"):
                title = Doc.get_text(section.find("Title"))
                for node in section.iter():

                    # Look for matches in the node's text property.
                    if node.text is not None and node.text.strip():
                        normalized = self.normalize(node.text)
                        context = self.Context(node)
                        if context.wrapper is not None:
                            args = title, regex, normalized, context, matches
                            self.scan_string(*args)

                    # Do a second pass looking for matches in the node's tail.
                    if node.tail is not None and node.tail.strip():
                        normalized = self.normalize(node.tail)
                        context = self.Context(node, using_tail=True)
                        if context.wrapper is not None:
                            args = title, regex, normalized, context, matches
                            self.scan_string(*args)
            self._matches = matches
        return self._matches
Esempio n. 21
0
    def request_date(self):
        """Date the request was submitted."""

        if not hasattr(self, "_request_date"):
            path = "PermissionInformation/PermissionRequestDate"
            self._request_date = Doc.get_text(self.doc.root.find(path))
        return self._request_date
Esempio n. 22
0
    def title(self):
        """Title of the Media document."""

        if not hasattr(self, "_title"):
            title = Doc.get_text(self.doc.root.find("MediaTitle", ""))
            self._title = title.strip()
        return self._title
Esempio n. 23
0
    def spanish_response(self):
        """Response to request to use Spanish media content."""

        path = "PermissionInformation/SpanishTranslationPermissionResponse"
        if not hasattr(self, "_spanish_response"):
            self._spanish_response = Doc.get_text(self.doc.root.find(path))
        return self._spanish_response
Esempio n. 24
0
    def title(self):
        """String for the title of this Media document."""

        if not hasattr(self, "_title"):
            title = Doc.get_text(self.root.find("MediaTitle"), "")
            self._title = title.strip()
        return self._title
Esempio n. 25
0
        def description(self):
            """String explaining how this subset is to be used."""

            if not hasattr(self, "_description"):
                node = self.__node.find("SubsetDescription")
                self._description = Doc.get_text(node, "")
            return self._description
Esempio n. 26
0
        def value(self):
            """String for the status value (if applicable)."""

            if not hasattr(self, "_value"):
                child = self.__node.find("ProcessingStatusValue")
                self._value = Doc.get_text(child, "").strip()
            return self._value
Esempio n. 27
0
        def method(self):
            """Name of the method used to validate these values."""

            if not hasattr(self, "_method"):
                node = self.__node.find("ParmInfoMethod")
                self._method = Doc.get_text(node)
            return self._method
Esempio n. 28
0
            def caption(self):
                """String to be displayed with the embedded video."""

                if not hasattr(self, "_caption"):
                    node = self.__node.find("Caption")
                    self._caption = Doc.get_text(node, "").strip()
                return self._caption
Esempio n. 29
0
        def date(self):
            """String for the date the status was set (if available)."""

            if not hasattr(self, "_date"):
                child = self.__node.find("ProcessingStatusDate")
                self._date = Doc.get_text(child, "").strip()[:10]
            return self._date
Esempio n. 30
0
    def last_modified(self):
        """When was this drug term document last modified?"""

        if not hasattr(self, "_last_modified"):
            node = self.doc.root.find("DateLastModified")
            self._last_modified = Doc.get_text(node)
        return self._last_modified