def filter_ids(self): """Sequence of filter ID integers for this set.""" if not hasattr(self, "_filter_ids"): members = self.__set.members self._filter_ids = [Doc.extract_id(m.id) for m in members] return self._filter_ids
def document(self): """`Document` object for the subject of the report.""" if not hasattr(self, "_document"): self._document = None doc_id = self.fields.getvalue(DOCID) if doc_id: try: int_id = Doc.extract_id(doc_id) self._document = Document(self, int_id) except Exception as e: self.bail("Not a valid document ID") else: fragment = self.fields.getvalue("DocTitle", "").strip() if fragment: fragment = f"{fragment}%" fields = "d.id", "d.title", "t.name" query = self.Query("document d", *fields).order(2) query.join("doc_type t", "t.id = d.doc_type") query.where(query.Condition("title", fragment, "LIKE")) rows = query.execute(self.cursor).fetchall() if not rows: self.bail("No matching documents found") elif len(rows) > 1: self.populate_form(self.form_page, rows) self.form_page.send() else: self._document = Document(self, rows[0][0]) return self._document
def citations(self): """Dictionary of the citations used by the summary document. The key is the citation text combined with the Pubmed ID, so any variants in the citation text for the same article will be reflected in the report. """ if not hasattr(self, "_citations"): self._citations = {} for node in self.root.iter("ReferenceList"): for child in node.findall("Citation"): citation = Citation(self.control, child) if citation.key and citation.key not in self._citations: self._citations[citation.key] = citation # Recurse if appropriate, rolling citations from linked modules # into this dictionary. if self.control.modules: for node in self.root.iter("SummaryModuleLink"): cdr_ref = node.get(f"{{{Doc.NS}}}ref") if cdr_ref: try: id = Doc.extract_id(cdr_ref) except Exception: self.control.bail("bad module link %s", cdr_ref) if id not in self.control.parsed: summary = Summary(self.control, id) for key in summary.citations: if key not in self._citations: citation = summary.citations[key] self._citations[key] = citation return self._citations
def name_id(self): """CDR ID for a GlossaryTermName document.""" if not hasattr(self, "_name_id"): self._name_id = self.fields.getvalue("name_id") if self._name_id: self._name_id = Doc.extract_id(self._name_id) return self._name_id
def id(self): """Integer for the image's CDR Media document.""" if not hasattr(self, "_id"): try: self._id = Doc.extract_id(self.__node.get("ref")) except: self._id = None return self._id
def id(self): """Integer for the selected summary's CDR ID.""" if not hasattr(self, "_id"): self._id = self.fields.getvalue("DocId") if self._id: self._id = Doc.extract_id(self._id) elif len(self.titles) == 1: self._id = self.titles[0].id return self._id
def cdr_id(self): """Get the entered/selected CDR ID as an integer""" if not hasattr(self, "_cdr_id"): doc_id = self.fields.getvalue("cdr-id", "").strip() try: self._cdr_id = Doc.extract_id(doc_id) except: self.bail("Invalid format for CDR ID") return self._cdr_id
def ids(self): """Term IDs selected for the report.""" if not hasattr(self, "_ids"): ids = self.fields.getvalue("ids") or "" try: self._ids = [Doc.extract_id(id) for id in ids.split()] except: self.bail(f"Invalid document ID format in {ids}") return self._ids
def board(self): """CDR Organization document integer ID for the PDQ board.""" if not hasattr(self, "_board"): try: ref = self.__node.find("BoardName").get(Control.CDR_REF) self._board = Doc.extract_id(ref) except Exception: self._board = None return self._board
def id(self): """Integer ID of the PDQ summary selected for the report.""" if not hasattr(self, "_id"): self._id = self.fields.getvalue("id") if self._id: try: self._id = Doc.extract_id(self._id) except Exception: self.bail("Invalid document ID") return self._id
def doc_id(self): """CDR ID of document to be checked.""" if not hasattr(self, "_doc_id"): self._doc_id = self.fields.getvalue("cdr-id") if self._doc_id: try: self._doc_id = Doc.extract_id(self._doc_id) except: self.bail("Invalid document ID") return self._doc_id
def cdr_id(self): """Integer for the summary document selected for the report.""" if not hasattr(self, "_cdr_id"): self._cdr_id = self.fields.getvalue("cdr-id") if self._cdr_id: try: self._cdr_id = Doc.extract_id(self._cdr_id) except Exception: self.bail("Invalid format for CDR ID") return self._cdr_id
def recipient(self): """Name of the person who got the mailer.""" if not hasattr(self, "_recipient"): node = self.doc.root.find("Recipient") try: doc_id = Doc.extract_id(node.get(Control.CDR_REF)) self._recipient = self.__control.recipients[doc_id] except Exception: self._recipient = None return self._recipient
def docs(self): """Sequence of document ID for the docs to be republished.""" if not hasattr(self, "_docs"): try: docs = self.fields.getvalue("docs", "").split() self._docs = [Doc.extract_id(doc) for doc in docs] except Exception: self.logger.exception("failure parsing IDs") self.bail("invalid document IDs") return self._docs
def summary(self): """Document title of the PDQ summary behind this mailer.""" if not hasattr(self, "_summary"): node = self.doc.root.find("Document") try: doc_id = Doc.extract_id(node.get(Control.CDR_REF)) self._summary = self.__control.summaries[doc_id] except Exception: self._summary = None return self._summary
def cdr_ids(self): """Set of unique CDR ID integers.""" if not hasattr(self, "_cdr_ids"): self._cdr_ids = set() for word in self.fields.getvalue("cdr-id", "").strip().split(): try: self._cdr_ids.add(Doc.extract_id(word)) except: self.bail("Invalid format for CDR ID") return self._cdr_ids
def text(self): """Text to be displayed above the image.""" if not hasattr(self, "_text"): node = self.node.find("MediaID") self._text = Doc.get_text(node, "").strip() if not hasattr(self, "_id"): try: self._id = Doc.extract_id(node.get(self.CDR_REF)) except: self._id = None return self._text
def id(self): """CDR ID for the video's Media document.""" if not hasattr(self, "_id"): node = self.node.find("VideoID") self._id = None if node is not None: try: self._id = Doc.extract_id(node.get(f"{{{Doc.NS}}}ref")) except: pass return self._id
def id(self): """CDR ID for the image document.""" if not hasattr(self, "_id"): node = self.node.find("MediaID") try: self._id = Doc.extract_id(node.get(f"{{{Doc.NS}}}ref")) except: self._id = None if not hasattr(self, "_text"): self._text = Doc.get_text(node, "").strip() return self._id
def target_id(self): """Integer for the CDR ID of the report's link target.""" if not hasattr(self, "_target_id"): self._target_id = None if self.doc_id: try: self._target_id = Doc.extract_id(self.doc_id) except: self.bail("invalid document ID format") elif len(self.titles) == 1: self._target_id = self.titles[0].id return self._target_id
def id(self): """Document ID for the report.""" if not hasattr(self, "_id"): self._id = self.fields.getvalue("DocId") if self._id: try: self._id = Doc.extract_id(self._id) except: self.bail("Invalid ID") elif self.summaries and len(self.summaries) == 1: self._id = self.summaries[0][0] return self._id
def media_id(self): """Media ID if we already have audio for this name.""" if not hasattr(self, "_media_id"): self._media_id = None node = self.node.find("MediaLink/MediaID") if node is not None: value = node.get(f"{{{Doc.NS}}}ref") try: self._media_id = Doc.extract_id(value) except Exception: pass return self._media_id
def id(self): """Integer for the document to be displayed.""" if not hasattr(self, "_id"): self._id = self.fields.getvalue("doc-id") if self._id: try: self._id = Doc.extract_id(self._id) except Exception: self.bail("invalid document ID format") elif len(self.titles) == 1: self._id = self.titles[0].value return self._id
def ids(self): """CDR IDs of documents which are to be marked as deleted.""" if not hasattr(self, "_ids"): self._ids = [] ids = self.fields.getvalue("ids") if ids: for id in ids.split(): try: self._ids.append(Doc.extract_id(id)) except: self.bail("Invalid document ID") return self._ids
def id(self): """Integer for the PDQ Citation document's unique CDR ID.""" if not hasattr(self, "_id"): self._id = None ref = self.__node.get(f"{{{Doc.NS}}}ref") if ref: try: self._id = Doc.extract_id(ref) except Exception: message = "In %s: bad citation reference %r" args = self.summary.doc.cdr_id, ref self.control.logger.exception(message, *args) return self._id
def diagnoses(self): """List of diagnosis string link to this Media document.""" if not hasattr(self, "_diagnoses"): self._diagnoses = [] path = "MediaContent/Diagnoses/Diagnosis" for node in self.doc.root.findall(path): ref = node.get(f"{{{Doc.NS}}}ref") try: id = Doc.extract_id(ref) self._diagnoses.append(self.control.diagnoses[id]) except: self._diagnoses.append(f"INVALID DIAGNOSIS ID {ref}") return self._diagnoses
def board_id(self): """Integer for the board's CDR Organization ID.""" if not hasattr(self, "_board_id"): self._board_id = None node = self.__node.find("BoardName") if node is not None: ref = node.get(f"{{{Doc.NS}}}ref") if ref: try: self._board_id = Doc.extract_id(ref) except: self.__control.logger.exception("board ID") return self._board_id
def filter_id(self): """Integer for the ID of a CDR Filter document.""" if not hasattr(self, "_filter_id"): self._filter_id = None if self.filter_name: key = self.filter_name.upper() self._filter_id = self.control.all_filters[key] elif not self.set_name: try: self._filter_id = Doc.extract_id(self.identifier) except Exception: id = self.identifier self.control.bail(f"{id!r} is not a well-formed CDR ID") return self._filter_id
def media_link_ids(self): """MediaLink IDs for the images of a summary. Extracting the MediaID (ref) attribute and converting the ID to an integer """ if not hasattr(self, "_media_link_ids"): self._media_link_ids = Doc.get_text(self.doc.root.find("MediaID")) media_doc_ids = self.doc.root.findall(".//MediaLink/MediaID") self._media_link_ids = [] for media_doc in media_doc_ids: self._media_link_ids.append( Doc.extract_id(media_doc.values()[0])) return self._media_link_ids
def id(self): """ID for term we'll use as our starting location in the hierarchy.""" if not hasattr(self, "_id"): self._id = None value = self.fields.getvalue("DocId") if value: try: self._id = Doc.extract_id(value) except Exception as e: self.bail(f"invalid id {value!r}") if not self._id and self.terms: if len(self.terms) == 1: self._id = self.terms[0][0] return self._id