inspection_api_controller.go 38KB

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