zh_his_api_controller.go 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  285. //reg_type, _ := c.GetInt64("p_type")
  286. med_type, _ := c.GetInt64("med_type")
  287. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  288. timeLayout := "2006-01-02"
  289. loc, _ := time.LoadLocation("Local")
  290. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  291. if err != nil {
  292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  293. return
  294. }
  295. recordDateTime := theTime.Unix()
  296. adminInfo := c.GetAdminUserInfo()
  297. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  298. if record.ID != 0 {
  299. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  301. return
  302. }
  303. }
  304. var patient service.Patients
  305. if id == 0 {
  306. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  307. } else {
  308. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  309. }
  310. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  311. sickConfig, _ := service.FindSickById(sick_type)
  312. departmentInfo, _ := service.GetDepartMentDetail(department)
  313. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  314. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  315. result := service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", certificates)
  316. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  317. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  318. var dat map[string]interface{}
  319. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  320. fmt.Println(dat)
  321. } else {
  322. fmt.Println(err)
  323. }
  324. userJSONBytes, _ := json.Marshal(dat)
  325. var res2 ResultTwo
  326. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  327. utils.ErrorLog("解析失败:%v", err)
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  329. return
  330. }
  331. if res2.Infcode == 0 {
  332. var insutypes []string
  333. var insutype string
  334. var is390 int = 0
  335. var is310 int = 0
  336. for _, item := range res2.Output.Iinfo {
  337. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  338. insutypes = append(insutypes, item.Insutype)
  339. }
  340. }
  341. if len(insutypes) == 1 {
  342. insutype = insutypes[0]
  343. } else {
  344. for _, i := range insutypes {
  345. if i == "390" {
  346. is390 = 1
  347. }
  348. if i == "310" {
  349. is310 = 1
  350. }
  351. }
  352. }
  353. if is390 == 1 {
  354. insutype = "390"
  355. }
  356. if is310 == 1 {
  357. insutype = "310"
  358. }
  359. if len(insutypes) == 0 {
  360. insutype = "310"
  361. }
  362. timestamp := time.Now().Unix()
  363. tempTime := time.Unix(timestamp, 0)
  364. timeFormat := tempTime.Format("20060102150405")
  365. chrgBchno := rand.Intn(100000) + 10000
  366. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  367. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  368. var struct2401 service.Struct2401
  369. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  370. struct2401.Insutype = insutype
  371. struct2401.MdtrtCertType = "02"
  372. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  373. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  374. struct2401.IptNo = ipt_otp_no
  375. struct2401.AtddrNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  376. struct2401.ChfpdrName = doctorInfo.UserName
  377. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  378. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  379. struct2401.AdmDeptName = departmentInfo.Name
  380. struct2401.AdmBed = deviceNumber.Number
  381. struct2401.AdmBed = "待定"
  382. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  383. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  384. struct2401.Begntime = start_time
  385. struct2401.DiseCodg = sickConfig.CountryCode
  386. struct2401.DiseName = sickConfig.ClassName
  387. var dises []service.DiseinfoStruct
  388. for index, item := range diagnosisConfig {
  389. var dise service.DiseinfoStruct
  390. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  391. dise.DiagType = "1"
  392. if index == 0 {
  393. dise.MaindiagFlag = "1"
  394. } else {
  395. dise.MaindiagFlag = "2"
  396. }
  397. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  398. dise.DiseDorName = doctorInfo.UserName
  399. dise.DiagCode = item.CountryCode
  400. dise.DiagName = item.ClassName
  401. dise.DiagDept = departmentInfo.Name
  402. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  403. dise.DiagTime = timeFormatOne
  404. dises = append(dises, dise)
  405. }
  406. struct2401.Diseinfo = dises
  407. result := service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  408. var dat map[string]interface{}
  409. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  410. fmt.Println(dat)
  411. } else {
  412. fmt.Println(err)
  413. }
  414. userJSONBytes, _ := json.Marshal(dat)
  415. var res ResultThree
  416. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  417. utils.ErrorLog("解析失败:%v", err)
  418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. return
  420. }
  421. if res.Infcode == 0 {
  422. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  423. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  424. infoStr := string(Iinfos)
  425. idetinfoStr := string(Idetinfos)
  426. inHospital := &models.HisHospitalCheckRecord{
  427. PatientId: id,
  428. Name: name,
  429. MedicalTreatmentType: med_type,
  430. RecordDate: recordDateTime,
  431. IdCardNo: id_card_no,
  432. AdminUserId: admin_user_id,
  433. Departments: department,
  434. UserOrgId: adminInfo.CurrentOrgId,
  435. Status: 1,
  436. Ctime: time.Now().Unix(),
  437. Mtime: time.Now().Unix(),
  438. Number: res.Output.Result.MdtrtID,
  439. Doctor: doctor,
  440. PsnNo: res2.Output.Baseinfo.PsnNo,
  441. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  442. Certno: res2.Output.Baseinfo.Certno,
  443. PsnName: res2.Output.Baseinfo.PsnName,
  444. Gend: res2.Output.Baseinfo.Gend,
  445. Naty: res2.Output.Baseinfo.Naty,
  446. MedType: med_type,
  447. InsutypeType: insutype,
  448. Brdy: res2.Output.Baseinfo.Brdy,
  449. Iinfo: infoStr,
  450. Idetinfo: idetinfoStr,
  451. IptOtpNo: ipt_otp_no,
  452. AdmBed: adm_bed,
  453. IdCardType: id_card_type,
  454. Diagnosis: diagnosis_ids,
  455. SickType: sick_type,
  456. MdtrtCertType: "02",
  457. InHosptialTime: start_time,
  458. OutHosptialTime: "",
  459. InHospitalStatus: 1,
  460. Certificates: certificates,
  461. Phone: phone,
  462. BalanceAccountsType: balance_accounts_type,
  463. }
  464. service.CreateHospitalRecord(inHospital)
  465. c.ServeSuccessJSON(map[string]interface{}{
  466. "msg": "办理入院成功",
  467. "info": inHospital,
  468. })
  469. } else {
  470. c.ServeSuccessJSON(map[string]interface{}{
  471. "failed_code": -10,
  472. "msg": res.ErrMsg,
  473. })
  474. }
  475. } else {
  476. c.ServeSuccessJSON(map[string]interface{}{
  477. "failed_code": -10,
  478. "msg": res2.ErrMsg,
  479. })
  480. return
  481. }
  482. }
  483. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  484. id, _ := this.GetInt64("id")
  485. patient_id, _ := this.GetInt64("patient_id")
  486. admin_user_id, _ := this.GetInt64("admin_user_id")
  487. //record_time := this.GetString("record_time")
  488. adminInfo := this.GetAdminUserInfo()
  489. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  490. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  491. record, _ := service.GetInHospitalRecord(id)
  492. if record.ID == 0 {
  493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  494. return
  495. }
  496. //timeLayout := "2006-01-02"
  497. //loc, _ := time.LoadLocation("Local")
  498. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  499. //if err != nil {
  500. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  501. // return
  502. //}
  503. //recordDateTime := theTime.Unix()
  504. var patient service.Patients
  505. if patient_id == 0 {
  506. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  507. } else {
  508. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  509. }
  510. fmt.Println(patient)
  511. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  512. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  513. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  514. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  515. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  516. sickConfig, _ := service.FindSickById(record.SickType)
  517. var struct2402 service.Struct2402
  518. timestamp := time.Now().Unix()
  519. tempTime := time.Unix(timestamp, 0)
  520. //timeFormat := tempTime.Format("20060102150405")
  521. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  522. struct2402.PsnNo = record.PsnNo
  523. struct2402.Insutype = record.InsutypeType
  524. struct2402.DscgWay = "1"
  525. struct2402.Endtime = timeFormatOne
  526. struct2402.DscgDeptName = departmentInfo.Number
  527. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  528. struct2402.MdtrtId = record.Number
  529. var dises []service.Diseinfo2402Struct
  530. for index, item := range diagnosisConfig {
  531. var dise service.Diseinfo2402Struct
  532. dise.PsnNo = record.PsnNo
  533. dise.DiagType = "1"
  534. if index == 0 {
  535. dise.MaindiagFlag = "1"
  536. } else {
  537. dise.MaindiagFlag = "2"
  538. }
  539. dise.MdtrtId = record.Number
  540. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  541. dise.DiseDorName = doctorInfo.UserName
  542. dise.DiagCode = item.CountryCode
  543. dise.DiagName = item.ClassName
  544. dise.DiagDept = departmentInfo.Name
  545. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  546. dise.DiagTime = timeFormatOne
  547. dises = append(dises, dise)
  548. }
  549. struct2402.Diseinfo = dises
  550. struct2402.DiseName = sickConfig.ClassName
  551. struct2402.DiseCode = sickConfig.CountryCode
  552. result := service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  553. var dat map[string]interface{}
  554. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  555. fmt.Println(dat)
  556. } else {
  557. fmt.Println(err)
  558. }
  559. userJSONBytes, _ := json.Marshal(dat)
  560. var res ResultEmpty
  561. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  562. utils.ErrorLog("解析失败:%v", err)
  563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  564. return
  565. }
  566. if res.Infcode == 0 {
  567. record.OutHospitalStatus = 1
  568. record.OutHosptialTime = struct2402.Endtime
  569. record.OutWay = 1
  570. service.CreateHospitalRecord(&record)
  571. this.ServeSuccessJSON(map[string]interface{}{
  572. "msg": "出院成功",
  573. })
  574. } else {
  575. this.ServeSuccessJSON(map[string]interface{}{
  576. "failed_code": -10,
  577. "msg": res.ErrMsg,
  578. })
  579. }
  580. }
  581. func (c *ZHHisApiController) GetSettleInfo() {
  582. order_id, _ := c.GetInt64("order_id")
  583. patient_id, _ := c.GetInt64("patient_id")
  584. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  585. admin_user_id, _ := c.GetInt64("admin_user_id")
  586. pay_way, _ := c.GetInt64("pay_way")
  587. pay_price, _ := c.GetFloat("pay_price")
  588. pay_card_no := c.GetString("pay_card_no")
  589. discount_price, _ := c.GetFloat("discount_price")
  590. preferential_price, _ := c.GetFloat("preferential_price")
  591. reality_price, _ := c.GetFloat("reality_price")
  592. found_price, _ := c.GetFloat("found_price")
  593. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  594. private_price, _ := c.GetFloat("private_price")
  595. fapiao_code := c.GetString("fapiao_code")
  596. fapiao_number := c.GetString("fapiao_number")
  597. order, _ := service.GetHisOrderByID(order_id)
  598. record, _ := service.GetInHospitalRecord(in_hospital_id)
  599. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  600. allTotal := fmt.Sprintf("%.2f", order.MedfeeSumamt)
  601. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  602. var rf []*ResultFive
  603. json.Unmarshal([]byte(record.Iinfo), &rf)
  604. chrg_bchno := order.Number
  605. cert_no := record.Certno
  606. var insutypes []string
  607. var insutype string
  608. var is390 int = 0
  609. var is310 int = 0
  610. if record.ID == 0 {
  611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  612. return
  613. }
  614. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  616. return
  617. }
  618. for _, item := range rf {
  619. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  620. insutypes = append(insutypes, item.Insutype)
  621. }
  622. }
  623. if len(insutypes) == 1 {
  624. insutype = insutypes[0]
  625. } else {
  626. for _, i := range insutypes {
  627. if i == "390" {
  628. is390 = 1
  629. }
  630. if i == "310" {
  631. is310 = 1
  632. }
  633. }
  634. }
  635. if is390 == 1 {
  636. insutype = "390"
  637. }
  638. if is310 == 1 {
  639. insutype = "310"
  640. }
  641. if len(insutypes) == 0 {
  642. insutype = "310"
  643. }
  644. if record.IdCardType == 1 {
  645. } else {
  646. cert_no = record.Certno
  647. }
  648. 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)
  649. var dat map[string]interface{}
  650. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  651. fmt.Println(dat)
  652. } else {
  653. fmt.Println(err)
  654. }
  655. userJSONBytes, _ := json.Marshal(dat)
  656. var res ResultSeven
  657. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  658. utils.ErrorLog("解析失败:%v", err)
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  660. return
  661. }
  662. if res.Infcode != 0 {
  663. errlog := &models.HisOrderError{
  664. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  665. Ctime: time.Now().Unix(),
  666. Mtime: time.Now().Unix(),
  667. Number: chrg_bchno,
  668. ErrMsg: res.ErrMsg,
  669. Status: 1,
  670. PatientId: patient_id,
  671. RecordTime: time.Now().Unix(),
  672. Stage: 6,
  673. }
  674. service.CreateErrMsgLog(errlog)
  675. c.ServeSuccessJSON(map[string]interface{}{
  676. "failed_code": -10,
  677. "msg": res.ErrMsg,
  678. })
  679. return
  680. } else {
  681. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  682. order.OrderStatus = 2
  683. order.DiscountPrice = discount_price
  684. order.MedicalInsurancePrice = medical_insurance_price
  685. order.FaPiaoNumber = fapiao_number
  686. order.FaPiaoCode = fapiao_code
  687. order.PayWay = pay_way
  688. order.PayPrice = pay_price
  689. order.PayCardNo = pay_card_no
  690. order.PreferentialPrice = preferential_price
  691. order.RealityPrice = reality_price
  692. order.FoundPrice = found_price
  693. order.PrivatePrice = private_price
  694. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  695. order.SetlId = res.Output.Setlinfo.SetlID
  696. order.PsnNo = res.Output.Setlinfo.PsnNo
  697. order.PsnName = res.Output.Setlinfo.PsnName
  698. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  699. order.Certno = res.Output.Setlinfo.Certno
  700. order.Gend = res.Output.Setlinfo.Gend
  701. order.Naty = res.Output.Setlinfo.Naty
  702. order.Age = res.Output.Setlinfo.Age
  703. order.Insutype = res.Output.Setlinfo.Insutype
  704. order.PsnType = res.Output.Setlinfo.PsnType
  705. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  706. order.SetlTime = res.Output.Setlinfo.SetlTime
  707. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  708. order.MedType = res.Output.Setlinfo.MedType
  709. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  710. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  711. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  712. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  713. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  714. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  715. order.HifpPay = res.Output.Setlinfo.HifpPay
  716. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  717. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  718. order.HifesPay = res.Output.Setlinfo.HifesPay
  719. order.HifobPay = res.Output.Setlinfo.HifobPay
  720. order.MafPay = res.Output.Setlinfo.MafPay
  721. order.OthPay = res.Output.Setlinfo.OthPay
  722. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  723. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  724. order.AcctPay = res.Output.Setlinfo.AcctPay
  725. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  726. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  727. order.Balc = res.Output.Setlinfo.Balc
  728. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  729. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  730. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  731. order.ClrWay = res.Output.Setlinfo.ClrWay
  732. order.Creator = order.Creator
  733. order.Modify = roles.AdminUserId
  734. order.RequestLog = src_resquest
  735. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  736. detailStr := string(setlDetail)
  737. order.SetlDetail = detailStr
  738. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  739. err = service.UpDateOrder(order)
  740. if err == nil {
  741. c.ServeSuccessJSON(map[string]interface{}{
  742. "msg": "结算成功",
  743. })
  744. } else {
  745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  746. return
  747. }
  748. }
  749. }
  750. func (c *ZHHisApiController) GetUploadInfo() {
  751. id, _ := c.GetInt64("id")
  752. record_time := c.GetString("record_time")
  753. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  754. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  755. admin_user_id, _ := c.GetInt64("admin_user_id")
  756. timeLayout := "2006-01-02"
  757. loc, _ := time.LoadLocation("Local")
  758. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  759. if err != nil {
  760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  761. return
  762. }
  763. recordDateTime := theTime.Unix()
  764. adminUser := c.GetAdminUserInfo()
  765. var prescriptions []*models.HisPrescription
  766. var start_time int64
  767. var end_time int64
  768. data := make(map[string]interface{})
  769. if settle_accounts_type == 1 { //日结
  770. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  771. } else { //月结
  772. start_time_str := c.GetString("start_time")
  773. end_time_str := c.GetString("end_time")
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. recordStartTime := theStartTime.Unix()
  782. start_time = recordStartTime
  783. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  784. if err != nil {
  785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  786. return
  787. }
  788. recordEndTime := theEndTime.Unix()
  789. end_time = recordEndTime
  790. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  791. }
  792. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  793. record, _ := service.GetInHospitalRecord(in_hospital_id)
  794. if record.ID == 0 {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  796. return
  797. }
  798. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  800. // return
  801. //}
  802. timestamp := time.Now().Unix()
  803. tempTime := time.Unix(timestamp, 0)
  804. timeFormat := tempTime.Format("20060102150405")
  805. chrgBchno := rand.Intn(100000) + 10000
  806. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  807. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  808. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  809. department, _ := service.GetDepartMentDetail(record.Departments)
  810. strconv.FormatInt(record.PatientId, 10)
  811. client := &http.Client{}
  812. data["psn_no"] = record.PsnNo
  813. data["mdtrt_id"] = record.Number
  814. data["chrg_bchno"] = chrg_bchno
  815. data["org_name"] = miConfig.OrgName
  816. data["doctor"] = roles.UserName
  817. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  818. data["dept"] = strconv.FormatInt(department.ID, 10)
  819. data["fixmedins_code"] = miConfig.Code
  820. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  821. data["dept_code"] = "15"
  822. } else {
  823. data["dept_code"] = department.Number
  824. }
  825. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  826. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  827. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  828. data["secret_key"] = miConfig.SecretKey
  829. var ids []int64
  830. fmt.Println(data)
  831. for _, item := range prescriptions {
  832. ids = append(ids, item.ID)
  833. }
  834. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  835. if config.IsOpen == 1 { //对接了医保,走医保流程
  836. var pagesize int = 100
  837. var start int = 1
  838. var stop int
  839. var pagecount int
  840. var curpage int
  841. var isSuccess bool = true
  842. var customs []*models.NewCustom
  843. for _, item := range prescriptions {
  844. if item.Type == 1 { //药品
  845. for _, subItem := range item.HisDoctorAdviceInfo {
  846. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 {
  847. //var randNum int
  848. //randNum = rand.Intn(10000) + 1000
  849. cus := &models.NewCustom{
  850. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  851. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  852. FeedetlSn: subItem.FeedetlSn,
  853. Price: fmt.Sprintf("%.2f", subItem.Price),
  854. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  855. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  856. }
  857. customs = append(customs, cus)
  858. }
  859. }
  860. }
  861. if item.Type == 2 { //项目
  862. for _, subItem := range item.HisPrescriptionProject {
  863. //var randNum int
  864. //randNum = rand.Intn(10000) + 1000
  865. if subItem.Type == 2 {
  866. if len(subItem.HisProject.MedicalCode) > 0 {
  867. cus := &models.NewCustom{
  868. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  869. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  870. FeedetlSn: subItem.FeedetlSn,
  871. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  872. MedListCodg: subItem.HisProject.MedicalCode,
  873. HospApprFlag: -1,
  874. }
  875. customs = append(customs, cus)
  876. }
  877. } else if subItem.Type == 3 {
  878. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 {
  879. cus := &models.NewCustom{
  880. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  881. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  882. FeedetlSn: subItem.FeedetlSn,
  883. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  884. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  885. HospApprFlag: -1,
  886. }
  887. customs = append(customs, cus)
  888. }
  889. }
  890. }
  891. }
  892. for _, subItem := range item.HisAdditionalCharge {
  893. if len(subItem.XtHisAddtionConfig.Code) > 0 {
  894. cus := &models.NewCustom{
  895. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  896. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  897. FeedetlSn: subItem.FeedetlSn,
  898. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  899. MedListCodg: subItem.XtHisAddtionConfig.Code,
  900. HospApprFlag: -1,
  901. }
  902. customs = append(customs, cus)
  903. }
  904. }
  905. }
  906. //总页数,向上取整,注意除之前要先转换类型为float64
  907. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  908. var ress []*ResultFour
  909. for curpage = 1; curpage <= pagecount; curpage++ {
  910. if curpage == 1 {
  911. start = 1
  912. } else {
  913. start = (curpage-1)*pagesize + 1
  914. }
  915. stop = curpage * pagesize
  916. if stop > len(customs) {
  917. stop = len(customs)
  918. }
  919. data["pre"] = customs[start-1 : stop]
  920. bytesData, _ := json.Marshal(data)
  921. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
  922. resp, _ := client.Do(req)
  923. defer resp.Body.Close()
  924. body, ioErr := ioutil.ReadAll(resp.Body)
  925. if ioErr != nil {
  926. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  928. return
  929. }
  930. var respJSON map[string]interface{}
  931. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  932. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  934. return
  935. }
  936. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  937. userJSONBytes, _ := json.Marshal(respJSON)
  938. var res ResultFour
  939. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  940. utils.ErrorLog("解析失败:%v", err)
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  942. return
  943. }
  944. if res.Infcode == 0 {
  945. ress = append(ress, &res)
  946. } else {
  947. isSuccess = false
  948. errlog := &models.HisOrderError{
  949. UserOrgId: adminUser.CurrentOrgId,
  950. Ctime: time.Now().Unix(),
  951. Mtime: time.Now().Unix(),
  952. Number: chrg_bchno,
  953. ErrMsg: "",
  954. Status: 1,
  955. PatientId: id,
  956. RecordTime: recordDateTime,
  957. Stage: 4,
  958. }
  959. service.CreateErrMsgLog(errlog)
  960. c.ServeSuccessJSON(map[string]interface{}{
  961. "failed_code": -10,
  962. "msg": "上传明细错误,请联系his厂商",
  963. })
  964. return
  965. }
  966. }
  967. if isSuccess == true {
  968. if settle_accounts_type == 1 {
  969. for _, subItem := range ress {
  970. for _, item := range subItem.Output.Result {
  971. temp := strings.Split(item.FeedetlSn, "-")
  972. var advice_id int64 = 0
  973. var project_id int64 = 0
  974. var types int64 = 0
  975. id, _ := strconv.ParseInt(temp[2], 10, 64)
  976. types, _ = strconv.ParseInt(temp[1], 10, 64)
  977. if temp[1] == "1" {
  978. advice_id = id
  979. project_id = 0
  980. } else if temp[1] == "2" {
  981. advice_id = 0
  982. project_id = id
  983. }
  984. info := &models.HisOrderInfo{
  985. OrderNumber: record.Number,
  986. FeedetlSn: item.FeedetlSn,
  987. UploadDate: time.Now().Unix(),
  988. AdviceId: advice_id,
  989. DetItemFeeSumamt: item.DetItemFeeSumamt,
  990. Cnt: item.Cnt,
  991. Pric: float64(item.Pric),
  992. PatientId: record.PatientId,
  993. PricUplmtAmt: item.PricUplmtAmt,
  994. SelfpayProp: item.SelfpayProp,
  995. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  996. OverlmtAmt: item.OverlmtAmt,
  997. PreselfpayAmt: item.PreselfpayAmt,
  998. BasMednFlag: item.BasMednFlag,
  999. MedChrgitmType: item.MedChrgitmType,
  1000. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1001. Status: 1,
  1002. Memo: item.Memo,
  1003. Mtime: time.Now().Unix(),
  1004. InscpScpAmt: item.InscpScpAmt,
  1005. DrtReimFlag: item.DrtReimFlag,
  1006. Ctime: time.Now().Unix(),
  1007. ListSpItemFlag: item.ListSpItemFlag,
  1008. ChldMedcFlag: item.ChldMedcFlag,
  1009. LmtUsedFlag: item.LmtUsedFlag,
  1010. ChrgitmLv: item.ChrgitmLv,
  1011. UserOrgId: adminUser.CurrentOrgId,
  1012. HisPatientId: record.ID,
  1013. OrderId: 0,
  1014. ProjectId: project_id,
  1015. Type: types,
  1016. SettleType: settle_accounts_type,
  1017. }
  1018. service.CreateOrderInfo(info)
  1019. }
  1020. }
  1021. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1022. if err == nil {
  1023. c.ServeSuccessJSON(map[string]interface{}{
  1024. "msg": "上传费用明细成功",
  1025. })
  1026. return
  1027. } else {
  1028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1029. return
  1030. }
  1031. } else {
  1032. var total float64
  1033. for _, item := range prescriptions {
  1034. if item.Type == 1 { //药品
  1035. for _, subItem := range item.HisDoctorAdviceInfo {
  1036. total = total + (subItem.Price * subItem.PrescribingNumber)
  1037. }
  1038. }
  1039. if item.Type == 2 { //项目
  1040. for _, subItem := range item.HisPrescriptionProject {
  1041. total = total + (subItem.Price * float64(subItem.Count))
  1042. }
  1043. }
  1044. }
  1045. for _, item := range prescriptions {
  1046. for _, subItem := range item.HisAdditionalCharge {
  1047. total = total + (subItem.Price * float64(subItem.Count))
  1048. }
  1049. }
  1050. allTotal := fmt.Sprintf("%.2f", total)
  1051. totals, _ := strconv.ParseFloat(allTotal, 64)
  1052. order := &models.HisOrder{
  1053. UserOrgId: adminUser.CurrentOrgId,
  1054. HisPatientId: record.ID,
  1055. PatientId: record.PatientId,
  1056. SettleAccountsDate: recordDateTime,
  1057. Ctime: time.Now().Unix(),
  1058. Mtime: time.Now().Unix(),
  1059. Status: 1,
  1060. Number: record.Number,
  1061. Infcode: 0,
  1062. WarnMsg: "",
  1063. Cainfo: "",
  1064. ErrMsg: "",
  1065. RespondTime: "",
  1066. InfRefmsgid: "",
  1067. OrderStatus: 1,
  1068. MdtrtId: record.Number,
  1069. IsMedicineInsurance: 1,
  1070. SettleType: settle_accounts_type,
  1071. SettleStartTime: start_time,
  1072. SettleEndTime: end_time,
  1073. Creator: roles.AdminUserId,
  1074. Modify: roles.AdminUserId,
  1075. PType: 1,
  1076. MedfeeSumamt: totals,
  1077. }
  1078. err = service.CreateOrder(order)
  1079. if err != nil {
  1080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1081. return
  1082. }
  1083. for _, subItem := range ress {
  1084. for _, item := range subItem.Output.Result {
  1085. temp := strings.Split(item.FeedetlSn, "-")
  1086. var advice_id int64 = 0
  1087. var project_id int64 = 0
  1088. var types int64 = 0
  1089. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1090. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1091. if temp[1] == "1" {
  1092. advice_id = id
  1093. project_id = 0
  1094. } else if temp[1] == "2" {
  1095. advice_id = 0
  1096. project_id = id
  1097. }
  1098. info := &models.HisOrderInfo{
  1099. OrderNumber: order.Number,
  1100. FeedetlSn: item.FeedetlSn,
  1101. UploadDate: time.Now().Unix(),
  1102. AdviceId: advice_id,
  1103. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1104. Cnt: item.Cnt,
  1105. Pric: float64(item.Pric),
  1106. PatientId: record.PatientId,
  1107. PricUplmtAmt: item.PricUplmtAmt,
  1108. SelfpayProp: item.SelfpayProp,
  1109. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1110. OverlmtAmt: item.OverlmtAmt,
  1111. PreselfpayAmt: item.PreselfpayAmt,
  1112. BasMednFlag: item.BasMednFlag,
  1113. MedChrgitmType: item.MedChrgitmType,
  1114. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1115. Status: 1,
  1116. Memo: item.Memo,
  1117. Mtime: time.Now().Unix(),
  1118. InscpScpAmt: item.InscpScpAmt,
  1119. DrtReimFlag: item.DrtReimFlag,
  1120. Ctime: time.Now().Unix(),
  1121. ListSpItemFlag: item.ListSpItemFlag,
  1122. ChldMedcFlag: item.ChldMedcFlag,
  1123. LmtUsedFlag: item.LmtUsedFlag,
  1124. ChrgitmLv: item.ChrgitmLv,
  1125. UserOrgId: adminUser.CurrentOrgId,
  1126. HisPatientId: record.ID,
  1127. OrderId: order.ID,
  1128. ProjectId: project_id,
  1129. Type: types,
  1130. SettleType: settle_accounts_type,
  1131. }
  1132. service.CreateOrderInfo(info)
  1133. }
  1134. }
  1135. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1136. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1137. c.ServeSuccessJSON(map[string]interface{}{
  1138. "msg": "上传费用明细成功",
  1139. })
  1140. }
  1141. }
  1142. }
  1143. }
  1144. func (c *ZHHisApiController) ZHRefund() {
  1145. order_id, _ := c.GetInt64("order_id")
  1146. admin_user_id, _ := c.GetInt64("admin_user_id")
  1147. adminUser := c.GetAdminUserInfo()
  1148. var order models.HisOrder
  1149. order, _ = service.GetHisOrderByID(order_id)
  1150. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1151. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1152. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1153. if config.IsOpen == 1 { //对接了医保,走医保流程
  1154. result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1155. var dat map[string]interface{}
  1156. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1157. fmt.Println(dat)
  1158. } else {
  1159. fmt.Println(err)
  1160. }
  1161. userJSONBytes, _ := json.Marshal(dat)
  1162. var res ResultSixteen
  1163. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1164. utils.ErrorLog("解析失败:%v", err)
  1165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1166. return
  1167. }
  1168. if res.Infcode == 0 {
  1169. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  1170. if err == nil {
  1171. c.ServeSuccessJSON(map[string]interface{}{
  1172. "msg": "退费成功",
  1173. })
  1174. } else {
  1175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1176. return
  1177. }
  1178. } else {
  1179. c.ServeSuccessJSON(map[string]interface{}{
  1180. "code": -10,
  1181. "msg": res.ErrMsg,
  1182. })
  1183. }
  1184. } else {
  1185. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1186. if err == nil {
  1187. c.ServeSuccessJSON(map[string]interface{}{
  1188. "msg": "退费成功",
  1189. })
  1190. } else {
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1192. return
  1193. }
  1194. }
  1195. }
  1196. func (c *ZHHisApiController) ZHRefundDetail() {
  1197. patient_id, _ := c.GetInt64("patient_id")
  1198. his_patient_id, _ := c.GetInt64("his_patient_id")
  1199. record_time := c.GetString("record_time")
  1200. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1201. order_id, _ := c.GetInt64("order_id")
  1202. admin_user_id, _ := c.GetInt64("admin_user_id")
  1203. timeLayout := "2006-01-02"
  1204. loc, _ := time.LoadLocation("Local")
  1205. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1206. if err != nil {
  1207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1208. return
  1209. }
  1210. recordDateTime := theTime.Unix()
  1211. adminUser := c.GetAdminUserInfo()
  1212. //var prescriptions []*models.HisPrescription
  1213. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1214. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1215. if settle_accounts_type == 1 { //日结
  1216. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1217. record, _ := service.GetInHospitalRecord(his_patient_id)
  1218. var isSuccess bool = true
  1219. for _, item := range infos {
  1220. result := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  1221. var dat map[string]interface{}
  1222. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1223. fmt.Println(dat)
  1224. } else {
  1225. fmt.Println(err)
  1226. }
  1227. userJSONBytes, _ := json.Marshal(dat)
  1228. var res2 ResultEmpty
  1229. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1230. utils.ErrorLog("解析失败:%v", err)
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1232. return
  1233. }
  1234. if res2.Infcode == -1 {
  1235. isSuccess = false
  1236. }
  1237. }
  1238. if isSuccess {
  1239. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1240. if err != nil {
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1242. return
  1243. }
  1244. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1245. if err1 != nil {
  1246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. }
  1249. c.ServeSuccessJSON(map[string]interface{}{
  1250. "msg": "撤销明细成功",
  1251. })
  1252. }
  1253. } else {
  1254. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1255. var order models.HisOrder
  1256. order, _ = service.GetHisOrderByID(order_id)
  1257. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1258. if config.IsOpen == 1 { //对接了医保,走医保流程
  1259. result := service.Gdyb2302(order.PsnNo, order.MdtrtId, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  1260. var dat map[string]interface{}
  1261. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1262. fmt.Println(dat)
  1263. } else {
  1264. fmt.Println(err)
  1265. }
  1266. userJSONBytes, _ := json.Marshal(dat)
  1267. var res2 ResultEmpty
  1268. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1269. utils.ErrorLog("解析失败:%v", err)
  1270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1271. return
  1272. }
  1273. if res2.Infcode == 0 {
  1274. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  1275. if err == nil {
  1276. c.ServeSuccessJSON(map[string]interface{}{
  1277. "msg": "退费成功",
  1278. })
  1279. } else {
  1280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1281. return
  1282. }
  1283. } else {
  1284. c.ServeSuccessJSON(map[string]interface{}{
  1285. "code": -10,
  1286. "msg": res2.ErrMsg,
  1287. })
  1288. }
  1289. } else {
  1290. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1291. if err == nil {
  1292. c.ServeSuccessJSON(map[string]interface{}{
  1293. "msg": "退费成功",
  1294. })
  1295. } else {
  1296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1297. return
  1298. }
  1299. }
  1300. }
  1301. }
  1302. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  1303. id, _ := this.GetInt64("id")
  1304. admin_user_id, _ := this.GetInt64("admin_user_id")
  1305. adminInfo := this.GetAdminUserInfo()
  1306. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1307. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1308. record, _ := service.GetInHospitalRecord(id)
  1309. if record.ID == 0 {
  1310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1311. return
  1312. }
  1313. result := service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1314. var dat map[string]interface{}
  1315. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1316. fmt.Println(dat)
  1317. } else {
  1318. fmt.Println(err)
  1319. }
  1320. userJSONBytes, _ := json.Marshal(dat)
  1321. var res ResultEmpty
  1322. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1323. utils.ErrorLog("解析失败:%v", err)
  1324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1325. return
  1326. }
  1327. if res.Infcode == 0 {
  1328. record.OutHospitalStatus = 0
  1329. service.CreateHospitalRecord(&record)
  1330. this.ServeSuccessJSON(map[string]interface{}{
  1331. "msg": "撤销出院成功",
  1332. })
  1333. } else {
  1334. this.ServeSuccessJSON(map[string]interface{}{
  1335. "failed_code": -10,
  1336. "msg": res.ErrMsg,
  1337. })
  1338. }
  1339. }
  1340. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  1341. id, _ := this.GetInt64("id")
  1342. admin_user_id, _ := this.GetInt64("admin_user_id")
  1343. adminInfo := this.GetAdminUserInfo()
  1344. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1345. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1346. record, _ := service.GetInHospitalRecord(id)
  1347. if record.ID == 0 {
  1348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1349. return
  1350. }
  1351. result := service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1352. var dat map[string]interface{}
  1353. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1354. fmt.Println(dat)
  1355. } else {
  1356. fmt.Println(err)
  1357. }
  1358. userJSONBytes, _ := json.Marshal(dat)
  1359. var res ResultEmpty
  1360. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1361. utils.ErrorLog("解析失败:%v", err)
  1362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1363. return
  1364. }
  1365. if res.Infcode == 0 {
  1366. record.Status = 0
  1367. service.CreateHospitalRecord(&record)
  1368. this.ServeSuccessJSON(map[string]interface{}{
  1369. "msg": "撤销入院成功",
  1370. })
  1371. } else {
  1372. this.ServeSuccessJSON(map[string]interface{}{
  1373. "failed_code": -10,
  1374. "msg": res.ErrMsg,
  1375. })
  1376. }
  1377. }