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