his_hospital_api_controller.go 39KB

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