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.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  516. dise.DiseDorName = doctorInfo.UserName
  517. dise.DiagCode = item.CountryCode
  518. dise.DiagName = item.ClassName
  519. dise.DiagDept = departmentInfo.Name
  520. dise.DiseDorNo = strconv.FormatInt(int64(doctorInfo.AdminUserId), 10)
  521. dise.DiagTime = timeFormatOne
  522. dises = append(dises, dise)
  523. }
  524. struct2402.Diseinfo = dises
  525. struct2402.DiseName = sickConfig.ClassName
  526. struct2402.DiseCode = sickConfig.CountryCode
  527. result := service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  528. var dat map[string]interface{}
  529. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  530. fmt.Println(dat)
  531. } else {
  532. fmt.Println(err)
  533. }
  534. userJSONBytes, _ := json.Marshal(dat)
  535. var res ResultEmpty
  536. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  537. utils.ErrorLog("解析失败:%v", err)
  538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  539. return
  540. }
  541. if res.Infcode == 0 {
  542. record.OutHospitalStatus = 1
  543. record.OutHosptialTime = struct2402.Endtime
  544. record.OutWay = 1
  545. service.CreateHospitalRecord(&record)
  546. this.ServeSuccessJSON(map[string]interface{}{
  547. "msg": "出院成功",
  548. })
  549. } else {
  550. this.ServeSuccessJSON(map[string]interface{}{
  551. "failed_code": -10,
  552. "msg": res.ErrMsg,
  553. })
  554. }
  555. }
  556. func (c *ZHHisApiController) GetSettleInfo() {
  557. order_id, _ := c.GetInt64("order_id")
  558. patient_id, _ := c.GetInt64("patient_id")
  559. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  560. admin_user_id, _ := c.GetInt64("admin_user_id")
  561. pay_way, _ := c.GetInt64("pay_way")
  562. pay_price, _ := c.GetFloat("pay_price")
  563. pay_card_no := c.GetString("pay_card_no")
  564. discount_price, _ := c.GetFloat("discount_price")
  565. preferential_price, _ := c.GetFloat("preferential_price")
  566. reality_price, _ := c.GetFloat("reality_price")
  567. found_price, _ := c.GetFloat("found_price")
  568. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  569. private_price, _ := c.GetFloat("private_price")
  570. fapiao_code := c.GetString("fapiao_code")
  571. fapiao_number := c.GetString("fapiao_number")
  572. order, _ := service.GetHisOrderByID(order_id)
  573. record, _ := service.GetInHospitalRecord(in_hospital_id)
  574. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  575. allTotal := fmt.Sprintf("%.2f", order.MedfeeSumamt)
  576. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  577. var rf []*ResultFive
  578. json.Unmarshal([]byte(record.Iinfo), &rf)
  579. chrg_bchno := order.Number
  580. cert_no := record.Certno
  581. var insutypes []string
  582. var insutype string
  583. var is390 int = 0
  584. var is310 int = 0
  585. if record.ID == 0 {
  586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  587. return
  588. }
  589. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  591. return
  592. }
  593. for _, item := range rf {
  594. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  595. insutypes = append(insutypes, item.Insutype)
  596. }
  597. }
  598. if len(insutypes) == 1 {
  599. insutype = insutypes[0]
  600. } else {
  601. for _, i := range insutypes {
  602. if i == "390" {
  603. is390 = 1
  604. }
  605. if i == "310" {
  606. is310 = 1
  607. }
  608. }
  609. }
  610. if is390 == 1 {
  611. insutype = "390"
  612. }
  613. if is310 == 1 {
  614. insutype = "310"
  615. }
  616. if len(insutypes) == 0 {
  617. insutype = "310"
  618. }
  619. if record.IdCardType == 1 {
  620. } else {
  621. cert_no = record.Certno
  622. }
  623. 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, strconv.FormatInt(record.MedType, 10), record.IdCardType, 0, 0, 0, 0, record.Certificates)
  624. var dat map[string]interface{}
  625. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  626. fmt.Println(dat)
  627. } else {
  628. fmt.Println(err)
  629. }
  630. userJSONBytes, _ := json.Marshal(dat)
  631. var res ResultSeven
  632. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  633. utils.ErrorLog("解析失败:%v", err)
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  635. return
  636. }
  637. if res.Infcode == -1 {
  638. errlog := &models.HisOrderError{
  639. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  640. Ctime: time.Now().Unix(),
  641. Mtime: time.Now().Unix(),
  642. Number: chrg_bchno,
  643. ErrMsg: res.ErrMsg,
  644. Status: 1,
  645. PatientId: patient_id,
  646. RecordTime: time.Now().Unix(),
  647. Stage: 6,
  648. }
  649. service.CreateErrMsgLog(errlog)
  650. c.ServeSuccessJSON(map[string]interface{}{
  651. "failed_code": -10,
  652. "msg": res.ErrMsg,
  653. })
  654. return
  655. } else {
  656. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  657. order.OrderStatus = 2
  658. order.DiscountPrice = discount_price
  659. order.MedicalInsurancePrice = medical_insurance_price
  660. order.FaPiaoNumber = fapiao_number
  661. order.FaPiaoCode = fapiao_code
  662. order.PayWay = pay_way
  663. order.PayPrice = pay_price
  664. order.PayCardNo = pay_card_no
  665. order.PreferentialPrice = preferential_price
  666. order.RealityPrice = reality_price
  667. order.FoundPrice = found_price
  668. order.PrivatePrice = private_price
  669. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  670. order.SetlId = res.Output.Setlinfo.SetlID
  671. order.PsnNo = res.Output.Setlinfo.PsnNo
  672. order.PsnName = res.Output.Setlinfo.PsnName
  673. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  674. order.Certno = res.Output.Setlinfo.Certno
  675. order.Gend = res.Output.Setlinfo.Gend
  676. order.Naty = res.Output.Setlinfo.Naty
  677. order.Age = res.Output.Setlinfo.Age
  678. order.Insutype = res.Output.Setlinfo.Insutype
  679. order.PsnType = res.Output.Setlinfo.PsnType
  680. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  681. order.SetlTime = res.Output.Setlinfo.SetlTime
  682. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  683. order.MedType = res.Output.Setlinfo.MedType
  684. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  685. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  686. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  687. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  688. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  689. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  690. order.HifpPay = res.Output.Setlinfo.HifpPay
  691. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  692. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  693. order.HifesPay = res.Output.Setlinfo.HifesPay
  694. order.HifobPay = res.Output.Setlinfo.HifobPay
  695. order.MafPay = res.Output.Setlinfo.MafPay
  696. order.OthPay = res.Output.Setlinfo.OthPay
  697. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  698. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  699. order.AcctPay = res.Output.Setlinfo.AcctPay
  700. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  701. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  702. order.Balc = res.Output.Setlinfo.Balc
  703. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  704. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  705. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  706. order.ClrWay = res.Output.Setlinfo.ClrWay
  707. order.Creator = order.Creator
  708. order.Modify = roles.AdminUserId
  709. order.RequestLog = src_resquest
  710. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  711. detailStr := string(setlDetail)
  712. order.SetlDetail = detailStr
  713. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  714. err = service.UpDateOrder(order)
  715. if err == nil {
  716. c.ServeSuccessJSON(map[string]interface{}{
  717. "msg": "结算成功",
  718. })
  719. } else {
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  721. return
  722. }
  723. }
  724. }
  725. func (c *ZHHisApiController) GetUploadInfo() {
  726. id, _ := c.GetInt64("id")
  727. record_time := c.GetString("record_time")
  728. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  729. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  730. admin_user_id, _ := c.GetInt64("admin_user_id")
  731. timeLayout := "2006-01-02"
  732. loc, _ := time.LoadLocation("Local")
  733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  734. if err != nil {
  735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  736. return
  737. }
  738. recordDateTime := theTime.Unix()
  739. adminUser := c.GetAdminUserInfo()
  740. var prescriptions []*models.HisPrescription
  741. var start_time int64
  742. var end_time int64
  743. data := make(map[string]interface{})
  744. if settle_accounts_type == 1 { //日结
  745. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  746. data["pre"] = prescriptions
  747. } else { //月结
  748. start_time_str := c.GetString("start_time")
  749. end_time_str := c.GetString("end_time")
  750. timeLayout := "2006-01-02"
  751. loc, _ := time.LoadLocation("Local")
  752. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  753. if err != nil {
  754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  755. return
  756. }
  757. recordStartTime := theStartTime.Unix()
  758. start_time = recordStartTime
  759. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  760. if err != nil {
  761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  762. return
  763. }
  764. recordEndTime := theEndTime.Unix()
  765. end_time = recordEndTime
  766. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  767. data["pre"] = prescriptions
  768. }
  769. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  770. record, _ := service.GetInHospitalRecord(in_hospital_id)
  771. if record.ID == 0 {
  772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  773. return
  774. }
  775. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  776. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  777. // return
  778. //}
  779. timestamp := time.Now().Unix()
  780. tempTime := time.Unix(timestamp, 0)
  781. timeFormat := tempTime.Format("20060102150405")
  782. chrgBchno := rand.Intn(100000) + 10000
  783. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  784. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  785. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  786. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  787. strconv.FormatInt(record.PatientId, 10)
  788. client := &http.Client{}
  789. data["psn_no"] = record.PsnNo
  790. data["mdtrt_id"] = record.Number
  791. data["chrg_bchno"] = chrg_bchno
  792. data["org_name"] = miConfig.OrgName
  793. data["doctor"] = roles.UserName
  794. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  795. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  796. data["fixmedins_code"] = miConfig.Code
  797. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  798. data["dept_code"] = "15"
  799. } else {
  800. data["dept_code"] = department.Number
  801. }
  802. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  803. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  804. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  805. data["secret_key"] = miConfig.SecretKey
  806. var ids []int64
  807. fmt.Println(data)
  808. for _, item := range prescriptions {
  809. ids = append(ids, item.ID)
  810. }
  811. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  812. if config.IsOpen == 1 { //对接了医保,走医保流程
  813. bytesData, _ := json.Marshal(data)
  814. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/zh/five", bytes.NewReader(bytesData))
  815. resp, _ := client.Do(req)
  816. defer resp.Body.Close()
  817. body, ioErr := ioutil.ReadAll(resp.Body)
  818. if ioErr != nil {
  819. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  821. return
  822. }
  823. var respJSON map[string]interface{}
  824. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  825. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  827. return
  828. }
  829. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  830. userJSONBytes, _ := json.Marshal(respJSON)
  831. var res ResultFour
  832. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  833. utils.ErrorLog("解析失败:%v", err)
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. return
  836. }
  837. var total float64
  838. for _, item := range prescriptions {
  839. if item.Type == 1 { //药品
  840. for _, subItem := range item.HisDoctorAdviceInfo {
  841. total = total + (subItem.Price * subItem.PrescribingNumber)
  842. }
  843. }
  844. if item.Type == 2 { //项目
  845. for _, subItem := range item.HisPrescriptionProject {
  846. total = total + (subItem.Price * float64(subItem.Count))
  847. }
  848. }
  849. }
  850. for _, item := range prescriptions {
  851. for _, subItem := range item.HisAdditionalCharge {
  852. total = total + (subItem.Price * float64(subItem.Count))
  853. }
  854. }
  855. allTotal := fmt.Sprintf("%.2f", total)
  856. totals, _ := strconv.ParseFloat(allTotal, 64)
  857. if res.Infcode == 0 {
  858. order := &models.HisOrder{
  859. UserOrgId: adminUser.CurrentOrgId,
  860. HisPatientId: record.ID,
  861. PatientId: record.PatientId,
  862. SettleAccountsDate: recordDateTime,
  863. Ctime: time.Now().Unix(),
  864. Mtime: time.Now().Unix(),
  865. Status: 1,
  866. Number: chrg_bchno,
  867. Infcode: res.Infcode,
  868. WarnMsg: res.WarnMsg,
  869. Cainfo: res.Cainfo,
  870. ErrMsg: res.ErrMsg,
  871. RespondTime: res.RefmsgTime,
  872. InfRefmsgid: res.InfRefmsgid,
  873. OrderStatus: 1,
  874. MdtrtId: record.Number,
  875. IsMedicineInsurance: 1,
  876. SettleType: settle_accounts_type,
  877. SettleStartTime: start_time,
  878. SettleEndTime: end_time,
  879. Creator: roles.AdminUserId,
  880. Modify: roles.AdminUserId,
  881. MedfeeSumamt: totals,
  882. }
  883. err = service.CreateOrder(order)
  884. if err != nil {
  885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  886. return
  887. }
  888. for _, item := range res.Output.Result {
  889. temp := strings.Split(item.FeedetlSn, "-")
  890. var advice_id int64 = 0
  891. var project_id int64 = 0
  892. var types int64 = 0
  893. id, _ := strconv.ParseInt(temp[2], 10, 64)
  894. types, _ = strconv.ParseInt(temp[1], 10, 64)
  895. if temp[1] == "1" {
  896. advice_id = id
  897. project_id = 0
  898. } else if temp[1] == "2" {
  899. advice_id = 0
  900. project_id = id
  901. }
  902. info := &models.HisOrderInfo{
  903. OrderNumber: order.Number,
  904. FeedetlSn: item.FeedetlSn,
  905. UploadDate: time.Now().Unix(),
  906. AdviceId: advice_id,
  907. DetItemFeeSumamt: item.DetItemFeeSumamt,
  908. Cnt: item.Cnt,
  909. Pric: float64(item.Pric),
  910. PatientId: record.PatientId,
  911. PricUplmtAmt: item.PricUplmtAmt,
  912. SelfpayProp: item.SelfpayProp,
  913. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  914. OverlmtAmt: item.OverlmtAmt,
  915. PreselfpayAmt: item.PreselfpayAmt,
  916. BasMednFlag: item.BasMednFlag,
  917. MedChrgitmType: item.MedChrgitmType,
  918. HiNegoDrugFlag: item.HiNegoDrugFlag,
  919. Status: 1,
  920. Memo: item.Memo,
  921. Mtime: time.Now().Unix(),
  922. InscpScpAmt: item.InscpScpAmt,
  923. DrtReimFlag: item.DrtReimFlag,
  924. Ctime: time.Now().Unix(),
  925. ListSpItemFlag: item.ListSpItemFlag,
  926. ChldMedcFlag: item.ChldMedcFlag,
  927. LmtUsedFlag: item.LmtUsedFlag,
  928. ChrgitmLv: item.ChrgitmLv,
  929. UserOrgId: adminUser.CurrentOrgId,
  930. HisPatientId: record.ID,
  931. OrderId: order.ID,
  932. ProjectId: project_id,
  933. Type: types,
  934. }
  935. service.CreateOrderInfo(info)
  936. }
  937. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  938. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  939. c.ServeSuccessJSON(map[string]interface{}{
  940. "msg": "上传费用明细成功",
  941. })
  942. } else {
  943. adminUser := c.GetAdminUserInfo()
  944. errlog := &models.HisOrderError{
  945. UserOrgId: adminUser.CurrentOrgId,
  946. Ctime: time.Now().Unix(),
  947. Mtime: time.Now().Unix(),
  948. ErrMsg: res.ErrMsg,
  949. Status: 1,
  950. PatientId: id,
  951. RecordTime: recordDateTime,
  952. Stage: 4,
  953. }
  954. service.CreateErrMsgLog(errlog)
  955. c.ServeSuccessJSON(map[string]interface{}{
  956. "failed_code": -10,
  957. "msg": res.ErrMsg,
  958. })
  959. return
  960. }
  961. }
  962. }
  963. func (c *ZHHisApiController) ZHRefund() {
  964. order_id, _ := c.GetInt64("order_id")
  965. admin_user_id, _ := c.GetInt64("admin_user_id")
  966. adminUser := c.GetAdminUserInfo()
  967. var order models.HisOrder
  968. order, _ = service.GetHisOrderByID(order_id)
  969. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  970. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  971. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  972. if config.IsOpen == 1 { //对接了医保,走医保流程
  973. result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  974. var dat map[string]interface{}
  975. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  976. fmt.Println(dat)
  977. } else {
  978. fmt.Println(err)
  979. }
  980. userJSONBytes, _ := json.Marshal(dat)
  981. var res ResultSixteen
  982. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  983. utils.ErrorLog("解析失败:%v", err)
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  985. return
  986. }
  987. if res.Infcode == 0 {
  988. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  989. if err == nil {
  990. c.ServeSuccessJSON(map[string]interface{}{
  991. "msg": "退费成功",
  992. })
  993. } else {
  994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  995. return
  996. }
  997. } else {
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "code": -10,
  1000. "msg": res.ErrMsg,
  1001. })
  1002. }
  1003. } else {
  1004. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1005. if err == nil {
  1006. c.ServeSuccessJSON(map[string]interface{}{
  1007. "msg": "退费成功",
  1008. })
  1009. } else {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1011. return
  1012. }
  1013. }
  1014. }
  1015. func (c *ZHHisApiController) ZHRefundDetail() {
  1016. order_id, _ := c.GetInt64("order_id")
  1017. admin_user_id, _ := c.GetInt64("admin_user_id")
  1018. adminUser := c.GetAdminUserInfo()
  1019. var order models.HisOrder
  1020. order, _ = service.GetHisOrderByID(order_id)
  1021. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1022. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1023. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1024. if config.IsOpen == 1 { //对接了医保,走医保流程
  1025. result := service.Gdyb2302(order.PsnNo, order.MdtrtId, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1026. var dat map[string]interface{}
  1027. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1028. fmt.Println(dat)
  1029. } else {
  1030. fmt.Println(err)
  1031. }
  1032. userJSONBytes, _ := json.Marshal(dat)
  1033. var res2 ResultEmpty
  1034. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1035. utils.ErrorLog("解析失败:%v", err)
  1036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1037. return
  1038. }
  1039. if res2.Infcode == 0 {
  1040. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  1041. if err == nil {
  1042. c.ServeSuccessJSON(map[string]interface{}{
  1043. "msg": "退费成功",
  1044. })
  1045. } else {
  1046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1047. return
  1048. }
  1049. } else {
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "code": -10,
  1052. "msg": res2.ErrMsg,
  1053. })
  1054. }
  1055. } else {
  1056. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  1057. if err == nil {
  1058. c.ServeSuccessJSON(map[string]interface{}{
  1059. "msg": "退费成功",
  1060. })
  1061. } else {
  1062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1063. return
  1064. }
  1065. }
  1066. }
  1067. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  1068. id, _ := this.GetInt64("id")
  1069. admin_user_id, _ := this.GetInt64("admin_user_id")
  1070. adminInfo := this.GetAdminUserInfo()
  1071. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1072. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1073. record, _ := service.GetInHospitalRecord(id)
  1074. if record.ID == 0 {
  1075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1076. return
  1077. }
  1078. result := service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1079. var dat map[string]interface{}
  1080. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1081. fmt.Println(dat)
  1082. } else {
  1083. fmt.Println(err)
  1084. }
  1085. userJSONBytes, _ := json.Marshal(dat)
  1086. var res ResultEmpty
  1087. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1088. utils.ErrorLog("解析失败:%v", err)
  1089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1090. return
  1091. }
  1092. if res.Infcode == 0 {
  1093. record.OutHospitalStatus = 0
  1094. service.CreateHospitalRecord(&record)
  1095. this.ServeSuccessJSON(map[string]interface{}{
  1096. "msg": "撤销出院成功",
  1097. })
  1098. } else {
  1099. this.ServeSuccessJSON(map[string]interface{}{
  1100. "failed_code": -10,
  1101. "msg": res.ErrMsg,
  1102. })
  1103. }
  1104. }
  1105. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  1106. id, _ := this.GetInt64("id")
  1107. admin_user_id, _ := this.GetInt64("admin_user_id")
  1108. adminInfo := this.GetAdminUserInfo()
  1109. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1110. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1111. record, _ := service.GetInHospitalRecord(id)
  1112. if record.ID == 0 {
  1113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1114. return
  1115. }
  1116. result := service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1117. var dat map[string]interface{}
  1118. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1119. fmt.Println(dat)
  1120. } else {
  1121. fmt.Println(err)
  1122. }
  1123. userJSONBytes, _ := json.Marshal(dat)
  1124. var res ResultEmpty
  1125. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1126. utils.ErrorLog("解析失败:%v", err)
  1127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1128. return
  1129. }
  1130. if res.Infcode == 0 {
  1131. record.Status = 0
  1132. service.CreateHospitalRecord(&record)
  1133. this.ServeSuccessJSON(map[string]interface{}{
  1134. "msg": "撤销入院成功",
  1135. })
  1136. } else {
  1137. this.ServeSuccessJSON(map[string]interface{}{
  1138. "failed_code": -10,
  1139. "msg": res.ErrMsg,
  1140. })
  1141. }
  1142. }