his_api_controller.go 73KB

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