zh_his_api_controller.go 46KB

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