his_hospital_api_controller.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "math/rand"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type HisHospitalApiController struct {
  14. BaseAuthAPIController
  15. }
  16. func HisHospitalManagerApiRegistRouters() {
  17. beego.Router("/api/hishospitalpatient/list", &HisHospitalApiController{}, "get:GetHisHospitalPatientList")
  18. beego.Router("/api/hospitalcharge/list", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientList")
  19. beego.Router("/api/hospotalcharge/info", &HisHospitalApiController{}, "get:GetHisHospitalChargePatientInfo")
  20. beego.Router("/api/hospitalprescription/list", &HisHospitalApiController{}, "get:GetHisHospitalPrescriptionList")
  21. beego.Router("/api/hospital/inhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalCheck")
  22. beego.Router("/api/hospital/outhopitalcheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalCheck")
  23. beego.Router("/api/hospital/settle/get", &HisHospitalApiController{}, "get:GetSettleInfo")
  24. beego.Router("/api/hospital/inthopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalUnCheck")
  25. beego.Router("/api/hospital/outhopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalUnCheck")
  26. beego.Router("/api/hospital/refund", &HisHospitalApiController{}, "get:ZHRefund")
  27. beego.Router("/api/hospital/upload", &HisHospitalApiController{}, "get:GetUploadInfo")
  28. beego.Router("/api/hospitaldetail/list", &HisHospitalApiController{}, "get:GetHisHospitalDetailPatientList")
  29. beego.Router("/api/hospitaldetail/info", &HisHospitalApiController{}, "get:GetHisHospitalDetailInfo")
  30. beego.Router("/api/monthhospitaldetail/get", &HisHospitalApiController{}, "get:GetHisHospitalMonthDetailInfo")
  31. }
  32. func (c *HisHospitalApiController) GetUploadInfo() {
  33. id, _ := c.GetInt64("id")
  34. record_time := c.GetString("record_time")
  35. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  36. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  37. timeLayout := "2006-01-02"
  38. loc, _ := time.LoadLocation("Local")
  39. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  40. if err != nil {
  41. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  42. return
  43. }
  44. recordDateTime := theTime.Unix()
  45. adminUser := c.GetAdminUserInfo()
  46. var prescriptions []*models.HisPrescription
  47. if settle_accounts_type == 1 { //日结
  48. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  49. } else { //月结
  50. start_time_str := c.GetString("start_time")
  51. end_time_str := c.GetString("end_time")
  52. timeLayout := "2006-01-02"
  53. loc, _ := time.LoadLocation("Local")
  54. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  55. if err != nil {
  56. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  57. return
  58. }
  59. recordStartTime := theStartTime.Unix()
  60. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  61. if err != nil {
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  63. return
  64. }
  65. recordEndTime := theEndTime.Unix()
  66. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  67. }
  68. record, _ := service.GetInHospitalRecord(in_hospital_id)
  69. if record.ID == 0 {
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  71. return
  72. }
  73. var ids []int64
  74. for _, item := range prescriptions {
  75. ids = append(ids, item.ID)
  76. }
  77. //config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  78. var customs []*models.NewCustom
  79. for _, item := range prescriptions {
  80. tm := time.Unix(item.PreTime, 0)
  81. if item.Type == 1 { //药品
  82. for _, subItem := range item.HisDoctorAdviceInfo {
  83. if len(subItem.Drug.MedicalInsuranceNumber) > 0 && subItem.Drug.IsUser != 1 {
  84. //var randNum int
  85. //randNum = rand.Intn(10000) + 1000
  86. cus := &models.NewCustom{
  87. DetItemFeeSumamt: subItem.Price * subItem.PrescribingNumber,
  88. Cut: subItem.PrescribingNumber,
  89. FeedetlSn: subItem.FeedetlSn,
  90. Price: subItem.Price,
  91. MedListCodg: subItem.Drug.MedicalInsuranceNumber,
  92. HospApprFlag: subItem.Drug.HospApprFlag,
  93. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  94. }
  95. customs = append(customs, cus)
  96. }
  97. }
  98. }
  99. if item.Type == 2 { //项目
  100. for _, subItem := range item.HisPrescriptionProject {
  101. if subItem.Type == 2 {
  102. if len(subItem.HisProject.MedicalCode) > 0 {
  103. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  104. cus := &models.NewCustom{
  105. DetItemFeeSumamt: subItem.Price * cnt,
  106. Cut: cnt,
  107. FeedetlSn: subItem.FeedetlSn,
  108. Price: float64(subItem.Price),
  109. MedListCodg: subItem.HisProject.MedicalCode,
  110. HospApprFlag: -1,
  111. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  112. }
  113. customs = append(customs, cus)
  114. }
  115. } else if subItem.Type == 3 {
  116. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  117. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  118. cus := &models.NewCustom{
  119. DetItemFeeSumamt: subItem.Price * cnt,
  120. Cut: cnt,
  121. FeedetlSn: subItem.FeedetlSn,
  122. Price: float64(subItem.Price),
  123. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  124. HospApprFlag: -1,
  125. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  126. }
  127. customs = append(customs, cus)
  128. }
  129. }
  130. }
  131. }
  132. }
  133. fmt.Println(settle_accounts_type)
  134. if settle_accounts_type == 1 {
  135. fmt.Println(customs)
  136. for _, subItem := range customs {
  137. temp := strings.Split(subItem.FeedetlSn, "-")
  138. var advice_id int64 = 0
  139. var project_id int64 = 0
  140. var types int64 = 0
  141. id, _ := strconv.ParseInt(temp[2], 10, 64)
  142. types, _ = strconv.ParseInt(temp[1], 10, 64)
  143. if temp[1] == "1" {
  144. advice_id = id
  145. project_id = 0
  146. } else if temp[1] == "2" {
  147. advice_id = 0
  148. project_id = id
  149. }
  150. info := &models.HisOrderInfo{
  151. OrderNumber: record.Number,
  152. FeedetlSn: subItem.FeedetlSn,
  153. UploadDate: recordDateTime,
  154. AdviceId: advice_id,
  155. DetItemFeeSumamt: subItem.DetItemFeeSumamt,
  156. Cnt: subItem.Cut,
  157. Pric: float64(subItem.Price),
  158. PatientId: record.PatientId,
  159. PricUplmtAmt: 0,
  160. SelfpayProp: 0,
  161. FulamtOwnpayAmt: 0,
  162. OverlmtAmt: 0,
  163. PreselfpayAmt: 0,
  164. Status: 1,
  165. Mtime: time.Now().Unix(),
  166. Ctime: time.Now().Unix(),
  167. UserOrgId: adminUser.CurrentOrgId,
  168. HisPatientId: record.ID,
  169. OrderId: 0,
  170. ProjectId: project_id,
  171. Type: types,
  172. SettleType: settle_accounts_type,
  173. }
  174. service.CreateOrderInfo(info)
  175. }
  176. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  177. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  178. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
  179. if err == nil {
  180. c.ServeSuccessJSON(map[string]interface{}{
  181. "msg": "上传费用明细成功",
  182. })
  183. return
  184. } else {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  186. return
  187. }
  188. } else {
  189. for _, subItem := range customs {
  190. temp := strings.Split(subItem.FeedetlSn, "-")
  191. var advice_id int64 = 0
  192. var project_id int64 = 0
  193. var types int64 = 0
  194. id, _ := strconv.ParseInt(temp[2], 10, 64)
  195. types, _ = strconv.ParseInt(temp[1], 10, 64)
  196. if temp[1] == "1" {
  197. advice_id = id
  198. project_id = 0
  199. } else if temp[1] == "2" {
  200. advice_id = 0
  201. project_id = id
  202. }
  203. info := &models.HisOrderInfo{
  204. OrderNumber: record.Number,
  205. FeedetlSn: subItem.FeedetlSn,
  206. UploadDate: recordDateTime,
  207. AdviceId: advice_id,
  208. DetItemFeeSumamt: subItem.DetItemFeeSumamt,
  209. Cnt: subItem.Cut,
  210. Pric: float64(subItem.Price),
  211. PatientId: record.PatientId,
  212. PricUplmtAmt: 0,
  213. SelfpayProp: 0,
  214. FulamtOwnpayAmt: 0,
  215. OverlmtAmt: 0,
  216. PreselfpayAmt: 0,
  217. Status: 1,
  218. Mtime: time.Now().Unix(),
  219. Ctime: time.Now().Unix(),
  220. UserOrgId: adminUser.CurrentOrgId,
  221. HisPatientId: record.ID,
  222. OrderId: 0,
  223. ProjectId: project_id,
  224. Type: types,
  225. SettleType: settle_accounts_type,
  226. }
  227. service.CreateOrderInfo(info)
  228. }
  229. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  230. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  231. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
  232. c.ServeSuccessJSON(map[string]interface{}{
  233. "msg": "上传费用明细成功",
  234. })
  235. }
  236. }
  237. func (c *HisHospitalApiController) GetHisHospitalPatientList() {
  238. record_date := c.GetString("record_date")
  239. types, _ := c.GetInt64("type", 0)
  240. sch_type, _ := c.GetInt64("sch_type", 0)
  241. timeLayout := "2006-01-02"
  242. loc, _ := time.LoadLocation("Local")
  243. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  244. if err != nil {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. recordDateTime := theTime.Unix()
  249. adminInfo := c.GetAdminUserInfo()
  250. //var patients []*service.HospitalPatient
  251. var all_tempPatients []*service.HospitalPatient
  252. tempPatients, _ := service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  253. tempPatients_two, _ := service.GetHisHospitalSchPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  254. if types == 0 {
  255. all_tempPatients, _ = service.GetAllHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  256. for _, item := range all_tempPatients {
  257. for index, subItem := range tempPatients_two {
  258. if item.ID == subItem.ID {
  259. tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...)
  260. }
  261. }
  262. }
  263. all_tempPatients = append(all_tempPatients, tempPatients_two...)
  264. }
  265. //当天有登记住院的和排班同时存在的话,删除掉排班的记录
  266. for _, item := range tempPatients {
  267. for index, subItem := range tempPatients_two {
  268. if item.ID == subItem.ID {
  269. tempPatients_two = append(tempPatients_two[:index], tempPatients_two[index+1:]...)
  270. }
  271. }
  272. }
  273. tempPatients = append(tempPatients, tempPatients_two...)
  274. var total_one int64
  275. var total_two int64
  276. for _, item := range tempPatients {
  277. if item.VMHisPrescriptionInfo.ID == 0 {
  278. total_one = total_one + 1
  279. }
  280. if item.VMHisPrescriptionInfo.ID > 0 {
  281. total_two = total_two + 1
  282. }
  283. }
  284. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  285. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  286. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  287. if types == 0 {
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": all_tempPatients,
  290. "total_one": total_one,
  291. "total_two": total_two,
  292. "info": adminUserInfo,
  293. "doctors": doctors,
  294. "department": department,
  295. })
  296. } else if types == 1 { //未就诊
  297. var patientsOne []*service.HospitalPatient
  298. for _, item := range tempPatients {
  299. if item.VMHisPrescriptionInfo.ID == 0 {
  300. patientsOne = append(patientsOne, item)
  301. }
  302. }
  303. c.ServeSuccessJSON(map[string]interface{}{
  304. "list": patientsOne,
  305. "total_one": total_one,
  306. "total_two": total_two,
  307. "info": adminUserInfo,
  308. "doctors": doctors,
  309. "department": department,
  310. })
  311. } else if types == 2 { //已就诊
  312. var patientsTwo []*service.HospitalPatient
  313. for _, item := range tempPatients {
  314. if item.VMHisPrescriptionInfo.ID > 0 {
  315. patientsTwo = append(patientsTwo, item)
  316. }
  317. }
  318. c.ServeSuccessJSON(map[string]interface{}{
  319. "list": patientsTwo,
  320. "total_one": total_one,
  321. "total_two": total_two,
  322. "info": adminUserInfo,
  323. "doctors": doctors,
  324. "department": department,
  325. })
  326. }
  327. }
  328. func (c *HisHospitalApiController) GetHisHospitalChargePatientList() {
  329. record_date := c.GetString("record_date")
  330. timeLayout := "2006-01-02"
  331. loc, _ := time.LoadLocation("Local")
  332. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  335. return
  336. }
  337. recordDateTime := theTime.Unix()
  338. adminInfo := c.GetAdminUserInfo()
  339. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  340. orders, _ := service.GetNewAllChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  341. tempPatients, _ := service.GetNewAllUnChargeHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
  342. var patients []*models.HisHospitalCheckRecord
  343. for _, item := range tempPatients {
  344. fmt.Println(item.ID)
  345. if item.ID > 0 && item.InHospitalStatus == 1 && item.HisHospitalOrder.OrderStatus != 2 {
  346. patients = append(patients, item)
  347. }
  348. }
  349. c.ServeSuccessJSON(map[string]interface{}{
  350. "list": patients,
  351. "list_two": patients,
  352. "charge_list": orders,
  353. })
  354. }
  355. func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
  356. patient_id, _ := c.GetInt64("patient_id")
  357. his_patient_id, _ := c.GetInt64("his_patient_id")
  358. record_date := c.GetString("record_date")
  359. start_time := c.GetString("start_time")
  360. end_time := c.GetString("end_time")
  361. order_status, _ := c.GetInt64("type", 0)
  362. p_type, _ := c.GetInt64("p_type", 0)
  363. timeLayout := "2006-01-02"
  364. loc, _ := time.LoadLocation("Local")
  365. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  366. if err != nil {
  367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  368. return
  369. }
  370. recordDateTime := theTime.Unix()
  371. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  372. if err != nil {
  373. }
  374. startRecordDateTime := startTime.Unix()
  375. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  376. if err != nil {
  377. }
  378. endRecordDateTime := endTime.Unix()
  379. admin := c.GetAdminUserInfo()
  380. his_patient_info, _ := service.GetNewHisHospitalPatientInfo(his_patient_id)
  381. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  382. var prescriptions []*models.HisHospitalPrescription
  383. if order_status == 1 || order_status == 0 {
  384. prescriptions, _ = service.GetNewUnChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  385. } else if order_status == 2 {
  386. prescriptions, _ = service.GetNewChargeHisHospitalPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  387. }
  388. var monthPrescriptions []*models.HisPrescription
  389. var settle_prescriptions []*models.HisHospitalPrescription
  390. if order_status == 1 || order_status == 0 {
  391. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  392. } else if order_status == 2 {
  393. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  394. }
  395. if order_status == 1 || order_status == 0 {
  396. settle_prescriptions, _ = service.GetSettleHisHospitalPrescription(admin.CurrentOrgId, patient_id, his_patient_id, his_patient_info.RecordDate)
  397. } else if order_status == 2 {
  398. settle_prescriptions, _ = service.GetSettleHisHospitalPrescriptionTwo(admin.CurrentOrgId, patient_id, his_patient_info.Number)
  399. }
  400. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  401. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  402. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  403. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  404. //获取所有科室信息
  405. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  406. c.ServeSuccessJSON(map[string]interface{}{
  407. "his_info": his_patient_info,
  408. "xt_info": xt_patient_info,
  409. "prescription": prescriptions,
  410. "case_history": case_history,
  411. "info": patientPrescriptionInfo,
  412. "month_prescriptions": monthPrescriptions,
  413. "order": order,
  414. "doctors": doctors,
  415. "department": department,
  416. "settle_prescriptions": settle_prescriptions,
  417. })
  418. return
  419. }
  420. func (c *HisHospitalApiController) GetHisHospitalrescriptionList() {
  421. record_date := c.GetString("record_date")
  422. keywords := c.GetString("keywords")
  423. page, _ := c.GetInt64("page")
  424. limit, _ := c.GetInt64("limit")
  425. timeLayout := "2006-01-02"
  426. loc, _ := time.LoadLocation("Local")
  427. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  428. if err != nil {
  429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  430. return
  431. }
  432. recordDateTime := theTime.Unix()
  433. adminInfo := c.GetAdminUserInfo()
  434. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  435. //adminInfo := c.GetAdminUserInfo()
  436. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  437. //fmt.Println(prescriptionOrder)
  438. if err == nil {
  439. c.ServeSuccessJSON(map[string]interface{}{
  440. "order": prescriptionOrder,
  441. "total": total,
  442. })
  443. } else {
  444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  445. return
  446. }
  447. }
  448. func (c *HisHospitalApiController) GetHisHospitalPrescriptionList() {
  449. record_date := c.GetString("record_date")
  450. keywords := c.GetString("keywords")
  451. page, _ := c.GetInt64("page")
  452. limit, _ := c.GetInt64("limit")
  453. timeLayout := "2006-01-02"
  454. loc, _ := time.LoadLocation("Local")
  455. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  456. if err != nil {
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. recordDateTime := theTime.Unix()
  461. adminInfo := c.GetAdminUserInfo()
  462. prescriptionOrder, err, total := service.GetHisHospitalPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  463. if err == nil {
  464. c.ServeSuccessJSON(map[string]interface{}{
  465. "order": prescriptionOrder,
  466. "total": total,
  467. })
  468. } else {
  469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  470. return
  471. }
  472. }
  473. func (c *HisHospitalApiController) GetZHInHospitalCheck() {
  474. id, _ := c.GetInt64("id")
  475. record_time := c.GetString("record_time")
  476. name := c.GetString("name")
  477. phone := c.GetString("phone")
  478. id_card_type, _ := c.GetInt64("id_card_type")
  479. certificates, _ := c.GetInt64("certificates")
  480. id_card_no := c.GetString("id_card_no")
  481. doctor, _ := c.GetInt64("doctor")
  482. admin_user_id, _ := c.GetInt64("admin_user_id")
  483. department, _ := c.GetInt64("department")
  484. adm_bed, _ := c.GetInt64("adm_bed")
  485. diagnosis_ids := c.GetString("diagnosis")
  486. sick_type, _ := c.GetInt64("sick_type")
  487. start_time := c.GetString("start_time")
  488. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  489. med_type, _ := c.GetInt64("med_type")
  490. timeLayout := "2006-01-02"
  491. loc, _ := time.LoadLocation("Local")
  492. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  493. if err != nil {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  495. return
  496. }
  497. recordDateTime := theTime.Unix()
  498. adminInfo := c.GetAdminUserInfo()
  499. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  500. if record.ID != 0 {
  501. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  503. return
  504. }
  505. }
  506. timestamp := time.Now().Unix()
  507. tempTime := time.Unix(timestamp, 0)
  508. timeFormat := tempTime.Format("20060102150405")
  509. chrgBchno := rand.Intn(100000) + 10000
  510. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  511. timeStr := time.Now().Format("2006-01-02 15:04:05")
  512. fmt.Println(timeStr)
  513. timeArr := strings.Split(timeStr, " ")
  514. fmt.Println(timeArr)
  515. timeArrTwo := strings.Split(timeArr[0], "-")
  516. timeArrThree := strings.Split(timeArr[1], ":")
  517. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(id, 10)
  518. inHospital := &models.HisHospitalCheckRecord{
  519. PatientId: id,
  520. Name: name,
  521. MedicalTreatmentType: med_type,
  522. RecordDate: recordDateTime,
  523. IdCardNo: id_card_no,
  524. AdminUserId: admin_user_id,
  525. Departments: department,
  526. UserOrgId: adminInfo.CurrentOrgId,
  527. Status: 1,
  528. Ctime: time.Now().Unix(),
  529. Mtime: time.Now().Unix(),
  530. Number: str,
  531. Doctor: doctor,
  532. Certno: id_card_no,
  533. MedType: med_type,
  534. IptOtpNo: ipt_otp_no,
  535. AdmBed: adm_bed,
  536. IdCardType: id_card_type,
  537. Diagnosis: diagnosis_ids,
  538. SickType: sick_type,
  539. MdtrtCertType: "02",
  540. InHosptialTime: start_time,
  541. OutHosptialTime: "",
  542. InHospitalStatus: 1,
  543. Certificates: certificates,
  544. Phone: phone,
  545. BalanceAccountsType: balance_accounts_type,
  546. }
  547. service.CreateHospitalRecord(inHospital)
  548. c.ServeSuccessJSON(map[string]interface{}{
  549. "msg": "办理入院成功",
  550. "info": inHospital,
  551. })
  552. }
  553. func (this *HisHospitalApiController) GetZHOutHospitalCheck() {
  554. id, _ := this.GetInt64("id")
  555. record_date := this.GetString("record_date")
  556. record, _ := service.GetInHospitalRecord(id)
  557. if record.ID == 0 {
  558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  559. return
  560. }
  561. timeLayout := "2006-01-02"
  562. loc, _ := time.LoadLocation("Local")
  563. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  564. recordDateTime := theTime.Unix()
  565. timestamp := time.Now().Unix()
  566. tempTime := time.Unix(timestamp, 0)
  567. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  568. record.OutHospitalStatus = 1
  569. record.OutHosptialTime = timeFormatOne
  570. record.OutWay = 1
  571. service.CreateHospitalRecord(&record)
  572. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  573. var total float64
  574. for _, item := range orders {
  575. total = total + item.DetItemFeeSumamt
  576. }
  577. order := &models.HisOrder{
  578. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  579. HisPatientId: record.ID,
  580. PatientId: record.PatientId,
  581. SettleAccountsDate: recordDateTime,
  582. Ctime: time.Now().Unix(),
  583. Mtime: time.Now().Unix(),
  584. Status: 1,
  585. Number: record.Number,
  586. Infcode: 0,
  587. WarnMsg: "",
  588. Cainfo: "",
  589. ErrMsg: "",
  590. RespondTime: "",
  591. InfRefmsgid: "",
  592. OrderStatus: 1,
  593. MdtrtId: record.Number,
  594. IsMedicineInsurance: 1,
  595. PType: 1,
  596. MedfeeSumamt: total,
  597. }
  598. err := service.CreateOrder(order)
  599. if err != nil {
  600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  601. return
  602. }
  603. this.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "出院成功",
  605. })
  606. }
  607. func (c *HisHospitalApiController) GetSettleInfo() {
  608. order_id, _ := c.GetInt64("order_id")
  609. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  610. pay_way, _ := c.GetInt64("pay_way")
  611. pay_price, _ := c.GetFloat("pay_price")
  612. pay_card_no := c.GetString("pay_card_no")
  613. discount_price, _ := c.GetFloat("discount_price")
  614. preferential_price, _ := c.GetFloat("preferential_price")
  615. reality_price, _ := c.GetFloat("reality_price")
  616. found_price, _ := c.GetFloat("found_price")
  617. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  618. private_price, _ := c.GetFloat("private_price")
  619. fapiao_code := c.GetString("fapiao_code")
  620. fapiao_number := c.GetString("fapiao_number")
  621. record, _ := service.GetInHospitalRecord(in_hospital_id)
  622. order, _ := service.GetHisOrderByID(order_id)
  623. chrg_bchno := order.Number
  624. if record.ID == 0 {
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  626. return
  627. }
  628. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  630. return
  631. }
  632. order.OrderStatus = 2
  633. order.DiscountPrice = discount_price
  634. order.MedicalInsurancePrice = medical_insurance_price
  635. order.FaPiaoNumber = fapiao_number
  636. order.FaPiaoCode = fapiao_code
  637. order.PayWay = pay_way
  638. order.PayPrice = pay_price
  639. order.PayCardNo = pay_card_no
  640. order.PreferentialPrice = preferential_price
  641. order.RealityPrice = reality_price
  642. order.FoundPrice = found_price
  643. order.PrivatePrice = private_price
  644. order.MdtrtId = record.Number
  645. order.MedfeeSumamt = order.MedfeeSumamt
  646. //order.SetlTime =
  647. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  648. err = service.UpDateOrder(order)
  649. if err == nil {
  650. c.ServeSuccessJSON(map[string]interface{}{
  651. "msg": "结算成功",
  652. })
  653. } else {
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  655. return
  656. }
  657. }
  658. func (c *HisHospitalApiController) ZHRefund() {
  659. order_id, _ := c.GetInt64("order_id")
  660. adminUser := c.GetAdminUserInfo()
  661. var order models.HisOrder
  662. order, _ = service.GetHisOrderByID(order_id)
  663. err := service.UpdataHospitalOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  664. if err == nil {
  665. c.ServeSuccessJSON(map[string]interface{}{
  666. "msg": "退费成功",
  667. })
  668. } else {
  669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  670. return
  671. }
  672. }
  673. func (this *HisHospitalApiController) GetZHOutHospitalUnCheck() {
  674. id, _ := this.GetInt64("id")
  675. record, _ := service.GetInHospitalRecord(id)
  676. if record.ID == 0 {
  677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  678. return
  679. }
  680. record.OutHospitalStatus = 0
  681. service.CreateHospitalRecord(&record)
  682. this.ServeSuccessJSON(map[string]interface{}{
  683. "msg": "撤销出院成功",
  684. })
  685. }
  686. func (this *HisHospitalApiController) GetZHInHospitalUnCheck() {
  687. id, _ := this.GetInt64("id")
  688. record, _ := service.GetInHospitalRecord(id)
  689. if record.ID == 0 {
  690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  691. return
  692. }
  693. record.Status = 0
  694. service.CreateHospitalRecord(&record)
  695. this.ServeSuccessJSON(map[string]interface{}{
  696. "msg": "撤销入院成功",
  697. })
  698. }
  699. func (c *HisHospitalApiController) GetHisHospitalDetailPatientList() {
  700. record_date := c.GetString("record_date")
  701. sch_type, _ := c.GetInt64("sch_type")
  702. timeLayout := "2006-01-02"
  703. loc, _ := time.LoadLocation("Local")
  704. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  705. if err != nil {
  706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  707. return
  708. }
  709. recordDateTime := theTime.Unix()
  710. adminInfo := c.GetAdminUserInfo()
  711. UnUploadPrescriptionPatients, _ := service.GetHisHospitalUnUploadPrescriptionDetailPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  712. UploadPrescriptionPatients, _ := service.GetHisHospitalUploadPrescriptionDetailPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  713. //var patients []*models.HisHospitalCheckRecord
  714. /* for _, item := range tempPatients {
  715. fmt.Println(item.ID)
  716. if item.ID > 0 && item.InHospitalStatus == 1 && item.HisHospitalOrder.OrderStatus != 2 {
  717. patients = append(patients, item)
  718. }
  719. }*/
  720. c.ServeSuccessJSON(map[string]interface{}{
  721. "list": UnUploadPrescriptionPatients,
  722. "list_two": UploadPrescriptionPatients,
  723. "upload_num": len(UploadPrescriptionPatients),
  724. "un_upload_num": len(UnUploadPrescriptionPatients),
  725. })
  726. }
  727. func (c *HisHospitalApiController) GetHisHospitalDetailInfo() {
  728. record_date := c.GetString("record_date")
  729. id, _ := c.GetInt64("id")
  730. is_upload, _ := c.GetInt64("is_upload")
  731. patient_id, _ := c.GetInt64("patient_id")
  732. start_time_str := c.GetString("start_time")
  733. end_time_str := c.GetString("end_time")
  734. record, _ := service.GetInHospitalRecord(id)
  735. timeLayout := "2006-01-02"
  736. loc, _ := time.LoadLocation("Local")
  737. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  738. if err != nil {
  739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  740. return
  741. }
  742. recordDateTime := theTime.Unix()
  743. adminInfo := c.GetAdminUserInfo()
  744. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  745. if err != nil {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  747. return
  748. }
  749. recordStartTime := theStartTime.Unix()
  750. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  751. if err != nil {
  752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  753. return
  754. }
  755. recordEndTime := theEndTime.Unix()
  756. var prescriptions []*models.HisPrescription
  757. if is_upload == 1 { //未上传
  758. prescriptions, _ = service.GetUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  759. } else if is_upload == 2 { //已上传
  760. prescriptions, _ = service.GetUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  761. }
  762. var monthPrescriptions []*models.HisPrescription
  763. if is_upload == 1 {
  764. monthPrescriptions, _ = service.GetMonthUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  765. } else if is_upload == 2 {
  766. monthPrescriptions, _ = service.GetMonthUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  767. }
  768. c.ServeSuccessJSON(map[string]interface{}{
  769. "prescription": prescriptions,
  770. "month_prescriptions": monthPrescriptions,
  771. "his_info": record,
  772. })
  773. }
  774. func (c *HisHospitalApiController) GetHisHospitalMonthDetailInfo() {
  775. id, _ := c.GetInt64("id")
  776. is_upload, _ := c.GetInt64("is_upload")
  777. patient_id, _ := c.GetInt64("patient_id")
  778. start_time_str := c.GetString("start_time")
  779. end_time_str := c.GetString("end_time")
  780. record, _ := service.GetInHospitalRecord(id)
  781. timeLayout := "2006-01-02"
  782. loc, _ := time.LoadLocation("Local")
  783. adminInfo := c.GetAdminUserInfo()
  784. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  785. if err != nil {
  786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  787. return
  788. }
  789. recordStartTime := theStartTime.Unix()
  790. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  791. if err != nil {
  792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  793. return
  794. }
  795. recordEndTime := theEndTime.Unix()
  796. //var prescriptions []*models.HisPrescription
  797. var monthPrescriptions []*models.HisPrescription
  798. if is_upload == 1 {
  799. monthPrescriptions, _ = service.GetMonthUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  800. } else if is_upload == 2 {
  801. monthPrescriptions, _ = service.GetMonthUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  802. } else {
  803. monthPrescriptions, _ = service.GetAllMonthHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
  804. }
  805. c.ServeSuccessJSON(map[string]interface{}{
  806. "month_prescriptions": monthPrescriptions,
  807. "his_info": record,
  808. })
  809. }