his_hospital_api_controller.go 38KB

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