Make a separate list for discharge doctor ad general medicine unit E

Reading File
Reading File
Browsing Directory

~/

Reading File
Browsing Directory

~/attachments/e302307a-bb0e-4d0e-b3ae-bec90965ffa5

Running Command

python - <<'PY' from openpyxl import load_workbook p='/tmp/workspace/attachments/e302307a-bb0e-4d0e-b3ae-bec90965ffa5/Mortality_Death_Report_September_2026_Unit_E.xlsx' wb=load_workbook(p, data_only=False) print(wb.sheetnames) for ws in wb.worksheets: print('\nSHEET',ws.title,ws.max_row,ws.max_column) for row in ws.iter_rows(min_row=1,max_row=min(ws.max_row,12),values_only=True): print(row) PY

Running Command

python - <<'PY' from openpyxl import load_workbook p='/tmp/workspace/attachments/e302307a-bb0e-4d0e-b3ae-bec90965ffa5/Mortality_Death_Report_September_2026_Unit_E.xlsx' wb=load_workbook(p, data_only=False) ws=wb['Mortality Death Report Sep 2026'] headers=[c.value for c in ws[2]] for i,h in enumerate(headers,1): print(i,repr(h)) matched=[] for r in range(3,ws.max_row+1): d=ws.cell(r,14).value; s=ws.cell(r,15).value if isinstance(d,str) and d.strip().upper()=='UNIT E (GENERAL MEDICINE)' and isinstance(s,str) and s.strip().upper()=='GENERAL MEDICINE': matched.append(r) print('matched',len(matched),'source rows',matched) print('existing records',sum(1 for r in range(3,wb['General Medicine Unit E'].max_row+1) if wb['General Medicine Unit E'].cell(r,1).value is not None)) PY

Running Command

python - <<'PY' from openpyxl import load_workbook from copy import copy from pathlib import Path src=Path('/tmp/workspace/attachments/e302307a-bb0e-4d0e-b3ae-bec90965ffa5/Mortality_Death_Report_September_2026_Unit_E.xlsx') outdir=Path('/tmp/workspace/discharge-doctor-unit-e/output') outdir.mkdir(parents=True,exist_ok=True) out=outdir/'Discharge_Doctor_General_Medicine_Unit_E_September_2026.xlsx' wb=load_workbook(src) source=wb['Mortality Death Report Sep 2026'] # Reuse the existing filtered sheet as output, replace its records from source to ensure filter logic is exact. if 'General Medicine Unit E' in wb.sheetnames: target=wb['General Medicine Unit E'] else: target=wb.create_sheet('General Medicine Unit E') # Clear existing rows below header to avoid stale entries for row in target.iter_rows(min_row=3, max_row=target.max_row, min_col=1, max_col=target.max_column): for cell in row: cell.value=None cell._style=copy(source.cell(3, cell.column)._style) if source.max_row>=3 else copy(cell._style) cell.comment=None cell.hyperlink=None # Match source formatting for title/header rows and layout for r in range(1,3): for c in range(1,source.max_column+1): sc=source.cell(r,c); tc=target.cell(r,c) tc.value=sc.value if sc.has_style: tc._style=copy(sc._style) if sc.number_format: tc.number_format=sc.number_format if sc.alignment: tc.alignment=copy(sc.alignment) if sc.font: tc.font=copy(sc.font) if sc.fill: tc.fill=copy(sc.fill) if sc.border: tc.border=copy(sc.border) for c in range(1,source.max_column+1): letter=source.cell(1,c).column_letter target.column_dimensions[letter].width=source.column_dimensions[letter].width for r in range(1,source.max_row+1): if source.row_dimensions[r].height: target.row_dimensions[r].height=source.row_dimensions[r].height # Retitle and define only matching discharge physician entries. target['A1']='Mortality Death Report September 2026 - Discharge Doctor: Unit E (General Medicine)' # Existing merged range A1:Z1 is retained. matched=[] for r in range(3,source.max_row+1): discharge=source.cell(r,14).value specialty=source.cell(r,15).value if (isinstance(discharge,str) and discharge.strip().upper()=='UNIT E (GENERAL MEDICINE)' and isinstance(specialty,str) and specialty.strip().upper()=='GENERAL MEDICINE'): matched.append(r) for out_r,src_r in enumerate(matched,start=3): for c in range(1,source.max_column+1): sc=source.cell(src_r,c); tc=target.cell(out_r,c) tc.value=sc.value if sc.has_style: tc._style=copy(sc._style) if sc.number_format: tc.number_format=sc.number_format if sc.alignment: tc.alignment=copy(sc.alignment) if sc.font: tc.font=copy(sc.font) if sc.fill: tc.fill=copy(sc.fill) if sc.border: tc.border=copy(sc.border) target.row_dimensions[out_r].height=source.row_dimensions[src_r].height # Remove all non-list sheets and rename final sheet clearly. for name in list(wb.sheetnames): if name != target.title: del wb[name] target.title='Discharge Dr Unit E' target.freeze_panes='A3' target.auto_filter.ref=f'A2:T{len(matched)+2}' target.sheet_view.showGridLines=False # Print configuration for c in range(1,21): target.cell(2,c).font=copy(target.cell(2,c).font) wb.save(out) print(f'Saved: {out}') print(f'Records: {len(matched)}') print('IP numbers:', [source.cell(r,2).value for r in matched]) PY python - <<'PY' from openpyxl import load_workbook p='/tmp/workspace/discharge-doctor-unit-e/output/Discharge_Doctor_General_Medicine_Unit_E_September_2026.xlsx' wb=load_workbook(p,data_only=False) ws=wb['Discharge Dr Unit E'] records=[r for r in range(3,ws.max_row+1) if ws.cell(r,1).value is not None] print(wb.sheetnames, ws.max_row, len(records), ws['A1'].value) print([(ws.cell(r,1).value,ws.cell(r,2).value,ws.cell(r,14).value,ws.cell(r,15).value) for r in records]) PY

Running Command

python - <<'PY' from openpyxl import load_workbook from pathlib import Path src=Path('/tmp/workspace/attachments/e302307a-bb0e-4d0e-b3ae-bec90965ffa5/Mortality_Death_Report_September_2026_Unit_E.xlsx') outdir=Path('/tmp/workspace/discharge-doctor-unit-e/output') outdir.mkdir(parents=True,exist_ok=True) out=outdir/'Discharge_Doctor_General_Medicine_Unit_E_September_2026.xlsx' wb=load_workbook(src) ws=wb['General Medicine Unit E'] # Verify records meet the requested discharge-doctor and specialty criteria. records=[] for r in range(3, ws.max_row+1): if ws.cell(r,1).value is not None: doctor=str(ws.cell(r,14).value or '').strip().upper() speciality=str(ws.cell(r,15).value or '').strip().upper() if doctor!='UNIT E (GENERAL MEDICINE)' or speciality!='GENERAL MEDICINE': raise ValueError(f'Unexpected record at row {r}: {doctor} / {speciality}') records.append(r) if not records: raise ValueError('No matching records found') # Preserve the existing filtered list and source formatting, retain this one output worksheet only. ws['A1']='Mortality Death Report September 2026 - Discharge Doctor: Unit E (General Medicine)' ws.title='Discharge Dr Unit E' ws.freeze_panes='A3' ws.auto_filter.ref=f'A2:T{records[-1]}' ws.sheet_view.showGridLines=False for name in list(wb.sheetnames): if name != ws.title: del wb[name] wb.save(out) print(out) print('records',len(records)) PY python - <<'PY' from openpyxl import load_workbook p='/tmp/workspace/discharge-doctor-unit-e/output/Discharge_Doctor_General_Medicine_Unit_E_September_2026.xlsx' wb=load_workbook(p,data_only=False) ws=wb['Discharge Dr Unit E'] rows=[r for r in range(3,ws.max_row+1) if ws.cell(r,1).value is not None] assert len(wb.sheetnames)==1 assert len(rows)==20 assert all(str(ws.cell(r,14).value).strip().upper()=='UNIT E (GENERAL MEDICINE)' and str(ws.cell(r,15).value).strip().upper()=='GENERAL MEDICINE' for r in rows) print('verified sheets=',wb.sheetnames,'records=',len(rows),'title=',ws['A1'].value) PY

Created a separate workbook containing the 20 records where the discharge doctor is UNIT E (GENERAL MEDICINE) and specialty is GENERAL MEDICINE.

Make a printable PDF version of this list

Reading File
Reading File
Browsing Directory

~/

Browsing Directory

~/discharge-doctor-unit-e

Running Command

mkdir -p "/tmp/workspace/discharge-doctor-unit-e/pdf" && python - <<'PY' from openpyxl import load_workbook from reportlab.lib import colors from reportlab.lib.enums import TA_CENTER, TA_LEFT from reportlab.lib.pagesizes import A3, landscape from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet from reportlab.lib.units import mm from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer, KeepTogether from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont from reportlab.lib.colors import HexColor from pypdf import PdfReader from pathlib import Path from datetime import datetime, time import re xlsx=Path('/tmp/workspace/discharge-doctor-unit-e/output/Discharge_Doctor_General_Medicine_Unit_E_September_2026.xlsx') out=Path('/tmp/workspace/discharge-doctor-unit-e/pdf/Discharge_Doctor_General_Medicine_Unit_E_September_2026.pdf') wb=load_workbook(xlsx, data_only=True) ws=wb['Discharge Dr Unit E'] # Input integrity check rows=[] for r in range(3, ws.max_row+1): if ws.cell(r,1).value is not None: if str(ws.cell(r,14).value or '').strip().upper()!='UNIT E (GENERAL MEDICINE)' or str(ws.cell(r,15).value or '').strip().upper()!='GENERAL MEDICINE': raise ValueError(f'Row {r} does not meet requested filter') rows.append([ws.cell(r,c).value for c in range(1,21)]) assert len(rows)==20 def clean(v): if v is None: return '' if isinstance(v, datetime): return v.strftime('%d-%b-%Y') if isinstance(v, time): return v.strftime('%H:%M') s=str(v).replace('\u200b','').replace('\r',' ').replace('\n','<br/>') s=re.sub(r' +',' ',s).strip() return s def date_time(d,t): ds=clean(d); ts=clean(t) # Source includes malformed placeholders in some records. Preserve usable values but avoid dated Excel zero display. bad={'30 Dec 1899','00:00'} if ds in bad: ds='' if ts in bad: ts='' return '<br/>'.join([x for x in [ds,ts] if x]) page=landscape(A3) styles=getSampleStyleSheet() title_style=ParagraphStyle('Title', parent=styles['Title'], fontName='Helvetica-Bold', fontSize=15, leading=18, alignment=TA_CENTER, textColor=HexColor('#17365D'), spaceAfter=2) subtitle_style=ParagraphStyle('Sub', parent=styles['Normal'], fontName='Helvetica', fontSize=8.5, leading=10, alignment=TA_CENTER, textColor=HexColor('#444444'), spaceAfter=7) head_style=ParagraphStyle('Head', parent=styles['Normal'], fontName='Helvetica-Bold', fontSize=5.9, leading=6.8, alignment=TA_CENTER, textColor=colors.white) cell_style=ParagraphStyle('Cell', parent=styles['Normal'], fontName='Helvetica', fontSize=5.5, leading=6.4, alignment=TA_LEFT) center_style=ParagraphStyle('Center', parent=cell_style, alignment=TA_CENTER) headers=['Sr.', 'IP No.', 'MRN', 'Patient name', 'Admission\ndate/time', 'Age', 'Sex', 'Death\ndate/time', 'LOS', 'Admitting doctor', 'Discharge doctor', 'Bed no.', 'Cause of death', 'Procedure / surgery', 'Payor', 'MLC'] # A3 landscape printable width 1152pt. Table width 1119pt, leaves 33pt within 18pt margins. widths=[20,65,62,85,65,40,35,65,25,65,70,55,250,140,47,35] data=[[Paragraph(h.replace('\n','<br/>'),head_style) for h in headers]] for v in rows: vals=[v[0],v[1],v[2],v[3],date_time(v[4],v[5]),v[6],v[7],date_time(v[8],v[9]),v[10],v[11],v[13],v[15],v[16],v[17],v[18],v[19]] line=[] for i, val in enumerate(vals): st=center_style if i in {0,1,2,4,5,6,7,8,11,14,15} else cell_style line.append(Paragraph(clean(val),st)) data.append(line) def footer(canvas, doc): canvas.saveState() canvas.setFont('Helvetica', 7) canvas.setFillColor(HexColor('#555555')) canvas.drawString(doc.leftMargin, 12*mm, 'Mortality Death Report - September 2026 | Discharge Doctor: Unit E (General Medicine)') canvas.drawRightString(page[0]-doc.rightMargin, 12*mm, f'Page {doc.page}') canvas.restoreState() doc=SimpleDocTemplate(str(out),pagesize=page,rightMargin=18, leftMargin=18,topMargin=18*mm,bottomMargin=20*mm,title='Discharge Doctor Unit E - September 2026') table=Table(data,colWidths=widths,repeatRows=1,splitByRow=1,hAlign='CENTER') table.setStyle(TableStyle([ ('BACKGROUND',(0,0),(-1,0),HexColor('#1F4E78')), ('TEXTCOLOR',(0,0),(-1,0),colors.white), ('GRID',(0,0),(-1,-1),0.25,HexColor('#A6A6A6')), ('VALIGN',(0,0),(-1,-1),'TOP'), ('LEFTPADDING',(0,0),(-1,-1),2.2),('RIGHTPADDING',(0,0),(-1,-1),2.2), ('TOPPADDING',(0,0),(-1,-1),2.5),('BOTTOMPADDING',(0,0),(-1,-1),2.5), ('ROWBACKGROUNDS',(0,1),(-1,-1),[colors.white,HexColor('#EAF2F8')]), ])) story=[Paragraph('Mortality Death Report - September 2026',title_style),Paragraph('Separate list by discharge doctor: Unit E (General Medicine) | 20 records',subtitle_style),table] doc.build(story,onFirstPage=footer,onLaterPages=footer) reader=PdfReader(str(out)) text='\n'.join(p.extract_text() or '' for p in reader.pages) assert len(reader.pages)>=1 and 'UNIT E (GENERAL MEDICINE)' in text and 'KANTABEN' in text print(f'Created {out} | pages={len(reader.pages)} | records={len(rows)} | bytes={out.stat().st_size}') PY

Browsing Directory

~/discharge-doctor-unit-e/pdf

Running Command

python - <<'PY' from pypdf import PdfReader p='/tmp/workspace/discharge-doctor-unit-e/pdf/Discharge_Doctor_General_Medicine_Unit_E_September_2026.pdf' r=PdfReader(p) print('pages',len(r.pages)) for i,page in enumerate(r.pages): print('PAGE',i+1,(page.extract_text() or '')[:1000]) PY

Printable A3 landscape PDF created, with repeating headers and page numbers across 2 pages.

Discharge Doctor General Medicine Unit E September 2026

PDF Document · PDF

This is a shared conversation. Sign in to Orris to start your own chat.