HIS系统打印发票、医嘱单使用的ireport,下面对ireport使用做简单介绍。
1、工作流程及设计思路:
使用ireport绘制模板,数据源获取数据,web系统读取jasper文件,通过ireport引擎将jasper转换成pdf,然后打印。其中jasper文件是通过ireport绘图工具由jrxml编译而来的。
2、代码:
<!-- 引入ireport 引擎 -->
<%@ page import="net.sf.jasperreports.engine.*"%>
<!-- 读jasper文件需要io操作 -->
<%@ page import="java.util.*"%><%@ page import="java.io.*"%>
<!-- 引入数据源 -->
<%@ page import="java.sql.*"%><%@ page import="cn.com.sinosoft.frame.resfactory.DBConnectionMgr"%>
<!-- 项目框架 -->
<%@ page import="cn.com.sinosoft.frame.constant.FrameConstant"%>
<!-- 输出流 -->
<%@ page import="javax.servlet.ServletOutputStream"%>
<%@ page import="cn.com.sinosoft.cmis.his.register.form.PrintZYyz"%>
<%@ page import="cn.com.sinosoft.frame.valueobject.UserView" %><%
//File reportFile = new File(application.getRealPath("/pdf/printzyLSyz.jasper"));
File reportFile = new File(application.getRealPath("/pdf/tempOrders.jasper"));
Map parameters = new HashMap();
String hos_patient_id =request.getParameter("HOS_PATIENT_ID");
String ADVICE_PROPERTYCODE =request.getParameter("ADVICE_PROPERTYCODE");
String orgname = "";
if(request.getSession() != null) {
UserView user= (UserView)request.getSession().getAttribute("PermMgr");
if (user != null) {
orgname = user.getUpname();
}
}
parameters = PrintZYyz.getLSYZMap(hos_patient_id,ADVICE_PROPERTYCODE,orgname);
Connection conn = null;
byte[] bytes = null;
response.reset();
out.clear();
out = pageContext.pushBody();
ServletOutputStream ouputStream = response.getOutputStream();
try {
conn = DBConnectionMgr
.getConnection(FrameConstant.MID_DATASOURCE_LEVEL);
System.out.println(reportFile.getPath());
bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),
parameters, conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
if (bytes != null) {
bytes = null;
}
if (ouputStream != null) {
ouputStream.close();
ouputStream = null;
}
} catch (Exception e) {
}
}
%>
jasper文件如上图。
jrxml源码:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="tempOrders"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="593"
pageHeight="842"
columnWidth="533"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />
<!-- jasper文件需要的参数:如,住院号 -->
<parameter name="HOS_PATIENT_ID" isForPrompting="true" class="java.lang.String">
<defaultValueExpression ><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="CLIENT_NAME" isForPrompting="true" class="java.lang.String">
<defaultValueExpression ><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="DEPARTMENT" isForPrompting="true" class="java.lang.String">
<defaultValueExpression ><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="TITLE" isForPrompting="true" class="java.lang.String">
<defaultValueExpression ><![CDATA[""]]></defaultValueExpression>
</parameter>
<parameter name="METIER" isForPrompting="true" class="java.lang.String"/>
<parameter name="HOMEPLACE" isForPrompting="false" class="java.lang.String"/>
<parameter name="AGE" isForPrompting="false" class="java.lang.String"/>
<parameter name="SEX" isForPrompting="false" class="java.lang.String"/>
<parameter name="ADVICE_PROPERTYCODE" isForPrompting="true" class="java.lang.String"/>
<parameter name="PATIENTID" isForPrompting="false" class="java.lang.String"/>
<parameter name="HOSPITAL" isForPrompting="false" class="java.lang.String">
<defaultValueExpression ><![CDATA[""]]></defaultValueExpression>
</parameter>
<!-- sql -->
<queryString><![CDATA[SELECT rownum as ROW_NUM,
substr(t.start_time, 0, 10) as ADVICE_DATE,
substr(t.start_time, 12) as ADVICE_TIME,
t.advice_category as ADVICE_CATEGORY,
(case
when t.med_name like '嘱托医嘱%' then
t.note
else
t.med_name || ' ' || t.num_per || t.unit_per || ' ' ||
t.FREQUENCY || ' ' || t.USAGE
end) as MED_NAME,
t.USAGE AS USAGE,
T.num_per || t.unit_per AS NUM_PER,
t.FREQUENCY AS FREQUENCY,
t.SEND_NUM AS SEND_NUM,
(select r.user_name
from pub_manage_user r
where r.user_idcode = t.add_opr_id) as DOC_ID,
(case
when vs.zxstatus = '1' then
to_char(vs.execut_time, 'yyyy-mm-dd hh24:mi:ss')
else
''
end) as EXECUT_TIME,
vs.nurse_id as NURSE_ID,
substr(to_char(t.end_time, 'yyyy-mm-dd hh24:mi:ss'), 0, 10) as ADVICE_STOPDATE,
substr(to_char(t.end_time, 'yyyy-mm-dd hh24:mi:ss'), 12) as ADVICE_STOPTIME,
(select r.user_name
from pub_manage_user r
where r.user_idcode = t.last_chg_opr_id) as DOC_STOPID,
t.med_name as m_name,
NVL((select med.dd_outp_class
from med_coding med
where med.med_seqid = t.med_seqid),
(select clc.dd_outp_class
from CLC_PRICELIST clc
where clc.pricelist_seqid = t.med_seqid)) as outp,
t.row_num as row_num
FROM V_HOS_DOCADVICE t, HOS_SETTLE_LIST ht, V_HOS_DOCTOR_ADVICEES1 vs
WHERE t.hos_patient_id = ht.hos_patient_id(+)
and t.advice_id = vs.advice_id(+)
and t.advice_propertycode = $P{ADVICE_PROPERTYCODE}
AND t.HOS_PATIENT_ID = $P{HOS_PATIENT_ID}
and t.is_nurse is null
and t.EDIT_PROPERTY = '0'
and t.isprint = 1
order by ADVICE_DATE,
ADVICE_TIME,
decode(outp, '27', 1),
decode(m_name, '嘱托医嘱', 1),
decode(outp,
'06',
1,
'05',
2,
'01',
3,
'02',
4,
'03',
5,
'04',
6,
'08',
7,
'09',
8,
'11',
9,
'13',
10,
'14',
11,
'99',
12),
t.row_num]]></queryString>
<field name="ADVICE_DATE" class="java.lang.String"/>
<field name="ADVICE_TIME" class="java.lang.String"/>
<field name="MED_NAME" class="java.lang.String"/>
<field name="USAGE" class="java.lang.String"/>
<field name="NUM_PER" class="java.lang.String"/>
<field name="FREQUENCY" class="java.lang.String"/>
<field name="SEND_NUM" class="java.lang.String"/>
<field name="DOC_ID" class="java.lang.String"/>
<field name="EXECUT_TIME" class="java.lang.String"/>
<field name="NURSE_ID" class="java.lang.String"/>
<field name="ROW_NUM" class="java.lang.String"/>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="0" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="46" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="95" isSplitAllowed="true" >
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="462"
y="41"
width="66"
height="18"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-1"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{PATIENTID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="80"
y="45"
width="45"
height="17"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-2"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{CLIENT_NAME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="227"
y="45"
width="37"
height="18"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-3"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{AGE}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="366"
y="42"
width="73"
height="18"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-4"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{METIER}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="286"
y="43"
width="53"
height="18"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-5"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{DEPARTMENT}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="159"
y="45"
width="34"
height="18"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-6"
stretchType="NoStretch"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{SEX}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="23" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="0"
y="0"
width="51"
height="21"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-9"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ADVICE_DATE}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="61"
y="1"
width="65"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-10"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{ADVICE_TIME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="126"
y="1"
width="230"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-11"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{MED_NAME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="356"
y="1"
width="53"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-16"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DOC_ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="409"
y="1"
width="65"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-17"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{EXECUT_TIME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="474"
y="1"
width="59"
height="20"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-18"
stretchType="RelativeToBandHeight"
positionType="FixRelativeToTop"
isPrintRepeatedValues="true"
isRemoveLineWhenBlank="false"
isPrintInFirstWholeBand="false"
isPrintWhenDetailOverflows="false"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single">
<font fontName="黑体" pdfFontName="STSong-Light" size="8" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{NURSE_ID}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="16" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="0" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
3、ireport绘图工具介绍:
编译jrxml,编译成jasper
jasper文件会在ireport安装目录中生成。
ireport安装目录如上图:
4、ireport工具资源包请到csdn下载中查询。