zh_his_api_controller.go 42KB

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