Example #1
0
 def _getTableRows(self, fileManData, fileNo, fieldsList):
     rows = []
     for ien in getKeys(fileManData.dataEntries, float):
         row = [""] * len(fieldsList)
         row[0] = ien
         dataEntry = fileManData.dataEntries[ien]
         name = dataEntry.name
         if isFilePointerType(dataEntry):
             link, name = convertFilePointerToHtml(name)
         if "datetime.datetime" in str(type(name)):
             name = str(name)
         if name is None:
             name = str(name)
         dataHtmlLink = "<a href=\"%s/%s/%s\">%s</a>" % (
             FILES_URL, fileNo.replace(
                 ".", "_"), getDataEntryHtmlFileName(ien, fileNo), name)
         for fldId in dataEntry.fields:
             dataField = dataEntry.fields[fldId]
             # Use index of field name to place data correctly in row
             if fldId == '.01':
                 row[fieldsList.index(dataField.name)] = dataHtmlLink
             else:
                 row[fieldsList.index(
                     dataField.name)] = self._dataFieldToHtml(
                         dataField,
                         False,
                         dataField.name,
                         writeLabels=False)
         rows.append(row)
     return rows
Example #2
0
 def _parseDataBySchema(self, dataRoot, fileSchema, outGlbData):
   """ first sort the schema Root by location """
   locFieldDict = sortSchemaByLocation(fileSchema)
   # for each data entry, parse data by location
   floatKey = getKeys(dataRoot, float)
   for ien in floatKey:
     if float(ien) <=0:
       continue
     dataEntry = dataRoot[ien]
     outDataEntry = FileManDataEntry(fileSchema.getFileNo(), ien)
     dataKeys = [x for x in dataEntry]
     sortedKey = sorted(dataKeys, key=functools.cmp_to_key(sortDataEntryFloatFirst))
     for locKey in sortedKey:
       if locKey == '0' and fileSchema.getFileNo() == '1':
         self._parseFileDetail(dataEntry[locKey], ien)
       if locKey in locFieldDict:
         fieldDict = locFieldDict[locKey] # a dict of {pos: field}
         curDataRoot = dataEntry[locKey]
         if len(fieldDict) == 1:
           fieldAttr = listvalues(fieldDict)[0]
           if fieldAttr.isSubFilePointerType(): # Multiple
             self._parseSubFileField(curDataRoot, fieldAttr, outDataEntry)
           else:
             self._parseSingleDataValueField(curDataRoot, fieldAttr,
                                             outDataEntry)
         else:
           self._parseDataValueField(curDataRoot, fieldDict, outDataEntry)
     outGlbData.addFileManDataEntry(ien, outDataEntry)
     if fileSchema.getFileNo() == self._curFileNo:
       self._addFileKeyIndex(self._curFileNo, ien, outDataEntry.name)
Example #3
0
 def _parseSubFilesNode(self, rootNode, fileNo):
     """ Get the subFiles used in the file """
     for key in getKeys(rootNode['SB'], float):
         assert key in self._allSchema
         assert self._allSchema[key].isSubFile()
         assert self._allSchema[key].getParentFile().getFileNo() == fileNo
         self._subFiles.add(key)
Example #4
0
 def _getKeyNameBySchema(self, dataRoot, keyLoc, keyField):
     floatKey = getKeys(dataRoot, float)
     for ien in floatKey:
         if float(ien) <= 0:
             continue
         dataEntry = dataRoot[ien]
         index, loc = keyLoc.split(';')
         if not index or index not in dataEntry:
             continue
         dataEntry = dataEntry[index]
         if not dataEntry.value:
             return (ien, None)
         values = dataEntry.value.split('^')
         dataValue = None
         if convertToType(loc, int):
             intLoc = int(loc)
             if intLoc > 0 and intLoc <= len(values):
                 dataValue = values[intLoc - 1]
         else:
             dataValue = str(dataEntry.value)
         if dataValue:
             return (ien,
                     self._parseIndividualFieldDetail(
                         dataValue, keyField, None))
     return (None, None)
Example #5
0
 def _convertFileManSubFileDataToHtml(self, fileManData, parentName):
     retval = "<ul>\n"
     for ien in getKeys(fileManData.dataEntries, float):
         dataEntry = fileManData.dataEntries[ien]
         retval += self._fileManDataEntryToHtml(dataEntry, False,
                                                parentName)
     retval += "</ul>\n"
     return retval
Example #6
0
def parsingVariablePointer(vpRoot):
    intKey = getKeys(vpRoot)
    outVptr = []
    for key in intKey:
        if '0' in vpRoot[key]:
            value = vpRoot[key]['0'].value
            if value:
                value = value.split('^')[0]
                outVptr.append(value)
    return outVptr
Example #7
0
 def parseSchemaDDFileV2(self, inputDDZWRFile):
     for ddRoot in readGlobalNodeFromZWRFileV2(inputDDZWRFile, '^DD'):
         files = getKeys(ddRoot, float)  # sort files by float value
         for file in files:
             if file not in self._allSchema:
                 self._allSchema[file] = Global("", file, "")
             self._generateFileSchema(ddRoot[file], self._allSchema[file])
     self._updateMultiple()
     self._sccSet = self._generateSCCSet()
     return self._allSchema
Example #8
0
 def _generateFileSchema(self, rootNode, fileSchema):
     """
   handle the "PT" and "SB" subscript first
 """
     for key in getKeys(rootNode, float):
         if key == '0':
             continue  # ignore the fields 0
         field = self._parseSchemaField(key, rootNode[key], fileSchema)
         if field:
             fileSchema.addFileManField(field)
     if 'SB' in rootNode:
         self._parseSubFilesNode(rootNode, fileSchema.getFileNo())
Example #9
0
 def _convertFileManDataToHtml(self, fileManData):
     fileManDataFileNo = fileManData.fileNo
     pathSafeFileManDataFileNo = fileManDataFileNo.replace(".", "_")
     for ien in getKeys(fileManData.dataEntries, float):
         dataEntry = fileManData.dataEntries[ien]
         name = dataEntry.name
         if not name:
             continue
         outDir = self.outDir
         fileNo = dataEntry.fileNo
         if fileNo:
             outDir = os.path.join(self.outDir, fileNo.replace(".", "_"))
         tName = safeElementId("%s-%s" % (pathSafeFileManDataFileNo, ien))
         if isFilePointerType(dataEntry):
             link, name = convertFilePointerToHtml(name)
         outHtmlFileName = getDataEntryHtmlFileName(ien, fileManDataFileNo)
         with open(os.path.join(outDir, outHtmlFileName), 'w') as output:
             output.write("<html>")
             outputDataRecordTableHeader(output, tName)
             output.write("<body id=\"dt_example\">")
             output.write(
                 "<a class=\"brand\" href=\"%s\" style=\"height:50px; padding: 0px;\"> \
                 <img src=\"https://osehra.org/sites/default/files/vivian.png\" width=\"137\" height=\"50\"/></a>"
                 % VIV_URL)
             output.write("""<div id="container" style="width:80%">""")
             output.write("<h1>%s (%s) &nbsp;&nbsp;  %s (%s)</h1>\n" %
                          (name, ien, fileManData.name, fileManDataFileNo))
             if fileNo in ['19', '101']:
                 # Todo: Check if the object exists in options/menus first.
                 output.write(
                     "<a style='font-size: 15px;' href='%s/vista_menus.php#%s?name=%s'>View in ViViaN Menu</a>"
                     % (VIV_URL, fileNo, urllib.parse.quote_plus(name)))
             outputFileEntryTableList(output, tName)
             # table body
             output.write("<tbody>\n")
             output.write(
                 self._fileManDataEntryToHtml(dataEntry, True, None))
             output.write("</tbody>\n")
             output.write("</table>\n")
             output.write("</div>\n")
             output.write("</div>\n")
             output.write("</body></html>")
Example #10
0
    def outputFileManDataAsHtml(self, fileNo, gblDataParser):
        """
      This is the entry pointer to generate Html output
      format based on FileMan Data object
      @TODO: integrate with FileManFileOutputFormat.py
    """
        crossRef = self.crossRef
        fileManDataMap = gblDataParser.outFileManData
        self.dataMap = gblDataParser
        fileManData = fileManDataMap[fileNo]
        fileNoPathSafe = fileNo.replace('.', '_')
        fileNoOutDir = os.path.join(self.outDir, fileNoPathSafe)
        if not os.path.exists(fileNoOutDir):
            os.mkdir(fileNoOutDir)
        if fileNo == '8994':
            if crossRef:
                allPackages = crossRef.getAllPackages()
                allRpcs = []
                for package in itervalues(allPackages):
                    if package.rpcs:
                        self._generateRPCListHtml(package.rpcs,
                                                  package.getName(),
                                                  fileNoOutDir)
                        allRpcs.extend(package.rpcs)
                if allRpcs:
                    self._generateRPCListHtml(allRpcs, "All", fileNoOutDir)
        elif fileNo == '101':
            menuOutDir = os.path.join(self.outDir, "menus", "101")
            if not os.path.exists(menuOutDir):
                os.makedirs(menuOutDir)
            allProtoMenuList = []
            if crossRef:
                allPackages = crossRef.getAllPackages()
                allHl7s = []
                allProtocols = []
                for ien in getKeys(fileManData.dataEntries, float):
                    dataEntry = fileManData.dataEntries[ien]
                    allProtocols.append(dataEntry)
                    fields = dataEntry.fields
                    if '4' in fields:
                        if fields['4'].value == 'menu':
                            allProtoMenuList.append(dataEntry)
                for package in itervalues(allPackages):
                    if package.hl7:
                        self._generateHL7ListByPackage(package.hl7,
                                                       package.getName(),
                                                       fileNoOutDir)
                        allHl7s.extend(package.hl7)
                    if package.protocol:
                        self._generateProtocolListByPackage(
                            package.protocol, package.getName(), fileNoOutDir)
                if allHl7s:
                    self._generateHL7ListByPackage(allHl7s, "All",
                                                   fileNoOutDir)
                if allProtocols:
                    self._generateProtocolListByPackage(
                        allProtocols, "All", fileNoOutDir)
            self._generateMenuDependency(allProtoMenuList, allProtocols,
                                         menuOutDir)
        elif fileNo == '779.2':
            if crossRef:
                allPackages = crossRef.getAllPackages()
                allHLOs = []
                for package in itervalues(allPackages):
                    if package.hlo:
                        self._generateHLOListByPackage(package.hlo,
                                                       package.getName(),
                                                       gblDataParser,
                                                       fileNoOutDir)
                        allHLOs.extend(package.hlo)
                if allHLOs:
                    self._generateHLOListByPackage(allHLOs, "All",
                                                   gblDataParser, fileNoOutDir)
        elif fileNo == '19':
            allOptionList = []
            allMenuList = []
            serverMenuList = []
            outJSON = {}
            menuOutDir = os.path.join(self.outDir, "menus", "19")
            if not os.path.exists(menuOutDir):
                os.makedirs(menuOutDir)
            for ien in getKeys(fileManData.dataEntries, float):
                dataEntry = fileManData.dataEntries[ien]
                allOptionList.append(dataEntry)
                fields = dataEntry.fields
                if '4' in fields:
                    if fields['4'].value == 'menu':
                        allMenuList.append(dataEntry)
                    # Seperate list for the "server" OPTIONS
                    elif fields['4'].value == 'server':
                        serverMenuList.append(dataEntry)
                else:
                    logger.error("ien: %s of file 19 does not have a type" %
                                 ien)

            self._generateDataListByPackage(allOptionList, "All",
                                            option_list_fields, "Option",
                                            [x[0] for x in option_list_fields],
                                            ["Name", "Lock"], fileNoOutDir)
            self._generateDataListByPackage(allMenuList, "All",
                                            menu_list_fields, "menus",
                                            [x[0] for x in menu_list_fields],
                                            ["Name", "Menu Text", "Lock"],
                                            fileNoOutDir)

            self._generateServerMenu(allMenuList, allOptionList,
                                     serverMenuList)
            self._generateMenuDependency(allMenuList, allOptionList,
                                         menuOutDir)

        allObjectsList = []
        outJSON = {}
        for ien in getKeys(fileManData.dataEntries, float):
            dataEntry = fileManData.dataEntries[ien]
            outJSON[ien] = dataEntry.fields
            allObjectsList.append(dataEntry)
        with open(os.path.join(self.outDir, "%s.json" % fileNoPathSafe),
                  'w') as output:
            json.dump(outJSON, output, ensure_ascii=False, cls=OSEHRAEncoder)

        self._generateDataTableHtml(fileManData, fileNo, fileNoOutDir)
        self._convertFileManDataToHtml(fileManData)
Example #11
0
 def _convertFileManSubFileDataToHtml(self, output, fileManData):
     output.write("<ol>\n")
     for ien in getKeys(fileManData.dataEntries, float):
         dataEntry = fileManData.dataEntries[ien]
         self._fileManDataEntryToHtml(output, dataEntry, False)
     output.write("</ol>\n")
Example #12
0
 def _parsingWordProcessingNode(self, dataRoot):
   outLst = []
   for key in getKeys(dataRoot, int):
     if '0' in dataRoot[key]:
       outLst.append("%s" % dataRoot[key]['0'].value)
   return outLst