inspection_api_controller.go 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type InspectionApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func InspectionApiRegistRouters() {
  18. beego.Router("/api/patient/inspection/list", &InspectionApiController{}, "Get:GetPatientInspections")
  19. beego.Router("/api/patient/inspection/reference", &InspectionApiController{}, "Get:PatientInspectionReference")
  20. beego.Router("/api/patient/inspection/create", &InspectionApiController{}, "Post:CreatePatientInspection")
  21. beego.Router("/api/patient/inspection/edit", &InspectionApiController{}, "Put:EditPatientInspection")
  22. beego.Router("/api/patient/inspection/delete", &InspectionApiController{}, "Delete:DeletePatientInspection")
  23. beego.Router("/api/patient/inspection/get", &InspectionApiController{}, "Get:GetAllPatientInspection")
  24. beego.Router("/api/patient/inspectioninit/get", &InspectionApiController{}, "Get:GetInitInsepction")
  25. beego.Router("/api/patient/pic_inspection/create", &InspectionApiController{}, "Post:CreatePatientPicInspection")
  26. beego.Router("/api/patient/pic_inspection/edit", &InspectionApiController{}, "Post:EditPatientPicInspection")
  27. }
  28. // PatientInspectionReference 请求检验检查大小项目
  29. // [get]: /api/patient/inspection/reference
  30. func (c *InspectionApiController) PatientInspectionReference() {
  31. patient, _ := c.GetInt64("patient")
  32. inspect_type, _ := c.GetInt64("type")
  33. if patient <= 0 {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  35. return
  36. }
  37. adminUserInfo := c.GetAdminUserInfo()
  38. references, err := service.GetInspectionReference(adminUserInfo.CurrentOrgId, inspect_type)
  39. if err != nil {
  40. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. return
  42. }
  43. patient_info, _ := service.GetPatientByID(adminUserInfo.CurrentOrgId, patient)
  44. counts, err := service.GetPatientInspectionProjectCount(adminUserInfo.CurrentOrgId, patient)
  45. if err != nil {
  46. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  47. return
  48. }
  49. countsMap := make(map[int64]int64, 0)
  50. for _, count := range counts {
  51. countsMap[count.ProjectId] = count.Count
  52. }
  53. referenceMap := make(map[string]*models.InspectionReferenceMap, 0)
  54. for _, reference := range references {
  55. if _, exist := referenceMap[reference.Project]; !exist {
  56. referenceMap[reference.Project] = new(models.InspectionReferenceMap)
  57. referenceMap[reference.Project].Project = reference.Project
  58. referenceMap[reference.Project].ProjectId = reference.ProjectId
  59. referenceMap[reference.Project].ProjectName = reference.ProjectName
  60. if _, cexit := countsMap[reference.ProjectId]; cexit {
  61. referenceMap[reference.Project].Count = countsMap[reference.ProjectId]
  62. }
  63. referenceMap[reference.Project].InspectionReference = make([]models.InspectionReference, 0)
  64. }
  65. referenceMap[reference.Project].InspectionReference = append(referenceMap[reference.Project].InspectionReference, *reference)
  66. }
  67. reference := make([]*models.InspectionReferenceMap, 0)
  68. for _, item := range referenceMap {
  69. reference = append(reference, item)
  70. }
  71. rl := len(reference)
  72. for index := 0; index < rl-1; index++ {
  73. for jndex := 0; jndex < rl-1-index; jndex++ {
  74. if reference[jndex].ProjectId > reference[jndex+1].ProjectId {
  75. var item models.InspectionReferenceMap
  76. item = *reference[jndex]
  77. reference[jndex] = reference[jndex+1]
  78. reference[jndex+1] = &item
  79. }
  80. }
  81. }
  82. list, err := service.GetInspectionReferenceByOrgId(0)
  83. c.ServeSuccessJSON(map[string]interface{}{
  84. "reference": reference,
  85. "patient_info": patient_info,
  86. "list": list,
  87. })
  88. return
  89. }
  90. func (c *InspectionApiController) CreatePatientInspection() {
  91. patient, _ := c.GetInt64("patient", 0)
  92. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  93. if patient <= 0 {
  94. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  95. return
  96. }
  97. adminUserInfo := c.GetAdminUserInfo()
  98. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  99. if patientInfo.ID == 0 {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  101. return
  102. }
  103. var from models.InepectionForm
  104. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  105. if err != nil {
  106. utils.ErrorLog("%v", err)
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  108. return
  109. }
  110. timeLayout := "2006-01-02 15:04"
  111. loc, _ := time.LoadLocation("Local")
  112. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  113. if err != nil {
  114. utils.ErrorLog(err.Error())
  115. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  116. return
  117. }
  118. if len(from.FormItem) == 0 {
  119. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  120. return
  121. }
  122. date := theTime.Unix()
  123. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
  124. if err != nil {
  125. utils.ErrorLog("%v", err)
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  127. return
  128. }
  129. if len(insp) > 0 {
  130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
  131. return
  132. }
  133. inspections := make([]models.Inspection, 0)
  134. for _, item := range from.FormItem {
  135. var inspection models.Inspection
  136. inspection.OrgId = adminUserInfo.CurrentOrgId
  137. inspection.PatientId = patient
  138. inspection.ProjectId = from.ProjectId
  139. inspection.ItemId = item.ItemId
  140. inspection.ItemName = item.ItemName
  141. inspection.ProjectName = item.ProjectName
  142. inspection.InspectType = item.RangeType
  143. inspection.InspectValue = item.Value
  144. inspection.InspectDate = date
  145. inspection.Status = 1
  146. inspection.CreatedTime = time.Now().Unix()
  147. inspection.UpdatedTime = time.Now().Unix()
  148. inspections = append(inspections, inspection)
  149. }
  150. err = service.CreatePatientInspection(inspections)
  151. if err != nil {
  152. utils.ErrorLog("%v", err)
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  154. return
  155. }
  156. if remind_cycle > 0 {
  157. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
  158. fmt.Println(infectiousRecord.InspectDate)
  159. var record_time int64
  160. switch remind_cycle {
  161. case 1: //1个月
  162. ts := time.Unix(infectiousRecord.InspectDate, 0)
  163. record_time = ts.AddDate(0, 1, 0).Unix()
  164. fmt.Println(record_time)
  165. break
  166. case 2: //2个月
  167. ts := time.Unix(infectiousRecord.InspectDate, 0)
  168. record_time = ts.AddDate(0, 2, 0).Unix()
  169. fmt.Println(record_time)
  170. break
  171. case 3: //3个月
  172. ts := time.Unix(infectiousRecord.InspectDate, 0)
  173. record_time = ts.AddDate(0, 3, 0).Unix()
  174. fmt.Println(record_time)
  175. break
  176. case 4: //6个月
  177. ts := time.Unix(infectiousRecord.InspectDate, 0)
  178. record_time = ts.AddDate(0, 6, 0).Unix()
  179. fmt.Println(record_time)
  180. break
  181. case 5: //12个月
  182. ts := time.Unix(infectiousRecord.InspectDate, 0)
  183. record_time = ts.AddDate(0, 12, 0).Unix()
  184. fmt.Println(record_time)
  185. break
  186. }
  187. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  188. if errs != nil {
  189. utils.ErrorLog("更新日期出错:%v", errs)
  190. }
  191. }
  192. c.ServeSuccessJSON(map[string]interface{}{
  193. "inspections": inspections,
  194. "remind_cycle": remind_cycle,
  195. })
  196. return
  197. }
  198. func (c *InspectionApiController) CreatePatientPicInspection() {
  199. patient, _ := c.GetInt64("patient", 0)
  200. if patient <= 0 {
  201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  202. return
  203. }
  204. adminUserInfo := c.GetAdminUserInfo()
  205. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  206. if patientInfo.ID == 0 {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. var from models.InepectionPICForm
  211. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  212. if err != nil {
  213. utils.ErrorLog("%v", err)
  214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  215. return
  216. }
  217. timeLayout := "2006-01-02 15:04"
  218. loc, _ := time.LoadLocation("Local")
  219. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  220. if err != nil {
  221. utils.ErrorLog(err.Error())
  222. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  223. return
  224. }
  225. if len(from.Imags) == 0 {
  226. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
  227. return
  228. }
  229. date := theTime.Unix()
  230. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
  231. if err != nil {
  232. utils.ErrorLog("%v", err)
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  234. return
  235. }
  236. if len(insp) > 0 {
  237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
  238. return
  239. }
  240. inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
  241. inspections := make([]models.Inspection, 0)
  242. for index, item := range from.Imags {
  243. var inspection models.Inspection
  244. inspection.OrgId = adminUserInfo.CurrentOrgId
  245. inspection.PatientId = patient
  246. inspection.ProjectId = from.ProjectId
  247. inspection.ItemId = inspection_re[index].ID
  248. inspection.ItemName = item.Desc
  249. inspection.ProjectName = ""
  250. inspection.InspectType = 3
  251. inspection.InspectValue = item.ImgUrl
  252. inspection.InspectDesc = item.Desc
  253. inspection.InspectDate = date
  254. inspection.Status = 1
  255. inspection.CreatedTime = time.Now().Unix()
  256. inspection.UpdatedTime = time.Now().Unix()
  257. inspections = append(inspections, inspection)
  258. }
  259. err = service.CreatePatientInspection(inspections)
  260. if err != nil {
  261. utils.ErrorLog("%v", err)
  262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  263. return
  264. }
  265. c.ServeSuccessJSON(map[string]interface{}{
  266. "inspections": inspections,
  267. })
  268. return
  269. }
  270. func (c *InspectionApiController) EditPatientPicInspection() {
  271. patient, _ := c.GetInt64("patient", 0)
  272. if patient <= 0 {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  274. return
  275. }
  276. adminUserInfo := c.GetAdminUserInfo()
  277. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  278. if patientInfo.ID == 0 {
  279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  280. return
  281. }
  282. var from models.InepectionPICForm
  283. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  284. if err != nil {
  285. utils.ErrorLog("%v", err)
  286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  287. return
  288. }
  289. timeLayout := "2006-01-02 15:04"
  290. loc, _ := time.LoadLocation("Local")
  291. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  292. if err != nil {
  293. utils.ErrorLog(err.Error())
  294. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  295. return
  296. }
  297. if len(from.Imags) == 0 {
  298. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
  299. return
  300. }
  301. date := theTime.Unix()
  302. inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
  303. inspections := make([]models.Inspection, 0)
  304. for index, item := range from.Imags {
  305. if item.ID == 0 {
  306. var inspection models.Inspection
  307. inspection.OrgId = adminUserInfo.CurrentOrgId
  308. inspection.PatientId = patient
  309. inspection.ProjectId = from.ProjectId
  310. inspection.ItemId = inspection_re[index].ID
  311. inspection.ItemName = item.Desc
  312. inspection.ProjectName = ""
  313. inspection.InspectType = 3
  314. inspection.InspectValue = item.ImgUrl
  315. inspection.InspectDesc = item.Desc
  316. inspection.InspectDate = date
  317. inspection.Status = 1
  318. inspection.CreatedTime = time.Now().Unix()
  319. inspection.UpdatedTime = time.Now().Unix()
  320. inspections = append(inspections, inspection)
  321. } else {
  322. var inspection models.Inspection
  323. inspection.ID = item.ID
  324. inspection.OrgId = adminUserInfo.CurrentOrgId
  325. inspection.PatientId = patient
  326. inspection.ProjectId = from.ProjectId
  327. inspection.ItemId = inspection_re[index].ID
  328. inspection.ItemName = item.Desc
  329. inspection.ProjectName = ""
  330. inspection.InspectType = 3
  331. inspection.InspectValue = item.ImgUrl
  332. inspection.InspectDesc = item.Desc
  333. inspection.InspectDate = date
  334. inspection.Status = 1
  335. inspection.CreatedTime = time.Now().Unix()
  336. inspection.UpdatedTime = time.Now().Unix()
  337. err = service.SavePatientInspection(inspection)
  338. }
  339. }
  340. for _, item := range from.DeleteImg {
  341. service.DeleteInspectionTwo(item.ID)
  342. }
  343. if len(inspections) > 0 {
  344. err = service.CreatePatientInspection(inspections)
  345. }
  346. if err != nil {
  347. utils.ErrorLog("%v", err)
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  349. return
  350. }
  351. c.ServeSuccessJSON(map[string]interface{}{
  352. "inspections": inspections,
  353. })
  354. return
  355. }
  356. func (c *InspectionApiController) EditPatientInspection() {
  357. patient, _ := c.GetInt64("patient", 0)
  358. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  359. // dates := c.GetString("dates")
  360. // projectid := c.GetString("projectid")
  361. if patient <= 0 {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. adminUserInfo := c.GetAdminUserInfo()
  366. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  367. if patientInfo.ID == 0 {
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  369. return
  370. }
  371. var from models.InepectionForm
  372. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  373. if err != nil {
  374. utils.ErrorLog("%v", err)
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. timeLayout := "2006-01-02 15:04"
  379. loc, _ := time.LoadLocation("Local")
  380. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  381. if err != nil {
  382. utils.ErrorLog(err.Error())
  383. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  384. return
  385. }
  386. oldTime, olderr := time.ParseInLocation(timeLayout, from.OldInspectDate, loc)
  387. if olderr != nil {
  388. utils.ErrorLog(olderr.Error())
  389. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  390. return
  391. }
  392. if len(from.FormItem) == 0 {
  393. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  394. return
  395. }
  396. date := theTime.Unix()
  397. oldDate := oldTime.Unix()
  398. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, oldDate, from.ProjectId)
  399. if err != nil {
  400. utils.ErrorLog("%v", err)
  401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. if len(insp) == 0 {
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  406. return
  407. }
  408. inspMap := make(map[int64]*models.Inspection)
  409. for _, item := range insp {
  410. inspMap[item.ID] = item
  411. }
  412. addinsp := make([]models.Inspection, 0)
  413. editinsp := make([]models.Inspection, 0)
  414. noMap := make([]int64, 0)
  415. fmt.Println(from.FormItem)
  416. for _, item := range from.FormItem {
  417. fmt.Println(item.ID)
  418. if item.ID == 0 {
  419. var inspection models.Inspection
  420. inspection.OrgId = adminUserInfo.CurrentOrgId
  421. inspection.PatientId = patient
  422. inspection.ProjectId = from.ProjectId
  423. inspection.ItemId = item.ItemId
  424. inspection.ItemName = item.ItemName
  425. inspection.ProjectName = item.ProjectName
  426. inspection.InspectType = item.RangeType
  427. inspection.InspectValue = item.Value
  428. inspection.InspectDate = date
  429. inspection.Status = 1
  430. inspection.CreatedTime = time.Now().Unix()
  431. inspection.UpdatedTime = time.Now().Unix()
  432. addinsp = append(addinsp, inspection)
  433. } else {
  434. inspection := *inspMap[item.ID]
  435. inspection.InspectValue = item.Value
  436. inspection.InspectDate = date
  437. inspection.UpdatedTime = time.Now().Unix()
  438. editinsp = append(editinsp, inspection)
  439. noMap = append(noMap, item.ID)
  440. }
  441. }
  442. err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
  443. if err != nil {
  444. utils.ErrorLog("%v", err)
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionEditFail)
  446. return
  447. }
  448. inspections := make([]models.Inspection, 0)
  449. inspections = append(inspections, editinsp...)
  450. inspections = append(inspections, addinsp...)
  451. if remind_cycle > 0 {
  452. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
  453. fmt.Println(infectiousRecord.InspectDate)
  454. var record_time int64
  455. switch remind_cycle {
  456. case 1: //1个月
  457. ts := time.Unix(infectiousRecord.InspectDate, 0)
  458. record_time = ts.AddDate(0, 1, 0).Unix()
  459. break
  460. case 2: //2个月
  461. ts := time.Unix(infectiousRecord.InspectDate, 0)
  462. record_time = ts.AddDate(0, 2, 0).Unix()
  463. break
  464. case 3: //3个月
  465. ts := time.Unix(infectiousRecord.InspectDate, 0)
  466. record_time = ts.AddDate(0, 3, 0).Unix()
  467. break
  468. case 4: //6个月
  469. ts := time.Unix(infectiousRecord.InspectDate, 0)
  470. record_time = ts.AddDate(0, 6, 0).Unix()
  471. break
  472. case 5: //12个月
  473. ts := time.Unix(infectiousRecord.InspectDate, 0)
  474. record_time = ts.AddDate(0, 12, 0).Unix()
  475. break
  476. }
  477. fmt.Println(record_time)
  478. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  479. if errs != nil {
  480. utils.ErrorLog("更新日期出错:%v", errs)
  481. }
  482. }
  483. c.ServeSuccessJSON(map[string]interface{}{
  484. "inspections": inspections,
  485. "remind_cycle": remind_cycle,
  486. })
  487. return
  488. }
  489. func (c *InspectionApiController) DeletePatientInspection() {
  490. patient, _ := c.GetInt64("patient", 0)
  491. ProjectId, _ := c.GetInt64("project_id", 0)
  492. InspectDate := c.GetString("date")
  493. if patient <= 0 || ProjectId <= 0 || len(InspectDate) < 10 {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  495. return
  496. }
  497. timeLayout := "2006-01-02 15:04"
  498. loc, _ := time.LoadLocation("Local")
  499. theTime, err := time.ParseInLocation(timeLayout, InspectDate, loc)
  500. if err != nil {
  501. utils.ErrorLog(err.Error())
  502. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  503. return
  504. }
  505. adminUserInfo := c.GetAdminUserInfo()
  506. date := theTime.Unix()
  507. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, ProjectId)
  508. if err != nil {
  509. utils.ErrorLog("%v", err)
  510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  511. return
  512. }
  513. if len(insp) == 0 {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  515. return
  516. }
  517. err = service.DeletePatientInspection(adminUserInfo.CurrentOrgId, patient, ProjectId, date)
  518. if err != nil {
  519. utils.ErrorLog("%v", err)
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDeleteFail)
  521. return
  522. }
  523. c.ServeSuccessJSON(map[string]interface{}{
  524. "msg": "ok",
  525. })
  526. return
  527. }
  528. func (c *InspectionApiController) GetPatientInspections() {
  529. patient, _ := c.GetInt64("patient", 0)
  530. projectId, _ := c.GetInt64("project_id", 0)
  531. if patient <= 0 || projectId <= 0 {
  532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  533. return
  534. }
  535. page, _ := c.GetInt64("page", 0)
  536. if page <= 0 {
  537. page = 1
  538. }
  539. adminUserInfo := c.GetAdminUserInfo()
  540. inspections, total, dateTime, err := service.GetPatientInspections(adminUserInfo.CurrentOrgId, patient, projectId, page)
  541. if err != nil {
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  543. return
  544. }
  545. date := ""
  546. if len(inspections) > 0 {
  547. date = time.Unix(dateTime, 0).Format("2006-01-02 15:04")
  548. }
  549. c.ServeSuccessJSON(map[string]interface{}{
  550. "inspections": inspections,
  551. "total": total,
  552. "date": date,
  553. })
  554. return
  555. }
  556. func (c *InspectionApiController) GetAllPatientInspection() {
  557. patient, _ := c.GetInt64("patient", 0)
  558. projectStr := c.GetString("project")
  559. start_time, _ := c.GetInt64("start_time")
  560. end_time, _ := c.GetInt64("end_time")
  561. upload_type, _ := c.GetInt64("type")
  562. ids := strings.Split(projectStr, "-")
  563. if patient <= 0 {
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. page, _ := c.GetInt64("page", 0)
  568. if page <= 0 {
  569. page = 1
  570. }
  571. adminUserInfo := c.GetAdminUserInfo()
  572. switch upload_type {
  573. case 1:
  574. var inspections []*models.Inspection
  575. for _, item := range ids {
  576. id, _ := strconv.ParseInt(item, 10, 64)
  577. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  578. //fmt.Println(err)
  579. //if err != nil {
  580. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  581. // return
  582. //}
  583. for _, inspection_item := range inspection {
  584. inspections = append(inspections, inspection_item)
  585. }
  586. }
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "inspections": inspections,
  589. "type": upload_type,
  590. })
  591. break
  592. case 2:
  593. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  594. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  595. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  596. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  597. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  598. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  599. c.ServeSuccessJSON(map[string]interface{}{
  600. "inspections_one": inspection_one,
  601. "inspections_two": inspection_two,
  602. "inspections_three": inspection_three,
  603. "type": upload_type,
  604. })
  605. break
  606. case 3:
  607. var inspections []*models.Inspection
  608. for _, item := range ids {
  609. id, _ := strconv.ParseInt(item, 10, 64)
  610. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  611. //fmt.Println(err)
  612. //if err != nil {
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. // return
  615. //}
  616. for _, inspection_item := range inspection {
  617. inspections = append(inspections, inspection_item)
  618. }
  619. }
  620. c.ServeSuccessJSON(map[string]interface{}{
  621. "inspections": inspections,
  622. "type": upload_type,
  623. })
  624. break
  625. case 4:
  626. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  627. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  628. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  629. id_four, _ := strconv.ParseInt(ids[3], 10, 64)
  630. id_five, _ := strconv.ParseInt(ids[4], 10, 64)
  631. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  632. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  633. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  634. inspection_four, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_four, start_time, end_time)
  635. inspection_five, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_five, start_time, end_time)
  636. c.ServeSuccessJSON(map[string]interface{}{
  637. "inspections_one": inspection_one,
  638. "inspections_two": inspection_two,
  639. "inspections_three": inspection_three,
  640. "inspections_four": inspection_four,
  641. "inspections_five": inspection_five,
  642. "type": upload_type,
  643. })
  644. break
  645. case 5:
  646. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  647. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  648. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  649. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  650. c.ServeSuccessJSON(map[string]interface{}{
  651. "inspections_one": inspection_one,
  652. "inspections_two": inspection_two,
  653. "type": upload_type,
  654. })
  655. break
  656. case 6:
  657. var inspections []*models.Inspection
  658. for _, item := range ids {
  659. id, _ := strconv.ParseInt(item, 10, 64)
  660. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  661. //fmt.Println(err)
  662. //if err != nil {
  663. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  664. // return
  665. //}
  666. for _, inspection_item := range inspection {
  667. inspections = append(inspections, inspection_item)
  668. }
  669. }
  670. c.ServeSuccessJSON(map[string]interface{}{
  671. "inspections": inspections,
  672. "type": upload_type,
  673. })
  674. break
  675. case 7:
  676. var inspections []*models.Inspection
  677. for _, item := range ids {
  678. id, _ := strconv.ParseInt(item, 10, 64)
  679. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  680. //fmt.Println(err)
  681. //if err != nil {
  682. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  683. // return
  684. //}
  685. for _, inspection_item := range inspection {
  686. inspections = append(inspections, inspection_item)
  687. }
  688. }
  689. c.ServeSuccessJSON(map[string]interface{}{
  690. "inspections": inspections,
  691. "type": upload_type,
  692. })
  693. break
  694. }
  695. return
  696. }
  697. func (c *InspectionApiController) GetInitInsepction() {
  698. references, _ := service.GetAllInspectionReference(0)
  699. c.ServeSuccessJSON(map[string]interface{}{
  700. "references": references,
  701. })
  702. return
  703. }