patient_dataconfig_api_controller.go 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "github.com/astaxie/beego"
  12. )
  13. func PatientDataConfigAPIControllerRegistRouters() {
  14. beego.Router("/api/patient/courses", &PatientDataConfigAPIController{}, "get:Courses")
  15. beego.Router("/api/patient/course/create", &PatientDataConfigAPIController{}, "get:CreateCourse")
  16. beego.Router("/api/patient/course/delete", &PatientDataConfigAPIController{}, "post:DeleteCourse")
  17. beego.Router("/api/patient/course/modify", &PatientDataConfigAPIController{}, "get:ModifyCourse")
  18. beego.Router("/api/patient/rescues", &PatientDataConfigAPIController{}, "get:Rescues")
  19. beego.Router("/api/patient/rescue/create", &PatientDataConfigAPIController{}, "post:CreateRescue")
  20. beego.Router("/api/patient/rescue/delete", &PatientDataConfigAPIController{}, "post:DeleteRescue")
  21. beego.Router("/api/patient/sickhistory", &PatientDataConfigAPIController{}, "get:GetSickHistorys")
  22. beego.Router("/api/patient/sickhistory/create", &PatientDataConfigAPIController{}, "get:CreateSickHistory")
  23. beego.Router("/api/patient/sickhistory/delete", &PatientDataConfigAPIController{}, "post:DeleteSickHistory")
  24. beego.Router("/api/patient/sickhistory/modify", &PatientDataConfigAPIController{}, "get:ModifySickHistory")
  25. beego.Router("/api/patient/physiquecheck", &PatientDataConfigAPIController{}, "get:GetPhysiqueChecks")
  26. beego.Router("/api/patient/physiquecheck/create", &PatientDataConfigAPIController{}, "get:CreatePhysiqueCheck")
  27. beego.Router("/api/patient/physiquecheck/delete", &PatientDataConfigAPIController{}, "post:DeletePhysiqueCheck")
  28. beego.Router("/api/patient/physiquecheck/modify", &PatientDataConfigAPIController{}, "get:ModifyPhysiqueCheck")
  29. }
  30. type PatientDataConfigAPIController struct {
  31. BaseAuthAPIController
  32. }
  33. func (this *PatientDataConfigAPIController) GetSickHistorys() {
  34. patientID, _ := this.GetInt64("patient_id")
  35. startTimeYMDStr := this.GetString("start_time")
  36. endTimeYMDStr := this.GetString("end_time")
  37. if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
  38. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  39. return
  40. }
  41. endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
  42. startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
  43. endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
  44. if parseStartTimeErr != nil || parseEndTimeErr != nil {
  45. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  46. return
  47. }
  48. adminUserInfo := this.GetAdminUserInfo()
  49. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  50. if getPatientErr != nil {
  51. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  52. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  53. return
  54. } else if patient == nil {
  55. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  56. return
  57. }
  58. records, getRecordsErr := service.GetPatientSickHistory(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
  59. if getRecordsErr != nil {
  60. this.ErrorLog("获取患者病程记录失败:%v", getRecordsErr)
  61. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  62. return
  63. }
  64. admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  65. if getAllAdminsErr != nil {
  66. this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
  67. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  68. return
  69. }
  70. this.ServeSuccessJSON(map[string]interface{}{
  71. "records": records,
  72. "doctors": admins,
  73. })
  74. }
  75. func (this *PatientDataConfigAPIController) CreateSickHistory() {
  76. patientID, _ := this.GetInt64("patient_id")
  77. content := this.GetString("content")
  78. record_time_str := this.GetString("record_time")
  79. title := this.GetString("title")
  80. is_shenyizhishi, _ := this.GetInt64("is_shenyizhishi")
  81. is_fumotouxishi, _ := this.GetInt64("is_fumotouxishi")
  82. is_guominyaowu, _ := this.GetInt64("is_guominyaowu")
  83. guominyaowu_desc := this.GetString("guominyaowu_desc")
  84. doctor_id, _ := this.GetInt64("doctor_id")
  85. if patientID <= 0 || len(content) == 0 {
  86. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. if len(record_time_str) == 0 {
  90. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  91. return
  92. }
  93. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  94. adminUserInfo := this.GetAdminUserInfo()
  95. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  96. if getPatientErr != nil {
  97. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  98. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  99. return
  100. } else if patient == nil {
  101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  102. return
  103. }
  104. now := time.Now().Unix()
  105. record := models.XtPatientSickHistory{
  106. OrgId: adminUserInfo.CurrentOrgId,
  107. PatientId: patientID,
  108. Recorder: adminUserInfo.AdminUser.Id,
  109. RecordTime: checkDate.Unix(),
  110. Content: content,
  111. Status: 1,
  112. Title: title,
  113. IsShenyizhiHistory: is_shenyizhishi,
  114. IsFumoDialysisHistory: is_fumotouxishi,
  115. HypersusceptibilityDesc: guominyaowu_desc,
  116. IsHypersusceptibility: is_guominyaowu,
  117. Ctime: now,
  118. Mtime: now,
  119. DoctorId: doctor_id,
  120. }
  121. createErr := service.CreatePatientSickHistory(&record)
  122. if createErr != nil {
  123. this.ErrorLog("创建患者病史记录失败:%v", createErr)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. return
  126. }
  127. this.ServeSuccessJSON(map[string]interface{}{
  128. "record": record,
  129. })
  130. }
  131. func (this *PatientDataConfigAPIController) DeleteSickHistory() {
  132. patientID, _ := this.GetInt64("patient_id")
  133. idsStr := this.GetString("ids")
  134. if patientID <= 0 || len(idsStr) == 0 {
  135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  136. return
  137. }
  138. adminUserInfo := this.GetAdminUserInfo()
  139. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  140. if getPatientErr != nil {
  141. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  143. return
  144. } else if patient == nil {
  145. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  146. return
  147. }
  148. recordIDStrs := strings.Split(idsStr, ",")
  149. recordIDs := make([]int64, 0, len(recordIDStrs))
  150. for _, idStr := range recordIDStrs {
  151. id, parseErr := strconv.Atoi(idStr)
  152. if parseErr != nil {
  153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. recordIDs = append(recordIDs, int64(id))
  157. }
  158. deleteErr := service.DeletePatientSickHistoryInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
  159. if deleteErr != nil {
  160. this.ErrorLog("删除患者病程记录失败:%v", deleteErr)
  161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. return
  163. }
  164. this.ServeSuccessJSON(nil)
  165. }
  166. func (this *PatientDataConfigAPIController) ModifySickHistory() {
  167. patientID, _ := this.GetInt64("patient_id")
  168. content := this.GetString("content")
  169. id, _ := this.GetInt64("id", 0)
  170. record_time_str := this.GetString("record_time")
  171. title := this.GetString("title")
  172. is_shenyizhishi, _ := this.GetInt64("is_shenyizhishi")
  173. is_fumotouxishi, _ := this.GetInt64("is_fumotouxishi")
  174. is_guominyaowu, _ := this.GetInt64("is_guominyaowu")
  175. guominyaowu_desc := this.GetString("guominyaowu_desc")
  176. doctor_id, _ := this.GetInt64("doctor_id")
  177. if patientID <= 0 || len(content) == 0 || id == 0 || len(record_time_str) == 0 {
  178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  179. return
  180. }
  181. //timeLayout := "2006-01-02"
  182. //loc, _ := time.LoadLocation("Local")
  183. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  184. fmt.Println("checkDate--------------", checkDate)
  185. adminUserInfo := this.GetAdminUserInfo()
  186. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  187. if getPatientErr != nil {
  188. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  190. return
  191. } else if patient == nil {
  192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  193. return
  194. }
  195. now := time.Now().Unix()
  196. record := models.XtPatientSickHistory{
  197. ID: id,
  198. OrgId: adminUserInfo.CurrentOrgId,
  199. PatientId: patientID,
  200. Recorder: adminUserInfo.AdminUser.Id,
  201. Content: content,
  202. Status: 1,
  203. Ctime: now,
  204. Mtime: now,
  205. Title: title,
  206. RecordTime: checkDate.Unix(),
  207. IsShenyizhiHistory: is_shenyizhishi,
  208. IsFumoDialysisHistory: is_fumotouxishi,
  209. HypersusceptibilityDesc: guominyaowu_desc,
  210. IsHypersusceptibility: is_guominyaowu,
  211. DoctorId: doctor_id,
  212. }
  213. createErr := service.ModifyPatientSickHistory(&record)
  214. if createErr != nil {
  215. this.ErrorLog("创建患者抢救记录失败:%v", createErr)
  216. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  217. return
  218. }
  219. this.ServeSuccessJSON(map[string]interface{}{
  220. "record": record,
  221. })
  222. }
  223. func (this *PatientDataConfigAPIController) GetPhysiqueChecks() {
  224. patientID, _ := this.GetInt64("patient_id")
  225. startTimeYMDStr := this.GetString("start_time")
  226. endTimeYMDStr := this.GetString("end_time")
  227. if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
  228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
  232. startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
  233. endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
  234. if parseStartTimeErr != nil || parseEndTimeErr != nil {
  235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  236. return
  237. }
  238. adminUserInfo := this.GetAdminUserInfo()
  239. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  240. if getPatientErr != nil {
  241. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  243. return
  244. } else if patient == nil {
  245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  246. return
  247. }
  248. records, getRecordsErr := service.GetPatientPhysiqueCheck(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
  249. if getRecordsErr != nil {
  250. this.ErrorLog("获取患者病程记录失败:%v", getRecordsErr)
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. return
  253. }
  254. admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  255. if getAllAdminsErr != nil {
  256. this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  258. return
  259. }
  260. this.ServeSuccessJSON(map[string]interface{}{
  261. "records": records,
  262. "doctors": admins,
  263. })
  264. }
  265. func (this *PatientDataConfigAPIController) CreatePhysiqueCheck() {
  266. patientID, _ := this.GetInt64("patient_id")
  267. doctor_id, _ := this.GetInt64("doctor_id")
  268. record_time_str := this.GetString("record_time")
  269. t := this.GetString("t")
  270. p := this.GetString("p")
  271. r := this.GetString("r")
  272. bp_left := this.GetString("bp_left")
  273. bp_right := this.GetString("bp_right")
  274. pinxuerongmao, _ := this.GetInt64("pinxuerongmao")
  275. tiwei, _ := this.GetInt64("tiwei")
  276. fuzhong, _ := this.GetInt64("fuzhong")
  277. chuxuedian, _ := this.GetInt64("chuxuedian")
  278. fayu, _ := this.GetInt64("fayu")
  279. yinyang, _ := this.GetInt64("yinyang")
  280. shenzhi, _ := this.GetInt64("shenzhi")
  281. pifunianmo, _ := this.GetInt64("pifunianmo")
  282. buwei := this.GetString("buwei")
  283. chengdu := this.GetString("chengdu")
  284. pixiachuxue, _ := this.GetInt64("pixiachuxue")
  285. zidian, _ := this.GetInt64("zidian")
  286. pifuwendu, _ := this.GetInt64("pifuwendu")
  287. qita := this.GetString("qita")
  288. linbazhongda, _ := this.GetInt64("linbazhongda")
  289. linbabuwei := this.GetString("linbabuwei")
  290. yanlian, _ := this.GetInt64("yanlian")
  291. tongkong, _ := this.GetInt64("tongkong")
  292. zuo := this.GetString("zuo")
  293. you := this.GetString("you")
  294. duiguangfanshe := this.GetString("duiguangfanshe")
  295. biantaoti := this.GetString("biantaoti")
  296. yanbu := this.GetString("yanbu")
  297. toubuqita := this.GetString("toubuqita")
  298. huxiyin := this.GetString("huxiyin")
  299. xiongmomocayin, _ := this.GetInt64("xiongmomocayin")
  300. feizhangbuwei, _ := this.GetInt64("feizhangbuwei")
  301. luoyin, _ := this.GetInt64("luoyin")
  302. desc := this.GetString("desc")
  303. xinzangdaxiao, _ := this.GetInt64("xinzangdaxiao")
  304. xinlv, _ := this.GetInt64("xinlv")
  305. xinbaomocasheng, _ := this.GetInt64("xinbaomocasheng")
  306. zayin, _ := this.GetInt64("zayin")
  307. fujiayin, _ := this.GetInt64("fujiayin")
  308. xinzangdesc := this.GetString("xinzangdesc")
  309. fushuizheng, _ := this.GetInt64("fushuizheng")
  310. ganjingjingmai := this.GetString("ganjingjingmai")
  311. gangzhang_yatong, _ := this.GetInt64("gangzhang_yatong")
  312. gangzhang_koutong, _ := this.GetInt64("gangzhang_koutong")
  313. pizhang_yatong, _ := this.GetInt64("pizhang_yatong")
  314. pizhang_koutong, _ := this.GetInt64("pizhang_koutong")
  315. shenzhang_yatong, _ := this.GetInt64("shenzhang_yatong")
  316. shenzhang_koutong, _ := this.GetInt64("shenzhang_koutong")
  317. fubu_desc := this.GetString("fubu_desc")
  318. oth_desc := this.GetString("oth_desc")
  319. if patientID <= 0 {
  320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  321. return
  322. }
  323. if len(record_time_str) == 0 {
  324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  325. return
  326. }
  327. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  328. adminUserInfo := this.GetAdminUserInfo()
  329. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  330. if getPatientErr != nil {
  331. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  333. return
  334. } else if patient == nil {
  335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  336. return
  337. }
  338. now := time.Now().Unix()
  339. record := models.XtPatientPhysiqueCheck{
  340. DoctorId: doctor_id,
  341. OrgId: adminUserInfo.CurrentOrgId,
  342. PatientId: patientID,
  343. Recorder: adminUserInfo.AdminUser.Id,
  344. RecordTime: checkDate.Unix(),
  345. Status: 1,
  346. Ctime: now,
  347. Mtime: now,
  348. T: t,
  349. P: p,
  350. R: r,
  351. BpRight: bp_right,
  352. BpLeft: bp_left,
  353. Pinxuerongmao: pinxuerongmao,
  354. Tiwei: tiwei,
  355. Fuzhong: fuzhong,
  356. Chuxuedian: chuxuedian,
  357. Fayu: fayu,
  358. Yinyang: yinyang,
  359. Shenzhi: shenzhi,
  360. Pifunianmo: pifunianmo,
  361. Buwei: buwei,
  362. Chengdu: chengdu,
  363. Pixiachuxue: pixiachuxue,
  364. Zidian: zidian,
  365. Pifuwendu: pifuwendu,
  366. Qita: qita,
  367. Linbazhongda: linbazhongda,
  368. Linbabuwei: linbabuwei,
  369. Yanlian: yanlian,
  370. Tongkong: tongkong,
  371. Zuo: zuo,
  372. You: you,
  373. Duiguangfanshe: duiguangfanshe,
  374. Biantaoti: biantaoti,
  375. Yanbu: yanbu,
  376. Toubuqita: toubuqita,
  377. Huxiyin: huxiyin,
  378. Xiongmomocayin: xiongmomocayin,
  379. Feizhangbuwei: feizhangbuwei,
  380. Luoyin: luoyin,
  381. Desc: desc,
  382. Xinzangdaxiao: xinzangdaxiao,
  383. Xinlv: xinlv,
  384. Xinbaomocasheng: xinbaomocasheng,
  385. Zayin: zayin,
  386. Fujiayin: fujiayin,
  387. Xinzangdesc: xinzangdesc,
  388. Fushuizheng: fushuizheng,
  389. Ganjingjingmai: ganjingjingmai,
  390. GangzhangYatong: gangzhang_yatong,
  391. GangzhangKoutong: gangzhang_koutong,
  392. PizhangKoutong: pizhang_koutong,
  393. PizhangYatong: pizhang_yatong,
  394. ShenzhangKoutong: shenzhang_koutong,
  395. ShenzhangYatong: shenzhang_yatong,
  396. FubuDesc: fubu_desc,
  397. OthDesc: oth_desc,
  398. }
  399. createErr := service.CreatePatientPhysiqueCheck(&record)
  400. if createErr != nil {
  401. this.ErrorLog("创建患者病史记录失败:%v", createErr)
  402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  403. return
  404. }
  405. this.ServeSuccessJSON(map[string]interface{}{
  406. "record": record,
  407. })
  408. }
  409. func (this *PatientDataConfigAPIController) DeletePhysiqueCheck() {
  410. patientID, _ := this.GetInt64("patient_id")
  411. idsStr := this.GetString("ids")
  412. if patientID <= 0 || len(idsStr) == 0 {
  413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  414. return
  415. }
  416. adminUserInfo := this.GetAdminUserInfo()
  417. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  418. if getPatientErr != nil {
  419. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  420. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  421. return
  422. } else if patient == nil {
  423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  424. return
  425. }
  426. recordIDStrs := strings.Split(idsStr, ",")
  427. recordIDs := make([]int64, 0, len(recordIDStrs))
  428. for _, idStr := range recordIDStrs {
  429. id, parseErr := strconv.Atoi(idStr)
  430. if parseErr != nil {
  431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  432. return
  433. }
  434. recordIDs = append(recordIDs, int64(id))
  435. }
  436. deleteErr := service.DeletePatientPhysiqueCheckInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
  437. if deleteErr != nil {
  438. this.ErrorLog("删除患者病程记录失败:%v", deleteErr)
  439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  440. return
  441. }
  442. this.ServeSuccessJSON(nil)
  443. }
  444. func (this *PatientDataConfigAPIController) ModifyPhysiqueCheck() {
  445. patientID, _ := this.GetInt64("patient_id")
  446. id, _ := this.GetInt64("id", 0)
  447. doctor_id, _ := this.GetInt64("doctor_id", 0)
  448. record_time_str := this.GetString("record_time")
  449. if patientID <= 0 || id == 0 || len(record_time_str) == 0 {
  450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. t := this.GetString("t")
  454. p := this.GetString("p")
  455. r := this.GetString("r")
  456. bp_left := this.GetString("bp_left")
  457. bp_right := this.GetString("bp_right")
  458. pinxuerongmao, _ := this.GetInt64("pinxuerongmao")
  459. tiwei, _ := this.GetInt64("tiwei")
  460. fuzhong, _ := this.GetInt64("fuzhong")
  461. chuxuedian, _ := this.GetInt64("chuxuedian")
  462. fayu, _ := this.GetInt64("fayu")
  463. yinyang, _ := this.GetInt64("yinyang")
  464. shenzhi, _ := this.GetInt64("shenzhi")
  465. pifunianmo, _ := this.GetInt64("pifunianmo")
  466. buwei := this.GetString("buwei")
  467. chengdu := this.GetString("chengdu")
  468. pixiachuxue, _ := this.GetInt64("pixiachuxue")
  469. zidian, _ := this.GetInt64("zidian")
  470. pifuwendu, _ := this.GetInt64("pifuwendu")
  471. qita := this.GetString("qita")
  472. linbazhongda, _ := this.GetInt64("linbazhongda")
  473. linbabuwei := this.GetString("linbabuwei")
  474. yanlian, _ := this.GetInt64("yanlian")
  475. tongkong, _ := this.GetInt64("tongkong")
  476. zuo := this.GetString("zuo")
  477. you := this.GetString("you")
  478. duiguangfanshe := this.GetString("duiguangfanshe")
  479. biantaoti := this.GetString("biantaoti")
  480. yanbu := this.GetString("yanbu")
  481. toubuqita := this.GetString("toubuqita")
  482. huxiyin := this.GetString("huxiyin")
  483. xiongmomocayin, _ := this.GetInt64("xiongmomocayin")
  484. feizhangbuwei, _ := this.GetInt64("feizhangbuwei")
  485. luoyin, _ := this.GetInt64("luoyin")
  486. desc := this.GetString("desc")
  487. xinzangdaxiao, _ := this.GetInt64("xinzangdaxiao")
  488. xinlv, _ := this.GetInt64("xinlv")
  489. xinbaomocasheng, _ := this.GetInt64("xinbaomocasheng")
  490. zayin, _ := this.GetInt64("zayin")
  491. fujiayin, _ := this.GetInt64("fujiayin")
  492. xinzangdesc := this.GetString("xinzangdesc")
  493. fushuizheng, _ := this.GetInt64("fushuizheng")
  494. ganjingjingmai := this.GetString("ganjingjingmai")
  495. gangzhang_yatong, _ := this.GetInt64("gangzhang_yatong")
  496. gangzhang_koutong, _ := this.GetInt64("gangzhang_koutong")
  497. pizhang_yatong, _ := this.GetInt64("pizhang_yatong")
  498. pizhang_koutong, _ := this.GetInt64("pizhang_koutong")
  499. shenzhang_yatong, _ := this.GetInt64("shenzhang_yatong")
  500. shenzhang_koutong, _ := this.GetInt64("shenzhang_koutong")
  501. fubu_desc := this.GetString("fubu_desc")
  502. oth_desc := this.GetString("oth_desc")
  503. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  504. adminUserInfo := this.GetAdminUserInfo()
  505. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  506. if getPatientErr != nil {
  507. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  509. return
  510. } else if patient == nil {
  511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  512. return
  513. }
  514. now := time.Now().Unix()
  515. record := models.XtPatientPhysiqueCheck{
  516. ID: id,
  517. OrgId: adminUserInfo.CurrentOrgId,
  518. PatientId: patientID,
  519. Recorder: adminUserInfo.AdminUser.Id,
  520. RecordTime: checkDate.Unix(),
  521. DoctorId: doctor_id,
  522. Status: 1,
  523. Ctime: now,
  524. Mtime: now,
  525. T: t,
  526. P: p,
  527. R: r,
  528. BpRight: bp_right,
  529. BpLeft: bp_left,
  530. Pinxuerongmao: pinxuerongmao,
  531. Tiwei: tiwei,
  532. Fuzhong: fuzhong,
  533. Chuxuedian: chuxuedian,
  534. Fayu: fayu,
  535. Yinyang: yinyang,
  536. Shenzhi: shenzhi,
  537. Pifunianmo: pifunianmo,
  538. Buwei: buwei,
  539. Chengdu: chengdu,
  540. Pixiachuxue: pixiachuxue,
  541. Zidian: zidian,
  542. Pifuwendu: pifuwendu,
  543. Qita: qita,
  544. Linbazhongda: linbazhongda,
  545. Linbabuwei: linbabuwei,
  546. Yanlian: yanlian,
  547. Tongkong: tongkong,
  548. Zuo: zuo,
  549. You: you,
  550. Duiguangfanshe: duiguangfanshe,
  551. Biantaoti: biantaoti,
  552. Yanbu: yanbu,
  553. Toubuqita: toubuqita,
  554. Huxiyin: huxiyin,
  555. Xiongmomocayin: xiongmomocayin,
  556. Feizhangbuwei: feizhangbuwei,
  557. Luoyin: luoyin,
  558. Desc: desc,
  559. Xinzangdaxiao: xinzangdaxiao,
  560. Xinlv: xinlv,
  561. Xinbaomocasheng: xinbaomocasheng,
  562. Zayin: zayin,
  563. Fujiayin: fujiayin,
  564. Xinzangdesc: xinzangdesc,
  565. Fushuizheng: fushuizheng,
  566. Ganjingjingmai: ganjingjingmai,
  567. GangzhangYatong: gangzhang_yatong,
  568. GangzhangKoutong: gangzhang_koutong,
  569. PizhangKoutong: pizhang_koutong,
  570. PizhangYatong: pizhang_yatong,
  571. ShenzhangKoutong: shenzhang_koutong,
  572. ShenzhangYatong: shenzhang_yatong,
  573. FubuDesc: fubu_desc,
  574. OthDesc: oth_desc,
  575. }
  576. createErr := service.ModifyPatientPhysiqueCheck(&record)
  577. if createErr != nil {
  578. this.ErrorLog("修改患者体格检查失败:%v", createErr)
  579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  580. return
  581. }
  582. this.ServeSuccessJSON(map[string]interface{}{
  583. "record": record,
  584. })
  585. }
  586. // /api/patient/courses [get]
  587. // @param patient_id:int
  588. // @param start_time:string (yyyy-MM-dd)
  589. // @param end_time:string (yyyy-MM-dd)
  590. func (this *PatientDataConfigAPIController) Courses() {
  591. patientID, _ := this.GetInt64("patient_id")
  592. startTimeYMDStr := this.GetString("start_time")
  593. endTimeYMDStr := this.GetString("end_time")
  594. if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
  595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  596. return
  597. }
  598. endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
  599. startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
  600. endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
  601. if parseStartTimeErr != nil || parseEndTimeErr != nil {
  602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  603. return
  604. }
  605. adminUserInfo := this.GetAdminUserInfo()
  606. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  607. if getPatientErr != nil {
  608. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  610. return
  611. } else if patient == nil {
  612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  613. return
  614. }
  615. records, getRecordsErr := service.GetPatientCourseOfDisease(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
  616. if getRecordsErr != nil {
  617. this.ErrorLog("获取患者病程记录失败:%v", getRecordsErr)
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  619. return
  620. }
  621. admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  622. if getAllAdminsErr != nil {
  623. this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
  624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  625. return
  626. }
  627. this.ServeSuccessJSON(map[string]interface{}{
  628. "records": records,
  629. "doctors": admins,
  630. })
  631. }
  632. // /api/patient/course/create [post]
  633. // @param patient_id:int
  634. // @param content:string
  635. func (this *PatientDataConfigAPIController) CreateCourse() {
  636. patientID, _ := this.GetInt64("patient_id")
  637. fmt.Println(patientID)
  638. content := this.GetString("content")
  639. record_time_str := this.GetString("record_time")
  640. title := this.GetString("title")
  641. if patientID <= 0 || len(content) == 0 {
  642. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  643. return
  644. }
  645. if len(record_time_str) == 0 {
  646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  647. return
  648. }
  649. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  650. adminUserInfo := this.GetAdminUserInfo()
  651. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  652. if getPatientErr != nil {
  653. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  654. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  655. return
  656. } else if patient == nil {
  657. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  658. return
  659. }
  660. now := time.Now().Unix()
  661. record := models.PatientDiseaseCourse{
  662. OrgID: adminUserInfo.CurrentOrgId,
  663. PatientID: patientID,
  664. Recorder: adminUserInfo.AdminUser.Id,
  665. RecordTime: checkDate.Unix(),
  666. Content: content,
  667. Status: 1,
  668. CreateTime: now,
  669. ModifyTime: now,
  670. Title: title,
  671. }
  672. createErr := service.CreatePatientCourseOfDisease(&record)
  673. if createErr != nil {
  674. this.ErrorLog("创建患者病程记录失败:%v", createErr)
  675. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  676. return
  677. }
  678. this.ServeSuccessJSON(map[string]interface{}{
  679. "record": record,
  680. })
  681. }
  682. // /api/patient/course/delete
  683. // @param patient_id:int
  684. // @param ids:string 一个或多个record_id以逗号相隔 ("1,3,7")
  685. func (this *PatientDataConfigAPIController) DeleteCourse() {
  686. patientID, _ := this.GetInt64("patient_id")
  687. idsStr := this.GetString("ids")
  688. if patientID <= 0 || len(idsStr) == 0 {
  689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  690. return
  691. }
  692. adminUserInfo := this.GetAdminUserInfo()
  693. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  694. if getPatientErr != nil {
  695. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  697. return
  698. } else if patient == nil {
  699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  700. return
  701. }
  702. recordIDStrs := strings.Split(idsStr, ",")
  703. recordIDs := make([]int64, 0, len(recordIDStrs))
  704. for _, idStr := range recordIDStrs {
  705. id, parseErr := strconv.Atoi(idStr)
  706. if parseErr != nil {
  707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. recordIDs = append(recordIDs, int64(id))
  711. }
  712. deleteErr := service.DeletePatientCoursesInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
  713. if deleteErr != nil {
  714. this.ErrorLog("删除患者病程记录失败:%v", deleteErr)
  715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  716. return
  717. }
  718. this.ServeSuccessJSON(nil)
  719. }
  720. // /api/patient/rescues [get]
  721. // @param patient_id:int
  722. // @param start_time:string (yyyy-MM-dd)
  723. // @param end_time:string (yyyy-MM-dd)
  724. func (this *PatientDataConfigAPIController) Rescues() {
  725. patientID, _ := this.GetInt64("patient_id")
  726. startTimeYMDStr := this.GetString("start_time")
  727. endTimeYMDStr := this.GetString("end_time")
  728. if patientID <= 0 || len(startTimeYMDStr) == 0 || len(endTimeYMDStr) == 0 {
  729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  730. return
  731. }
  732. endTimeYMDHmsStr := endTimeYMDStr + " 23:59:59"
  733. startTime, parseStartTimeErr := utils.ParseTimeStringToTime("2006-01-02", startTimeYMDStr)
  734. endTime, parseEndTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
  735. if parseStartTimeErr != nil || parseEndTimeErr != nil {
  736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  737. return
  738. }
  739. adminUserInfo := this.GetAdminUserInfo()
  740. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  741. if getPatientErr != nil {
  742. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  743. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  744. return
  745. } else if patient == nil {
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. records, getRecordsErr := service.GetPatientRescueRecords(adminUserInfo.CurrentOrgId, patientID, startTime.Unix(), endTime.Unix())
  750. if getRecordsErr != nil {
  751. this.ErrorLog("获取患者抢救记录失败:%v", getRecordsErr)
  752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  753. return
  754. }
  755. admins, getAllAdminsErr := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  756. if getAllAdminsErr != nil {
  757. this.ErrorLog("获取所有管理员失败:%v", getAllAdminsErr)
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  759. return
  760. }
  761. this.ServeSuccessJSON(map[string]interface{}{
  762. "records": records,
  763. "doctors": admins,
  764. })
  765. }
  766. // /api/patient/rescue/create [post]
  767. // @param patient_id:int
  768. // @param content:string
  769. func (this *PatientDataConfigAPIController) CreateRescue() {
  770. patientID, _ := this.GetInt64("patient_id")
  771. content := this.GetString("content")
  772. if patientID <= 0 || len(content) == 0 {
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  774. return
  775. }
  776. adminUserInfo := this.GetAdminUserInfo()
  777. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  778. if getPatientErr != nil {
  779. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  781. return
  782. } else if patient == nil {
  783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  784. return
  785. }
  786. now := time.Now().Unix()
  787. record := models.PatientRescueRecord{
  788. OrgID: adminUserInfo.CurrentOrgId,
  789. PatientID: patientID,
  790. Recorder: adminUserInfo.AdminUser.Id,
  791. RecordTime: now,
  792. Content: content,
  793. Status: 1,
  794. CreateTime: now,
  795. ModifyTime: now,
  796. }
  797. createErr := service.CreatePatientRescueRecord(&record)
  798. if createErr != nil {
  799. this.ErrorLog("创建患者抢救记录失败:%v", createErr)
  800. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  801. return
  802. }
  803. this.ServeSuccessJSON(map[string]interface{}{
  804. "record": record,
  805. })
  806. }
  807. // /api/patient/rescue/delete
  808. // @param patient_id:int
  809. // @param ids:string 一个或多个record_id以逗号相隔 ("1,3,7")
  810. func (this *PatientDataConfigAPIController) DeleteRescue() {
  811. patientID, _ := this.GetInt64("patient_id")
  812. idsStr := this.GetString("ids")
  813. if patientID <= 0 || len(idsStr) == 0 {
  814. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  815. return
  816. }
  817. adminUserInfo := this.GetAdminUserInfo()
  818. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  819. if getPatientErr != nil {
  820. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  822. return
  823. } else if patient == nil {
  824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  825. return
  826. }
  827. recordIDStrs := strings.Split(idsStr, ",")
  828. recordIDs := make([]int64, 0, len(recordIDStrs))
  829. for _, idStr := range recordIDStrs {
  830. id, parseErr := strconv.Atoi(idStr)
  831. if parseErr != nil {
  832. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  833. return
  834. }
  835. recordIDs = append(recordIDs, int64(id))
  836. }
  837. deleteErr := service.DeletePatientResuceRecordsInBatch(adminUserInfo.CurrentOrgId, patientID, recordIDs)
  838. if deleteErr != nil {
  839. this.ErrorLog("删除患者抢救记录失败:%v", deleteErr)
  840. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  841. return
  842. }
  843. this.ServeSuccessJSON(nil)
  844. }
  845. func (this *PatientDataConfigAPIController) ModifyCourse() {
  846. patientID, _ := this.GetInt64("patient_id")
  847. content := this.GetString("content")
  848. id, _ := this.GetInt64("id", 0)
  849. record_time_str := this.GetString("record_time")
  850. title := this.GetString("title")
  851. if patientID <= 0 || len(content) == 0 || id == 0 || len(record_time_str) == 0 {
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  853. return
  854. }
  855. //timeLayout := "2006-01-02"
  856. //loc, _ := time.LoadLocation("Local")
  857. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", record_time_str)
  858. fmt.Println("checkDate--------------", checkDate)
  859. adminUserInfo := this.GetAdminUserInfo()
  860. patient, getPatientErr := service.GetPatientByID(adminUserInfo.CurrentOrgId, patientID)
  861. if getPatientErr != nil {
  862. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  863. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  864. return
  865. } else if patient == nil {
  866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  867. return
  868. }
  869. now := time.Now().Unix()
  870. record := models.PatientDiseaseCourse{
  871. ID: id,
  872. OrgID: adminUserInfo.CurrentOrgId,
  873. PatientID: patientID,
  874. Recorder: adminUserInfo.AdminUser.Id,
  875. Content: content,
  876. Status: 1,
  877. CreateTime: now,
  878. ModifyTime: now,
  879. Title: title,
  880. RecordTime: checkDate.Unix(),
  881. }
  882. createErr := service.ModifyPatientCourses(&record)
  883. if createErr != nil {
  884. this.ErrorLog("创建患者抢救记录失败:%v", createErr)
  885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  886. return
  887. }
  888. this.ServeSuccessJSON(map[string]interface{}{
  889. "record": record,
  890. })
  891. }