inspection_api_controller.go 34KB

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