inspection_api_controller.go 36KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/astaxie/beego"
  14. )
  15. type InspectionApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func InspectionApiRegistRouters() {
  19. beego.Router("/api/patient/inspection/list", &InspectionApiController{}, "Get:GetPatientInspections")
  20. beego.Router("/api/patient/inspection/reference", &InspectionApiController{}, "Get:PatientInspectionReference")
  21. beego.Router("/api/patient/inspection/create", &InspectionApiController{}, "Post:CreatePatientInspection")
  22. beego.Router("/api/patient/inspection/edit", &InspectionApiController{}, "Put:EditPatientInspection")
  23. beego.Router("/api/patient/inspection/delete", &InspectionApiController{}, "Delete:DeletePatientInspection")
  24. beego.Router("/api/patient/inspection/get", &InspectionApiController{}, "Get:GetAllPatientInspection")
  25. beego.Router("/api/patient/inspectioninit/get", &InspectionApiController{}, "Get:GetInitInsepction")
  26. beego.Router("/api/patient/pic_inspection/create", &InspectionApiController{}, "Post:CreatePatientPicInspection")
  27. beego.Router("/api/patient/pic_inspection/edit", &InspectionApiController{}, "Post:EditPatientPicInspection")
  28. beego.Router("/api/patient/inspection_remind/get", &InspectionApiController{}, "Get:GetInspectionRemind")
  29. beego.Router("/api/patient/inspection_remind/set", &InspectionApiController{}, "Get:SetInspectionRemind")
  30. beego.Router("/api/getnewinspectionList", &InspectionApiController{}, "Get:GetNewInspectionList")
  31. beego.Router("/api/getnewinspectiondetaillist", &InspectionApiController{}, "Get:GetNewInspectionDetailList")
  32. beego.Router("/api/editpatientnewinspection", &InspectionApiController{}, "Post:EditPatientNewInspection")
  33. beego.Router("/api/getinspecitonbypatientgroup", &InspectionApiController{}, "Get:GetInpsectionByPatientGroup")
  34. beego.Router("/api/getinspectionchildlist", &InspectionApiController{}, "Get:GetInspectionChildList")
  35. }
  36. func (c *InspectionApiController) SetInspectionRemind() {
  37. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  38. patient, _ := c.GetInt64("patient", 0)
  39. project_id, _ := c.GetInt64("project_id", 0)
  40. is_open, _ := c.GetInt64("is_open", 0)
  41. if remind_cycle > 0 {
  42. infectiousRecord, _ := service.FindLastRecordDate(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
  43. fmt.Println(infectiousRecord.InspectDate)
  44. var record_time int64
  45. switch remind_cycle {
  46. case 1: //1个月
  47. ts := time.Unix(infectiousRecord.InspectDate, 0)
  48. record_time = ts.AddDate(0, 1, 0).Unix()
  49. fmt.Println(record_time)
  50. break
  51. case 2: //2个月
  52. ts := time.Unix(infectiousRecord.InspectDate, 0)
  53. record_time = ts.AddDate(0, 2, 0).Unix()
  54. fmt.Println(record_time)
  55. break
  56. case 3: //3个月
  57. ts := time.Unix(infectiousRecord.InspectDate, 0)
  58. record_time = ts.AddDate(0, 3, 0).Unix()
  59. fmt.Println(record_time)
  60. break
  61. case 4: //6个月
  62. ts := time.Unix(infectiousRecord.InspectDate, 0)
  63. record_time = ts.AddDate(0, 6, 0).Unix()
  64. fmt.Println(record_time)
  65. break
  66. case 5: //12个月
  67. ts := time.Unix(infectiousRecord.InspectDate, 0)
  68. record_time = ts.AddDate(0, 12, 0).Unix()
  69. fmt.Println(record_time)
  70. break
  71. }
  72. var errs error
  73. if infectiousRecord.ID == 0 {
  74. record_time = 0
  75. }
  76. //根据project_id查找是否存在提醒记录,没有的话新建,有的话更新提醒时间
  77. reminds, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
  78. if reminds.ID == 0 {
  79. remind := models.XtCheckRemind{
  80. ProjectId: project_id,
  81. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  82. Status: 1,
  83. LastRemindDate: record_time,
  84. PatientId: patient,
  85. RemindCycle: remind_cycle,
  86. IsOpen: is_open,
  87. }
  88. errs = service.CreateRemind(remind)
  89. } else {
  90. errs = service.UpDateCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, record_time, project_id, remind_cycle)
  91. }
  92. fmt.Println(errs)
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "remind_cycle": remind_cycle,
  95. })
  96. } else {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. }
  101. func (c *InspectionApiController) GetInspectionRemind() {
  102. patient, _ := c.GetInt64("patient")
  103. project_id, _ := c.GetInt64("project_id")
  104. remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, project_id)
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "remind": remind,
  107. })
  108. }
  109. // PatientInspectionReference 请求检验检查大小项目
  110. // [get]: /api/patient/inspection/reference
  111. func (c *InspectionApiController) PatientInspectionReference() {
  112. patient, _ := c.GetInt64("patient")
  113. inspect_type, _ := c.GetInt64("type")
  114. if patient <= 0 {
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. adminUserInfo := c.GetAdminUserInfo()
  119. references, err := service.GetInspectionReference(adminUserInfo.CurrentOrgId, inspect_type)
  120. if err != nil {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  122. return
  123. }
  124. patient_info, _ := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, patient)
  125. counts, err := service.GetPatientInspectionProjectCount(adminUserInfo.CurrentOrgId, patient)
  126. if err != nil {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  128. return
  129. }
  130. countsMap := make(map[int64]int64, 0)
  131. for _, count := range counts {
  132. countsMap[count.ProjectId] = count.Count
  133. }
  134. referenceMap := make(map[string]*models.InspectionReferenceMap, 0)
  135. for _, reference := range references {
  136. if _, exist := referenceMap[reference.ProjectName]; !exist {
  137. referenceMap[reference.ProjectName] = new(models.InspectionReferenceMap)
  138. referenceMap[reference.ProjectName].Project = reference.Project
  139. referenceMap[reference.ProjectName].ProjectId = reference.ProjectId
  140. referenceMap[reference.ProjectName].ProjectName = reference.ProjectName
  141. if _, cexit := countsMap[reference.ProjectId]; cexit {
  142. referenceMap[reference.ProjectName].Count = countsMap[reference.ProjectId]
  143. }
  144. referenceMap[reference.ProjectName].InspectionReference = make([]models.InspectionReference, 0)
  145. }
  146. referenceMap[reference.ProjectName].InspectionReference = append(referenceMap[reference.ProjectName].InspectionReference, *reference)
  147. }
  148. reference := make([]*models.InspectionReferenceMap, 0)
  149. for _, item := range referenceMap {
  150. reference = append(reference, item)
  151. }
  152. rl := len(reference)
  153. for index := 0; index < rl-1; index++ {
  154. for jndex := 0; jndex < rl-1-index; jndex++ {
  155. if reference[jndex].ProjectId > reference[jndex+1].ProjectId {
  156. var item models.InspectionReferenceMap
  157. item = *reference[jndex]
  158. reference[jndex] = reference[jndex+1]
  159. reference[jndex+1] = &item
  160. }
  161. }
  162. }
  163. list, err := service.GetInspectionReferenceByOrgId(0)
  164. c.ServeSuccessJSON(map[string]interface{}{
  165. "reference": reference,
  166. "patient_info": patient_info,
  167. "list": list,
  168. })
  169. return
  170. }
  171. func (c *InspectionApiController) CreatePatientInspection() {
  172. patient, _ := c.GetInt64("patient", 0)
  173. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  174. if patient <= 0 {
  175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  176. return
  177. }
  178. adminUserInfo := c.GetAdminUserInfo()
  179. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  180. if patientInfo.ID == 0 {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  182. return
  183. }
  184. var from models.InepectionForm
  185. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  186. if err != nil {
  187. utils.ErrorLog("%v", err)
  188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. timeLayout := "2006-01-02 15:04"
  192. loc, _ := time.LoadLocation("Local")
  193. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  194. if err != nil {
  195. utils.ErrorLog(err.Error())
  196. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  197. return
  198. }
  199. if len(from.FormItem) == 0 {
  200. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  201. return
  202. }
  203. date := theTime.Unix()
  204. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
  205. if err != nil {
  206. utils.ErrorLog("%v", err)
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. if len(insp) > 0 {
  211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
  212. return
  213. }
  214. inspections := make([]models.Inspection, 0)
  215. for _, item := range from.FormItem {
  216. var inspection models.Inspection
  217. inspection.OrgId = adminUserInfo.CurrentOrgId
  218. inspection.PatientId = patient
  219. inspection.ProjectId = from.ProjectId
  220. inspection.ItemId = item.ItemId
  221. inspection.ItemName = item.ItemName
  222. inspection.ProjectName = item.ProjectName
  223. inspection.InspectType = item.RangeType
  224. inspection.InspectValue = item.Value
  225. inspection.InspectDate = date
  226. inspection.Status = 1
  227. inspection.CreatedTime = time.Now().Unix()
  228. inspection.UpdatedTime = time.Now().Unix()
  229. inspections = append(inspections, inspection)
  230. }
  231. err = service.CreatePatientInspection(inspections)
  232. if err != nil {
  233. utils.ErrorLog("%v", err)
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  235. return
  236. }
  237. if inspections[0].ProjectId == 14 {
  238. if remind_cycle > 0 {
  239. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
  240. fmt.Println(infectiousRecord.InspectDate)
  241. var record_time int64
  242. switch remind_cycle {
  243. case 1: //1个月
  244. ts := time.Unix(infectiousRecord.InspectDate, 0)
  245. record_time = ts.AddDate(0, 1, 0).Unix()
  246. fmt.Println(record_time)
  247. break
  248. case 2: //2个月
  249. ts := time.Unix(infectiousRecord.InspectDate, 0)
  250. record_time = ts.AddDate(0, 2, 0).Unix()
  251. fmt.Println(record_time)
  252. break
  253. case 3: //3个月
  254. ts := time.Unix(infectiousRecord.InspectDate, 0)
  255. record_time = ts.AddDate(0, 3, 0).Unix()
  256. fmt.Println(record_time)
  257. break
  258. case 4: //6个月
  259. ts := time.Unix(infectiousRecord.InspectDate, 0)
  260. record_time = ts.AddDate(0, 6, 0).Unix()
  261. fmt.Println(record_time)
  262. break
  263. case 5: //12个月
  264. ts := time.Unix(infectiousRecord.InspectDate, 0)
  265. record_time = ts.AddDate(0, 12, 0).Unix()
  266. fmt.Println(record_time)
  267. break
  268. }
  269. var errs error
  270. if inspections[0].ProjectId == 14 {
  271. errs = service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  272. }
  273. if errs != nil {
  274. utils.ErrorLog("更新日期出错:%v", errs)
  275. }
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "inspections": inspections,
  279. "remind_cycle": remind_cycle,
  280. })
  281. } else {
  282. //更新提醒时间
  283. reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
  284. if reminds.ID > 0 {
  285. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
  286. var record_time int64
  287. switch reminds.RemindCycle {
  288. case 1: //1个月
  289. ts := time.Unix(infectiousRecord.InspectDate, 0)
  290. record_time = ts.AddDate(0, 1, 0).Unix()
  291. fmt.Println(record_time)
  292. break
  293. case 2: //2个月
  294. ts := time.Unix(infectiousRecord.InspectDate, 0)
  295. record_time = ts.AddDate(0, 2, 0).Unix()
  296. fmt.Println(record_time)
  297. break
  298. case 3: //3个月
  299. ts := time.Unix(infectiousRecord.InspectDate, 0)
  300. record_time = ts.AddDate(0, 3, 0).Unix()
  301. fmt.Println(record_time)
  302. break
  303. case 4: //6个月
  304. ts := time.Unix(infectiousRecord.InspectDate, 0)
  305. record_time = ts.AddDate(0, 6, 0).Unix()
  306. fmt.Println(record_time)
  307. break
  308. case 5: //12个月
  309. ts := time.Unix(infectiousRecord.InspectDate, 0)
  310. record_time = ts.AddDate(0, 12, 0).Unix()
  311. fmt.Println(record_time)
  312. break
  313. }
  314. errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, inspections[0].ProjectId)
  315. if errs != nil {
  316. utils.ErrorLog("更新日期出错:%v", errs)
  317. }
  318. }
  319. c.ServeSuccessJSON(map[string]interface{}{
  320. "inspections": inspections,
  321. })
  322. }
  323. return
  324. }
  325. func (c *InspectionApiController) CreatePatientPicInspection() {
  326. patient, _ := c.GetInt64("patient", 0)
  327. if patient <= 0 {
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. adminUserInfo := c.GetAdminUserInfo()
  332. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  333. if patientInfo.ID == 0 {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  335. return
  336. }
  337. var from models.InepectionPICForm
  338. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  339. if err != nil {
  340. utils.ErrorLog("%v", err)
  341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  342. return
  343. }
  344. timeLayout := "2006-01-02 15:04"
  345. loc, _ := time.LoadLocation("Local")
  346. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  347. if err != nil {
  348. utils.ErrorLog(err.Error())
  349. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  350. return
  351. }
  352. if len(from.Imags) == 0 {
  353. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
  354. return
  355. }
  356. date := theTime.Unix()
  357. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, from.ProjectId)
  358. if err != nil {
  359. utils.ErrorLog("%v", err)
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  361. return
  362. }
  363. if len(insp) > 0 {
  364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateExit)
  365. return
  366. }
  367. inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
  368. inspections := make([]models.Inspection, 0)
  369. for index, item := range from.Imags {
  370. var inspection models.Inspection
  371. inspection.OrgId = adminUserInfo.CurrentOrgId
  372. inspection.PatientId = patient
  373. inspection.ProjectId = from.ProjectId
  374. inspection.ItemId = inspection_re[index].ID
  375. inspection.ItemName = item.Desc
  376. inspection.ProjectName = ""
  377. inspection.InspectType = 3
  378. inspection.InspectValue = item.ImgUrl
  379. inspection.InspectDesc = item.Desc
  380. inspection.InspectDate = date
  381. inspection.Status = 1
  382. inspection.CreatedTime = time.Now().Unix()
  383. inspection.UpdatedTime = time.Now().Unix()
  384. inspections = append(inspections, inspection)
  385. }
  386. err = service.CreatePatientInspection(inspections)
  387. if err != nil {
  388. utils.ErrorLog("%v", err)
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  390. return
  391. }
  392. if inspections[0].ProjectId != 14 {
  393. //更新提醒时间
  394. reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
  395. if reminds.ID > 0 {
  396. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, inspections[0].ProjectId)
  397. var record_time int64
  398. switch reminds.RemindCycle {
  399. case 1: //1个月
  400. ts := time.Unix(infectiousRecord.InspectDate, 0)
  401. record_time = ts.AddDate(0, 1, 0).Unix()
  402. fmt.Println(record_time)
  403. break
  404. case 2: //2个月
  405. ts := time.Unix(infectiousRecord.InspectDate, 0)
  406. record_time = ts.AddDate(0, 2, 0).Unix()
  407. fmt.Println(record_time)
  408. break
  409. case 3: //3个月
  410. ts := time.Unix(infectiousRecord.InspectDate, 0)
  411. record_time = ts.AddDate(0, 3, 0).Unix()
  412. fmt.Println(record_time)
  413. break
  414. case 4: //6个月
  415. ts := time.Unix(infectiousRecord.InspectDate, 0)
  416. record_time = ts.AddDate(0, 6, 0).Unix()
  417. fmt.Println(record_time)
  418. break
  419. case 5: //12个月
  420. ts := time.Unix(infectiousRecord.InspectDate, 0)
  421. record_time = ts.AddDate(0, 12, 0).Unix()
  422. fmt.Println(record_time)
  423. break
  424. }
  425. errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, inspections[0].ProjectId)
  426. if errs != nil {
  427. utils.ErrorLog("更新日期出错:%v", errs)
  428. }
  429. }
  430. }
  431. c.ServeSuccessJSON(map[string]interface{}{
  432. "inspections": inspections,
  433. })
  434. return
  435. }
  436. func (c *InspectionApiController) EditPatientPicInspection() {
  437. patient, _ := c.GetInt64("patient", 0)
  438. if patient <= 0 {
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. adminUserInfo := c.GetAdminUserInfo()
  443. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  444. if patientInfo.ID == 0 {
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  446. return
  447. }
  448. var from models.InepectionPICForm
  449. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  450. if err != nil {
  451. utils.ErrorLog("%v", err)
  452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  453. return
  454. }
  455. timeLayout := "2006-01-02 15:04"
  456. loc, _ := time.LoadLocation("Local")
  457. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  458. if err != nil {
  459. utils.ErrorLog(err.Error())
  460. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  461. return
  462. }
  463. if len(from.Imags) == 0 {
  464. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未上传图片")
  465. return
  466. }
  467. date := theTime.Unix()
  468. inspection_re, _ := service.GetInspectionReferenceTwo(from.ProjectId)
  469. inspections := make([]models.Inspection, 0)
  470. for index, item := range from.Imags {
  471. if item.ID == 0 {
  472. var inspection models.Inspection
  473. inspection.OrgId = adminUserInfo.CurrentOrgId
  474. inspection.PatientId = patient
  475. inspection.ProjectId = from.ProjectId
  476. inspection.ItemId = inspection_re[index].ID
  477. inspection.ItemName = item.Desc
  478. inspection.ProjectName = ""
  479. inspection.InspectType = 3
  480. inspection.InspectValue = item.ImgUrl
  481. inspection.InspectDesc = item.Desc
  482. inspection.InspectDate = date
  483. inspection.Status = 1
  484. inspection.CreatedTime = time.Now().Unix()
  485. inspection.UpdatedTime = time.Now().Unix()
  486. inspections = append(inspections, inspection)
  487. } else {
  488. var inspection models.Inspection
  489. inspection.ID = item.ID
  490. inspection.OrgId = adminUserInfo.CurrentOrgId
  491. inspection.PatientId = patient
  492. inspection.ProjectId = from.ProjectId
  493. inspection.ItemId = inspection_re[index].ID
  494. inspection.ItemName = item.Desc
  495. inspection.ProjectName = ""
  496. inspection.InspectType = 3
  497. inspection.InspectValue = item.ImgUrl
  498. inspection.InspectDesc = item.Desc
  499. inspection.InspectDate = date
  500. inspection.Status = 1
  501. inspection.CreatedTime = time.Now().Unix()
  502. inspection.UpdatedTime = time.Now().Unix()
  503. err = service.SavePatientInspection(inspection)
  504. }
  505. }
  506. for _, item := range from.DeleteImg {
  507. service.DeleteInspectionTwo(item.ID)
  508. }
  509. if len(inspections) > 0 {
  510. err = service.CreatePatientInspection(inspections)
  511. }
  512. if err != nil {
  513. utils.ErrorLog("%v", err)
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionAddFail)
  515. return
  516. }
  517. c.ServeSuccessJSON(map[string]interface{}{
  518. "inspections": inspections,
  519. })
  520. return
  521. }
  522. func (c *InspectionApiController) EditPatientInspection() {
  523. patient, _ := c.GetInt64("patient", 0)
  524. remind_cycle, _ := c.GetInt64("remind_cycle", 0)
  525. // dates := c.GetString("dates")
  526. // projectid := c.GetString("projectid")
  527. if patient <= 0 {
  528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  529. return
  530. }
  531. adminUserInfo := c.GetAdminUserInfo()
  532. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  533. if patientInfo.ID == 0 {
  534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  535. return
  536. }
  537. var from models.InepectionForm
  538. err := json.Unmarshal(c.Ctx.Input.RequestBody, &from)
  539. if err != nil {
  540. utils.ErrorLog("%v", err)
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  542. return
  543. }
  544. timeLayout := "2006-01-02 15:04"
  545. loc, _ := time.LoadLocation("Local")
  546. theTime, err := time.ParseInLocation(timeLayout, from.InspectDate, loc)
  547. if err != nil {
  548. utils.ErrorLog(err.Error())
  549. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  550. return
  551. }
  552. oldTime, olderr := time.ParseInLocation(timeLayout, from.OldInspectDate, loc)
  553. if olderr != nil {
  554. utils.ErrorLog(olderr.Error())
  555. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  556. return
  557. }
  558. if len(from.FormItem) == 0 {
  559. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "未填写项目")
  560. return
  561. }
  562. date := theTime.Unix()
  563. oldDate := oldTime.Unix()
  564. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, oldDate, from.ProjectId)
  565. if err != nil {
  566. utils.ErrorLog("%v", err)
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  568. return
  569. }
  570. if len(insp) == 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  572. return
  573. }
  574. inspMap := make(map[string]models.Inspection)
  575. for _, item := range insp {
  576. a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(item.ItemId, 10)
  577. inspMap[a] = item
  578. }
  579. addinsp := make([]models.Inspection, 0)
  580. editinsp := make([]models.Inspection, 0)
  581. noMap := make([]int64, 0)
  582. fmt.Println("00000000000000000000000000000000000000000000000000000")
  583. for _, item := range from.FormItem {
  584. fmt.Println("name:", item.ItemId, "value:", item.Value)
  585. ref, _ := service.GetInspectionReferenceById(item.ItemId)
  586. //if item.ID == 0 {
  587. // var inspection models.Inspection
  588. // inspection.OrgId = adminUserInfo.CurrentOrgId
  589. // inspection.PatientId = patient
  590. // inspection.ProjectId = from.ProjectId
  591. // inspection.ItemId = item.ItemId
  592. // inspection.ItemName = item.ItemName
  593. // inspection.ProjectName = item.ProjectName
  594. // inspection.InspectType = item.RangeType
  595. // inspection.InspectValue = item.Value
  596. // inspection.InspectDate = date
  597. // inspection.Status = 1
  598. // inspection.CreatedTime = time.Now().Unix()
  599. // inspection.UpdatedTime = time.Now().Unix()
  600. // addinsp = append(addinsp, inspection)
  601. //} else {
  602. //fmt.Println(item.ID)
  603. a := strconv.FormatInt(item.ProjectId, 10) + "-" + strconv.FormatInt(ref.ItemId, 10)
  604. fmt.Println(a)
  605. fmt.Println(inspMap)
  606. inspection := inspMap[a]
  607. inspection.ID = item.ID
  608. inspection.OrgId = adminUserInfo.CurrentOrgId
  609. inspection.PatientId = patient
  610. inspection.ProjectId = from.ProjectId
  611. inspection.ItemId = item.ItemId
  612. inspection.ItemName = item.ItemName
  613. inspection.ProjectName = item.ProjectName
  614. inspection.InspectType = item.RangeType
  615. inspection.InspectValue = item.Value
  616. inspection.InspectDate = date
  617. inspection.Status = 1
  618. inspection.InspectValue = item.Value
  619. inspection.InspectDate = date
  620. inspection.UpdatedTime = time.Now().Unix()
  621. editinsp = append(editinsp, inspection)
  622. noMap = append(noMap, item.ID)
  623. //}
  624. }
  625. //fmt.Println(editinsp)
  626. //return
  627. err = service.EditPatientInspection(addinsp, editinsp, noMap, patient, adminUserInfo.CurrentOrgId, from.ProjectId, date)
  628. if err != nil {
  629. utils.ErrorLog("%v", err)
  630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionEditFail)
  631. return
  632. }
  633. inspections := make([]models.Inspection, 0)
  634. inspections = append(inspections, editinsp...)
  635. inspections = append(inspections, addinsp...)
  636. if remind_cycle > 0 {
  637. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, 14)
  638. fmt.Println(infectiousRecord.InspectDate)
  639. var record_time int64
  640. switch remind_cycle {
  641. case 1: //1个月
  642. ts := time.Unix(infectiousRecord.InspectDate, 0)
  643. record_time = ts.AddDate(0, 1, 0).Unix()
  644. break
  645. case 2: //2个月
  646. ts := time.Unix(infectiousRecord.InspectDate, 0)
  647. record_time = ts.AddDate(0, 2, 0).Unix()
  648. break
  649. case 3: //3个月
  650. ts := time.Unix(infectiousRecord.InspectDate, 0)
  651. record_time = ts.AddDate(0, 3, 0).Unix()
  652. break
  653. case 4: //6个月
  654. ts := time.Unix(infectiousRecord.InspectDate, 0)
  655. record_time = ts.AddDate(0, 6, 0).Unix()
  656. break
  657. case 5: //12个月
  658. ts := time.Unix(infectiousRecord.InspectDate, 0)
  659. record_time = ts.AddDate(0, 12, 0).Unix()
  660. break
  661. }
  662. fmt.Println(record_time)
  663. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient, record_time, remind_cycle)
  664. if errs != nil {
  665. utils.ErrorLog("更新日期出错:%v", errs)
  666. }
  667. }
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "inspections": inspections,
  670. "remind_cycle": remind_cycle,
  671. })
  672. return
  673. }
  674. func (c *InspectionApiController) DeletePatientInspection() {
  675. patient, _ := c.GetInt64("patient", 0)
  676. ProjectId, _ := c.GetInt64("project_id", 0)
  677. InspectDate := c.GetString("date")
  678. if patient <= 0 || ProjectId <= 0 || len(InspectDate) < 10 {
  679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  680. return
  681. }
  682. timeLayout := "2006-01-02 15:04"
  683. loc, _ := time.LoadLocation("Local")
  684. theTime, err := time.ParseInLocation(timeLayout, InspectDate, loc)
  685. if err != nil {
  686. utils.ErrorLog(err.Error())
  687. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "检验日期不正确")
  688. return
  689. }
  690. adminUserInfo := c.GetAdminUserInfo()
  691. date := theTime.Unix()
  692. insp, err := service.GetPatientInspectionByDate(adminUserInfo.CurrentOrgId, patient, date, ProjectId)
  693. if err != nil {
  694. utils.ErrorLog("%v", err)
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. if len(insp) == 0 {
  699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDateNotExit)
  700. return
  701. }
  702. err = service.DeletePatientInspection(adminUserInfo.CurrentOrgId, patient, ProjectId, date)
  703. if err != nil {
  704. utils.ErrorLog("%v", err)
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInspectionDeleteFail)
  706. return
  707. }
  708. //更新提醒时间
  709. reminds, _ := service.GetCheckRemindRecordTime(adminUserInfo.CurrentOrgId, patient, ProjectId)
  710. if reminds.ID > 0 {
  711. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient, ProjectId)
  712. fmt.Println(infectiousRecord)
  713. if infectiousRecord.ID > 0 {
  714. var record_time int64
  715. switch reminds.RemindCycle {
  716. case 1: //1个月
  717. ts := time.Unix(infectiousRecord.InspectDate, 0)
  718. record_time = ts.AddDate(0, 1, 0).Unix()
  719. fmt.Println(record_time)
  720. break
  721. case 2: //2个月
  722. ts := time.Unix(infectiousRecord.InspectDate, 0)
  723. record_time = ts.AddDate(0, 2, 0).Unix()
  724. fmt.Println(record_time)
  725. break
  726. case 3: //3个月
  727. ts := time.Unix(infectiousRecord.InspectDate, 0)
  728. record_time = ts.AddDate(0, 3, 0).Unix()
  729. fmt.Println(record_time)
  730. break
  731. case 4: //6个月
  732. ts := time.Unix(infectiousRecord.InspectDate, 0)
  733. record_time = ts.AddDate(0, 6, 0).Unix()
  734. fmt.Println(record_time)
  735. break
  736. case 5: //12个月
  737. ts := time.Unix(infectiousRecord.InspectDate, 0)
  738. record_time = ts.AddDate(0, 12, 0).Unix()
  739. fmt.Println(record_time)
  740. break
  741. }
  742. errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, record_time, ProjectId)
  743. if errs != nil {
  744. utils.ErrorLog("更新日期出错:%v", errs)
  745. }
  746. } else {
  747. errs := service.UpDateCheckRemindRecordTimeTwo(adminUserInfo.CurrentOrgId, patient, 0, ProjectId)
  748. if errs != nil {
  749. utils.ErrorLog("更新日期出错:%v", errs)
  750. }
  751. }
  752. }
  753. c.ServeSuccessJSON(map[string]interface{}{
  754. "msg": "ok",
  755. })
  756. return
  757. }
  758. func (c *InspectionApiController) GetPatientInspections() {
  759. patient, _ := c.GetInt64("patient", 0)
  760. projectId, _ := c.GetInt64("project_id", 0)
  761. if patient <= 0 || projectId <= 0 {
  762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  763. return
  764. }
  765. page, _ := c.GetInt64("page", 0)
  766. if page <= 0 {
  767. page = 1
  768. }
  769. adminUserInfo := c.GetAdminUserInfo()
  770. inspections, total, dateTime, err := service.GetPatientInspections(adminUserInfo.CurrentOrgId, patient, projectId, page)
  771. fmt.Println("inspections", inspections)
  772. if err != nil {
  773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  774. return
  775. }
  776. date := ""
  777. if len(inspections) > 0 {
  778. date = time.Unix(dateTime, 0).Format("2006-01-02 15:04")
  779. }
  780. remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, projectId)
  781. //remind, _ := service.GetCheckRemindRecordTime(c.GetAdminUserInfo().CurrentOrgId, patient, projectId)
  782. config, _ := service.GetCheckRemindConfigById(c.GetAdminUserInfo().CurrentOrgId)
  783. c.ServeSuccessJSON(map[string]interface{}{
  784. "inspections": inspections,
  785. "total": total,
  786. "date": date,
  787. "remind": remind,
  788. "config": config,
  789. })
  790. return
  791. }
  792. func (c *InspectionApiController) GetAllPatientInspection() {
  793. patient, _ := c.GetInt64("patient", 0)
  794. projectStr := c.GetString("project")
  795. start_time, _ := c.GetInt64("start_time")
  796. end_time, _ := c.GetInt64("end_time")
  797. upload_type, _ := c.GetInt64("type")
  798. ids := strings.Split(projectStr, "-")
  799. if patient <= 0 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  801. return
  802. }
  803. page, _ := c.GetInt64("page", 0)
  804. if page <= 0 {
  805. page = 1
  806. }
  807. adminUserInfo := c.GetAdminUserInfo()
  808. switch upload_type {
  809. case 1:
  810. var inspections []models.Inspection
  811. for _, item := range ids {
  812. id, _ := strconv.ParseInt(item, 10, 64)
  813. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  814. // fmt.Println(err)
  815. //
  816. // if err != nil {
  817. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  818. // return
  819. // }
  820. for _, inspection_item := range inspection {
  821. inspections = append(inspections, inspection_item)
  822. }
  823. }
  824. c.ServeSuccessJSON(map[string]interface{}{
  825. "inspections": inspections,
  826. "type": upload_type,
  827. })
  828. break
  829. case 2:
  830. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  831. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  832. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  833. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  834. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  835. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  836. c.ServeSuccessJSON(map[string]interface{}{
  837. "inspections_one": inspection_one,
  838. "inspections_two": inspection_two,
  839. "inspections_three": inspection_three,
  840. "type": upload_type,
  841. })
  842. break
  843. case 3:
  844. var inspections []models.Inspection
  845. for _, item := range ids {
  846. id, _ := strconv.ParseInt(item, 10, 64)
  847. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  848. // fmt.Println(err)
  849. //
  850. // if err != nil {
  851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  852. // return
  853. // }
  854. for _, inspection_item := range inspection {
  855. inspections = append(inspections, inspection_item)
  856. }
  857. }
  858. c.ServeSuccessJSON(map[string]interface{}{
  859. "inspections": inspections,
  860. "type": upload_type,
  861. })
  862. break
  863. case 4:
  864. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  865. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  866. id_three, _ := strconv.ParseInt(ids[2], 10, 64)
  867. id_four, _ := strconv.ParseInt(ids[3], 10, 64)
  868. id_five, _ := strconv.ParseInt(ids[4], 10, 64)
  869. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  870. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  871. inspection_three, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_three, start_time, end_time)
  872. inspection_four, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_four, start_time, end_time)
  873. inspection_five, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_five, start_time, end_time)
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "inspections_one": inspection_one,
  876. "inspections_two": inspection_two,
  877. "inspections_three": inspection_three,
  878. "inspections_four": inspection_four,
  879. "inspections_five": inspection_five,
  880. "type": upload_type,
  881. })
  882. break
  883. case 5:
  884. id_one, _ := strconv.ParseInt(ids[0], 10, 64)
  885. id_two, _ := strconv.ParseInt(ids[1], 10, 64)
  886. inspection_one, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_one, start_time, end_time)
  887. inspection_two, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id_two, start_time, end_time)
  888. c.ServeSuccessJSON(map[string]interface{}{
  889. "inspections_one": inspection_one,
  890. "inspections_two": inspection_two,
  891. "type": upload_type,
  892. })
  893. break
  894. case 6:
  895. var inspections []models.Inspection
  896. for _, item := range ids {
  897. id, _ := strconv.ParseInt(item, 10, 64)
  898. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  899. // fmt.Println(err)
  900. //
  901. // if err != nil {
  902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  903. // return
  904. // }
  905. for _, inspection_item := range inspection {
  906. inspections = append(inspections, inspection_item)
  907. }
  908. }
  909. c.ServeSuccessJSON(map[string]interface{}{
  910. "inspections": inspections,
  911. "type": upload_type,
  912. })
  913. break
  914. case 7:
  915. var inspections []models.Inspection
  916. for _, item := range ids {
  917. id, _ := strconv.ParseInt(item, 10, 64)
  918. inspection, _, _ := service.GetAllPatientInspection(adminUserInfo.CurrentOrgId, patient, page, id, start_time, end_time)
  919. // fmt.Println(err)
  920. //
  921. // if err != nil {
  922. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. // return
  924. // }
  925. for _, inspection_item := range inspection {
  926. inspections = append(inspections, inspection_item)
  927. }
  928. }
  929. c.ServeSuccessJSON(map[string]interface{}{
  930. "inspections": inspections,
  931. "type": upload_type,
  932. })
  933. break
  934. }
  935. return
  936. }
  937. func (c *InspectionApiController) GetInitInsepction() {
  938. references, _ := service.GetAllInspectionReference(0)
  939. c.ServeSuccessJSON(map[string]interface{}{
  940. "references": references,
  941. })
  942. return
  943. }
  944. func (c *InspectionApiController) GetNewInspectionList() {
  945. patient, _ := c.GetInt64("patient")
  946. project_id, _ := c.GetInt64("project_id")
  947. orgId := c.GetAdminUserInfo().CurrentOrgId
  948. inspection, _ := service.GetNewInspectionList(patient, project_id, orgId)
  949. inspectionGroup, _ := service.GetNewGroupInspectionList(patient, project_id, orgId)
  950. inspectionInspectDateGroup, _ := service.GetNewGroupInspectionInspectionList(patient, project_id, orgId)
  951. c.ServeSuccessJSON(map[string]interface{}{
  952. "inspectionGroup": inspectionGroup,
  953. "inspection": inspection,
  954. "list": inspectionInspectDateGroup,
  955. })
  956. }
  957. func (c *InspectionApiController) GetNewInspectionDetailList() {
  958. project_id, _ := c.GetInt64("project_id")
  959. inspect_date, _ := c.GetInt64("inspect_date")
  960. patient_id, _ := c.GetInt64("patient_id")
  961. inspection, _ := service.GetNewInspectionDetailList(project_id, inspect_date, patient_id)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "inspection": inspection,
  964. })
  965. }
  966. func (c *InspectionApiController) EditPatientNewInspection() {
  967. dataBody := make(map[string]interface{}, 0)
  968. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  969. if err != nil {
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. inspection := models.Inspection{}
  974. if dataBody["id"] == nil || reflect.TypeOf(dataBody["id"]).String() != "float64" {
  975. utils.ErrorLog("id")
  976. return
  977. }
  978. id := int64(dataBody["id"].(float64))
  979. inspection.ID = id
  980. fmt.Println("id------------------------------", id)
  981. }
  982. func (c *InspectionApiController) GetInpsectionByPatientGroup() {
  983. patient_id, _ := c.GetInt64("patient_id")
  984. org_id := c.GetAdminUserInfo().CurrentOrgId
  985. patient, _ := service.GetPatientDetailTwo(patient_id)
  986. inspection, _ := service.GetInspectionGroup(patient.BloodId, org_id)
  987. if len(inspection) > 0 {
  988. for _, item := range inspection {
  989. lastInspection, _ := service.GetLastInspectionProject(item.PatientId, org_id, item.ProjectId)
  990. item.InspectDate = lastInspection.InspectDate
  991. inspecList, _ := service.GetInspectionByProjectId(item.PatientId, org_id, item.ProjectId)
  992. item.Count = int64(len(inspecList))
  993. }
  994. }
  995. c.ServeSuccessJSON(map[string]interface{}{
  996. "inspection": inspection,
  997. })
  998. }
  999. func (c *InspectionApiController) GetInspectionChildList() {
  1000. patient_id, _ := c.GetInt64("patient_id")
  1001. project_id, _ := c.GetInt64("project_id")
  1002. org_id := c.GetAdminUserInfo().CurrentOrgId
  1003. patient, _ := service.GetPatientDetailTwo(patient_id)
  1004. referenceList, _ := service.GetInSpctionRerefce(project_id, org_id)
  1005. inspection, _ := service.GetInspectionGroupByRecordDate(patient.BloodId, project_id, org_id)
  1006. if len(inspection) > 0 {
  1007. for _, item := range inspection {
  1008. inspeclist, _ := service.GetInspectionByProject(patient.BloodId, project_id, org_id, item.InspectDate)
  1009. for _, it := range inspeclist {
  1010. item.Child = append(item.Child, it)
  1011. }
  1012. }
  1013. }
  1014. patients, _ := service.GetPatientByIDOne(org_id, patient.BloodId)
  1015. c.ServeSuccessJSON(map[string]interface{}{
  1016. "inspection": inspection,
  1017. "patients": patients,
  1018. "referenceList": referenceList,
  1019. })
  1020. }