his_hospital_api_controller.go 33KB

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