zh_his_api_controller.go 45KB

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