inspection_api_controller.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_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. }
  26. //PatientInspectionReference 请求检验检查大小项目
  27. //[get]: /api/patient/inspection/reference
  28. func (c *InspectionApiController) PatientInspectionReference() {
  29. patient, _ := c.GetInt64("patient")
  30. if patient <= 0 {
  31. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  32. return
  33. }
  34. adminUserInfo := c.GetAdminUserInfo()
  35. references, err := service.GetInspectionReference(adminUserInfo.CurrentOrgId)
  36. if err != nil {
  37. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. return
  39. }
  40. patient_info, _ := service.GetPatientByID(adminUserInfo.CurrentOrgId, patient)
  41. counts, err := service.GetPatientInspectionProjectCount(adminUserInfo.CurrentOrgId, patient)
  42. if err != nil {
  43. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  44. return
  45. }
  46. countsMap := make(map[int64]int64, 0)
  47. for _, count := range counts {
  48. countsMap[count.ProjectId] = count.Count
  49. }
  50. referenceMap := make(map[string]*models.InspectionReferenceMap, 0)
  51. for _, reference := range references {
  52. if _, exist := referenceMap[reference.Project]; !exist {
  53. referenceMap[reference.Project] = new(models.InspectionReferenceMap)
  54. referenceMap[reference.Project].Project = reference.Project
  55. referenceMap[reference.Project].ProjectId = reference.ProjectId
  56. referenceMap[reference.Project].ProjectName = reference.ProjectName
  57. if _, cexit := countsMap[reference.ProjectId]; cexit {
  58. referenceMap[reference.Project].Count = countsMap[reference.ProjectId]
  59. }
  60. referenceMap[reference.Project].InspectionReference = make([]models.InspectionReference, 0)
  61. }
  62. referenceMap[reference.Project].InspectionReference = append(referenceMap[reference.Project].InspectionReference, *reference)
  63. }
  64. reference := make([]*models.InspectionReferenceMap, 0)
  65. for _, item := range referenceMap {
  66. reference = append(reference, item)
  67. }
  68. rl := len(reference)
  69. for index := 0; index < rl-1; index++ {
  70. for jndex := 0; jndex < rl-1-index; jndex++ {
  71. if reference[jndex].ProjectId > reference[jndex+1].ProjectId {
  72. var item models.InspectionReferenceMap
  73. item = *reference[jndex]
  74. reference[jndex] = reference[jndex+1]
  75. reference[jndex+1] = &item
  76. }
  77. }
  78. }
  79. list, err := service.GetInspectionReferenceByOrgId(0)
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "reference": reference,
  82. "patient_info": patient_info,
  83. "list": list,
  84. })
  85. return
  86. }
  87. func (c *InspectionApiController) CreatePatientInspection() {
  88. patient, _ := c.GetInt64("patient", 0)
  89. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  90. if patient <= 0 {
  91. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  92. return
  93. }
  94. adminUserInfo := c.GetAdminUserInfo()
  95. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  96. if patientInfo.ID == 0 {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  98. return
  99. }
  100. var from models.InepectionForm
  101. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  102. if err != nil {
  103. utils.ErrorLog("%v", err)
  104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  105. return
  106. }
  107. timeLayout := "2006-01-02 15:04"
  108. loc, _ := time.LoadLocation("Local")
  109. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  110. if err != nil {
  111. utils.ErrorLog(err.Error())
  112. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  113. return
  114. }
  115. if len(from.FormItem) == 0 {
  116. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  117. return
  118. }
  119. date := theTime.Unix()
  120. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
  121. if err != nil {
  122. utils.ErrorLog("%v", err)
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. if len(insp) > 0 {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
  128. return
  129. }
  130. inspections := make([]models.Inspection, 0)
  131. for _, item := range from.FormItem {
  132. var inspection models.Inspection
  133. inspection.OrgId = adminUserInfo.CurrentOrgId
  134. inspection.PatientId = patient
  135. inspection.ProjectId = from.ProjectId
  136. inspection.ItemId = item.ItemId
  137. inspection.ItemName = item.ItemName
  138. inspection.ProjectName = item.ProjectName
  139. inspection.InspectType = item.RangeType
  140. inspection.InspectValue = item.Value
  141. inspection.InspectDate = date
  142. inspection.Status = 1
  143. inspection.CreatedTime = time.Now().Unix()
  144. inspection.UpdatedTime = time.Now().Unix()
  145. inspections = append(inspections, inspection)
  146. }
  147. err = service.CreatePatientInspection(inspections)
  148. if err != nil {
  149. utils.ErrorLog("%v", err)
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  151. return
  152. }
  153. if remind_cycle > 0 {
  154. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
  155. fmt.Println(infectiousRecord.InspectDate)
  156. var record_time int64
  157. switch remind_cycle {
  158. case 1: //1个月
  159. ts := time.Unix(infectiousRecord.InspectDate, 0)
  160. record_time = ts.AddDate(0, 1, 0).Unix()
  161. fmt.Println(record_time)
  162. break
  163. case 2: //2个月
  164. ts := time.Unix(infectiousRecord.InspectDate, 0)
  165. record_time = ts.AddDate(0, 2, 0).Unix()
  166. fmt.Println(record_time)
  167. break
  168. case 3: //3个月
  169. ts := time.Unix(infectiousRecord.InspectDate, 0)
  170. record_time = ts.AddDate(0, 3, 0).Unix()
  171. fmt.Println(record_time)
  172. break
  173. case 4: //6个月
  174. ts := time.Unix(infectiousRecord.InspectDate, 0)
  175. record_time = ts.AddDate(0, 6, 0).Unix()
  176. fmt.Println(record_time)
  177. break
  178. case 5: //12个月
  179. ts := time.Unix(infectiousRecord.InspectDate, 0)
  180. record_time = ts.AddDate(0, 12, 0).Unix()
  181. fmt.Println(record_time)
  182. break
  183. }
  184. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  185. if errs != nil {
  186. utils.ErrorLog("更新日期出错:%v", errs)
  187. }
  188. }
  189. c.ServeSuccessJSON(map[string]interface{}{
  190. "inspections": inspections,
  191. "remind_cycle": remind_cycle,
  192. })
  193. return
  194. }
  195. func (c *InspectionApiController) EditPatientInspection() {
  196. patient, _ := c.GetInt64("patient", 0)
  197. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  198. // dates := c.GetString("dates")
  199. // projectid := c.GetString("projectid")
  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.InepectionForm
  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. oldTime, olderr := time.ParseInLocation(timeLayout, from.OldInspectDate, loc)
  226. if olderr != nil {
  227. utils.ErrorLog(olderr.Error())
  228. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  229. return
  230. }
  231. if len(from.FormItem) == 0 {
  232. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  233. return
  234. }
  235. date := theTime.Unix()
  236. oldDate := oldTime.Unix()
  237. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, oldDate, from.ProjectId)
  238. if err != nil {
  239. utils.ErrorLog("%v", err)
  240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  241. return
  242. }
  243. if len(insp) == 0 {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  245. return
  246. }
  247. inspMap := make(map[int64]*models.Inspection)
  248. for _, item := range insp {
  249. inspMap[item.ID] = item
  250. }
  251. addinsp := make([]models.Inspection, 0)
  252. editinsp := make([]models.Inspection, 0)
  253. noMap := make([]int64, 0)
  254. fmt.Println(from.FormItem)
  255. for _, item := range from.FormItem {
  256. fmt.Println(item.ID)
  257. if item.ID == 0 {
  258. var inspection models.Inspection
  259. inspection.OrgId = adminUserInfo.CurrentOrgId
  260. inspection.PatientId = patient
  261. inspection.ProjectId = from.ProjectId
  262. inspection.ItemId = item.ItemId
  263. inspection.ItemName = item.ItemName
  264. inspection.ProjectName = item.ProjectName
  265. inspection.InspectType = item.RangeType
  266. inspection.InspectValue = item.Value
  267. inspection.InspectDate = date
  268. inspection.Status = 1
  269. inspection.CreatedTime = time.Now().Unix()
  270. inspection.UpdatedTime = time.Now().Unix()
  271. addinsp = append(addinsp, inspection)
  272. } else {
  273. inspection := *inspMap[item.ID]
  274. inspection.InspectValue = item.Value
  275. inspection.InspectDate = date
  276. inspection.UpdatedTime = time.Now().Unix()
  277. editinsp = append(editinsp, inspection)
  278. noMap = append(noMap, item.ID)
  279. }
  280. }
  281. err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
  282. if err != nil {
  283. utils.ErrorLog("%v", err)
  284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionEditFail)
  285. return
  286. }
  287. inspections := make([]models.Inspection, 0)
  288. inspections = append(inspections, editinsp...)
  289. inspections = append(inspections, addinsp...)
  290. if remind_cycle > 0 {
  291. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
  292. fmt.Println(infectiousRecord.InspectDate)
  293. var record_time int64
  294. switch remind_cycle {
  295. case 1: //1个月
  296. ts := time.Unix(infectiousRecord.InspectDate, 0)
  297. record_time = ts.AddDate(0, 1, 0).Unix()
  298. break
  299. case 2: //2个月
  300. ts := time.Unix(infectiousRecord.InspectDate, 0)
  301. record_time = ts.AddDate(0, 2, 0).Unix()
  302. break
  303. case 3: //3个月
  304. ts := time.Unix(infectiousRecord.InspectDate, 0)
  305. record_time = ts.AddDate(0, 3, 0).Unix()
  306. break
  307. case 4: //6个月
  308. ts := time.Unix(infectiousRecord.InspectDate, 0)
  309. record_time = ts.AddDate(0, 6, 0).Unix()
  310. break
  311. case 5: //12个月
  312. ts := time.Unix(infectiousRecord.InspectDate, 0)
  313. record_time = ts.AddDate(0, 12, 0).Unix()
  314. break
  315. }
  316. fmt.Println(record_time)
  317. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  318. if errs != nil {
  319. utils.ErrorLog("更新日期出错:%v", errs)
  320. }
  321. }
  322. c.ServeSuccessJSON(map[string]interface{}{
  323. "inspections": inspections,
  324. "remind_cycle": remind_cycle,
  325. })
  326. return
  327. }
  328. func (c *InspectionApiController) DeletePatientInspection() {
  329. patient, _ := c.GetInt64("patient", 0)
  330. ProjectId, _ := c.GetInt64("project_id", 0)
  331. InspectDate := c.GetString("date")
  332. if patient <= 0 || ProjectId <= 0 || len(InspectDate) < 10 {
  333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  334. return
  335. }
  336. timeLayout := "2006-01-02 15:04"
  337. loc, _ := time.LoadLocation("Local")
  338. theTime, err := time.ParseInLocation(timeLayout, InspectDate, loc)
  339. if err != nil {
  340. utils.ErrorLog(err.Error())
  341. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  342. return
  343. }
  344. adminUserInfo := c.GetAdminUserInfo()
  345. date := theTime.Unix()
  346. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, ProjectId)
  347. if err != nil {
  348. utils.ErrorLog("%v", err)
  349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  350. return
  351. }
  352. if len(insp) == 0 {
  353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  354. return
  355. }
  356. err = service.DeletePatientInspection(adminUserInfo.CurrentOrgId, patient, ProjectId, date)
  357. if err != nil {
  358. utils.ErrorLog("%v", err)
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDeleteFail)
  360. return
  361. }
  362. c.ServeSuccessJSON(map[string]interface{}{
  363. "msg": "ok",
  364. })
  365. return
  366. }
  367. func (c *InspectionApiController) GetPatientInspections() {
  368. patient, _ := c.GetInt64("patient", 0)
  369. projectId, _ := c.GetInt64("project_id", 0)
  370. if patient <= 0 || projectId <= 0 {
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  372. return
  373. }
  374. page, _ := c.GetInt64("page", 0)
  375. if page <= 0 {
  376. page = 1
  377. }
  378. adminUserInfo := c.GetAdminUserInfo()
  379. inspections, total, dateTime, err := service.GetPatientInspections(adminUserInfo.CurrentOrgId, patient, projectId, page)
  380. if err != nil {
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  382. return
  383. }
  384. date := ""
  385. if len(inspections) > 0 {
  386. date = time.Unix(dateTime, 0).Format("2006-01-02 15:04")
  387. }
  388. c.ServeSuccessJSON(map[string]interface{}{
  389. "inspections": inspections,
  390. "total": total,
  391. "date": date,
  392. })
  393. return
  394. }
  395. func (c *InspectionApiController) GetAllPatientInspection() {
  396. patient, _ := c.GetInt64("patient", 0)
  397. projectStr := c.GetString("project")
  398. start_time, _ := c.GetInt64("start_time")
  399. end_time, _ := c.GetInt64("end_time")
  400. upload_type, _ := c.GetInt64("type")
  401. ids := strings.Split(projectStr, "-")
  402. if patient <= 0 {
  403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  404. return
  405. }
  406. page, _ := c.GetInt64("page", 0)
  407. if page <= 0 {
  408. page = 1
  409. }
  410. adminUserInfo := c.GetAdminUserInfo()
  411. switch upload_type {
  412. case 1:
  413. var inspections []*models.Inspection
  414. for _, item := range ids {
  415. id, _ := strconv.ParseInt(item, 10, 64)
  416. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  417. //fmt.Println(err)
  418. //if err != nil {
  419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  420. // return
  421. //}
  422. for _, inspection_item := range inspection {
  423. inspections = append(inspections, inspection_item)
  424. }
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "inspections": inspections,
  428. "type": upload_type,
  429. })
  430. break
  431. case 2:
  432. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  433. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  434. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  435. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  436. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  437. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  438. c.ServeSuccessJSON(map[string]interface{}{
  439. "inspections_one": inspection_one,
  440. "inspections_two": inspection_two,
  441. "inspections_three": inspection_three,
  442. "type": upload_type,
  443. })
  444. break
  445. case 3:
  446. var inspections []*models.Inspection
  447. for _, item := range ids {
  448. id, _ := strconv.ParseInt(item, 10, 64)
  449. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  450. //fmt.Println(err)
  451. //if err != nil {
  452. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  453. // return
  454. //}
  455. for _, inspection_item := range inspection {
  456. inspections = append(inspections, inspection_item)
  457. }
  458. }
  459. c.ServeSuccessJSON(map[string]interface{}{
  460. "inspections": inspections,
  461. "type": upload_type,
  462. })
  463. break
  464. case 4:
  465. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  466. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  467. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  468. id_four, _ := strconv.ParseInt(ids[3], 10, 64)
  469. id_five, _ := strconv.ParseInt(ids[4], 10, 64)
  470. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  471. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  472. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  473. inspection_four, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_four, start_time, end_time)
  474. inspection_five, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_five, start_time, end_time)
  475. c.ServeSuccessJSON(map[string]interface{}{
  476. "inspections_one": inspection_one,
  477. "inspections_two": inspection_two,
  478. "inspections_three": inspection_three,
  479. "inspections_four": inspection_four,
  480. "inspections_five": inspection_five,
  481. "type": upload_type,
  482. })
  483. break
  484. case 5:
  485. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  486. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  487. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  488. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "inspections_one": inspection_one,
  491. "inspections_two": inspection_two,
  492. "type": upload_type,
  493. })
  494. break
  495. case 6:
  496. var inspections []*models.Inspection
  497. for _, item := range ids {
  498. id, _ := strconv.ParseInt(item, 10, 64)
  499. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  500. //fmt.Println(err)
  501. //if err != nil {
  502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  503. // return
  504. //}
  505. for _, inspection_item := range inspection {
  506. inspections = append(inspections, inspection_item)
  507. }
  508. }
  509. c.ServeSuccessJSON(map[string]interface{}{
  510. "inspections": inspections,
  511. "type": upload_type,
  512. })
  513. break
  514. case 7:
  515. var inspections []*models.Inspection
  516. for _, item := range ids {
  517. id, _ := strconv.ParseInt(item, 10, 64)
  518. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  519. //fmt.Println(err)
  520. //if err != nil {
  521. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  522. // return
  523. //}
  524. for _, inspection_item := range inspection {
  525. inspections = append(inspections, inspection_item)
  526. }
  527. }
  528. c.ServeSuccessJSON(map[string]interface{}{
  529. "inspections": inspections,
  530. "type": upload_type,
  531. })
  532. break
  533. }
  534. return
  535. }
  536. func (c *InspectionApiController) GetInitInsepction() {
  537. references, _ := service.GetAllInspectionReference(0)
  538. c.ServeSuccessJSON(map[string]interface{}{
  539. "references": references,
  540. })
  541. return
  542. }