劉德軍
摘要:該文針對醫(yī)院信息建設(shè)中門診電子病歷的打印格式問題,通過調(diào)用EXCEL,用最簡單方法來快速實現(xiàn)電子病歷的格式化打印功能。
關(guān)鍵詞:c#;EXCEL;電子病歷;打印
中圖分類號:TP311 文獻標(biāo)識碼:A 文章編號:1009-3044(2015)24-0132-02
C# Call EXCEL to Achieve the Electronic Medical Records Of the Printing
LIU De-jun
(Sheyang County People's Hospital Information Branch, Yancheng 224300, China)
Abstract: This paper is aimed at the problem of the electronic medical record in hospital information construction, through calling EXCEL, using the most simple method to achieve the electronic medical records of the format printing function.
Key words: c#; EXCEL; electronic medical record; print
門診病歷是醫(yī)務(wù)人員對門急診患者疾病的發(fā)生、發(fā)展、轉(zhuǎn)歸,進行檢查、診斷、治療等醫(yī)療活動過程的按規(guī)定的格式和要求書寫的記錄。我院門診病歷電子化以后,電子病歷的打印功能的實現(xiàn)勢在必行。
經(jīng)過對《病歷書寫規(guī)范》的認(rèn)真研究,發(fā)現(xiàn)電子病歷打印因多種內(nèi)容、格式混合導(dǎo)致存在如下問題:① 病歷行數(shù)不固定;② 打印位置控制復(fù)雜,有的左對齊,有的右對齊,有的居中;③ 跨頁控制復(fù)雜,可能涉及一段文字中間換頁;④ 字體格式控制;⑤ 如何做好病歷防偽功能。
設(shè)計之初準(zhǔn)備用C#控制處理打印,具體開發(fā)過程中發(fā)現(xiàn)很多問題,特別是頁面控制處理起來相當(dāng)復(fù)雜,而且達不到預(yù)想的效果。因此轉(zhuǎn)變思路,改調(diào)用EXCEL,利用EXCEL的強大編輯和處理功能,解決了上述問題,順利完成了系統(tǒng)的開發(fā)工作。
1 方法簡介
要解決上述問題,必須實現(xiàn)以下幾個功能:
1)按電子病歷格式設(shè)計好EXCEL文件作為模板(包括字體大小、對齊方式、自動換行、頁眉頁腳、頂端標(biāo)題行等);
2)創(chuàng)建一個EXCEL進程,并加載設(shè)計好的模板文件;
3)從系統(tǒng)調(diào)出相關(guān)的病歷信息填寫進對應(yīng)單元格;
4)控制EXCEL打印出填寫的內(nèi)容,完成后關(guān)閉創(chuàng)建的EXCEL進程。
2 程序?qū)崿F(xiàn)
2.1 準(zhǔn)備工作
1)準(zhǔn)備一張具有防偽底紋標(biāo)志的背景圖片,大小根據(jù)病歷紙大小自行設(shè)置。
2)新建一個名為“門診電子病歷模板.xlsx”的EXCEL工作簿,只保留sheet1表。具體格式如表1。
3)創(chuàng)建一個C#Windows窗體應(yīng)用程序。在“解決方案資源管理器”→“引用”右擊→“添加引用”→“.NET”選項卡,選擇組件名稱為“Microsoft.Office.Interop.Excel”,版本號為“12.0.0.0”。
4)在程序命名空間中添加如下內(nèi)容:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Data;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;
2.2 程序主要代碼
public int OmrPrint(string clinicNo,string id)
{ //clinicNo為病員就診號, ID為病歷序號,根據(jù)這兩個參數(shù)查詢門診基本信息
ClinicRecordPrint.OracleLobData queryBase = new OracleLobData();
//根據(jù)病歷ID查詢門診病歷信息
DataSet dsMain = queryBase.DefineDataSet(id);
//根據(jù)掛號流水號查詢診斷信息
DataSet dsDiag = queryBase.GetClinicDiag(clinicNo);
DataSet dsOrder = queryBase.GetClinicOrder(clinicNo);
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();//創(chuàng)建一個Excel進程
app.Visible = false; //不顯示EXCEL界面,顯示可方便調(diào)試
Workbooks wbks = app.Workbooks;
Workbook _wbk = wbks.Add(System.Windows.Forms.Application.StartupPath + @"\門診電子病歷模板.xlsx");//打開電子病歷模板
Worksheet WS1 = (Worksheet)_wbk.Worksheets[1];//設(shè)置當(dāng)前工作表
if (dsMain.Tables[0].Rows.Count > 0)
{//填寫日期、科室、姓名、性別、病歷號、主訴、現(xiàn)病史、既往史、過敏史、體檢、輔助檢查、處理意見,dsMain為患者病歷信息記錄集。
WS1.Cells[2, 1] = "日期:" + dsMain.Tables[0].Rows[0]["保存日期"].ToString() + " " + "科室:" + dsMain.Tables[0].Rows[0]["???].ToString() + " " + "姓名:" + dsMain.Tables[0].Rows[0]["姓名"].ToString() + " " + "性別:" + dsMain.Tables[0].Rows[0]["性別"].ToString() + " " + "病歷號:" + dsMain.Tables[0].Rows[0]["門診號"].ToString();
WS1.Cells[3, 2] = dsMain.Tables[0].Rows[0]["主訴"].ToString();
...(略)
WS1.Cells[9, 2] = dsMain.Tables[0].Rows[0]["處理意見"].ToString();}
else
{ return -1; }
//填寫患者診斷信息
if (dsDiag.Tables[0].Rows.Count > 0)
{ try
{worksheet1.Cells[10, 2] = "初步診斷:";
int j = 1;
foreach (DataRow dr in dsDiag.Tables[0].Rows)
{if (j == 1)//單條診斷填寫
{ worksheet1.Cells[10, 2] = " 初步診斷:" + dr[0].ToString();}
else
{ if (dsDiag.Tables[0].Rows.Count == j)//多條診斷中最后一條追加填寫。
{worksheet1.Cells[10, 2] = " " + ((Microsoft.Office.Interop.Excel.Range)worksheet1.Cells[10, 2]).Text.ToString() + " " + dr[0].ToString();}
Else //多條診斷中間部分追加填寫并加回車換行
{worksheet1.Cells[10, 2] = " " + ((Microsoft.Office.Interop.Excel.Range)worksheet1.Cells[10, 2]).Text.ToString() + " " + dr[0].ToString() + "\r\n";} }
j++;}}
catch (Exception ee)
{MessageBox.Show(ee.Message);
//后續(xù)處理:退出和釋放
_wbk.Close(null, null, null);
wbks.Close();
//釋放掉多余的excel進程
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
app = null; }}
else
{return -1; } }
//填寫醫(yī)生簽名(ordIndex為增加的行)
WS1.Cells[12 + ordIndex, 2] = "醫(yī)生簽名:" + dsMain.Tables[0].Rows[0]["醫(yī)生簽名"].ToString();
WS1.Range[WS1.Cells[12 + ordIndex, 2], WS1.Cells[12 + ordIndex, 2]].HorizontalAlignment = 4;//右對齊
WS1.Cells.EntireRow.AutoFit();//自動調(diào)整所有行的行高
//屏蔽掉系統(tǒng)跳出的Alert
app.AlertBeforeOverwriting = false;
app.DisplayAlerts = false;
WS1.PrintOutEx(1, 1, 1, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);//打印病歷
//后續(xù)處理:退出和釋放
_wbk.Close(null, null, null);
wbks.Close();
//釋放掉多余的excel進程
app.Quit();
app = null;
return 1; }
3 結(jié)束語
選擇EXCEL,基于以下幾點考慮:① 可設(shè)置底紋圖片且可打??;② 可設(shè)置頂端標(biāo)題行;③ 可自動調(diào)整行高;④ 模板格式編輯方便。本系統(tǒng)在windows XP,VS2010+office 2007環(huán)境下調(diào)試通過。
參考文獻:
[1] 明日科技,C#從入門到精通[M]. 3版.清華大學(xué)出版社,2012.
[2] Nagel C, Evjen B.C#高級編程[M]. 李銘.譯. 8版.清華大學(xué)出版社,2013.
[3] Walkenbach J.中文版Excel 2007高級VBA編程寶典[M]. 馮飛,焦瑜凈,譯.清華大學(xué)出版社,2011.