zh_his_api_controller.go 46KB

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