his_hospital_api_controller.go 30KB

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