def toPDF(self): pdfSet = PDFSettings() pdfSet.pdfDir=self.pdfDir pdfSet.addStyles() cW = pdfSet.cW pdfSet.GCN = self.GCN pdfSet.TCN = self.TCN pdfSet.verNum = self.verNum pdfSet.subDate = self.subDate pdfSet.subTime = self.subTime pdfSet.inFileName = self.inFileName pdfSet.testProd = self.testProd #fileNameBase = pdfSet.pdfDir + os.sep + '277-' + self.TCN fileNameBase = pdfSet.pdfDir + os.sep + '277-' + self.subDateTime fileName = fileNameBase + '.pdf' doc = SimpleDocTemplate(fileName, pagesize=letter, leftMargin=pdfSet.marginSize, rightMargin=pdfSet.marginSize, topMargin=pdfSet.marginSize + pdfSet.lineHeight*2, bottomMargin=pdfSet.marginSize + pdfSet.lineHeight*2) doc.leftPadding = 0 Story = [] stylesheet=getSampleStyleSheet() style1 = stylesheet['Normal'] style1.fontName = pdfSet.regFont style1.fontSize = pdfSet.fontSize style1.borderPadding = 0 #codeStyle.leading = 8 style2 = copy.copy(style1) style2.firstLineIndent = -15 style2.leftIndent = 20 style3 = copy.copy(style1) style3.fontName = pdfSet.boldFont tmpPara = "Payor: %s [%s] - Received %s, processed %s" % (self.payor.Name, self.payor.ID, self.date837Rec, self.date837Rec) Story.append(Paragraph(tmpPara, style1)) Story.append(Spacer(1,pdfSet.lineHeight*.5)) tmpPara = "Submitter: %s [%s] %s - %s" % (self.submitter.Name, self.submitter.ID, self.submitter.amount, self.submitter.action) Story.append(Paragraph(tmpPara, style1)) if len(self.submitter.amtString) > 1: Story.append(Paragraph(self.submitter.amtString, style1)) tmpPara = self.submitter.qtyString + ' - Status code: ' + self.submitter.statusCode Story.append(Paragraph(tmpPara, style1)) Story.append(Spacer(1,pdfSet.lineHeight*.5)) for billProv in self.bP: #bpSection = [] tmpPara = "Billing Provider: %s [%s] %s - %s" % (billProv.Name, billProv.ID, billProv.amount, billProv.action) Story.append(Paragraph(tmpPara, style1)) if len(billProv.amtString) > 1: Story.append(Paragraph(billProv.amtString, style1)) tmpPara = billProv.qtyString + ' - Status code: ' + billProv.statusCode Story.append(Paragraph(tmpPara, style1)) #bpSec.append(Spacer(1,pdfSet.lineHeight*.5)) if len(billProv.claim) > 0: statWidths = [26*cW, 18*cW, 9*cW, 8*cW, 8*cW, 5*cW, 3*cW, 9*cW, 18*cW, 9*cW] statStyle = TableStyle([('VALIGN', (0,0), (-1,-1), 'TOP'), ('ALIGN', (0,0), (-1,-1), 'LEFT'), ('FONT', (0,0), (-1,-1), pdfSet.regFont, pdfSet.fontSize), ('BOTTOMPADDING',(0,0),(-1,-1),pdfSet.pad), ('TOPPADDING', (0,0),(-1,-1),pdfSet.pad), ('RIGHTPADDING', (0,0),(-1,-1),pdfSet.pad), ('LEFTPADDING', (0,0),(-1,-1),pdfSet.pad), ('LINEBELOW', (0,1), (-1,1), 1, (0,0,0,1))]) statStyle.add('ALIGN', (4,0), (4,-1), 'DECIMAL') errStyle = copy.copy(statStyle) errStyle.add('FONT', (0,0), (-1,-1), pdfSet.regFont, pdfSet.fontSize) statLines = [(None, None, None, None, None, None, None, None, 'Status codes', None), ("Patient", "Claim Number", None, None, None, None, None, "Action", 'Cat. Code Source', None)] for clm in billProv.claim: for clmLine in clm.line: if clmLine.action == 'Accept': statLines.append([clmLine.Name, clmLine.ID, clmLine.date1, clmLine.date2, clmLine.amount, None, None, clmLine.action, clmLine.statusCode, None]) else: statLines.append([clmLine.Name, clmLine.ID, clmLine.date1, clmLine.date2, clmLine.amount, None, '**', clmLine.action, clmLine.statusCode, '**']) tbl = Table(statLines, colWidths=statWidths, rowHeights=None, style=statStyle) tbl.hAlign = 'LEFT' tbl.leftPadding = 0 Story.append(tbl) Story.append(Spacer(1,pdfSet.lineHeight*2)) #Story.append(KeepTogether(bpSection)) glossary = [] glossary.append(Paragraph("GLOSSARY: Code categories, status codes, and entities", style3)) for gloss in (self.catGlossary, self.codeGlossary, self.srcGlossary): if len(gloss) > 0: for code, message in gloss.iteritems(): tmpPara = "%s: %s " % (code, message) glossary.append(Paragraph(tmpPara, style2)) Story.append(KeepTogether(glossary)) attempt = 1 while attempt > 0: #avoid blowing up due to duplicate filename try: open(fileName, 'wb') doc.build(Story, onFirstPage=pdfSet.firstPage, onLaterPages=pdfSet.laterPages) attempt = 0 except IOError: doc.filename = fileName = '%s(%s).pdf' % (fileNameBase, attempt) attempt += 1 os.startfile(fileName)