his_hospital_api_controller.go 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "github.com/shopspring/decimal"
  10. "math/rand"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type HisHospitalApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func HisHospitalManagerApiRegistRouters() {
  19. beego.Router("/api/hishospitalpatient/list", &HisHospitalApiController{}, "get:GetHisHospitalPatientList")
  20. beego.Router("/api/hospitalcharge/list", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientList")
  21. beego.Router("/api/hospotalcharge/info", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientInfo")
  22. beego.Router("/api/hospitalprescription/list", &HisHospitalApiController{}, "get:GetHisHospitalPrescriptionList")
  23. beego.Router("/api/hospital/inhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalCheck")
  24. beego.Router("/api/hospital/outhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalCheck")
  25. beego.Router("/api/hospital/settle/get", &HisHospitalApiController{}, "get:GetSettleInfo")
  26. beego.Router("/api/hospital/inthopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalUnCheck")
  27. beego.Router("/api/hospital/outhopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalUnCheck")
  28. beego.Router("/api/hospital/refund", &HisHospitalApiController{}, "get:ZHRefund")
  29. beego.Router("/api/hospital/upload", &HisHospitalApiController{}, "get:GetUploadInfo")
  30. beego.Router("/api/hospital/refunddetail", &HisHospitalApiController{}, "get:RefundDetail")
  31. beego.Router("/api/hospitaldetail/list", &HisHospitalApiController{}, "get:GetHisHospitalDetailPatientList")
  32. beego.Router("/api/hospitaldetail/info", &HisHospitalApiController{}, "get:GetHisHospitalDetailInfo")
  33. beego.Router("/api/monthhospitaldetail/get", &HisHospitalApiController{}, "get:GetHisHospitalMonthDetailInfo")
  34. beego.Router("/api/exportuncharge/get", &HisHospitalApiController{}, "get:GetExportHisHospitalUnChargeData")
  35. beego.Router("/api/hospital/inhopitalcheck/list", &HisHospitalApiController{}, "get:GetZHInHospitalCheckList")
  36. beego.Router("/api/fapiao/modifytwo", &HisHospitalApiController{}, "post:ModifyFaPiaoCode")
  37. }
  38. func (this *HisHospitalApiController) ModifyFaPiaoCode() {
  39. order_id, _ := this.GetInt64("id")
  40. fapiao_number := this.GetString("fapiao_number")
  41. order, _ := service.GetHisOrderByID(order_id)
  42. if order.ID == 0 {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  44. return
  45. }
  46. order.FaPiaoNumber = fapiao_number
  47. err := service.SaveOrderTwo(&order)
  48. if err != nil {
  49. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  50. return
  51. }
  52. this.ServeSuccessJSON(map[string]interface{}{
  53. "order": order,
  54. "msg": "修改成功",
  55. })
  56. }
  57. func (this *HisHospitalApiController) GetZHInHospitalCheckList() {
  58. timeLayout := "2006-01-02"
  59. loc, _ := time.LoadLocation("Local")
  60. keyword := this.GetString("keyword")
  61. start_time := this.GetString("start_time")
  62. end_time := this.GetString("end_time")
  63. limit, _ := this.GetInt64("limit")
  64. page, _ := this.GetInt64("page")
  65. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+":00", loc)
  66. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+":59", loc)
  67. adminUserInfo := this.GetAdminUserInfo()
  68. orgId := adminUserInfo.CurrentOrgId
  69. history, total, err := service.GetHisInHospitalHistory(keyword, startTime.Unix(), endTime.Unix(), limit, page, orgId)
  70. department, err := service.GetAllDepartMent(orgId)
  71. appId := adminUserInfo.CurrentAppId
  72. doctor, err := service.GetAllDoctor(orgId, appId)
  73. if err != nil {
  74. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  75. return
  76. }
  77. this.ServeSuccessJSON(map[string]interface{}{
  78. "history": history,
  79. "total": total,
  80. "department": department,
  81. "doctor": doctor,
  82. })
  83. }
  84. func (c *HisHospitalApiController) RefundDetail() {
  85. patient_id, _ := c.GetInt64("patient_id")
  86. his_patient_id, _ := c.GetInt64("his_patient_id")
  87. record_time := c.GetString("record_time")
  88. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  89. timeLayout := "2006-01-02"
  90. loc, _ := time.LoadLocation("Local")
  91. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  92. if err != nil {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. recordDateTime := theTime.Unix()
  97. adminUser := c.GetAdminUserInfo()
  98. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  99. if err != nil {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. recordDateTimeTwo := theTimeTwo.Unix()
  104. if settle_accounts_type == 1 { //日结
  105. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  108. return
  109. }
  110. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  111. if err1 != nil {
  112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  113. return
  114. }
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "msg": "撤销明细成功",
  117. })
  118. } else {
  119. record, _ := service.GetInHospitalRecord(his_patient_id)
  120. err := service.UpdataHospitalOrderStatusTwo(record.Number, adminUser.CurrentOrgId)
  121. if err == nil {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "msg": "撤销明细成功",
  124. })
  125. } else {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  127. return
  128. }
  129. }
  130. }
  131. func (c *HisHospitalApiController) GetUploadInfo() {
  132. id, _ := c.GetInt64("id")
  133. record_time := c.GetString("record_time")
  134. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  135. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  136. timeLayout := "2006-01-02"
  137. loc, _ := time.LoadLocation("Local")
  138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  139. if err != nil {
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. recordDateTime := theTime.Unix()
  144. adminUser := c.GetAdminUserInfo()
  145. var prescriptions []*models.HisPrescription
  146. if settle_accounts_type == 1 { //日结
  147. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  148. } else { //月结
  149. start_time_str := c.GetString("start_time")
  150. end_time_str := c.GetString("end_time")
  151. timeLayout := "2006-01-02"
  152. loc, _ := time.LoadLocation("Local")
  153. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  154. if err != nil {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  156. return
  157. }
  158. recordStartTime := theStartTime.Unix()
  159. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  160. if err != nil {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  162. return
  163. }
  164. recordEndTime := theEndTime.Unix()
  165. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  166. }
  167. record, _ := service.GetInHospitalRecord(in_hospital_id)
  168. if record.ID == 0 {
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  170. return
  171. }
  172. var ids []int64
  173. for _, item := range prescriptions {
  174. ids = append(ids, item.ID)
  175. }
  176. //config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  177. var customs []*models.NewCustom
  178. for _, item := range prescriptions {
  179. tm := time.Unix(item.PreTime, 0)
  180. if item.Type == 1 { //药品
  181. for _, subItem := range item.HisDoctorAdviceInfo {
  182. //if subItem.Drug.IsUser != 1 {
  183. //var randNum int
  184. //randNum = rand.Intn(10000) + 1000
  185. if len(subItem.FeedetlSn) == 0 {
  186. fmt.Println("drug")
  187. fmt.Println(subItem.ID)
  188. }
  189. cus := &models.NewCustom{
  190. DetItemFeeSumamt: subItem.Price * subItem.PrescribingNumber,
  191. Cut: subItem.PrescribingNumber,
  192. FeedetlSn: subItem.FeedetlSn,
  193. Price: subItem.Price,
  194. MedListCodg: subItem.Drug.MedicalInsuranceNumber,
  195. HospApprFlag: subItem.Drug.HospApprFlag,
  196. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  197. }
  198. customs = append(customs, cus)
  199. //}
  200. }
  201. }
  202. if item.Type == 2 { //项目
  203. for _, subItem := range item.HisPrescriptionProject {
  204. if subItem.Type == 2 {
  205. if len(subItem.FeedetlSn) == 0 {
  206. fmt.Println("project")
  207. fmt.Println(subItem.ID)
  208. }
  209. //if len(subItem.HisProject.MedicalCode) > 0 {
  210. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  211. cus := &models.NewCustom{
  212. DetItemFeeSumamt: subItem.Price * cnt,
  213. Cut: cnt,
  214. FeedetlSn: subItem.FeedetlSn,
  215. Price: float64(subItem.Price),
  216. MedListCodg: subItem.HisProject.MedicalCode,
  217. HospApprFlag: -1,
  218. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  219. }
  220. customs = append(customs, cus)
  221. //}/* *//**/
  222. } else if subItem.Type == 3 {
  223. if len(subItem.FeedetlSn) == 0 {
  224. fmt.Println("good")
  225. fmt.Println(subItem.ID)
  226. }
  227. //if subItem.GoodInfo.IsUser != 1 {
  228. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  229. cus := &models.NewCustom{
  230. DetItemFeeSumamt: subItem.Price * cnt,
  231. Cut: cnt,
  232. FeedetlSn: subItem.FeedetlSn,
  233. Price: float64(subItem.Price),
  234. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  235. HospApprFlag: -1,
  236. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  237. }
  238. customs = append(customs, cus)
  239. }
  240. //}
  241. }
  242. }
  243. }
  244. fmt.Println(settle_accounts_type)
  245. if settle_accounts_type == 1 {
  246. fmt.Println(customs)
  247. for _, subItem := range customs {
  248. if len(subItem.FeedetlSn) > 0 {
  249. temp := strings.Split(subItem.FeedetlSn, "-")
  250. var advice_id int64 = 0
  251. var project_id int64 = 0
  252. var types int64 = 0
  253. id, _ := strconv.ParseInt(temp[2], 10, 64)
  254. types, _ = strconv.ParseInt(temp[1], 10, 64)
  255. if temp[1] == "1" {
  256. advice_id = id
  257. project_id = 0
  258. } else if temp[1] == "2" {
  259. advice_id = 0
  260. project_id = id
  261. }
  262. info := &models.HisOrderInfo{
  263. OrderNumber: record.Number,
  264. FeedetlSn: subItem.FeedetlSn,
  265. UploadDate: recordDateTime,
  266. AdviceId: advice_id,
  267. DetItemFeeSumamt: subItem.DetItemFeeSumamt,
  268. Cnt: subItem.Cut,
  269. Pric: float64(subItem.Price),
  270. PatientId: record.PatientId,
  271. PricUplmtAmt: 0,
  272. SelfpayProp: 0,
  273. FulamtOwnpayAmt: 0,
  274. OverlmtAmt: 0,
  275. PreselfpayAmt: 0,
  276. Status: 1,
  277. Mtime: time.Now().Unix(),
  278. Ctime: time.Now().Unix(),
  279. UserOrgId: adminUser.CurrentOrgId,
  280. HisPatientId: record.ID,
  281. OrderId: 0,
  282. ProjectId: project_id,
  283. Type: types,
  284. SettleType: settle_accounts_type,
  285. }
  286. if info.AdviceId > 0 && info.ProjectId == 0 {
  287. info.MedChrgitmType = "09"
  288. } else if info.AdviceId == 0 && info.ProjectId > 0 {
  289. p, _ := service.GetHisPrescriptionProjectByIDTwo(info.ProjectId)
  290. if p.Type == 2 {
  291. if p.HisProject.CostClassify == 3 {
  292. info.MedChrgitmType = "04"
  293. }
  294. if p.HisProject.CostClassify == 2 {
  295. info.MedChrgitmType = "05"
  296. }
  297. if p.HisProject.CostClassify == 8 {
  298. info.MedChrgitmType = "03"
  299. }
  300. } else {
  301. info.MedChrgitmType = "08"
  302. }
  303. }
  304. service.CreateOrderInfo(info)
  305. }
  306. }
  307. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  308. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  309. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
  310. if err == nil {
  311. c.ServeSuccessJSON(map[string]interface{}{
  312. "msg": "上传费用明细成功",
  313. })
  314. return
  315. } else {
  316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  317. return
  318. }
  319. } else {
  320. for _, subItem := range customs {
  321. if len(subItem.FeedetlSn) == 0 {
  322. fmt.Println("1111111")
  323. fmt.Println(subItem.FeedetlSn)
  324. fmt.Println("1111111")
  325. }
  326. if len(subItem.FeedetlSn) > 0 {
  327. fmt.Println(subItem.FeedetlSn)
  328. temp := strings.Split(subItem.FeedetlSn, "-")
  329. var advice_id int64 = 0
  330. var project_id int64 = 0
  331. var types int64 = 0
  332. fmt.Println("~~~~")
  333. fmt.Println(temp)
  334. fmt.Println("~~~~~")
  335. id, _ := strconv.ParseInt(temp[2], 10, 64)
  336. types, _ = strconv.ParseInt(temp[1], 10, 64)
  337. if temp[1] == "1" {
  338. advice_id = id
  339. project_id = 0
  340. } else if temp[1] == "2" {
  341. advice_id = 0
  342. project_id = id
  343. }
  344. info := &models.HisOrderInfo{
  345. OrderNumber: record.Number,
  346. FeedetlSn: subItem.FeedetlSn,
  347. UploadDate: recordDateTime,
  348. AdviceId: advice_id,
  349. DetItemFeeSumamt: subItem.DetItemFeeSumamt,
  350. Cnt: subItem.Cut,
  351. Pric: float64(subItem.Price),
  352. PatientId: record.PatientId,
  353. PricUplmtAmt: 0,
  354. SelfpayProp: 0,
  355. FulamtOwnpayAmt: 0,
  356. OverlmtAmt: 0,
  357. PreselfpayAmt: 0,
  358. Status: 1,
  359. Mtime: time.Now().Unix(),
  360. Ctime: time.Now().Unix(),
  361. UserOrgId: adminUser.CurrentOrgId,
  362. HisPatientId: record.ID,
  363. OrderId: 0,
  364. ProjectId: project_id,
  365. Type: types,
  366. SettleType: settle_accounts_type,
  367. }
  368. service.CreateOrderInfo(info)
  369. }
  370. }
  371. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  372. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  373. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
  374. c.ServeSuccessJSON(map[string]interface{}{
  375. "msg": "上传费用明细成功",
  376. })
  377. }
  378. }
  379. func (c *HisHospitalApiController) GetHisHospitalPatientList() {
  380. record_date := c.GetString("record_date")
  381. types, _ := c.GetInt64("type", 0)
  382. sch_type, _ := c.GetInt64("sch_type", 0)
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  386. if err != nil {
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. recordDateTime := theTime.Unix()
  391. adminInfo := c.GetAdminUserInfo()
  392. //var patients []*service.HospitalPatient
  393. var all_tempPatients []*service.HospitalPatient
  394. var tempPatients []*service.HospitalPatient
  395. var tempPatients_two []*service.HospitalPatient
  396. if adminInfo.CurrentOrgId == 10768 {
  397. tempPatients, _ = service.GetHisHospitalPatientListBySource(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  398. tempPatients_two, _ = service.GetHisHospitalSchPatientListBySource(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  399. } else {
  400. tempPatients, _ = service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  401. tempPatients_two, _ = service.GetHisHospitalSchPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  402. }
  403. if types == 0 {
  404. if adminInfo.CurrentOrgId == 10768 {
  405. all_tempPatients, _ = service.GetAllHisHospitalPatientListBySource(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  406. } else {
  407. all_tempPatients, _ = service.GetAllHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  408. }
  409. for _, item := range all_tempPatients {
  410. for index, subItem := range tempPatients_two {
  411. if item.ID == subItem.ID {
  412. tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...)
  413. }
  414. }
  415. }
  416. all_tempPatients = append(all_tempPatients, tempPatients_two...)
  417. }
  418. //当天有登记住院的和排班同时存在的话,删除掉排班的记录
  419. for _, item := range tempPatients {
  420. for index, subItem := range tempPatients_two {
  421. if item.ID == subItem.ID {
  422. tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...)
  423. }
  424. }
  425. }
  426. tempPatients = append(tempPatients, tempPatients_two...)
  427. var total_one int64
  428. var total_two int64
  429. for _, item := range tempPatients {
  430. if len(item.HisPrescription) == 0 {
  431. total_one = total_one + 1
  432. }
  433. if len(item.HisPrescription) > 0 {
  434. total_two = total_two + 1
  435. }
  436. }
  437. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  438. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  439. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  440. if types == 0 {
  441. c.ServeSuccessJSON(map[string]interface{}{
  442. "list": all_tempPatients,
  443. "total_one": total_one,
  444. "total_two": total_two,
  445. "info": adminUserInfo,
  446. "doctors": doctors,
  447. "department": department,
  448. })
  449. } else if types == 1 { //未就诊
  450. var patientsOne []*service.HospitalPatient
  451. for _, item := range tempPatients {
  452. if len(item.HisPrescription) == 0 {
  453. patientsOne = append(patientsOne, item)
  454. }
  455. }
  456. c.ServeSuccessJSON(map[string]interface{}{
  457. "list": patientsOne,
  458. "total_one": total_one,
  459. "total_two": total_two,
  460. "info": adminUserInfo,
  461. "doctors": doctors,
  462. "department": department,
  463. })
  464. } else if types == 2 { //已就诊
  465. var patientsTwo []*service.HospitalPatient
  466. for _, item := range tempPatients {
  467. if len(item.HisPrescription) > 0 {
  468. patientsTwo = append(patientsTwo, item)
  469. }
  470. }
  471. c.ServeSuccessJSON(map[string]interface{}{
  472. "list": patientsTwo,
  473. "total_one": total_one,
  474. "total_two": total_two,
  475. "info": adminUserInfo,
  476. "doctors": doctors,
  477. "department": department,
  478. })
  479. }
  480. }
  481. func (c *HisHospitalApiController) GetHisHospitalChargePatientList() {
  482. record_date := c.GetString("record_date")
  483. timeLayout := "2006-01-02"
  484. loc, _ := time.LoadLocation("Local")
  485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  486. if err != nil {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. recordDateTime := theTime.Unix()
  491. adminInfo := c.GetAdminUserInfo()
  492. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  493. orders, _ := service.GetNewAllChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  494. tempPatients, _ := service.GetNewAllUnChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  495. var patients []*models.HisHospitalCheckRecord
  496. for _, item := range tempPatients {
  497. fmt.Println(item.ID)
  498. if item.ID > 0 && item.InHospitalStatus == 1 && item.HisHospitalOrder.OrderStatus != 2 {
  499. patients = append(patients, item)
  500. }
  501. }
  502. c.ServeSuccessJSON(map[string]interface{}{
  503. "list": patients,
  504. "list_two": patients,
  505. "charge_list": orders,
  506. })
  507. }
  508. func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
  509. patient_id, _ := c.GetInt64("patient_id")
  510. his_patient_id, _ := c.GetInt64("his_patient_id")
  511. record_date := c.GetString("record_date")
  512. start_time := c.GetString("start_time")
  513. end_time := c.GetString("end_time")
  514. order_status, _ := c.GetInt64("type", 0)
  515. p_type, _ := c.GetInt64("p_type", 0)
  516. timeLayout := "2006-01-02"
  517. loc, _ := time.LoadLocation("Local")
  518. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  519. if err != nil {
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  521. return
  522. }
  523. recordDateTime := theTime.Unix()
  524. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  525. if err != nil {
  526. }
  527. startRecordDateTime := startTime.Unix()
  528. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  529. if err != nil {
  530. }
  531. endRecordDateTime := endTime.Unix()
  532. admin := c.GetAdminUserInfo()
  533. his_patient_info, _ := service.GetNewHisHospitalPatientInfo(his_patient_id)
  534. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  535. var prescriptions []*models.HisHospitalPrescription
  536. if order_status == 1 || order_status == 0 {
  537. prescriptions, _ = service.GetNewUnChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  538. } else if order_status == 2 {
  539. prescriptions, _ = service.GetNewChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  540. }
  541. var monthPrescriptions []*models.HisPrescription
  542. var settle_prescriptions []*models.HisHospitalPrescription
  543. if order_status == 1 || order_status == 0 {
  544. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  545. } else if order_status == 2 {
  546. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  547. }
  548. if order_status == 1 || order_status == 0 {
  549. settle_prescriptions, _ = service.GetSettleHisHospitalPrescription(admin.CurrentOrgId, patient_id, his_patient_info.Number)
  550. } else if order_status == 2 {
  551. settle_prescriptions, _ = service.GetSettleHisHospitalPrescriptionTwo(admin.CurrentOrgId, patient_id, his_patient_info.Number)
  552. }
  553. var settle_total float64
  554. for _, item := range settle_prescriptions {
  555. if len(item.HisPrescriptionProject) > 0 {
  556. for _, subItem := range item.HisPrescriptionProject {
  557. count, _ := strconv.ParseFloat(subItem.Count, 64)
  558. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  559. settle_total = settle_total + total
  560. }
  561. }
  562. if len(item.HisDoctorAdviceInfo) > 0 {
  563. for _, subItem := range item.HisDoctorAdviceInfo {
  564. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  565. settle_total = settle_total + total
  566. }
  567. }
  568. }
  569. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  570. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  571. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  572. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  573. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  574. //获取所有科室信息
  575. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  576. c.ServeSuccessJSON(map[string]interface{}{
  577. "his_info": his_patient_info,
  578. "xt_info": xt_patient_info,
  579. "prescription": prescriptions,
  580. "case_history": case_history,
  581. "info": patientPrescriptionInfo,
  582. "month_prescriptions": monthPrescriptions,
  583. "order": order,
  584. "doctors": doctors,
  585. "department": department,
  586. "settle_prescriptions": settle_prescriptions,
  587. "settle_total": settle_total,
  588. })
  589. return
  590. }
  591. func (c *HisHospitalApiController) GetHisHospitalrescriptionList() {
  592. record_date := c.GetString("record_date")
  593. keywords := c.GetString("keywords")
  594. page, _ := c.GetInt64("page")
  595. limit, _ := c.GetInt64("limit")
  596. timeLayout := "2006-01-02"
  597. loc, _ := time.LoadLocation("Local")
  598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  599. if err != nil {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  601. return
  602. }
  603. recordDateTime := theTime.Unix()
  604. adminInfo := c.GetAdminUserInfo()
  605. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  606. //adminInfo := c.GetAdminUserInfo()
  607. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  608. //fmt.Println(prescriptionOrder)
  609. if err == nil {
  610. c.ServeSuccessJSON(map[string]interface{}{
  611. "order": prescriptionOrder,
  612. "total": total,
  613. })
  614. } else {
  615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  616. return
  617. }
  618. }
  619. func (c *HisHospitalApiController) GetHisHospitalPrescriptionList() {
  620. record_date := c.GetString("record_date")
  621. keywords := c.GetString("keywords")
  622. page, _ := c.GetInt64("page")
  623. limit, _ := c.GetInt64("limit")
  624. timeLayout := "2006-01-02"
  625. loc, _ := time.LoadLocation("Local")
  626. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  627. if err != nil {
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  629. return
  630. }
  631. recordDateTime := theTime.Unix()
  632. adminInfo := c.GetAdminUserInfo()
  633. prescriptionOrder, err, total := service.GetHisHospitalPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  634. if err == nil {
  635. c.ServeSuccessJSON(map[string]interface{}{
  636. "order": prescriptionOrder,
  637. "total": total,
  638. })
  639. } else {
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  641. return
  642. }
  643. }
  644. func (c *HisHospitalApiController) GetZHInHospitalCheck() {
  645. id, _ := c.GetInt64("id")
  646. record_time := c.GetString("record_time")
  647. name := c.GetString("name")
  648. phone := c.GetString("phone")
  649. id_card_type, _ := c.GetInt64("id_card_type")
  650. certificates, _ := c.GetInt64("certificates")
  651. id_card_no := c.GetString("id_card_no")
  652. doctor, _ := c.GetInt64("doctor")
  653. admin_user_id, _ := c.GetInt64("admin_user_id")
  654. department, _ := c.GetInt64("department")
  655. adm_bed, _ := c.GetInt64("adm_bed")
  656. diagnosis_ids := c.GetString("diagnosis")
  657. sick_type, _ := c.GetInt64("sick_type")
  658. start_time := c.GetString("start_time")
  659. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  660. med_type, _ := c.GetInt64("med_type")
  661. timeLayout := "2006-01-02"
  662. loc, _ := time.LoadLocation("Local")
  663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  664. if err != nil {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. recordDateTime := theTime.Unix()
  669. adminInfo := c.GetAdminUserInfo()
  670. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  671. if record.ID != 0 {
  672. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  674. return
  675. }
  676. }
  677. timestamp := time.Now().Unix()
  678. tempTime := time.Unix(timestamp, 0)
  679. timeFormat := tempTime.Format("20060102150405")
  680. chrgBchno := rand.Intn(100000) + 10000
  681. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  682. timeStr := time.Now().Format("2006-01-02 15:04:05")
  683. fmt.Println(timeStr)
  684. timeArr := strings.Split(timeStr, " ")
  685. fmt.Println(timeArr)
  686. timeArrTwo := strings.Split(timeArr[0], "-")
  687. timeArrThree := strings.Split(timeArr[1], ":")
  688. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(id, 10)
  689. inHospital := &models.HisHospitalCheckRecord{
  690. PatientId: id,
  691. Name: name,
  692. MedicalTreatmentType: med_type,
  693. RecordDate: recordDateTime,
  694. IdCardNo: id_card_no,
  695. AdminUserId: admin_user_id,
  696. Departments: department,
  697. UserOrgId: adminInfo.CurrentOrgId,
  698. Status: 1,
  699. Ctime: time.Now().Unix(),
  700. Mtime: time.Now().Unix(),
  701. Number: str,
  702. Doctor: doctor,
  703. Certno: id_card_no,
  704. MedType: med_type,
  705. IptOtpNo: ipt_otp_no,
  706. AdmBed: adm_bed,
  707. IdCardType: id_card_type,
  708. Diagnosis: diagnosis_ids,
  709. SickType: sick_type,
  710. MdtrtCertType: "02",
  711. InHosptialTime: start_time,
  712. OutHosptialTime: "",
  713. InHospitalStatus: 1,
  714. Certificates: certificates,
  715. Phone: phone,
  716. BalanceAccountsType: balance_accounts_type,
  717. }
  718. service.CreateHospitalRecord(inHospital)
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "msg": "办理入院成功",
  721. "info": inHospital,
  722. })
  723. }
  724. func (this *HisHospitalApiController) GetZHOutHospitalCheck() {
  725. id, _ := this.GetInt64("id")
  726. record_time := this.GetString("record_time")
  727. out_time := this.GetString("out_time")
  728. record, _ := service.GetInHospitalRecord(id)
  729. if record.ID == 0 {
  730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  731. return
  732. }
  733. timeLayout := "2006-01-02"
  734. loc, _ := time.LoadLocation("Local")
  735. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  736. recordDateTime := theTime.Unix()
  737. //timestamp := time.Now().Unix()
  738. //tempTime := time.Unix(timestamp, 0)
  739. //timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  740. record.OutHospitalStatus = 1
  741. record.OutHosptialTime = out_time
  742. record.OutWay = 1
  743. service.CreateHospitalRecord(&record)
  744. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  745. var total float64
  746. for _, item := range orders {
  747. total = total + item.DetItemFeeSumamt
  748. }
  749. order := &models.HisOrder{
  750. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  751. HisPatientId: record.ID,
  752. PatientId: record.PatientId,
  753. SettleAccountsDate: recordDateTime,
  754. Ctime: time.Now().Unix(),
  755. Mtime: time.Now().Unix(),
  756. Status: 1,
  757. Number: record.Number,
  758. Infcode: 0,
  759. WarnMsg: "",
  760. Cainfo: "",
  761. ErrMsg: "",
  762. RespondTime: "",
  763. InfRefmsgid: "",
  764. OrderStatus: 1,
  765. MdtrtId: record.Number,
  766. IsMedicineInsurance: 1,
  767. PType: 1,
  768. MedfeeSumamt: total,
  769. PsnPartAmt: total,
  770. }
  771. err := service.CreateOrder(order)
  772. if err != nil {
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  774. return
  775. }
  776. this.ServeSuccessJSON(map[string]interface{}{
  777. "msg": "出院成功",
  778. })
  779. }
  780. func (c *HisHospitalApiController) GetSettleInfo() {
  781. order_id, _ := c.GetInt64("order_id")
  782. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  783. pay_way, _ := c.GetInt64("pay_way")
  784. pay_price, _ := c.GetFloat("pay_price")
  785. pay_card_no := c.GetString("pay_card_no")
  786. discount_price, _ := c.GetFloat("discount_price")
  787. preferential_price, _ := c.GetFloat("preferential_price")
  788. reality_price, _ := c.GetFloat("reality_price")
  789. found_price, _ := c.GetFloat("found_price")
  790. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  791. private_price, _ := c.GetFloat("private_price")
  792. fapiao_code := c.GetString("fapiao_code")
  793. fapiao_number := c.GetString("fapiao_number")
  794. id, _ := c.GetInt64("patient_id")
  795. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  796. tmp_decimal := c.GetString("tmp_decimal")
  797. var decimal float64 //本次使用的押金
  798. var errmsg error
  799. tx := service.XTWriteDB().Begin() //开了事务
  800. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  801. defer func() {
  802. if errmsg != nil {
  803. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  804. tx.Rollback()
  805. } else {
  806. tx.Commit()
  807. }
  808. }()
  809. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  810. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  811. return
  812. }
  813. if len(tmp_decimal) > 0 {
  814. if tmp_decimal[0] == 45 {
  815. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  816. return
  817. }
  818. }
  819. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  820. if errs != nil {
  821. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  822. return
  823. }
  824. decimal = tt
  825. record, _ := service.GetInHospitalRecordTX(in_hospital_id, tx)
  826. order, _ := service.GetHisOrderByIDTX(order_id, tx)
  827. chrg_bchno := order.Number
  828. if record.ID == 0 {
  829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  830. return
  831. }
  832. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  834. return
  835. }
  836. order.OrderStatus = 2
  837. order.DiscountPrice = discount_price
  838. order.MedicalInsurancePrice = medical_insurance_price
  839. order.FaPiaoNumber = fapiao_number
  840. order.FaPiaoCode = fapiao_code
  841. order.PayWay = pay_way
  842. order.PayPrice = pay_price
  843. order.PayCardNo = pay_card_no
  844. order.PreferentialPrice = preferential_price
  845. order.RealityPrice = reality_price
  846. order.FoundPrice = found_price
  847. order.PrivatePrice = private_price
  848. order.MdtrtId = record.Number
  849. order.MedfeeSumamt = order.MedfeeSumamt
  850. order.PsnCashPay = order.MedfeeSumamt
  851. order.PsnName = record.Name
  852. order.Certno = record.IdCardNo
  853. order.IsMedicineInsurance = 0
  854. order.Decimal = decimal
  855. year2 := time.Now().Format("2006")
  856. month2 := time.Now().Format("01")
  857. day2 := time.Now().Format("02")
  858. hour := time.Now().Format("15")
  859. min := time.Now().Format("04")
  860. second := time.Now().Format("05")
  861. order.SetlTime = year2 + "-" + month2 + "-" + day2 + " " + hour + ":" + min + ":" + second
  862. //order.SetlTime =
  863. err := service.UpdataOrderStatusTwoTX(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId, tx)
  864. err = service.UpDateOrderTX(order, tx)
  865. //判断是否使用了押金
  866. if dec_way == "true" {
  867. tmpstring := strconv.FormatInt(order.ID, 10)
  868. //扣押金
  869. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  870. if errmsg != nil {
  871. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  872. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  873. return
  874. }
  875. }
  876. if err == nil {
  877. c.ServeSuccessJSON(map[string]interface{}{
  878. "msg": "结算成功",
  879. })
  880. } else {
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  882. return
  883. }
  884. }
  885. func (c *HisHospitalApiController) ZHRefund() {
  886. order_id, _ := c.GetInt64("order_id")
  887. order, _ := service.GetHisOrderByID(order_id)
  888. adminUser := c.GetAdminUserInfo()
  889. orgid := c.GetAdminUserInfo().CurrentOrgId
  890. err := service.UpdataHospitalOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  891. if err != nil {
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  893. return
  894. }
  895. tmp := strconv.FormatInt(order.ID, 10)
  896. //当押金不为零时产生退费记录
  897. if order.Decimal != 0 {
  898. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  899. if err != nil {
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  901. return
  902. }
  903. }
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "退费成功",
  906. })
  907. }
  908. func (this *HisHospitalApiController) GetZHOutHospitalUnCheck() {
  909. id, _ := this.GetInt64("id")
  910. record, _ := service.GetInHospitalRecord(id)
  911. if record.ID == 0 {
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  913. return
  914. }
  915. record.OutHospitalStatus = 0
  916. service.CreateHospitalRecord(&record)
  917. this.ServeSuccessJSON(map[string]interface{}{
  918. "msg": "撤销出院成功",
  919. })
  920. }
  921. func (this *HisHospitalApiController) GetZHInHospitalUnCheck() {
  922. id, _ := this.GetInt64("id")
  923. record, _ := service.GetInHospitalRecord(id)
  924. if record.ID == 0 {
  925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  926. return
  927. }
  928. record.Status = 0
  929. service.CreateHospitalRecord(&record)
  930. this.ServeSuccessJSON(map[string]interface{}{
  931. "msg": "撤销入院成功",
  932. })
  933. }
  934. func (c *HisHospitalApiController) GetHisHospitalDetailPatientList() {
  935. record_date := c.GetString("record_date")
  936. sch_type, _ := c.GetInt64("sch_type")
  937. timeLayout := "2006-01-02"
  938. loc, _ := time.LoadLocation("Local")
  939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  940. if err != nil {
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. recordDateTime := theTime.Unix()
  945. adminInfo := c.GetAdminUserInfo()
  946. UnUploadPrescriptionPatients, _ := service.GetHisHospitalUnUploadPrescriptionDetailPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  947. UploadPrescriptionPatients, _ := service.GetHisHospitalUploadPrescriptionDetailPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  948. //var patients []*models.HisHospitalCheckRecord
  949. /* for _, item := range tempPatients {
  950. fmt.Println(item.ID)
  951. if item.ID > 0 && item.InHospitalStatus == 1 && item.HisHospitalOrder.OrderStatus != 2 {
  952. patients = append(patients, item)
  953. }
  954. }*/
  955. c.ServeSuccessJSON(map[string]interface{}{
  956. "list": UnUploadPrescriptionPatients,
  957. "list_two": UploadPrescriptionPatients,
  958. "upload_num": len(UploadPrescriptionPatients),
  959. "un_upload_num": len(UnUploadPrescriptionPatients),
  960. })
  961. }
  962. func (c *HisHospitalApiController) GetHisHospitalDetailInfo() {
  963. record_date := c.GetString("record_date")
  964. id, _ := c.GetInt64("id")
  965. is_upload, _ := c.GetInt64("is_upload")
  966. patient_id, _ := c.GetInt64("patient_id")
  967. start_time_str := c.GetString("start_time")
  968. end_time_str := c.GetString("end_time")
  969. record, _ := service.GetInHospitalRecord(id)
  970. timeLayout := "2006-01-02"
  971. loc, _ := time.LoadLocation("Local")
  972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  973. if err != nil {
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. recordDateTime := theTime.Unix()
  978. adminInfo := c.GetAdminUserInfo()
  979. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  980. if err != nil {
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  982. return
  983. }
  984. recordStartTime := theStartTime.Unix()
  985. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  986. if err != nil {
  987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  988. return
  989. }
  990. recordEndTime := theEndTime.Unix()
  991. var prescriptions []*models.HisPrescription
  992. if is_upload == 1 { //未上传
  993. prescriptions, _ = service.GetUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  994. } else if is_upload == 2 { //已上传
  995. prescriptions, _ = service.GetUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  996. }
  997. var monthPrescriptions []*models.HisPrescription
  998. if is_upload == 1 {
  999. monthPrescriptions, _ = service.GetMonthUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  1000. } else if is_upload == 2 {
  1001. monthPrescriptions, _ = service.GetMonthUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  1002. }
  1003. c.ServeSuccessJSON(map[string]interface{}{
  1004. "prescription": prescriptions,
  1005. "month_prescriptions": monthPrescriptions,
  1006. "his_info": record,
  1007. })
  1008. }
  1009. func (c *HisHospitalApiController) GetHisHospitalMonthDetailInfo() {
  1010. id, _ := c.GetInt64("id")
  1011. is_upload, _ := c.GetInt64("is_upload")
  1012. patient_id, _ := c.GetInt64("patient_id")
  1013. start_time_str := c.GetString("start_time")
  1014. end_time_str := c.GetString("end_time")
  1015. record, _ := service.GetInHospitalRecord(id)
  1016. timeLayout := "2006-01-02"
  1017. loc, _ := time.LoadLocation("Local")
  1018. adminInfo := c.GetAdminUserInfo()
  1019. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1020. if err != nil {
  1021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1022. return
  1023. }
  1024. recordStartTime := theStartTime.Unix()
  1025. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1026. if err != nil {
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1028. return
  1029. }
  1030. recordEndTime := theEndTime.Unix()
  1031. //var prescriptions []*models.HisPrescription
  1032. var monthPrescriptions []*models.HisPrescription
  1033. if is_upload == 1 {
  1034. monthPrescriptions, _ = service.GetMonthUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  1035. } else if is_upload == 2 {
  1036. monthPrescriptions, _ = service.GetMonthUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  1037. } else {
  1038. monthPrescriptions, _ = service.GetAllMonthHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  1039. }
  1040. c.ServeSuccessJSON(map[string]interface{}{
  1041. "month_prescriptions": monthPrescriptions,
  1042. "his_info": record,
  1043. })
  1044. }
  1045. func (c *HisHospitalApiController) GetExportHisHospitalUnChargeData() {
  1046. start_time_str := c.GetString("start_time")
  1047. end_time_str := c.GetString("end_time")
  1048. timeLayout := "2006-01-02"
  1049. loc, _ := time.LoadLocation("Local")
  1050. adminInfo := c.GetAdminUserInfo()
  1051. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1052. if err != nil {
  1053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1054. return
  1055. }
  1056. recordStartTime := theStartTime.Unix()
  1057. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1058. if err != nil {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. recordEndTime := theEndTime.Unix()
  1063. //var prescriptions []*models.HisPrescription
  1064. var prescriptions []*models.ExportHisPrescription
  1065. prescriptions, _ = service.GetUnChargeHisHospitalPrescription(adminInfo.CurrentOrgId, recordStartTime, recordEndTime)
  1066. c.ServeSuccessJSON(map[string]interface{}{
  1067. "month_prescriptions": prescriptions,
  1068. })
  1069. }