his_api_controller.go 64KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  32. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  33. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  34. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  35. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  36. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  37. }
  38. func (c *HisApiController) Sscard() {
  39. r := CardInit()
  40. if r == 0 {
  41. GetBaseInfo()
  42. }
  43. c.ServeSuccessJSON(map[string]interface{}{
  44. "list": "11",
  45. })
  46. }
  47. func GetBaseInfo() error {
  48. //handle := syscall.MustLoadDLL("SSCard.dll")
  49. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  50. //
  51. //str := make([]byte, 256)
  52. //str1 := make([]byte, 256)
  53. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  54. //if ferr != nil {
  55. // fmt.Println("ReadCardBas 报错", ferr.Error())
  56. // return ferr
  57. //}
  58. //
  59. //fmt.Println(string(str))
  60. //
  61. //fmt.Println(r)
  62. return nil
  63. }
  64. func CardInit() int {
  65. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  66. //add := DllTestDef.MustFindProc("Init")
  67. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  68. //if err != nil {
  69. // fmt.Println("SSCard的运算结果为:", ret)
  70. //}
  71. //result := int(ret)
  72. return 0
  73. }
  74. func IntPtr(n int) uintptr {
  75. return uintptr(n)
  76. }
  77. func StrPtr(s string) uintptr {
  78. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  79. }
  80. type ResultTwo struct {
  81. ErrMsg interface{} `json:"err_msg"`
  82. InfRefmsgid string `json:"inf_refmsgid"`
  83. Infcode int64 `json:"infcode"`
  84. Output struct {
  85. Baseinfo struct {
  86. Age float64 `json:"age"`
  87. Brdy string `json:"brdy"`
  88. Certno string `json:"certno"`
  89. Gend string `json:"gend"`
  90. Naty string `json:"naty"`
  91. PsnCertType string `json:"psn_cert_type"`
  92. PsnName string `json:"psn_name"`
  93. PsnNo string `json:"psn_no"`
  94. } `json:"baseinfo"`
  95. Idetinfo []interface{} `json:"idetinfo"`
  96. Iinfo []struct {
  97. Balc int64 `json:"balc"`
  98. CvlservFlag string `json:"cvlserv_flag"`
  99. EmpName string `json:"emp_name"`
  100. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  101. Insutype string `json:"insutype"`
  102. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  103. PausInsuDate interface{} `json:"paus_insu_date"`
  104. PsnInsuDate string `json:"psn_insu_date"`
  105. PsnInsuStas string `json:"psn_insu_stas"`
  106. PsnType string `json:"psn_type"`
  107. } `json:"insuinfo"`
  108. } `json:"output"`
  109. RefmsgTime string `json:"refmsg_time"`
  110. RespondTime string `json:"respond_time"`
  111. Signtype interface{} `json:"signtype"`
  112. WarnInfo interface{} `json:"warn_info"`
  113. }
  114. type ResultThree struct {
  115. Cainfo interface{} `json:"cainfo"`
  116. ErrMsg interface{} `json:"err_msg"`
  117. InfRefmsgid string `json:"inf_refmsgid"`
  118. Infcode int64 `json:"infcode"`
  119. Output struct {
  120. Data struct {
  121. IptOtpNo string `json:"ipt_otp_no"`
  122. MdtrtID string `json:"mdtrt_id"`
  123. PsnNo string `json:"psn_no"`
  124. } `json:"data"`
  125. } `json:"output"`
  126. RefmsgTime string `json:"refmsg_time"`
  127. RespondTime string `json:"respond_time"`
  128. Signtype interface{} `json:"signtype"`
  129. WarnMsg interface{} `json:"warn_msg"`
  130. }
  131. type ResultFour struct {
  132. Cainfo string `json:"cainfo"`
  133. ErrMsg string `json:"err_msg"`
  134. InfRefmsgid string `json:"inf_refmsgid"`
  135. Infcode int64 `json:"infcode"`
  136. Output struct {
  137. Result []struct {
  138. BasMednFlag string `json:"bas_medn_flag"`
  139. ChldMedcFlag string `json:"chld_medc_flag"`
  140. ChrgitmLv string `json:"chrgitm_lv"`
  141. Cnt float64 `json:"cnt"`
  142. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  143. DrtReimFlag string `json:"drt_reim_flag"`
  144. FeedetlSn string `json:"feedetl_sn"`
  145. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  146. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  147. InscpScpAmt float64 `json:"inscp_scp_amt"`
  148. ListSpItemFlag string `json:"list_sp_item_flag"`
  149. LmtUsedFlag string `json:"lmt_used_flag"`
  150. MedChrgitmType string `json:"med_chrgitm_type"`
  151. Memo string `json:"memo"`
  152. OverlmtAmt float64 `json:"overlmt_amt"`
  153. PreselfpayAmt float64 `json:"preselfpay_amt"`
  154. Pric float64 `json:"pric"`
  155. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  156. SelfpayProp float64 `json:"selfpay_prop"`
  157. } `json:"result"`
  158. } `json:"output"`
  159. RefmsgTime string `json:"refmsg_time"`
  160. RespondTime string `json:"respond_time"`
  161. Signtype string `json:"signtype"`
  162. WarnMsg string `json:"warn_msg"`
  163. }
  164. type ResultFive struct {
  165. Insutype string `json:"insutype"`
  166. }
  167. type ResultSix struct {
  168. Cainfo interface{} `json:"cainfo"`
  169. ErrMsg interface{} `json:"err_msg"`
  170. InfRefmsgid string `json:"inf_refmsgid"`
  171. Infcode int64 `json:"infcode"`
  172. Output struct {
  173. } `json:"output"`
  174. RefmsgTime string `json:"refmsg_time"`
  175. RespondTime string `json:"respond_time"`
  176. Signtype interface{} `json:"signtype"`
  177. WarnMsg interface{} `json:"warn_msg"`
  178. }
  179. type ResultSeven struct {
  180. Cainfo string `json:"cainfo"`
  181. ErrMsg string `json:"err_msg"`
  182. InfRefmsgid string `json:"inf_refmsgid"`
  183. Infcode int64 `json:"infcode"`
  184. Output struct {
  185. Setldetail []interface{} `json:"setldetail"`
  186. Setlinfo struct {
  187. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  188. AcctPay float64 `json:"acct_pay"`
  189. ActPayDedc float64 `json:"act_pay_dedc"`
  190. Age float64 `json:"age"`
  191. Balc float64 `json:"balc"`
  192. Brdy string `json:"brdy"`
  193. Certno string `json:"certno"`
  194. ClrOptins string `json:"clr_optins"`
  195. ClrType string `json:"clr_type"`
  196. ClrWay string `json:"clr_way"`
  197. CvlservFlag string `json:"cvlserv_flag"`
  198. CvlservPay float64 `json:"cvlserv_pay"`
  199. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  200. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  201. Gend string `json:"gend"`
  202. HifesPay float64 `json:"hifes_pay"`
  203. HifmiPay float64 `json:"hifmi_pay"`
  204. HifpPay float64 `json:"hifp_pay"`
  205. HospPartAmt float64 `json:"hosp_part_amt"`
  206. InscpScpAmt float64 `json:"inscp_scp_amt"`
  207. Insutype string `json:"insutype"`
  208. MafPay float64 `json:"maf_pay"`
  209. MdtrtCertType string `json:"mdtrt_cert_type"`
  210. HifobPay float64 `json:"hifob_pay"`
  211. MdtrtID string `json:"mdtrt_id"`
  212. MedType string `json:"med_type"`
  213. MedfeeSumamt float64 `json:"medfee_sumamt"`
  214. MedinsSetlID string `json:"medins_setl_id"`
  215. Naty string `json:"naty"`
  216. OthPay float64 `json:"oth_pay"`
  217. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  218. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  219. PreselfpayAmt float64 `json:"preselfpay_amt"`
  220. PsnCashPay float64 `json:"psn_cash_pay"`
  221. PsnCertType string `json:"psn_cert_type"`
  222. PsnName string `json:"psn_name"`
  223. PsnNo string `json:"psn_no"`
  224. PsnPartAmt float64 `json:"psn_part_amt"`
  225. PsnType string `json:"psn_type"`
  226. SetlID string `json:"setl_id"`
  227. SetlTime string `json:"setl_time"`
  228. } `json:"setlinfo"`
  229. } `json:"output"`
  230. RefmsgTime string `json:"refmsg_time"`
  231. RespondTime string `json:"respond_time"`
  232. Signtype interface{} `json:"signtype"`
  233. WarnMsg interface{} `json:"warn_msg"`
  234. }
  235. type ResultEight struct {
  236. Cainfo string `json:"cainfo"`
  237. ErrMsg string `json:"err_msg"`
  238. InfRefmsgid string `json:"inf_refmsgid"`
  239. Infcode int64 `json:"infcode"`
  240. Output struct {
  241. Stmtinfo struct {
  242. SetlOptins string `json:"setl_optins"`
  243. StmtRslt string `json:"stmt_rslt"`
  244. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  245. } `json:"stmtinfo"`
  246. } `json:"output"`
  247. RefmsgTime string `json:"refmsg_time"`
  248. RespondTime string `json:"respond_time"`
  249. Signtype interface{} `json:"signtype"`
  250. WarnMsg interface{} `json:"warn_msg"`
  251. }
  252. type ResultNine struct {
  253. Cainfo string `json:"cainfo"`
  254. ErrMsg string `json:"err_msg"`
  255. InfRefmsgid string `json:"inf_refmsgid"`
  256. Infcode int64 `json:"infcode"`
  257. Output struct {
  258. FileQuryNo string `json:"file_qury_no"`
  259. } `json:"output"`
  260. RefmsgTime string `json:"refmsg_time"`
  261. RespondTime string `json:"respond_time"`
  262. Signtype interface{} `json:"signtype"`
  263. WarnMsg interface{} `json:"warn_msg"`
  264. }
  265. type ResultTen struct {
  266. Cainfo string `json:"cainfo"`
  267. ErrMsg string `json:"err_msg"`
  268. InfRefmsgid string `json:"inf_refmsgid"`
  269. Infcode int64 `json:"infcode"`
  270. Output struct {
  271. DldEndtime string `json:"dld_endtime"`
  272. FileQuryNo string `json:"file_qury_no"`
  273. Filename string `json:"filename"`
  274. } `json:"output"`
  275. RefmsgTime string `json:"refmsg_time"`
  276. RespondTime string `json:"respond_time"`
  277. Signtype interface{} `json:"signtype"`
  278. WarnMsg interface{} `json:"warn_msg"`
  279. }
  280. type ResultEleven struct {
  281. Cainfo string `json:"cainfo"`
  282. ErrMsg string `json:"err_msg"`
  283. InfRefmsgid string `json:"inf_refmsgid"`
  284. Infcode int64 `json:"infcode"`
  285. Output struct {
  286. Setlinfo struct {
  287. FixmedinsName string `json:"fixmedins_name"`
  288. FixmedinsCode string `json:"fixmedins_code"`
  289. PsnNo string `json:"psn_no"`
  290. PsnName string `json:"psn_name"`
  291. HifobPay float64 `json:"hifob_pay"`
  292. Gend string `json:"gend"`
  293. Brdy string `json:"brdy"`
  294. PsnCertType string `json:"psn_cert_type"`
  295. PsnType string `json:"psn_type"`
  296. EmpName string `json:"emp_name"`
  297. Certno string `json:"certno"`
  298. Insutype string `json:"insutype"`
  299. MedfeeSumamt float64 `json:"medfee_sumamt"`
  300. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  301. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  302. PreselfpayAmt float64 `json:"preselfpay_amt"`
  303. InscpScpAmt float64 `json:"inscp_scp_amt"`
  304. ActPayDedc float64 `json:"act_pay_dedc"`
  305. HifpPay float64 `json:"hifp_pay"`
  306. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  307. CvlservPay float64 `json:"cvlserv_pay"`
  308. HifesPay float64 `json:"hifes_pay"`
  309. HifmiPay float64 `json:"hifmi_pay"`
  310. MafPay float64 `json:"maf_pay"`
  311. OthPay float64 `json:"oth_pay"`
  312. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  313. PsnPay float64 `json:"psn_pay"`
  314. AcctPay float64 `json:"acct_pay"`
  315. CashPayamt float64 `json:"cash_payamt"`
  316. Balc float64 `json:"balc"`
  317. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  318. MedinsSetlId string `json:"medins_setl_id"`
  319. RefdSetlFlag string `json:"refd_setl_flag"`
  320. SetlTime string `json:"setl_time"`
  321. } `json:"setlinfo"`
  322. } `json:"output"`
  323. RefmsgTime string `json:"refmsg_time"`
  324. RespondTime string `json:"respond_time"`
  325. Signtype interface{} `json:"signtype"`
  326. WarnMsg interface{} `json:"warn_msg"`
  327. }
  328. type Custom struct {
  329. DetItemFeeSumamt string
  330. Cut string
  331. FeedetlSn string
  332. Price string
  333. MedListCodg string
  334. Type int64
  335. AdviceId int64
  336. ProjectId int64
  337. ItemId int64
  338. }
  339. //获取个人信息----挂号-----上传就诊信息
  340. func (c *HisApiController) GetRegisterInfo() {
  341. id, _ := c.GetInt64("id")
  342. record_time := c.GetString("record_time")
  343. name := c.GetString("name")
  344. gender, _ := c.GetInt64("gender")
  345. age, _ := c.GetInt64("age")
  346. birthday := c.GetString("birthday")
  347. phone := c.GetString("phone")
  348. medical_care, _ := c.GetInt64("medical_care")
  349. id_card := c.GetString("id_card")
  350. register_type, _ := c.GetInt64("register_type")
  351. registration_fee, _ := c.GetFloat("registration_fee")
  352. medical_expenses, _ := c.GetFloat("medical_expenses")
  353. certificates, _ := c.GetInt64("certificates")
  354. settlementValue, _ := c.GetInt64("settlement_value")
  355. social_type, _ := c.GetInt64("social_type")
  356. medical_insurance_card := c.GetString("medical_insurance_card")
  357. timeLayout := "2006-01-02"
  358. loc, _ := time.LoadLocation("Local")
  359. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  360. birthUnix := birthdays.Unix()
  361. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  362. if err != nil {
  363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  364. return
  365. }
  366. recordDateTime := theTime.Unix()
  367. adminInfo := c.GetAdminUserInfo()
  368. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  369. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  370. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  371. if patient == nil {
  372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  373. return
  374. }
  375. if len(patient.IdCardNo) == 0 {
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  377. return
  378. }
  379. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  380. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  381. if config.IsOpen == 1 {
  382. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  383. resp, requestErr := http.Get(api)
  384. if requestErr != nil {
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  386. return
  387. }
  388. defer resp.Body.Close()
  389. body, ioErr := ioutil.ReadAll(resp.Body)
  390. if ioErr != nil {
  391. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  393. return
  394. }
  395. var respJSON map[string]interface{}
  396. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  397. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  399. return
  400. }
  401. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  402. userJSONBytes, _ := json.Marshal(userJSON)
  403. var res ResultTwo
  404. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  405. utils.ErrorLog("解析失败:%v", err)
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  407. return
  408. }
  409. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  410. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  411. infoStr := string(Iinfos)
  412. idetinfoStr := string(Idetinfos)
  413. if res.Infcode == -1 {
  414. his := models.VMHisPatient{
  415. Name: name,
  416. Gender: gender,
  417. Birthday: birthUnix,
  418. MedicalTreatmentType: medical_care,
  419. IdType: certificates,
  420. IdCardNo: id_card,
  421. BalanceAccountsType: settlementValue,
  422. SocialType: social_type,
  423. MedicalInsuranceNumber: medical_insurance_card,
  424. RegisterType: register_type,
  425. RegisterCost: registration_fee,
  426. TreatmentCost: medical_expenses,
  427. Status: 1,
  428. Ctime: time.Now().Unix(),
  429. Mtime: time.Now().Unix(),
  430. PsnNo: res.Output.Baseinfo.PsnNo,
  431. PsnCertType: res.Output.Baseinfo.PsnCertType,
  432. Certno: res.Output.Baseinfo.Certno,
  433. PsnName: res.Output.Baseinfo.PsnName,
  434. Gend: res.Output.Baseinfo.Gend,
  435. Naty: res.Output.Baseinfo.Naty,
  436. Brdy: res.Output.Baseinfo.Brdy,
  437. Age: res.Output.Baseinfo.Age,
  438. Iinfo: infoStr,
  439. Idetinfo: idetinfoStr,
  440. PatientId: patient.ID,
  441. RecordDate: theTime.Unix(),
  442. UserOrgId: adminInfo.CurrentOrgId,
  443. AdminUserId: adminInfo.AdminUser.Id,
  444. IsReturn: 1,
  445. }
  446. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  448. return
  449. }
  450. timestamp := time.Now().Unix()
  451. tempTime := time.Unix(timestamp, 0)
  452. timeFormat := tempTime.Format("20060102150405")
  453. chrgBchno := rand.Intn(100000) + 10000
  454. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  455. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  456. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  457. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  458. if count <= 0 {
  459. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  460. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  461. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  462. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  463. resp, requestErr := http.Get(api)
  464. if requestErr != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  466. return
  467. }
  468. defer resp.Body.Close()
  469. body, ioErr := ioutil.ReadAll(resp.Body)
  470. if ioErr != nil {
  471. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  473. return
  474. }
  475. var respJSON map[string]interface{}
  476. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  477. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  479. return
  480. }
  481. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  482. userJSONBytes, _ := json.Marshal(respJSON)
  483. var res ResultThree
  484. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  485. utils.ErrorLog("解析失败:%v", err)
  486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  487. return
  488. }
  489. if res.Infcode == -1 {
  490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  491. return
  492. }
  493. his.Number = res.Output.Data.MdtrtID
  494. his.PsnNo = res.Output.Data.PsnNo
  495. his.IptOtpNo = res.Output.Data.IptOtpNo
  496. his.IdCardNo = patient.IdCardNo
  497. his.PhoneNumber = patient.Phone
  498. his.UserOrgId = adminInfo.CurrentOrgId
  499. his.Status = 1
  500. his.Ctime = time.Now().Unix()
  501. his.Mtime = time.Now().Unix()
  502. err := service.CreateHisPatientTwo(&his)
  503. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  504. if err == nil {
  505. api := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  506. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  507. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  508. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  509. resp, requestErr := http.Get(api)
  510. if requestErr != nil {
  511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  512. return
  513. }
  514. body, ioErr := ioutil.ReadAll(resp.Body)
  515. if ioErr != nil {
  516. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  518. return
  519. }
  520. var respJSON map[string]interface{}
  521. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  522. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  527. userJSONBytes, _ := json.Marshal(respJSON)
  528. fmt.Println(respJSON)
  529. fmt.Println(userJSONBytes)
  530. var res ResultSix
  531. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  532. utils.ErrorLog("解析失败:%v", err)
  533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  534. return
  535. }
  536. if res.Infcode == -1 {
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  538. return
  539. }
  540. c.ServeSuccessJSON(map[string]interface{}{
  541. "his_info": his,
  542. })
  543. } else {
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  545. return
  546. }
  547. }
  548. } else {
  549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  550. return
  551. }
  552. } else {
  553. timeStr := time.Now().Format("2006-01-02")
  554. timeArr := strings.Split(timeStr, "-")
  555. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  556. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  557. var hisPatient models.XtHisPatient
  558. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  559. hisPatient = models.XtHisPatient{
  560. Name: name,
  561. Age: age,
  562. Gender: gender,
  563. Birthday: birthUnix,
  564. Phone: phone,
  565. MedicalTreatmentType: medical_care,
  566. IdType: certificates,
  567. IdCardNo: id_card,
  568. BalanceAccountsType: settlementValue,
  569. SocialType: social_type,
  570. MedicalInsuranceNumber: medical_insurance_card,
  571. RegisterType: register_type,
  572. RegisterCost: registration_fee,
  573. TreatmentCost: medical_expenses,
  574. AdminUserId: adminInfo.AdminUser.Id,
  575. UserOrgId: adminInfo.CurrentOrgId,
  576. Status: 1,
  577. RecordDate: recordDateTime,
  578. IsReturn: 1,
  579. PatientId: patient.ID,
  580. Ctime: time.Now().Unix(),
  581. Mtime: time.Now().Unix(),
  582. Number: str,
  583. }
  584. service.CreateHisPatient(&hisPatient)
  585. }
  586. c.ServeSuccessJSON(map[string]interface{}{
  587. "his_info": hisPatient,
  588. })
  589. }
  590. }
  591. //上传明细----结算
  592. func (c *HisApiController) GetUploadInfo() {
  593. id, _ := c.GetInt64("id")
  594. record_time := c.GetString("record_time")
  595. pay_way, _ := c.GetInt64("pay_way")
  596. pay_price, _ := c.GetFloat("pay_price")
  597. pay_card_no := c.GetString("pay_card_no")
  598. discount_price, _ := c.GetFloat("discount_price")
  599. preferential_price, _ := c.GetFloat("preferential_price")
  600. reality_price, _ := c.GetFloat("reality_price")
  601. found_price, _ := c.GetFloat("found_price")
  602. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  603. private_price, _ := c.GetFloat("private_price")
  604. timeLayout := "2006-01-02"
  605. loc, _ := time.LoadLocation("Local")
  606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  607. if err != nil {
  608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  609. return
  610. }
  611. recordDateTime := theTime.Unix()
  612. adminUser := c.GetAdminUserInfo()
  613. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  614. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  615. timestamp := time.Now().Unix()
  616. tempTime := time.Unix(timestamp, 0)
  617. timeFormat := tempTime.Format("20060102150405")
  618. chrgBchno := rand.Intn(100000) + 10000
  619. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  620. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  621. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  622. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  623. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  624. strconv.FormatInt(his.PatientId, 10)
  625. client := &http.Client{}
  626. data := make(map[string]interface{})
  627. data["psn_no"] = his.PsnNo
  628. data["mdtrt_id"] = his.Number
  629. data["pre"] = prescriptions
  630. data["chrg_bchno"] = chrg_bchno
  631. data["org_name"] = miConfig.OrgName
  632. data["doctor"] = patientPrescription.Doctor
  633. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  634. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  635. data["fixmedins_code"] = miConfig.Code
  636. data["dept_code"] = department.Number
  637. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  638. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  639. data["secret_key"] = miConfig.SecretKey
  640. fmt.Println(his.PsnNo)
  641. fmt.Println(his.Number)
  642. fmt.Println(miConfig.OrgName)
  643. fmt.Println(chrg_bchno)
  644. fmt.Println(patientPrescription.Doctor)
  645. fmt.Println(miConfig.Code)
  646. fmt.Println(department.Number)
  647. fmt.Println(strconv.FormatInt(patientPrescription.Departments, 10))
  648. fmt.Println(miConfig.InsuplcAdmdvs)
  649. fmt.Println(miConfig.MdtrtareaAdmvs)
  650. fmt.Println(miConfig.SecretKey)
  651. var ids []int64
  652. //var idsTwo []int64
  653. //
  654. for _, item := range prescriptions {
  655. ids = append(ids, item.ID)
  656. }
  657. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  658. if config.IsOpen == 1 { //对接了医保,走医保流程
  659. bytesData, _ := json.Marshal(data)
  660. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  661. resp, _ := client.Do(req)
  662. defer resp.Body.Close()
  663. body, ioErr := ioutil.ReadAll(resp.Body)
  664. if ioErr != nil {
  665. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  667. return
  668. }
  669. var respJSON map[string]interface{}
  670. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  671. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  673. return
  674. }
  675. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  676. userJSONBytes, _ := json.Marshal(respJSON)
  677. var res ResultFour
  678. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  679. utils.ErrorLog("解析失败:%v", err)
  680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  681. return
  682. }
  683. if res.Infcode == 0 {
  684. order := &models.HisOrder{
  685. UserOrgId: adminUser.CurrentOrgId,
  686. HisPatientId: his.ID,
  687. PatientId: his.PatientId,
  688. SettleAccountsDate: recordDateTime,
  689. Ctime: time.Now().Unix(),
  690. Mtime: time.Now().Unix(),
  691. Status: 1,
  692. Number: chrg_bchno,
  693. Infcode: res.Infcode,
  694. WarnMsg: res.WarnMsg,
  695. Cainfo: res.Cainfo,
  696. ErrMsg: res.ErrMsg,
  697. RespondTime: res.RefmsgTime,
  698. InfRefmsgid: res.InfRefmsgid,
  699. OrderStatus: 1,
  700. PayWay: pay_way,
  701. PayPrice: pay_price,
  702. PayCardNo: pay_card_no,
  703. DiscountPrice: discount_price,
  704. PreferentialPrice: preferential_price,
  705. RealityPrice: reality_price,
  706. FoundPrice: found_price,
  707. MedicalInsurancePrice: medical_insurance_price,
  708. PrivatePrice: private_price,
  709. IsMedicineInsurance: 1,
  710. }
  711. err = service.CreateOrder(order)
  712. if err != nil {
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  714. return
  715. }
  716. for _, item := range res.Output.Result {
  717. temp := strings.Split(item.FeedetlSn, "-")
  718. var advice_id int64 = 0
  719. var project_id int64 = 0
  720. var types int64 = 0
  721. id, _ := strconv.ParseInt(temp[2], 10, 64)
  722. types, _ = strconv.ParseInt(temp[1], 10, 64)
  723. if temp[1] == "1" {
  724. advice_id = id
  725. project_id = 0
  726. } else if temp[1] == "2" {
  727. advice_id = 0
  728. project_id = id
  729. }
  730. info := &models.HisOrderInfo{
  731. OrderNumber: order.Number,
  732. FeedetlSn: item.FeedetlSn,
  733. UploadDate: time.Now().Unix(),
  734. AdviceId: advice_id,
  735. DetItemFeeSumamt: item.DetItemFeeSumamt,
  736. Cnt: item.Cnt,
  737. Pric: float64(item.Pric),
  738. PatientId: his.PatientId,
  739. PricUplmtAmt: item.PricUplmtAmt,
  740. SelfpayProp: item.SelfpayProp,
  741. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  742. OverlmtAmt: item.OverlmtAmt,
  743. PreselfpayAmt: item.PreselfpayAmt,
  744. BasMednFlag: item.BasMednFlag,
  745. MedChrgitmType: item.MedChrgitmType,
  746. HiNegoDrugFlag: item.HiNegoDrugFlag,
  747. Status: 1,
  748. Memo: item.Memo,
  749. Mtime: time.Now().Unix(),
  750. InscpScpAmt: item.InscpScpAmt,
  751. DrtReimFlag: item.DrtReimFlag,
  752. Ctime: time.Now().Unix(),
  753. ListSpItemFlag: item.ListSpItemFlag,
  754. ChldMedcFlag: item.ChldMedcFlag,
  755. LmtUsedFlag: item.LmtUsedFlag,
  756. ChrgitmLv: item.ChrgitmLv,
  757. UserOrgId: adminUser.CurrentOrgId,
  758. HisPatientId: his.ID,
  759. OrderId: order.ID,
  760. ProjectId: project_id,
  761. Type: types,
  762. }
  763. service.CreateOrderInfo(info)
  764. }
  765. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  766. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  767. var total float64
  768. for _, item := range prescriptions {
  769. if item.Type == 1 { //药品
  770. for _, subItem := range item.HisDoctorAdviceInfo {
  771. total = total + (subItem.Price * subItem.PrescribingNumber)
  772. }
  773. }
  774. if item.Type == 2 { //项目
  775. for _, subItem := range item.HisPrescriptionProject {
  776. total = total + (subItem.Price * float64(subItem.Count))
  777. }
  778. }
  779. }
  780. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  781. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  782. allTotal := fmt.Sprintf("%.2f", total)
  783. if res.Infcode == 0 {
  784. var rf []*ResultFive
  785. json.Unmarshal([]byte(his.Iinfo), &rf)
  786. psn_no := his.PsnNo
  787. mdtrt_id := his.Number
  788. chrg_bchno := chrg_bchno
  789. cert_no := his.Certno
  790. insutype := rf[0].Insutype
  791. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  792. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  793. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  794. resp, requestErr := http.Get(api)
  795. if requestErr != nil {
  796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  797. return
  798. }
  799. defer resp.Body.Close()
  800. body, ioErr := ioutil.ReadAll(resp.Body)
  801. if ioErr != nil {
  802. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  804. return
  805. }
  806. var respJSON map[string]interface{}
  807. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  808. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  810. return
  811. }
  812. fmt.Println(respJSON)
  813. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  814. userJSONBytes, _ := json.Marshal(respJSON)
  815. var res ResultSeven
  816. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  817. utils.ErrorLog("解析失败:%v", err)
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  819. return
  820. }
  821. if res.Infcode == -1 {
  822. errlog := &models.HisOrderError{
  823. UserOrgId: adminUser.CurrentOrgId,
  824. Ctime: time.Now().Unix(),
  825. Mtime: time.Now().Unix(),
  826. Number: chrg_bchno,
  827. ErrMsg: res.ErrMsg,
  828. Status: 1,
  829. PatientId: id,
  830. RecordTime: recordDateTime,
  831. Stage: 7,
  832. }
  833. service.CreateErrMsgLog(errlog)
  834. } else {
  835. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  836. order.OrderStatus = 2
  837. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  838. order.SetlId = res.Output.Setlinfo.SetlID
  839. order.PsnNo = res.Output.Setlinfo.PsnNo
  840. order.PsnName = res.Output.Setlinfo.PsnName
  841. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  842. order.Certno = res.Output.Setlinfo.Certno
  843. order.Gend = res.Output.Setlinfo.Gend
  844. order.Naty = res.Output.Setlinfo.Naty
  845. order.Age = res.Output.Setlinfo.Age
  846. order.Insutype = res.Output.Setlinfo.Insutype
  847. order.PsnType = res.Output.Setlinfo.PsnType
  848. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  849. order.SetlTime = res.Output.Setlinfo.SetlTime
  850. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  851. order.MedType = res.Output.Setlinfo.MedType
  852. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  853. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  854. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  855. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  856. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  857. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  858. order.HifpPay = res.Output.Setlinfo.HifpPay
  859. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  860. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  861. order.HifesPay = res.Output.Setlinfo.HifesPay
  862. order.HifobPay = res.Output.Setlinfo.HifobPay
  863. order.MafPay = res.Output.Setlinfo.MafPay
  864. order.OthPay = res.Output.Setlinfo.OthPay
  865. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  866. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  867. order.AcctPay = res.Output.Setlinfo.AcctPay
  868. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  869. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  870. order.Balc = res.Output.Setlinfo.Balc
  871. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  872. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  873. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  874. order.ClrWay = res.Output.Setlinfo.ClrWay
  875. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  876. detailStr := string(setlDetail)
  877. order.SetlDetail = detailStr
  878. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  879. err = service.UpDateOrder(order)
  880. if err == nil {
  881. c.ServeSuccessJSON(map[string]interface{}{
  882. "msg": "结算成功",
  883. })
  884. }
  885. }
  886. } else {
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  888. return
  889. }
  890. } else {
  891. }
  892. } else {
  893. var total float64
  894. for _, item := range prescriptions {
  895. if item.Type == 1 { //药品
  896. for _, subItem := range item.HisDoctorAdviceInfo {
  897. total = total + (subItem.Price * subItem.PrescribingNumber)
  898. }
  899. }
  900. if item.Type == 2 { //项目
  901. for _, subItem := range item.HisPrescriptionProject {
  902. total = total + (subItem.Price * float64(subItem.Count))
  903. }
  904. }
  905. for _, subItem := range item.HisAdditionalCharge {
  906. total = total + (subItem.Price * float64(subItem.Count))
  907. }
  908. }
  909. allTotal := fmt.Sprintf("%.2f", total)
  910. totals, _ := strconv.ParseFloat(allTotal, 64)
  911. order := &models.HisOrder{
  912. UserOrgId: adminUser.CurrentOrgId,
  913. HisPatientId: his.ID,
  914. PatientId: id,
  915. SettleAccountsDate: recordDateTime,
  916. Ctime: time.Now().Unix(),
  917. Mtime: time.Now().Unix(),
  918. Status: 1,
  919. OrderStatus: 2,
  920. Number: chrg_bchno,
  921. MedfeeSumamt: totals,
  922. PayWay: pay_way,
  923. PayPrice: pay_price,
  924. PayCardNo: pay_card_no,
  925. DiscountPrice: discount_price,
  926. PreferentialPrice: preferential_price,
  927. RealityPrice: reality_price,
  928. FoundPrice: found_price,
  929. MedicalInsurancePrice: medical_insurance_price,
  930. PrivatePrice: private_price,
  931. }
  932. err = service.CreateOrder(order)
  933. if err != nil {
  934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  935. return
  936. }
  937. var customs []*Custom
  938. for _, item := range prescriptions {
  939. if item.Type == 1 { //药品
  940. for _, subItem := range item.HisDoctorAdviceInfo {
  941. cus := &Custom{
  942. AdviceId: subItem.ID,
  943. ProjectId: 0,
  944. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  945. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  946. FeedetlSn: subItem.FeedetlSn,
  947. Price: fmt.Sprintf("%.2f", subItem.Price),
  948. MedListCodg: subItem.MedListCodg,
  949. Type: 1,
  950. }
  951. customs = append(customs, cus)
  952. }
  953. }
  954. if item.Type == 2 { //项目
  955. for _, subItem := range item.HisPrescriptionProject {
  956. cus := &Custom{
  957. AdviceId: 0,
  958. ProjectId: subItem.ID,
  959. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  960. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  961. FeedetlSn: subItem.FeedetlSn,
  962. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  963. MedListCodg: subItem.MedListCodg,
  964. Type: 2,
  965. }
  966. customs = append(customs, cus)
  967. }
  968. }
  969. for _, item := range item.HisAdditionalCharge {
  970. cus := &Custom{
  971. ItemId: item.ID,
  972. AdviceId: 0,
  973. ProjectId: 0,
  974. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  975. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  976. FeedetlSn: item.FeedetlSn,
  977. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  978. MedListCodg: item.XtHisAddtionConfig.Code,
  979. Type: 3,
  980. }
  981. customs = append(customs, cus)
  982. }
  983. }
  984. for _, item := range customs {
  985. var advice_id int64 = 0
  986. var project_id int64 = 0
  987. var item_id int64 = 0
  988. var types int64 = 0
  989. if item.Type == 1 {
  990. advice_id = item.AdviceId
  991. project_id = 0
  992. item_id = 0
  993. } else if item.Type == 2 {
  994. advice_id = 0
  995. item_id = 0
  996. project_id = item.ProjectId
  997. } else if item.Type == 3 {
  998. advice_id = 0
  999. item_id = item.ItemId
  1000. project_id = 0
  1001. }
  1002. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1003. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1004. pric, _ := strconv.ParseFloat(item.Price, 32)
  1005. info := &models.HisOrderInfo{
  1006. OrderNumber: order.Number,
  1007. UploadDate: time.Now().Unix(),
  1008. AdviceId: advice_id,
  1009. DetItemFeeSumamt: detItemFeeSumamt,
  1010. Cnt: cut,
  1011. Pric: pric,
  1012. PatientId: id,
  1013. Status: 1,
  1014. Mtime: time.Now().Unix(),
  1015. Ctime: time.Now().Unix(),
  1016. UserOrgId: adminUser.CurrentOrgId,
  1017. HisPatientId: his.ID,
  1018. OrderId: order.ID,
  1019. ProjectId: project_id,
  1020. Type: types,
  1021. ItemId: item_id,
  1022. }
  1023. service.CreateOrderInfo(info)
  1024. }
  1025. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1026. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1027. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1028. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1029. if err == nil {
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "结算成功",
  1032. })
  1033. }
  1034. }
  1035. }
  1036. //退款
  1037. func (c *HisApiController) Refund() {
  1038. order_id, _ := c.GetInt64("order_id")
  1039. number := c.GetString("number")
  1040. record_time := c.GetString("record_time")
  1041. patient_id, _ := c.GetInt64("patient_id")
  1042. timeLayout := "2006-01-02"
  1043. loc, _ := time.LoadLocation("Local")
  1044. adminUser := c.GetAdminUserInfo()
  1045. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1046. fmt.Println(err)
  1047. if err != nil {
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1049. return
  1050. }
  1051. recordDateTime := theTime.Unix()
  1052. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1053. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1054. order, _ := service.GetHisOrderByID(order_id)
  1055. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1056. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1057. if config.IsOpen == 1 { //对接了医保,走医保流程
  1058. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1059. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1060. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1061. resp, requestErr := http.Get(api)
  1062. if requestErr != nil {
  1063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1064. return
  1065. }
  1066. body, ioErr := ioutil.ReadAll(resp.Body)
  1067. if ioErr != nil {
  1068. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1069. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1070. return
  1071. }
  1072. var respJSON map[string]interface{}
  1073. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1074. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1076. return
  1077. }
  1078. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1079. userJSONBytes, _ := json.Marshal(respJSON)
  1080. fmt.Println(respJSON)
  1081. fmt.Println(userJSONBytes)
  1082. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1083. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1084. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1085. resp2, requestErr2 := http.Get(api2)
  1086. if requestErr2 != nil {
  1087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1088. return
  1089. }
  1090. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1091. if ioErr2 != nil {
  1092. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1094. return
  1095. }
  1096. var respJSON2 map[string]interface{}
  1097. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1098. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1100. return
  1101. }
  1102. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1103. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1104. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1105. resp3, requestErr3 := http.Get(api3)
  1106. if requestErr3 != nil {
  1107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1108. return
  1109. }
  1110. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1111. if ioErr3 != nil {
  1112. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1114. return
  1115. }
  1116. var respJSON3 map[string]interface{}
  1117. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1118. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1120. return
  1121. }
  1122. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1123. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1124. if err == nil {
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "msg": "退费成功",
  1127. })
  1128. } else {
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1130. return
  1131. }
  1132. } else {
  1133. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1134. if err == nil {
  1135. c.ServeSuccessJSON(map[string]interface{}{
  1136. "msg": "退费成功",
  1137. })
  1138. } else {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1140. return
  1141. }
  1142. }
  1143. }
  1144. //对账
  1145. func (c *HisApiController) GetCheckAccount() {
  1146. start_time := c.GetString("start_time")
  1147. end_time := c.GetString("end_time")
  1148. insutype := c.GetString("insutype")
  1149. clr_type := c.GetString("clr_type")
  1150. adminUser := c.GetAdminUserInfo()
  1151. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1152. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1153. timeLayout := "2006-01-02"
  1154. loc, _ := time.LoadLocation("Local")
  1155. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1156. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1157. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1158. decimal.DivisionPrecision = 2
  1159. var medfee_sumamt float64
  1160. var acct_pay float64
  1161. var fund_pay_sumamt float64
  1162. fixmedins_setl_cnt := int64(len(orders))
  1163. for _, item := range orders {
  1164. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1165. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1166. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1167. }
  1168. var user_name string
  1169. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1170. if role.ID == 0 {
  1171. user_name = "xxx"
  1172. } else {
  1173. user_name = role.UserName
  1174. }
  1175. if config.IsOpen == 1 {
  1176. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1177. "insutype=" + insutype +
  1178. "&clr_type=" + clr_type +
  1179. "&setl_optins=" + miConfig.OrgName +
  1180. "&stmt_begndate=" + start_time +
  1181. "&stm_enddate=" + end_time +
  1182. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1183. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1184. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1185. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1186. "&fixmedins_code=" + miConfig.Code +
  1187. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1188. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1189. "&secret_key=" + miConfig.SecretKey +
  1190. "&org_name=" + miConfig.OrgName +
  1191. "&doctor=" + user_name
  1192. fmt.Println(api)
  1193. resp, requestErr := http.Get(api)
  1194. if requestErr != nil {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1196. return
  1197. }
  1198. body, ioErr := ioutil.ReadAll(resp.Body)
  1199. fmt.Println(body)
  1200. if ioErr != nil {
  1201. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1203. return
  1204. }
  1205. var respJSON map[string]interface{}
  1206. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1207. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1209. return
  1210. }
  1211. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1212. userJSONBytes, _ := json.Marshal(respJSON)
  1213. var res ResultEight
  1214. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1215. utils.ErrorLog("解析失败:%v", err)
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1217. return
  1218. }
  1219. if res.Infcode == 0 {
  1220. c.ServeSuccessJSON(map[string]interface{}{
  1221. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1222. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1223. })
  1224. } else {
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1226. }
  1227. }
  1228. }
  1229. //对账明细
  1230. func (c *HisApiController) GetCheckDetailAccount() {
  1231. start_time := c.GetString("start_time")
  1232. end_time := c.GetString("end_time")
  1233. adminUser := c.GetAdminUserInfo()
  1234. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1235. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1236. timeLayout := "2006-01-02"
  1237. loc, _ := time.LoadLocation("Local")
  1238. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1239. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1240. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1241. Mkdir(miConfig.OrgName)
  1242. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1243. file_name := file + ".txt"
  1244. zip_name := file + ".zip"
  1245. zip_path := miConfig.OrgName + "/" + zip_name
  1246. file_path := miConfig.OrgName + "/" + file_name
  1247. decimal.DivisionPrecision = 2
  1248. var medfee_sumamt float64
  1249. var psn_cash_pay float64
  1250. var fund_pay_sumamt float64
  1251. fixmedins_setl_cnt := int64(len(orders))
  1252. for _, item := range orders {
  1253. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1254. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1255. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1256. }
  1257. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1258. defer f.Close()
  1259. if err != nil {
  1260. fmt.Println(err.Error())
  1261. } else {
  1262. for _, item := range orders {
  1263. var refd_setl_flag string
  1264. if item.OrderStatus == 2 {
  1265. refd_setl_flag = "0"
  1266. }
  1267. if item.OrderStatus == 3 {
  1268. refd_setl_flag = "1"
  1269. }
  1270. var str string
  1271. str = item.SetlId + " " +
  1272. item.MdtrtId + " " +
  1273. item.PsnNo + " " +
  1274. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1275. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1276. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1277. _, err = f.Write([]byte(str))
  1278. }
  1279. }
  1280. Zip(file_path, zip_path)
  1281. fmt.Println(ReadFile(zip_path))
  1282. fmt.Println(string(ReadFile(zip_path)))
  1283. if config.IsOpen == 1 {
  1284. var user_name string
  1285. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1286. if role.ID == 0 {
  1287. user_name = "xxx"
  1288. } else {
  1289. user_name = role.UserName
  1290. }
  1291. baseParams := models.BaseParams{
  1292. SecretKey: miConfig.SecretKey,
  1293. FixmedinsCode: miConfig.Code,
  1294. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1295. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1296. OrgName: miConfig.OrgName,
  1297. Doctor: user_name,
  1298. }
  1299. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1300. var dat map[string]interface{}
  1301. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1302. fmt.Println(dat)
  1303. } else {
  1304. fmt.Println(err)
  1305. }
  1306. userJSONBytes, _ := json.Marshal(dat)
  1307. var res ResultNine
  1308. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1309. utils.ErrorLog("解析失败:%v", err)
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1311. return
  1312. }
  1313. if res.Infcode == 0 {
  1314. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1315. "file_qury_no=" + res.Output.FileQuryNo +
  1316. "&setl_optins=" + miConfig.OrgName +
  1317. "&stmt_begndate=" + start_time +
  1318. "&stm_enddate=" + end_time +
  1319. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1320. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1321. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1322. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1323. "&fixmedins_code=" + miConfig.Code +
  1324. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1325. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1326. "&secret_key=" + miConfig.SecretKey +
  1327. "&org_name=" + miConfig.OrgName +
  1328. "&doctor=" + user_name
  1329. resp, requestErr := http.Get(api)
  1330. if requestErr != nil {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1332. return
  1333. }
  1334. body, ioErr := ioutil.ReadAll(resp.Body)
  1335. if ioErr != nil {
  1336. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1338. return
  1339. }
  1340. var respJSON map[string]interface{}
  1341. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1342. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1344. return
  1345. }
  1346. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1347. userJSONBytes, _ := json.Marshal(respJSON)
  1348. var res ResultTen
  1349. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1350. utils.ErrorLog("解析失败:%v", err)
  1351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1352. return
  1353. }
  1354. if res.Infcode == 0 {
  1355. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1356. c.ServeSuccessJSON(map[string]interface{}{
  1357. "msg": "明细对账成功",
  1358. })
  1359. }
  1360. } else {
  1361. }
  1362. }
  1363. }
  1364. func (c *HisApiController) GetSettleAccounts() {
  1365. //id, _ := c.GetInt64("id")
  1366. //record_time := c.GetString("record_time")
  1367. order_id, _ := c.GetInt64("order_id")
  1368. //timeLayout := "2006-01-02"
  1369. //loc, _ := time.LoadLocation("Local")
  1370. //
  1371. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1372. //if err != nil {
  1373. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1374. // return
  1375. //}
  1376. //recordDateTime := theTime.Unix()
  1377. adminUser := c.GetAdminUserInfo()
  1378. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1379. order, _ := service.GetHisOrderByID(order_id)
  1380. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1381. var bedCostTotal float64 = 0 //床位总费
  1382. var bedCostSelfTotal float64 = 0 //床位自费
  1383. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1384. var operationCostTotal float64 = 0 //手术费
  1385. var operationCostSelfTotal float64 = 0 //手术费
  1386. var operationCostPartSelfTotal float64 = 0 //手术费
  1387. var otherCostTotal float64 = 0 //其他费用
  1388. var otherCostSelfTotal float64 = 0 //其他费用
  1389. var otherCostPartSelfTotal float64 = 0 //其他费用
  1390. var materialCostTotal float64 = 0 //材料费
  1391. var materialCostSelfTotal float64 = 0 //材料费
  1392. var materialCostPartSelfTotal float64 = 0 //材料费
  1393. var westernMedicineCostTotal float64 = 0 //西药费
  1394. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1395. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1396. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1397. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1398. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1399. var checkCostTotal float64 = 0 //检查费
  1400. var checkCostSelfTotal float64 = 0 //检查费
  1401. var checkCostPartSelfTotal float64 = 0 //检查费
  1402. var laboratoryCostTotal float64 = 0 //化验费
  1403. var laboratoryCostSelfTotal float64 = 0 //化验费
  1404. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1405. var treatCostTotal float64 = 0 //治疗费用
  1406. var treatCostSelfTotal float64 = 0 //治疗费用
  1407. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1408. decimal.DivisionPrecision = 2
  1409. for _, item := range orderInfos {
  1410. if item.MedChrgitmType == "01" { //床位费
  1411. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1412. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1413. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1414. }
  1415. if item.MedChrgitmType == "03" { //检查费
  1416. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1417. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1418. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1419. }
  1420. if item.MedChrgitmType == "04" { //化验费
  1421. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1422. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1423. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1424. }
  1425. if item.MedChrgitmType == "05" { //治疗费
  1426. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1427. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1428. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1429. }
  1430. if item.MedChrgitmType == "06" { //手术费
  1431. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1432. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1433. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1434. }
  1435. if item.MedChrgitmType == "08" { //材料费
  1436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1437. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1438. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1439. }
  1440. if item.MedChrgitmType == "09" { //西药费
  1441. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1442. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1443. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1444. }
  1445. if item.MedChrgitmType == "11" { //中成费
  1446. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1447. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1448. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1449. }
  1450. if item.MedChrgitmType == "14" { //其他费
  1451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1454. }
  1455. }
  1456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1457. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1458. var user_name string
  1459. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  1460. if role.ID == 0 {
  1461. user_name = "xxx"
  1462. } else {
  1463. user_name = role.UserName
  1464. }
  1465. baseParams := models.BaseParams{
  1466. SecretKey: miConfig.SecretKey,
  1467. FixmedinsCode: miConfig.Code,
  1468. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1469. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1470. OrgName: miConfig.OrgName,
  1471. Doctor: user_name,
  1472. }
  1473. businessParams := models.BusinessParams{
  1474. PsnNo: order.PsnNo,
  1475. MdtrtId: order.MdtrtId,
  1476. SetlId: order.SetlId,
  1477. }
  1478. if config.IsOpen == 1 {
  1479. result := service.Gdyb5203(baseParams, businessParams)
  1480. var dat map[string]interface{}
  1481. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1482. fmt.Println(dat)
  1483. } else {
  1484. fmt.Println(err)
  1485. }
  1486. userJSONBytes, _ := json.Marshal(dat)
  1487. var res ResultEleven
  1488. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1489. utils.ErrorLog("解析失败:%v", err)
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1491. return
  1492. }
  1493. if res.Infcode == 0 {
  1494. c.ServeSuccessJSON(map[string]interface{}{
  1495. "info": res.Output.Setlinfo,
  1496. "bedCostTotal": bedCostTotal,
  1497. "bedCostSelfTotal": bedCostSelfTotal,
  1498. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1499. "operationCostTotal": operationCostTotal,
  1500. "operationCostSelfTotal": operationCostSelfTotal,
  1501. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1502. "otherCostTotal": otherCostTotal,
  1503. "otherCostSelfTotal": otherCostSelfTotal,
  1504. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1505. "materialCostTotal": materialCostTotal,
  1506. "materialCostSelfTotal": materialCostSelfTotal,
  1507. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1508. "westernMedicineCostTotal": westernMedicineCostTotal,
  1509. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1510. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1511. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1512. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1513. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1514. "checkCostTotal": checkCostTotal,
  1515. "checkCostSelfTotal": checkCostSelfTotal,
  1516. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1517. "laboratoryCostTotal": laboratoryCostTotal,
  1518. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1519. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1520. "treatCostTotal": treatCostTotal,
  1521. "treatCostSelfTotal": treatCostSelfTotal,
  1522. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1523. })
  1524. }
  1525. }
  1526. }
  1527. func PathExists(path string) (bool, error) {
  1528. _, err := os.Stat(path)
  1529. if err == nil {
  1530. return true, nil
  1531. }
  1532. if os.IsNotExist(err) {
  1533. return false, nil
  1534. }
  1535. return false, err
  1536. }
  1537. //创建文件夹
  1538. func Mkdir(dir string) {
  1539. // 创建文件夹
  1540. exist, err := PathExists(dir)
  1541. if err != nil {
  1542. fmt.Println(err.Error())
  1543. } else {
  1544. if exist {
  1545. fmt.Println(dir + "文件夹已存在!")
  1546. } else {
  1547. // 文件夹名称,权限
  1548. err := os.Mkdir(dir, os.ModePerm)
  1549. if err != nil {
  1550. fmt.Println(dir+"文件夹创建失败:", err.Error())
  1551. } else {
  1552. fmt.Println(dir + "文件夹创建成功!")
  1553. }
  1554. }
  1555. }
  1556. }
  1557. //压缩文件
  1558. func Zip(srcFile string, destZip string) error {
  1559. zipfile, err := os.Create(destZip)
  1560. if err != nil {
  1561. return err
  1562. }
  1563. defer zipfile.Close()
  1564. archive := zip.NewWriter(zipfile)
  1565. defer archive.Close()
  1566. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  1567. if err != nil {
  1568. return err
  1569. }
  1570. header, err := zip.FileInfoHeader(info)
  1571. if err != nil {
  1572. return err
  1573. }
  1574. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  1575. // header.Name = path
  1576. if info.IsDir() {
  1577. header.Name += "/"
  1578. } else {
  1579. header.Method = zip.Deflate
  1580. }
  1581. writer, err := archive.CreateHeader(header)
  1582. if err != nil {
  1583. return err
  1584. }
  1585. if !info.IsDir() {
  1586. file, err := os.Open(path)
  1587. if err != nil {
  1588. return err
  1589. }
  1590. defer file.Close()
  1591. _, err = io.Copy(writer, file)
  1592. }
  1593. return err
  1594. })
  1595. return err
  1596. }
  1597. func ReadFile(filePath string) []byte {
  1598. f, err := os.Open(filePath)
  1599. if err != nil {
  1600. fmt.Println("read file fail", err)
  1601. return nil
  1602. }
  1603. defer f.Close()
  1604. fd, err := ioutil.ReadAll(f)
  1605. if err != nil {
  1606. fmt.Println("read to fd fail", err)
  1607. return nil
  1608. }
  1609. return fd
  1610. }