powerbuilder调用动态库实现医疗电子票据接口打印医疗电子发票
pb调用C#动态库实现福建博思软件医疗电子票据管理平台接口,解决pb无法实现的问题。
部分源代码
//[收集废弃对象,释放内存]
GarbageCollect()
if sqlca.sqlcode = -1 then
disconnect using sqlca;
connect using sqlca;
dw_1.settransobject(sqlca)
dw_2.settransobject(sqlca)
dw_3.settransobject(sqlca)
dw_4.settransobject(sqlca)
end if
dec li_i
dec li_i1,li_i2,li_i3
string ls_null[]
//----------------------------------------------------------------------------------------------------
string busNo,busType,payer,busDateTime,placeCode,payee,author,totalAmt,remark
string alipayCode,weChatOrderNo,weChatMedTransNo,openID,tel,email,payerType,idCardNo,cardType,cardNo
string medicalInstitution,medCareInstitution,medCareTypeCode,medicalCareType,medicalInsuranceID,consultationDate
string category,patientCategoryCode,patientNo,patientId,sex,age,caseNumber,specialDiseasesName
string accountPay,fundPay,otherfundPay,ownPay,selfConceitedAmt,selfPayAmt,selfCashPay
string cashPay,chequePay,transferAccountPay,cashRecharge,chequeRecharge,transferRecharge
string cashRefund,chequeRefund,transferRefund,ownAcBalance,reimbursementAmt,balancedNumber
string otherInfo,otherMedicalList,payChannelDetail,eBillRelateNo,chargeDetail,listDetail,payChannelDetailt
string ls_out
string ls_qm_data//【生成签名数据】
string ls_noise//[生成唯一数据]
string ls_data//[生成POST数据]
string ls_url//[POST-url]
string ls_postout_data//[提交开具门诊电子票据返回数据]
//---------------------------------------------------------------------------------------------------
string li_sortNo[],ls_chargeCode[],ls_chargeName[],ls_unit[],ld_std[],ld_number[],ld_amt[],ld_selfAmt[],ls_remark[]
//---------------------------------------------------------------------------------------------------
string listDetailNo[],chargeCode[],chargeName[],prescribeCode[], listTypeCode[], listTypeName[],code[],name[], form[], specification[], unit[], std[], number[], amt[], selfAmt[],receivableAmt[],ls_medicalCareType[], medCareItemType[], medReimburseRate[],lss_remark[],sortNo[],chrgtype[]
//---------------------------------------------------------------------------------------------------
string infoNo[], infoName[], infoValue[],infoOther[]
//---------------------------------------------------------------------------------------------------
string ls_billBatchCode,ls_billNo,ls_random,ls_createTime,ls_pictureUrl,ls_bz,ls_pictureUrl_r
if dw_1.rowcount()>0 then
//===============[存在数据,则关闭数据窗口刷新]==========
timer(0)
for li_i=1 to dw_1.rowcount()
dw_1.scrolltorow(li_i)
//------------------------------[A-1,生成收费项目明细chargeDetail]-----------------------------------------
if dw_3.rowcount()>0 then
for li_i1 =1 to dw_3.rowcount()
li_sortNo[li_i1]=string(li_i1)
ls_chargeCode[li_i1]=dw_3.object.chargeCode[li_i1]
ls_chargeName[li_i1]=dw_3.object.chargeName[li_i1]
ls_unit[li_i1]=""
ld_std[li_i1]=string(round(dw_3.object.amt[li_i1],2))//[不能为空]
ld_number[li_i1]="1"//string(dw_3.object.number[li_i1])
ld_amt[li_i1]=string(round(dw_3.object.amt[li_i1],2))
ld_selfAmt[li_i1]=string(round(dw_3.object.selfAmt[li_i1],2))
ls_remark[li_i1]=''
next
chargeDetail = inv_wxpay.of_create_chargedetail(li_sortNo,ls_chargeCode,ls_chargeName,ls_unit,ld_std,ld_number,ld_amt,ld_selfAmt,ls_remark)
//[数组赋空值]
li_sortNo=ls_null
li_sortNo=ls_null
ls_chargeCode=ls_null
ls_chargeName=ls_null
ls_unit=ls_null
ld_std=ls_null
ld_number=ls_null
ld_amt=ls_null
ld_selfAmt=ls_null
ls_remark=ls_null
end if
//-----------------------------------[A-2,生成清单项目listDetail]-------------------------------------------------------
if dw_4.rowcount()>0 then
for li_i2=1 to dw_4.rowcount()
listDetailNo[li_i2]=string(dw_4.object.listDetailNo[li_i2])
chargeCode[li_i2]=dw_4.object.chargeCode[li_i2]
chargeName[li_i2]=dw_4.object.chargeName[li_i2]
prescribeCode[li_i2]=dw_4.object.prescribeCode[li_i2]
listTypeCode[li_i2]=dw_4.object.listTypeCode[li_i2]
listTypeName[li_i2]=dw_4.object.listTypeName[li_i2]
code[li_i2]=dw_4.object.code[li_i2]
name[li_i2]=dw_4.object.name[li_i2]
form[li_i2]=dw_4.object.form[li_i2]
specification[li_i2]=dw_4.object.specification[li_i2]
unit[li_i2]=dw_4.object.unit[li_i2]
std[li_i2]=string(round(dw_4.object.std[li_i2],2))
number[li_i2]=string(dw_4.object.number[li_i2])
amt[li_i2]=string(round(dw_4.object.amt[li_i2],2))
selfAmt[li_i2]=string(round(dw_4.object.selfAmt[li_i2],2))
receivableAmt[li_i2]=string(round(dw_4.object.receivableAmt[li_i2],2))
ls_medicalCareType[li_i2]=dw_4.object.medicalCareType[li_i2]
medCareItemType[li_i2]=dw_4.object.medCareItemType[li_i2]
medReimburseRate[li_i2]=dw_4.object.medReimburseRate[li_i2]
lss_remark[li_i2]=''
sortNo[li_i2]=string(dw_4.object.sortNo[li_i2])
chrgtype[li_i2]=dw_4.object.chrgtype[li_i2]
next
listDetail= inv_wxpay.of_create_listDetail(listDetailNo, chargeCode, chargeName, prescribeCode, listTypeCode, listTypeName,code, name, form, specification, unit, std, number, amt, selfAmt,receivableAmt, ls_medicalCareType, medCareItemType, medReimburseRate, lss_remark, sortNo, chrgtype)
//[数组赋空值]
listDetailNo=ls_null
chargeCode=ls_null
chargeName=ls_null
prescribeCode=ls_null
listTypeCode=ls_null
listTypeName=ls_null
code=ls_null
name=ls_null
form=ls_null
specification=ls_null
unit=ls_null
std=ls_null
number=ls_null
amt=ls_null
selfAmt=ls_null
receivableAmt=ls_null
ls_medicalCareType=ls_null
medCareItemType=ls_null
medReimburseRate=ls_null
lss_remark=ls_null
sortNo=ls_null
chrgtype=ls_null
end if
//-----------------------------------------------[A-5,交费渠道列表payChannelDetailt]------------------------------
string payChannelCode[],payChannelValue[]
if (dw_1.object.yb_zhje[li_i]+dw_1.object.yb_tcje[li_i])>0 then
payChannelCode[1]='11'
payChannelValue[1]=string(round(dw_1.object.yb_zhje[li_i] + dw_1.object.yb_tcje[li_i] + dw_1.object.xjje[li_i],2))
payChannelDetailt=inv_wxpay.of_create_payChannelDetailt(payChannelCode,payChannelValue)
else
payChannelCode[1]='02'
payChannelValue[1]=string(round(dw_1.object.yb_zhje[li_i] + dw_1.object.yb_tcje[li_i] + dw_1.object.xjje[li_i],2))
payChannelDetailt=inv_wxpay.of_create_payChannelDetailt(payChannelCode,payChannelValue)
end if
//[数组赋空值]
payChannelCode=ls_null
payChannelValue=ls_null
//-----------------------------------------------[医疗门诊电子票据,invoiceEBillOutpatient]--------------------------------------------
if dw_2.rowcount()>0 then
busNo=f_isnull(dw_2.object.busNo[1])
busType=f_isnull(dw_2.object.busType[1])
payer=f_isnull(dw_2.object.payer[1])
busDateTime=string(dw_2.object.busDateTime[1],'yyyymmddhhmmssfff')//dw_2.object.busDateTime[1],转换为17位模式
placeCode=f_isnull(gs_dzpj_placecode)
payee=f_isnull(dw_2.object. payee[1])
author=f_isnull(dw_2.object.author[1])
totalAmt=f_isnull(string(round(dw_2.object.totalAmt[1],2)))
remark=f_isnull(dw_2.object.remark[1])
alipayCode=f_isnull(dw_2.object.alipayCode[1])
weChatOrderNo=f_isnull(dw_2.object.weChatOrderNo[1])
weChatMedTransNo=f_isnull(dw_2.object.weChatMedTransNo[1])
openID=f_isnull(dw_2.object.openID[1])
tel=f_isnull(dw_2.object.tel[1])
email=f_isnull(dw_2.object.email[1])
payerType=f_isnull(dw_2.object.payerType[1])
idCardNo=f_isnull(dw_2.object. idCardNo[1])
cardType=f_isnull(dw_2.object.cardType[1])
cardNo=f_isnull_not(dw_2.object.cardNo[1])//不能为空
medicalInstitution=f_isnull(dw_2.object.medicalInstitution[1])
medCareInstitution=f_isnull(dw_2.object.medCareInstitution[1])
medCareTypeCode=f_isnull(dw_2.object.medCareTypeCode[1])
medicalCareType=f_isnull(dw_2.object.medicalCareType[1])
medicalInsuranceID=f_isnull(dw_2.object.medicalInsuranceID[1])
consultationDate=f_isnull(dw_2.object.consultationDate[1])
category=f_isnull(dw_2.object.category[1])
patientCategoryCode=f_isnull(dw_2.object.patientCategoryCode[1])
patientNo=f_isnull(dw_2.object.patientNo[1])
patientId=f_isnull(dw_2.object.patientId[1])
sex=f_isnull(dw_2.object.sex[1])
//age=dw_2.object.age[1]
caseNumber=f_isnull(dw_2.object.caseNumber[1])
specialDiseasesName=f_isnull(dw_2.object.specialDiseasesName[1])
accountPay=f_isnull(string(round(dw_2.object.accountPay[1],2)))
fundPay=f_isnull(string(round(dw_2.object.fundPay[1],2)))
otherfundPay=f_isnull(string(round(dw_2.object.otherfundPay[1],2)))
ownPay=f_isnull(string(round(dw_2.object.ownPay[1],2)))
selfConceitedAmt=f_isnull(string(round(dw_2.object.selfConceitedAmt[1],2)))
selfPayAmt=f_isnull(string(round(dw_2.object.selfPayAmt[1],2)))
selfCashPay=f_isnull(string(round(dw_2.object.selfCashPay[1],2)))
cashPay=f_isnull(string(round(dw_2.object.cashPay[1],2)))
chequePay=f_isnull(string(round(dw_2.object.chequePay[1],2)))
transferAccountPay=f_isnull(string(round(dw_2.object.transferAccountPay[1],2)))
cashRecharge=f_isnull(string(round(dw_2.object.cashRecharge[1],2)))
chequeRecharge=f_isnull(string(round(dw_2.object.chequeRecharge[1],2)))
transferRecharge=f_isnull(string(round(dw_2.object.transferRecharge[1],2)))
cashRefund=f_isnull(string(round(dw_2.object.cashRefund[1],2)))
chequeRefund=f_isnull(string(round(dw_2.object.chequeRefund[1],2)))
transferRefund=f_isnull(string(round(dw_2.object.transferRefund[1],2)))
ownAcBalance=f_isnull(string(round(dw_2.object.ownAcBalance[1],2)))
reimbursementAmt=f_isnull(string(round(dw_2.object.reimbursementAmt[1],2)))
balancedNumber=f_isnull(string(dw_2.object.balancedNumber[1]))
//otherInfo=
//otherMedicalList=
payChannelDetail=payChannelDetailt
eBillRelateNo=f_isnull(dw_2.object.eBillRelateNo[1])
chargeDetail=f_isnull(chargeDetail)
listDetail=f_isnull(listDetail)
//[生成JSON格式字符串]
ls_out = inv_wxpay.of_create_invoiceEBillOutpatient(busNo,busType, payer, busDateTime, placeCode, payee, author,totalAmt, remark, alipayCode, weChatOrderNo, weChatMedTransNo, openID, tel, email,payerType, idCardNo, cardType, cardNo, medicalInstitution, medCareInstitution,medCareTypeCode, medicalCareType, medicalInsuranceID, consultationDate, category, patientCategoryCode,patientNo, patientId, sex, age, caseNumber, specialDiseasesName,accountPay, fundPay, otherfundPay, ownPay, selfConceitedAmt, selfPayAmt, selfCashPay, cashPay, chequePay, transferAccountPay, cashRecharge, chequeRecharge, transferRecharge, cashRefund,chequeRefund, transferRefund, ownAcBalance, reimbursementAmt, balancedNumber, otherInfo, otherMedicalList, payChannelDetail, eBillRelateNo,chargeDetail, listDetail)
ls_out = inv_wxpay.of_EncodeBase64('utf-8', ls_out)//[base64编码]
end if
//--------------------------[生成电子签名]--------------------------------
ls_noise=inv_wxpay.of_newuuidstring()
ls_qm_data=inv_wxpay.of_dzpj_sign_refund(gs_dzpj_appid,ls_out,ls_noise,'1.0',gs_dzpj_appkey)
//-------------------------[生成JSON格式POST请求数据]---------------------
ls_data=inv_wxpay.of_dzpj_post_data(gs_dzpj_appid,ls_out, ls_noise,'1.0',ls_qm_data)
//-------------------------[电子票据接口POST]------------------------------------
ls_url=gs_dzpj_url+'invoiceEBillOutpatient'
ls_postout_data=inv_wxpay.of_post_dzpj(ls_url,ls_data)//[执行POST]
ls_postout_data=inv_wxpay.of_json_to_xml(ls_postout_data)//[返回数据转换成XML,有data节点数据]
ls_postout_data=inv_wxpay.of_DecodeBase64("utf-8",gf_xml_resolve_pos(ls_postout_data,"data"))//[第一步取出data,并解码]
ls_postout_data=inv_wxpay.of_json_to_xml(ls_postout_data)//[返回数据转换成XML,有message节点数据]
//**********************************[以下判断开票是否成功]******************************************************
if gf_xml_resolve_pos(ls_postout_data,"result")='S0000' then//[成功]
ls_postout_data=inv_wxpay.of_DecodeBase64("utf-8",gf_xml_resolve_pos(ls_postout_data,"message"))//[第一步取出message,并解码]
gf_wf_log('POST数据-成功[JSON]',ls_postout_data)//[写入日志]
ls_postout_data=inv_wxpay.of_json_to_xml(ls_postout_data)//[转换为XML]
inv_wxpay.of_BinaryStreamToPicture(gf_xml_resolve_pos(ls_postout_data,"billQRCode"),busNo)//[生成二维码]
//[解析各字段写入数据表,并更新数据开票状态-成功]
ls_billBatchCode=gf_xml_resolve_pos(ls_postout_data,"billBatchCode")
ls_billNo=gf_xml_resolve_pos(ls_postout_data,"billNo")
ls_random=gf_xml_resolve_pos(ls_postout_data,"random")
ls_createTime=gf_xml_resolve_pos(ls_postout_data,"createTime")
ls_pictureUrl=gf_xml_resolve_pos(ls_postout_data,"pictureUrl")//[替换“&”为“&”]
ls_pictureUrl_r=''
ls_pictureUrl_r=Replace(ls_pictureUrl, pos(ls_pictureUrl,'&'), 5, '&' )
ls_bz='出票成功'
//[生成二维码展示]
inv_wxpay.of_MakeQRBarcode(ls_pictureUrl_r,p_1)
st_1.text='出票成功,出票流水号:['+busNo+'] 电子票据号码:['+ls_billNo+'] 出票时间:['+ls_createTime+']'
dw_1.object.billBatchCode[li_i]=ls_billBatchCode
dw_1.object.billNo[li_i]=ls_billNo
dw_1.object.random[li_i]=ls_random
update sk_mzsj set billBatchCode=:ls_billBatchCode,billNo=:ls_billNo,random=:ls_random,createTime=:ls_createTime,pictureUrl=:ls_pictureUrl_r,remark=:ls_bz,if_dzpj=1
where fph=:busNo;
if sqlca.sqlcode=0 then
commit;
else
rollback;
end if
else//[开票不成功]
ls_postout_data=inv_wxpay.of_DecodeBase64("utf-8",gf_xml_resolve_pos(ls_postout_data,"message"))//[第一步取出message,并解码]
//[错误提示remak,并更新数据开票状态--不成功]
st_1.text='出票不成功,错误信息:['+ls_postout_data+'] '
update sk_mzsj set remark=:ls_postout_data where fph=:busNo;
if sqlca.sqlcode=0 then
commit;
else
rollback;
end if
end if
//**********************************[以上判断开票是否成功]******************************************************
next
//=============【出票完成后,执行数据窗口刷新】====================================
timer(id_timer)
dw_1.settransobject(sqlca)
dw_1.retrieve()
else//[若不存在数据,执行数据窗口刷新,刷新频率在配置文件WX.INI中配置]
timer(id_timer)
dw_1.settransobject(sqlca)
dw_1.retrieve()
end if