zh_his_api_controller.go 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. package zh
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/controllers"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "io/ioutil"
  13. "math"
  14. "math/rand"
  15. "net/http"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. type ZHHisApiController struct {
  21. controllers.BaseAuthAPIController
  22. }
  23. type ResultTwo struct {
  24. ErrMsg string `json:"err_msg"`
  25. InfRefmsgid string `json:"inf_refmsgid"`
  26. Infcode int64 `json:"infcode"`
  27. Output struct {
  28. Baseinfo struct {
  29. Age float64 `json:"age"`
  30. Brdy string `json:"brdy"`
  31. Certno string `json:"certno"`
  32. Gend string `json:"gend"`
  33. Naty string `json:"naty"`
  34. PsnCertType string `json:"psn_cert_type"`
  35. PsnName string `json:"psn_name"`
  36. PsnNo string `json:"psn_no"`
  37. } `json:"baseinfo"`
  38. Idetinfo []interface{} `json:"idetinfo"`
  39. Iinfo []struct {
  40. Balc float64 `json:"balc"`
  41. CvlservFlag string `json:"cvlserv_flag"`
  42. EmpName string `json:"emp_name"`
  43. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  44. Insutype string `json:"insutype"`
  45. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  46. PausInsuDate string `json:"paus_insu_date"`
  47. PsnInsuDate string `json:"psn_insu_date"`
  48. PsnInsuStas string `json:"psn_insu_stas"`
  49. PsnType string `json:"psn_type"`
  50. } `json:"insuinfo"`
  51. } `json:"output"`
  52. RefmsgTime string `json:"refmsg_time"`
  53. RespondTime string `json:"respond_time"`
  54. Signtype interface{} `json:"signtype"`
  55. WarnInfo interface{} `json:"warn_info"`
  56. }
  57. type ResultThree struct {
  58. Cainfo interface{} `json:"cainfo"`
  59. ErrMsg string `json:"err_msg"`
  60. InfRefmsgid string `json:"inf_refmsgid"`
  61. Infcode int64 `json:"infcode"`
  62. Output struct {
  63. Result struct {
  64. MdtrtID string `json:"mdtrt_id"`
  65. } `json:"result"`
  66. } `json:"output"`
  67. RefmsgTime string `json:"refmsg_time"`
  68. RespondTime string `json:"respond_time"`
  69. Signtype interface{} `json:"signtype"`
  70. WarnMsg interface{} `json:"warn_msg"`
  71. }
  72. type ResultFour struct {
  73. Cainfo string `json:"cainfo"`
  74. ErrMsg string `json:"err_msg"`
  75. InfRefmsgid string `json:"inf_refmsgid"`
  76. Infcode int64 `json:"infcode"`
  77. Output struct {
  78. Result []struct {
  79. BasMednFlag string `json:"bas_medn_flag"`
  80. ChldMedcFlag string `json:"chld_medc_flag"`
  81. ChrgitmLv string `json:"chrgitm_lv"`
  82. Cnt float64 `json:"cnt"`
  83. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  84. DrtReimFlag string `json:"drt_reim_flag"`
  85. FeedetlSn string `json:"feedetl_sn"`
  86. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  87. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  88. InscpScpAmt float64 `json:"inscp_scp_amt"`
  89. ListSpItemFlag string `json:"list_sp_item_flag"`
  90. LmtUsedFlag string `json:"lmt_used_flag"`
  91. MedChrgitmType string `json:"med_chrgitm_type"`
  92. Memo string `json:"memo"`
  93. OverlmtAmt float64 `json:"overlmt_amt"`
  94. PreselfpayAmt float64 `json:"preselfpay_amt"`
  95. Pric float64 `json:"pric"`
  96. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  97. SelfpayProp float64 `json:"selfpay_prop"`
  98. } `json:"result"`
  99. } `json:"output"`
  100. RefmsgTime string `json:"refmsg_time"`
  101. RespondTime string `json:"respond_time"`
  102. Signtype string `json:"signtype"`
  103. WarnMsg string `json:"warn_msg"`
  104. }
  105. type ResultFive struct {
  106. Balc float64 `json:"balc"`
  107. CvlservFlag string `json:"cvlserv_flag"`
  108. EmpName string `json:"emp_name"`
  109. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  110. Insutype string `json:"insutype"`
  111. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  112. PausInsuDate string `json:"paus_insu_date"`
  113. PsnInsuDate string `json:"psn_insu_date"`
  114. PsnInsuStas string `json:"psn_insu_stas"`
  115. PsnType string `json:"psn_type"`
  116. }
  117. type ResultSeven struct {
  118. Cainfo string `json:"cainfo"`
  119. ErrMsg string `json:"err_msg"`
  120. InfRefmsgid string `json:"inf_refmsgid"`
  121. Infcode int64 `json:"infcode"`
  122. Output struct {
  123. Setldetail []interface{} `json:"setldetail"`
  124. Setlinfo struct {
  125. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  126. AcctPay float64 `json:"acct_pay"`
  127. ActPayDedc float64 `json:"act_pay_dedc"`
  128. Age float64 `json:"age"`
  129. Balc float64 `json:"balc"`
  130. Brdy string `json:"brdy"`
  131. Certno string `json:"certno"`
  132. ClrOptins string `json:"clr_optins"`
  133. ClrType string `json:"clr_type"`
  134. ClrWay string `json:"clr_way"`
  135. CvlservFlag string `json:"cvlserv_flag"`
  136. CvlservPay float64 `json:"cvlserv_pay"`
  137. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  138. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  139. Gend string `json:"gend"`
  140. HifesPay float64 `json:"hifes_pay"`
  141. HifmiPay float64 `json:"hifmi_pay"`
  142. HifpPay float64 `json:"hifp_pay"`
  143. HospPartAmt float64 `json:"hosp_part_amt"`
  144. InscpScpAmt float64 `json:"inscp_scp_amt"`
  145. Insutype string `json:"insutype"`
  146. MafPay float64 `json:"maf_pay"`
  147. MdtrtCertType string `json:"mdtrt_cert_type"`
  148. HifobPay float64 `json:"hifob_pay"`
  149. MdtrtID string `json:"mdtrt_id"`
  150. MedType string `json:"med_type"`
  151. MedfeeSumamt float64 `json:"medfee_sumamt"`
  152. MedinsSetlID string `json:"medins_setl_id"`
  153. Naty string `json:"naty"`
  154. OthPay float64 `json:"oth_pay"`
  155. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  156. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  157. PreselfpayAmt float64 `json:"preselfpay_amt"`
  158. PsnCashPay float64 `json:"psn_cash_pay"`
  159. PsnCertType string `json:"psn_cert_type"`
  160. PsnName string `json:"psn_name"`
  161. PsnNo string `json:"psn_no"`
  162. PsnPartAmt float64 `json:"psn_part_amt"`
  163. PsnType string `json:"psn_type"`
  164. SetlID string `json:"setl_id"`
  165. SetlTime string `json:"setl_time"`
  166. } `json:"setlinfo"`
  167. } `json:"output"`
  168. RefmsgTime string `json:"refmsg_time"`
  169. RespondTime string `json:"respond_time"`
  170. Signtype interface{} `json:"signtype"`
  171. WarnMsg interface{} `json:"warn_msg"`
  172. }
  173. type ResultSixteen struct {
  174. Cainfo string `json:"cainfo"`
  175. ErrMsg string `json:"err_msg"`
  176. InfRefmsgid string `json:"inf_refmsgid"`
  177. Infcode int64 `json:"infcode"`
  178. Output struct {
  179. Setldetail []interface{} `json:"setldetail"`
  180. Setlinfo struct {
  181. MdtrtID string `json:"mdtrt_id"`
  182. SetlID string `json:"setl_id"`
  183. ClrOptins string `json:"clr_optins"`
  184. SetlTime string `json:"setl_time"`
  185. MedfeeSumamt float64 `json:"medfee_sumamt"`
  186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  187. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  188. PreselfpayAmt float64 `json:"preselfpay_amt"`
  189. InscpScpAmt float64 `json:"inscp_scp_amt"`
  190. ActPayDedc float64 `json:"act_pay_dedc"`
  191. HifpPay float64 `json:"hifp_pay"`
  192. PoolPropSe float64 `json:"pool_prop_selfpay"`
  193. Lfpay float64 `json:"selfpay"`
  194. CvlservPay float64 `json:"cvlserv_pay"`
  195. HifesPay float64 `json:"hifes_pay"`
  196. HifmiPay float64 `json:"hifmi_pay"`
  197. HifobPay float64 `json:"hifob_pay"`
  198. MafPay float64 `json:"maf_pay"`
  199. OthPay float64 `json:"oth_pay"`
  200. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  201. PsnPartAmt float64 `json:"psn_part_amt"`
  202. AcctPay float64 `json:"acct_pay"`
  203. Balc float64 `json:"balc"`
  204. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  205. HospPartAmt float64 `json:"hosp_part_amt"`
  206. MedinsSetlID string `json:"medins_setl_id"`
  207. PdnCashPay string `json:"pdn_cash_pay"`
  208. } `json:"setlinfo"`
  209. } `json:"output"`
  210. RefmsgTime string `json:"refmsg_time"`
  211. RespondTime string `json:"respond_time"`
  212. Signtype interface{} `json:"signtype"`
  213. WarnMsg interface{} `json:"warn_msg"`
  214. }
  215. type Custom struct {
  216. DetItemFeeSumamt string
  217. Cut string
  218. FeedetlSn string
  219. Price string
  220. MedListCodg string
  221. Type int64
  222. AdviceId int64
  223. ProjectId int64
  224. ItemId int64
  225. }
  226. type ResultEmpty struct {
  227. Cainfo interface{} `json:"cainfo"`
  228. ErrMsg string `json:"err_msg"`
  229. InfRefmsgid string `json:"inf_refmsgid"`
  230. Infcode int64 `json:"infcode"`
  231. Output struct {
  232. } `json:"output"`
  233. RefmsgTime string `json:"refmsg_time"`
  234. RespondTime string `json:"respond_time"`
  235. Signtype interface{} `json:"signtype"`
  236. WarnMsg interface{} `json:"warn_msg"`
  237. }
  238. type CustomResult struct {
  239. BasMednFlag string `json:"bas_medn_flag"`
  240. ChldMedcFlag string `json:"chld_medc_flag"`
  241. ChrgitmLv string `json:"chrgitm_lv"`
  242. Cnt float64 `json:"cnt"`
  243. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  244. DrtReimFlag string `json:"drt_reim_flag"`
  245. FeedetlSn string `json:"feedetl_sn"`
  246. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  247. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  248. InscpScpAmt float64 `json:"inscp_scp_amt"`
  249. ListSpItemFlag string `json:"list_sp_item_flag"`
  250. LmtUsedFlag string `json:"lmt_used_flag"`
  251. MedChrgitmType string `json:"med_chrgitm_type"`
  252. Memo string `json:"memo"`
  253. OverlmtAmt float64 `json:"overlmt_amt"`
  254. PreselfpayAmt float64 `json:"preselfpay_amt"`
  255. Pric float64 `json:"pric"`
  256. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  257. SelfpayProp float64 `json:"selfpay_prop"`
  258. }
  259. func ZHHisManagerApiRegistRouters() {
  260. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  261. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  262. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  263. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  264. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  265. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  266. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  267. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  268. }
  269. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  270. id, _ := c.GetInt64("id")
  271. record_time := c.GetString("record_time")
  272. name := c.GetString("name")
  273. phone := c.GetString("phone")
  274. id_card_type, _ := c.GetInt64("id_card_type")
  275. certificates, _ := c.GetInt64("certificates")
  276. id_card_no := c.GetString("id_card_no")
  277. doctor, _ := c.GetInt64("doctor")
  278. admin_user_id, _ := c.GetInt64("admin_user_id")
  279. department, _ := c.GetInt64("department")
  280. adm_bed, _ := c.GetInt64("adm_bed")
  281. diagnosis_ids := c.GetString("diagnosis")
  282. sick_type, _ := c.GetInt64("sick_type")
  283. start_time := c.GetString("start_time")
  284. //reg_type, _ := c.GetInt64("p_type")
  285. med_type, _ := c.GetInt64("med_type")
  286. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  287. timeLayout := "2006-01-02"
  288. loc, _ := time.LoadLocation("Local")
  289. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  290. if err != nil {
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  292. return
  293. }
  294. recordDateTime := theTime.Unix()
  295. adminInfo := c.GetAdminUserInfo()
  296. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  297. if record.ID != 0 {
  298. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  300. return
  301. }
  302. }
  303. var patient service.Patients
  304. if id == 0 {
  305. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  306. } else {
  307. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  308. }
  309. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  310. sickConfig, _ := service.FindSickById(sick_type)
  311. departmentInfo, _ := service.GetDepartMentDetail(department)
  312. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  313. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  314. result := service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", certificates)
  315. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  316. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  317. var dat map[string]interface{}
  318. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  319. fmt.Println(dat)
  320. } else {
  321. fmt.Println(err)
  322. }
  323. userJSONBytes, _ := json.Marshal(dat)
  324. var res2 ResultTwo
  325. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  326. utils.ErrorLog("解析失败:%v", err)
  327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  328. return
  329. }
  330. if res2.Infcode == 0 {
  331. var insutypes []string
  332. var insutype string
  333. var is390 int = 0
  334. var is310 int = 0
  335. for _, item := range res2.Output.Iinfo {
  336. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  337. insutypes = append(insutypes, item.Insutype)
  338. }
  339. }
  340. if len(insutypes) == 1 {
  341. insutype = insutypes[0]
  342. } else {
  343. for _, i := range insutypes {
  344. if i == "390" {
  345. is390 = 1
  346. }
  347. if i == "310" {
  348. is310 = 1
  349. }
  350. }
  351. }
  352. if is390 == 1 {
  353. insutype = "390"
  354. }
  355. if is310 == 1 {
  356. insutype = "310"
  357. }
  358. if len(insutypes) == 0 {
  359. insutype = "310"
  360. }
  361. timestamp := time.Now().Unix()
  362. tempTime := time.Unix(timestamp, 0)
  363. timeFormat := tempTime.Format("20060102150405")
  364. chrgBchno := rand.Intn(100000) + 10000
  365. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  366. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  367. var struct2401 service.Struct2401
  368. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  369. struct2401.Insutype = insutype
  370. struct2401.MdtrtCertType = "02"
  371. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  372. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  373. struct2401.IptNo = ipt_otp_no
  374. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  375. struct2401.ChfpdrName = doctorInfo.UserName
  376. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  377. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  378. struct2401.AdmDeptName = departmentInfo.Name
  379. struct2401.AdmBed = deviceNumber.Number
  380. struct2401.AdmBed = "待定"
  381. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  382. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  383. struct2401.Begntime = start_time
  384. struct2401.DiseCodg = sickConfig.CountryCode
  385. struct2401.DiseName = sickConfig.ClassName
  386. var dises []service.DiseinfoStruct
  387. for index, item := range diagnosisConfig {
  388. var dise service.DiseinfoStruct
  389. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  390. dise.DiagType = "1"
  391. if index == 0 {
  392. dise.MaindiagFlag = "1"
  393. } else {
  394. dise.MaindiagFlag = "2"
  395. }
  396. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  397. dise.DiseDorName = doctorInfo.UserName
  398. dise.DiagCode = item.CountryCode
  399. dise.DiagName = item.ClassName
  400. dise.DiagDept = departmentInfo.Name
  401. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  402. dise.DiagTime = timeFormatOne
  403. dises = append(dises, dise)
  404. }
  405. struct2401.Diseinfo = dises
  406. result := service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  407. var dat map[string]interface{}
  408. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  409. fmt.Println(dat)
  410. } else {
  411. fmt.Println(err)
  412. }
  413. userJSONBytes, _ := json.Marshal(dat)
  414. var res ResultThree
  415. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  416. utils.ErrorLog("解析失败:%v", err)
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  418. return
  419. }
  420. if res.Infcode == 0 {
  421. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  422. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  423. infoStr := string(Iinfos)
  424. idetinfoStr := string(Idetinfos)
  425. inHospital := &models.HisHospitalCheckRecord{
  426. PatientId: id,
  427. Name: name,
  428. MedicalTreatmentType: med_type,
  429. RecordDate: recordDateTime,
  430. IdCardNo: id_card_no,
  431. AdminUserId: admin_user_id,
  432. Departments: department,
  433. UserOrgId: adminInfo.CurrentOrgId,
  434. Status: 1,
  435. Ctime: time.Now().Unix(),
  436. Mtime: time.Now().Unix(),
  437. Number: res.Output.Result.MdtrtID,
  438. Doctor: doctor,
  439. PsnNo: res2.Output.Baseinfo.PsnNo,
  440. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  441. Certno: res2.Output.Baseinfo.Certno,
  442. PsnName: res2.Output.Baseinfo.PsnName,
  443. Gend: res2.Output.Baseinfo.Gend,
  444. Naty: res2.Output.Baseinfo.Naty,
  445. MedType: med_type,
  446. InsutypeType: insutype,
  447. Brdy: res2.Output.Baseinfo.Brdy,
  448. Iinfo: infoStr,
  449. Idetinfo: idetinfoStr,
  450. IptOtpNo: ipt_otp_no,
  451. AdmBed: adm_bed,
  452. IdCardType: id_card_type,
  453. Diagnosis: diagnosis_ids,
  454. SickType: sick_type,
  455. MdtrtCertType: "02",
  456. InHosptialTime: start_time,
  457. OutHosptialTime: "",
  458. InHospitalStatus: 1,
  459. Certificates: certificates,
  460. Phone: phone,
  461. }
  462. service.CreateHospitalRecord(inHospital)
  463. c.ServeSuccessJSON(map[string]interface{}{
  464. "msg": "办理入院成功",
  465. "info": inHospital,
  466. })
  467. } else {
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "failed_code": -10,
  470. "msg": res.ErrMsg,
  471. })
  472. }
  473. } else {
  474. c.ServeSuccessJSON(map[string]interface{}{
  475. "failed_code": -10,
  476. "msg": res2.ErrMsg,
  477. })
  478. return
  479. }
  480. }
  481. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  482. id, _ := this.GetInt64("id")
  483. patient_id, _ := this.GetInt64("patient_id")
  484. admin_user_id, _ := this.GetInt64("admin_user_id")
  485. //record_time := this.GetString("record_time")
  486. adminInfo := this.GetAdminUserInfo()
  487. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  488. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  489. record, _ := service.GetInHospitalRecord(id)
  490. if record.ID == 0 {
  491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  492. return
  493. }
  494. //timeLayout := "2006-01-02"
  495. //loc, _ := time.LoadLocation("Local")
  496. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  497. //if err != nil {
  498. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  499. // return
  500. //}
  501. //recordDateTime := theTime.Unix()
  502. var patient service.Patients
  503. if patient_id == 0 {
  504. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  505. } else {
  506. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  507. }
  508. fmt.Println(patient)
  509. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  510. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  511. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  512. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  513. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  514. sickConfig, _ := service.FindSickById(record.SickType)
  515. var struct2402 service.Struct2402
  516. timestamp := time.Now().Unix()
  517. tempTime := time.Unix(timestamp, 0)
  518. //timeFormat := tempTime.Format("20060102150405")
  519. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  520. struct2402.PsnNo = record.PsnNo
  521. struct2402.Insutype = record.InsutypeType
  522. struct2402.DscgWay = "1"
  523. struct2402.Endtime = timeFormatOne
  524. struct2402.DscgDeptName = departmentInfo.Number
  525. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  526. struct2402.MdtrtId = record.Number
  527. var dises []service.Diseinfo2402Struct
  528. for index, item := range diagnosisConfig {
  529. var dise service.Diseinfo2402Struct
  530. dise.PsnNo = record.PsnNo
  531. dise.DiagType = "1"
  532. if index == 0 {
  533. dise.MaindiagFlag = "1"
  534. } else {
  535. dise.MaindiagFlag = "2"
  536. }
  537. dise.MdtrtId = record.Number
  538. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  539. dise.DiseDorName = doctorInfo.UserName
  540. dise.DiagCode = item.CountryCode
  541. dise.DiagName = item.ClassName
  542. dise.DiagDept = departmentInfo.Name
  543. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  544. dise.DiagTime = timeFormatOne
  545. dises = append(dises, dise)
  546. }
  547. struct2402.Diseinfo = dises
  548. struct2402.DiseName = sickConfig.ClassName
  549. struct2402.DiseCode = sickConfig.CountryCode
  550. result := service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  551. var dat map[string]interface{}
  552. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  553. fmt.Println(dat)
  554. } else {
  555. fmt.Println(err)
  556. }
  557. userJSONBytes, _ := json.Marshal(dat)
  558. var res ResultEmpty
  559. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  560. utils.ErrorLog("解析失败:%v", err)
  561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  562. return
  563. }
  564. if res.Infcode == 0 {
  565. record.OutHospitalStatus = 1
  566. record.OutHosptialTime = struct2402.Endtime
  567. record.OutWay = 1
  568. service.CreateHospitalRecord(&record)
  569. this.ServeSuccessJSON(map[string]interface{}{
  570. "msg": "出院成功",
  571. })
  572. } else {
  573. this.ServeSuccessJSON(map[string]interface{}{
  574. "failed_code": -10,
  575. "msg": res.ErrMsg,
  576. })
  577. }
  578. }
  579. func (c *ZHHisApiController) GetSettleInfo() {
  580. order_id, _ := c.GetInt64("order_id")
  581. patient_id, _ := c.GetInt64("patient_id")
  582. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  583. admin_user_id, _ := c.GetInt64("admin_user_id")
  584. pay_way, _ := c.GetInt64("pay_way")
  585. pay_price, _ := c.GetFloat("pay_price")
  586. pay_card_no := c.GetString("pay_card_no")
  587. discount_price, _ := c.GetFloat("discount_price")
  588. preferential_price, _ := c.GetFloat("preferential_price")
  589. reality_price, _ := c.GetFloat("reality_price")
  590. found_price, _ := c.GetFloat("found_price")
  591. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  592. private_price, _ := c.GetFloat("private_price")
  593. fapiao_code := c.GetString("fapiao_code")
  594. fapiao_number := c.GetString("fapiao_number")
  595. order, _ := service.GetHisOrderByID(order_id)
  596. record, _ := service.GetInHospitalRecord(in_hospital_id)
  597. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  598. allTotal := fmt.Sprintf("%.2f", order.MedfeeSumamt)
  599. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  600. var rf []*ResultFive
  601. json.Unmarshal([]byte(record.Iinfo), &rf)
  602. chrg_bchno := order.Number
  603. cert_no := record.Certno
  604. var insutypes []string
  605. var insutype string
  606. var is390 int = 0
  607. var is310 int = 0
  608. if record.ID == 0 {
  609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  610. return
  611. }
  612. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  614. return
  615. }
  616. for _, item := range rf {
  617. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  618. insutypes = append(insutypes, item.Insutype)
  619. }
  620. }
  621. if len(insutypes) == 1 {
  622. insutype = insutypes[0]
  623. } else {
  624. for _, i := range insutypes {
  625. if i == "390" {
  626. is390 = 1
  627. }
  628. if i == "310" {
  629. is310 = 1
  630. }
  631. }
  632. }
  633. if is390 == 1 {
  634. insutype = "390"
  635. }
  636. if is310 == 1 {
  637. insutype = "310"
  638. }
  639. if len(insutypes) == 0 {
  640. insutype = "310"
  641. }
  642. if record.IdCardType == 1 {
  643. } else {
  644. cert_no = record.Certno
  645. }
  646. result, src_resquest := service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  647. var dat map[string]interface{}
  648. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  649. fmt.Println(dat)
  650. } else {
  651. fmt.Println(err)
  652. }
  653. userJSONBytes, _ := json.Marshal(dat)
  654. var res ResultSeven
  655. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  656. utils.ErrorLog("解析失败:%v", err)
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  658. return
  659. }
  660. if res.Infcode == -1 {
  661. errlog := &models.HisOrderError{
  662. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  663. Ctime: time.Now().Unix(),
  664. Mtime: time.Now().Unix(),
  665. Number: chrg_bchno,
  666. ErrMsg: res.ErrMsg,
  667. Status: 1,
  668. PatientId: patient_id,
  669. RecordTime: time.Now().Unix(),
  670. Stage: 6,
  671. }
  672. service.CreateErrMsgLog(errlog)
  673. c.ServeSuccessJSON(map[string]interface{}{
  674. "failed_code": -10,
  675. "msg": res.ErrMsg,
  676. })
  677. return
  678. } else {
  679. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  680. order.OrderStatus = 2
  681. order.DiscountPrice = discount_price
  682. order.MedicalInsurancePrice = medical_insurance_price
  683. order.FaPiaoNumber = fapiao_number
  684. order.FaPiaoCode = fapiao_code
  685. order.PayWay = pay_way
  686. order.PayPrice = pay_price
  687. order.PayCardNo = pay_card_no
  688. order.PreferentialPrice = preferential_price
  689. order.RealityPrice = reality_price
  690. order.FoundPrice = found_price
  691. order.PrivatePrice = private_price
  692. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  693. order.SetlId = res.Output.Setlinfo.SetlID
  694. order.PsnNo = res.Output.Setlinfo.PsnNo
  695. order.PsnName = res.Output.Setlinfo.PsnName
  696. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  697. order.Certno = res.Output.Setlinfo.Certno
  698. order.Gend = res.Output.Setlinfo.Gend
  699. order.Naty = res.Output.Setlinfo.Naty
  700. order.Age = res.Output.Setlinfo.Age
  701. order.Insutype = res.Output.Setlinfo.Insutype
  702. order.PsnType = res.Output.Setlinfo.PsnType
  703. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  704. order.SetlTime = res.Output.Setlinfo.SetlTime
  705. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  706. order.MedType = res.Output.Setlinfo.MedType
  707. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  708. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  709. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  710. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  711. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  712. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  713. order.HifpPay = res.Output.Setlinfo.HifpPay
  714. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  715. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  716. order.HifesPay = res.Output.Setlinfo.HifesPay
  717. order.HifobPay = res.Output.Setlinfo.HifobPay
  718. order.MafPay = res.Output.Setlinfo.MafPay
  719. order.OthPay = res.Output.Setlinfo.OthPay
  720. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  721. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  722. order.AcctPay = res.Output.Setlinfo.AcctPay
  723. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  724. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  725. order.Balc = res.Output.Setlinfo.Balc
  726. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  727. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  728. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  729. order.ClrWay = res.Output.Setlinfo.ClrWay
  730. order.Creator = order.Creator
  731. order.Modify = roles.AdminUserId
  732. order.RequestLog = src_resquest
  733. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  734. detailStr := string(setlDetail)
  735. order.SetlDetail = detailStr
  736. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  737. err = service.UpDateOrder(order)
  738. if err == nil {
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "msg": "结算成功",
  741. })
  742. } else {
  743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  744. return
  745. }
  746. }
  747. }
  748. func (c *ZHHisApiController) GetUploadInfo() {
  749. id, _ := c.GetInt64("id")
  750. record_time := c.GetString("record_time")
  751. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  752. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  753. admin_user_id, _ := c.GetInt64("admin_user_id")
  754. timeLayout := "2006-01-02"
  755. loc, _ := time.LoadLocation("Local")
  756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  757. if err != nil {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. recordDateTime := theTime.Unix()
  762. adminUser := c.GetAdminUserInfo()
  763. var prescriptions []*models.HisPrescription
  764. var start_time int64
  765. var end_time int64
  766. data := make(map[string]interface{})
  767. if settle_accounts_type == 1 { //日结
  768. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  769. } else { //月结
  770. start_time_str := c.GetString("start_time")
  771. end_time_str := c.GetString("end_time")
  772. timeLayout := "2006-01-02"
  773. loc, _ := time.LoadLocation("Local")
  774. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  775. if err != nil {
  776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  777. return
  778. }
  779. recordStartTime := theStartTime.Unix()
  780. start_time = recordStartTime
  781. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  782. if err != nil {
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. recordEndTime := theEndTime.Unix()
  787. end_time = recordEndTime
  788. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  789. }
  790. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  791. record, _ := service.GetInHospitalRecord(in_hospital_id)
  792. if record.ID == 0 {
  793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  794. return
  795. }
  796. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  797. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  798. // return
  799. //}
  800. timestamp := time.Now().Unix()
  801. tempTime := time.Unix(timestamp, 0)
  802. timeFormat := tempTime.Format("20060102150405")
  803. chrgBchno := rand.Intn(100000) + 10000
  804. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  805. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  806. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  807. department, _ := service.GetDepartMentDetail(record.Departments)
  808. strconv.FormatInt(record.PatientId, 10)
  809. client := &http.Client{}
  810. data["psn_no"] = record.PsnNo
  811. data["mdtrt_id"] = record.Number
  812. data["chrg_bchno"] = chrg_bchno
  813. data["org_name"] = miConfig.OrgName
  814. data["doctor"] = roles.UserName
  815. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  816. data["dept"] = strconv.FormatInt(department.ID, 10)
  817. data["fixmedins_code"] = miConfig.Code
  818. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  819. data["dept_code"] = "15"
  820. } else {
  821. data["dept_code"] = department.Number
  822. }
  823. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  824. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  825. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  826. data["secret_key"] = miConfig.SecretKey
  827. var ids []int64
  828. fmt.Println(data)
  829. for _, item := range prescriptions {
  830. ids = append(ids, item.ID)
  831. }
  832. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  833. if config.IsOpen == 1 { //对接了医保,走医保流程
  834. var pagesize int = 100
  835. var start int = 1
  836. var stop int
  837. var pagecount int
  838. var curpage int
  839. var isSuccess bool = true
  840. var customs []*models.NewCustom
  841. for _, item := range prescriptions {
  842. if item.Type == 1 { //药品
  843. for _, subItem := range item.HisDoctorAdviceInfo {
  844. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  845. //var randNum int
  846. //randNum = rand.Intn(10000) + 1000
  847. cus := &models.NewCustom{
  848. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  849. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  850. FeedetlSn: subItem.FeedetlSn,
  851. Price: fmt.Sprintf("%.2f", subItem.Price),
  852. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  853. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  854. }
  855. customs = append(customs, cus)
  856. }
  857. }
  858. }
  859. if item.Type == 2 { //项目
  860. for _, subItem := range item.HisPrescriptionProject {
  861. //var randNum int
  862. //randNum = rand.Intn(10000) + 1000
  863. if len(subItem.HisProject.MedicalCode) > 0 {
  864. cus := &models.NewCustom{
  865. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  866. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  867. FeedetlSn: subItem.FeedetlSn,
  868. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  869. MedListCodg: subItem.HisProject.MedicalCode,
  870. HospApprFlag: -1,
  871. }
  872. customs = append(customs, cus)
  873. }
  874. }
  875. }
  876. for _, subItem := range item.HisAdditionalCharge {
  877. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  878. cus := &models.NewCustom{
  879. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  880. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  881. FeedetlSn: subItem.FeedetlSn,
  882. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  883. MedListCodg: subItem.XtHisAddtionConfig.Code,
  884. HospApprFlag: -1,
  885. }
  886. customs = append(customs, cus)
  887. }
  888. }
  889. }
  890. //总页数,向上取整,注意除之前要先转换类型为float64
  891. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  892. var ress []*ResultFour
  893. for curpage = 1; curpage <= pagecount; curpage++ {
  894. if curpage == 1 {
  895. start = 1
  896. } else {
  897. start = (curpage-1)*pagesize + 1
  898. }
  899. stop = curpage * pagesize
  900. if stop > len(customs) {
  901. stop = len(customs)
  902. }
  903. data["pre"] = customs[start-1 : stop]
  904. bytesData, _ := json.Marshal(data)
  905. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
  906. resp, _ := client.Do(req)
  907. defer resp.Body.Close()
  908. body, ioErr := ioutil.ReadAll(resp.Body)
  909. if ioErr != nil {
  910. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  912. return
  913. }
  914. var respJSON map[string]interface{}
  915. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  916. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  918. return
  919. }
  920. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  921. userJSONBytes, _ := json.Marshal(respJSON)
  922. var res ResultFour
  923. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  924. utils.ErrorLog("解析失败:%v", err)
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  926. return
  927. }
  928. if res.Infcode == 0 {
  929. ress = append(ress, &res)
  930. } else {
  931. isSuccess = false
  932. errlog := &models.HisOrderError{
  933. UserOrgId: adminUser.CurrentOrgId,
  934. Ctime: time.Now().Unix(),
  935. Mtime: time.Now().Unix(),
  936. Number: chrg_bchno,
  937. ErrMsg: "",
  938. Status: 1,
  939. PatientId: id,
  940. RecordTime: recordDateTime,
  941. Stage: 4,
  942. }
  943. service.CreateErrMsgLog(errlog)
  944. c.ServeSuccessJSON(map[string]interface{}{
  945. "failed_code": -10,
  946. "msg": "上传明细错误,请联系his厂商",
  947. })
  948. return
  949. }
  950. }
  951. if isSuccess == true {
  952. var total float64
  953. for _, item := range prescriptions {
  954. if item.Type == 1 { //药品
  955. for _, subItem := range item.HisDoctorAdviceInfo {
  956. total = total + (subItem.Price * subItem.PrescribingNumber)
  957. }
  958. }
  959. if item.Type == 2 { //项目
  960. for _, subItem := range item.HisPrescriptionProject {
  961. total = total + (subItem.Price * float64(subItem.Count))
  962. }
  963. }
  964. }
  965. for _, item := range prescriptions {
  966. for _, subItem := range item.HisAdditionalCharge {
  967. total = total + (subItem.Price * float64(subItem.Count))
  968. }
  969. }
  970. allTotal := fmt.Sprintf("%.2f", total)
  971. totals, _ := strconv.ParseFloat(allTotal, 64)
  972. order := &models.HisOrder{
  973. UserOrgId: adminUser.CurrentOrgId,
  974. HisPatientId: record.ID,
  975. PatientId: record.PatientId,
  976. SettleAccountsDate: recordDateTime,
  977. Ctime: time.Now().Unix(),
  978. Mtime: time.Now().Unix(),
  979. Status: 1,
  980. Number: chrg_bchno,
  981. Infcode: 0,
  982. WarnMsg: "",
  983. Cainfo: "",
  984. ErrMsg: "",
  985. RespondTime: "",
  986. InfRefmsgid: "",
  987. OrderStatus: 1,
  988. MdtrtId: record.Number,
  989. IsMedicineInsurance: 1,
  990. SettleType: settle_accounts_type,
  991. SettleStartTime: start_time,
  992. SettleEndTime: end_time,
  993. Creator: roles.AdminUserId,
  994. Modify: roles.AdminUserId,
  995. PType: 1,
  996. MedfeeSumamt: totals,
  997. }
  998. err = service.CreateOrder(order)
  999. if err != nil {
  1000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1001. return
  1002. }
  1003. for _, subItem := range ress {
  1004. for _, item := range subItem.Output.Result {
  1005. temp := strings.Split(item.FeedetlSn, "-")
  1006. var advice_id int64 = 0
  1007. var project_id int64 = 0
  1008. var types int64 = 0
  1009. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1010. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1011. if temp[1] == "1" {
  1012. advice_id = id
  1013. project_id = 0
  1014. } else if temp[1] == "2" {
  1015. advice_id = 0
  1016. project_id = id
  1017. }
  1018. info := &models.HisOrderInfo{
  1019. OrderNumber: order.Number,
  1020. FeedetlSn: item.FeedetlSn,
  1021. UploadDate: time.Now().Unix(),
  1022. AdviceId: advice_id,
  1023. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1024. Cnt: item.Cnt,
  1025. Pric: float64(item.Pric),
  1026. PatientId: record.PatientId,
  1027. PricUplmtAmt: item.PricUplmtAmt,
  1028. SelfpayProp: item.SelfpayProp,
  1029. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1030. OverlmtAmt: item.OverlmtAmt,
  1031. PreselfpayAmt: item.PreselfpayAmt,
  1032. BasMednFlag: item.BasMednFlag,
  1033. MedChrgitmType: item.MedChrgitmType,
  1034. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1035. Status: 1,
  1036. Memo: item.Memo,
  1037. Mtime: time.Now().Unix(),
  1038. InscpScpAmt: item.InscpScpAmt,
  1039. DrtReimFlag: item.DrtReimFlag,
  1040. Ctime: time.Now().Unix(),
  1041. ListSpItemFlag: item.ListSpItemFlag,
  1042. ChldMedcFlag: item.ChldMedcFlag,
  1043. LmtUsedFlag: item.LmtUsedFlag,
  1044. ChrgitmLv: item.ChrgitmLv,
  1045. UserOrgId: adminUser.CurrentOrgId,
  1046. HisPatientId: record.ID,
  1047. OrderId: order.ID,
  1048. ProjectId: project_id,
  1049. Type: types,
  1050. }
  1051. service.CreateOrderInfo(info)
  1052. }
  1053. }
  1054. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1055. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1056. c.ServeSuccessJSON(map[string]interface{}{
  1057. "msg": "上传费用明细成功",
  1058. })
  1059. }
  1060. }
  1061. }
  1062. func (c *ZHHisApiController) ZHRefund() {
  1063. order_id, _ := c.GetInt64("order_id")
  1064. admin_user_id, _ := c.GetInt64("admin_user_id")
  1065. adminUser := c.GetAdminUserInfo()
  1066. var order models.HisOrder
  1067. order, _ = service.GetHisOrderByID(order_id)
  1068. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1069. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1070. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1071. if config.IsOpen == 1 { //对接了医保,走医保流程
  1072. result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1073. var dat map[string]interface{}
  1074. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1075. fmt.Println(dat)
  1076. } else {
  1077. fmt.Println(err)
  1078. }
  1079. userJSONBytes, _ := json.Marshal(dat)
  1080. var res ResultSixteen
  1081. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1082. utils.ErrorLog("解析失败:%v", err)
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1084. return
  1085. }
  1086. if res.Infcode == 0 {
  1087. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  1088. if err == nil {
  1089. c.ServeSuccessJSON(map[string]interface{}{
  1090. "msg": "退费成功",
  1091. })
  1092. } else {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1094. return
  1095. }
  1096. } else {
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "code": -10,
  1099. "msg": res.ErrMsg,
  1100. })
  1101. }
  1102. } else {
  1103. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1104. if err == nil {
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "msg": "退费成功",
  1107. })
  1108. } else {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1110. return
  1111. }
  1112. }
  1113. }
  1114. func (c *ZHHisApiController) ZHRefundDetail() {
  1115. order_id, _ := c.GetInt64("order_id")
  1116. admin_user_id, _ := c.GetInt64("admin_user_id")
  1117. adminUser := c.GetAdminUserInfo()
  1118. var order models.HisOrder
  1119. order, _ = service.GetHisOrderByID(order_id)
  1120. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1121. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1122. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1123. if config.IsOpen == 1 { //对接了医保,走医保流程
  1124. result := service.Gdyb2302(order.PsnNo, order.MdtrtId, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1125. var dat map[string]interface{}
  1126. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1127. fmt.Println(dat)
  1128. } else {
  1129. fmt.Println(err)
  1130. }
  1131. userJSONBytes, _ := json.Marshal(dat)
  1132. var res2 ResultEmpty
  1133. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1134. utils.ErrorLog("解析失败:%v", err)
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1136. return
  1137. }
  1138. if res2.Infcode == 0 {
  1139. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  1140. if err == nil {
  1141. c.ServeSuccessJSON(map[string]interface{}{
  1142. "msg": "退费成功",
  1143. })
  1144. } else {
  1145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1146. return
  1147. }
  1148. } else {
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "code": -10,
  1151. "msg": res2.ErrMsg,
  1152. })
  1153. }
  1154. } else {
  1155. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1156. if err == nil {
  1157. c.ServeSuccessJSON(map[string]interface{}{
  1158. "msg": "退费成功",
  1159. })
  1160. } else {
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1162. return
  1163. }
  1164. }
  1165. }
  1166. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  1167. id, _ := this.GetInt64("id")
  1168. admin_user_id, _ := this.GetInt64("admin_user_id")
  1169. adminInfo := this.GetAdminUserInfo()
  1170. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1171. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1172. record, _ := service.GetInHospitalRecord(id)
  1173. if record.ID == 0 {
  1174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1175. return
  1176. }
  1177. result := service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1178. var dat map[string]interface{}
  1179. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1180. fmt.Println(dat)
  1181. } else {
  1182. fmt.Println(err)
  1183. }
  1184. userJSONBytes, _ := json.Marshal(dat)
  1185. var res ResultEmpty
  1186. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1187. utils.ErrorLog("解析失败:%v", err)
  1188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1189. return
  1190. }
  1191. if res.Infcode == 0 {
  1192. record.OutHospitalStatus = 0
  1193. service.CreateHospitalRecord(&record)
  1194. this.ServeSuccessJSON(map[string]interface{}{
  1195. "msg": "撤销出院成功",
  1196. })
  1197. } else {
  1198. this.ServeSuccessJSON(map[string]interface{}{
  1199. "failed_code": -10,
  1200. "msg": res.ErrMsg,
  1201. })
  1202. }
  1203. }
  1204. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  1205. id, _ := this.GetInt64("id")
  1206. admin_user_id, _ := this.GetInt64("admin_user_id")
  1207. adminInfo := this.GetAdminUserInfo()
  1208. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1209. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1210. record, _ := service.GetInHospitalRecord(id)
  1211. if record.ID == 0 {
  1212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1213. return
  1214. }
  1215. result := service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1216. var dat map[string]interface{}
  1217. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1218. fmt.Println(dat)
  1219. } else {
  1220. fmt.Println(err)
  1221. }
  1222. userJSONBytes, _ := json.Marshal(dat)
  1223. var res ResultEmpty
  1224. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1225. utils.ErrorLog("解析失败:%v", err)
  1226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1227. return
  1228. }
  1229. if res.Infcode == 0 {
  1230. record.Status = 0
  1231. service.CreateHospitalRecord(&record)
  1232. this.ServeSuccessJSON(map[string]interface{}{
  1233. "msg": "撤销入院成功",
  1234. })
  1235. } else {
  1236. this.ServeSuccessJSON(map[string]interface{}{
  1237. "failed_code": -10,
  1238. "msg": res.ErrMsg,
  1239. })
  1240. }
  1241. }