inspection_service.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. package service
  2. import (
  3. "errors"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "XT_New/models"
  8. )
  9. func GetInspectionReference(orgId int64, inspect_type int64) (reference []*models.InspectionReference, err error) {
  10. if inspect_type == 0 {
  11. var count int
  12. err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = 0", orgId).Count(&count).Error
  13. if count > 0 {
  14. err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = 0", orgId).Order("project_id,created_time").Find(&reference).Error
  15. } else {
  16. err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = 0").Order("project_id,created_time").Find(&reference).Error
  17. }
  18. } else {
  19. var count int
  20. err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = ?", orgId, inspect_type).Count(&count).Error
  21. if count > 0 {
  22. err = readDb.Model(&models.InspectionReference{}).Where("org_id=? and status=1 and inspection_type = ?", orgId, inspect_type).Order("project_id,created_time").Find(&reference).Error
  23. } else {
  24. err = readDb.Model(&models.InspectionReference{}).Where("org_id=0 and status=1 and inspection_type = ?", inspect_type).Order("project_id,created_time").Find(&reference).Error
  25. }
  26. }
  27. return
  28. }
  29. func GetPatientInspectionProjectCount(orgId, patientId int64) (projectCounts []*models.UserInspectionProjectCount, err error) {
  30. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and status=1", patientId, orgId).Select("count(distinct inspect_date) as count, project_id, patient_id").Group("project_id").Scan(&projectCounts).Error
  31. return
  32. }
  33. func GetPatientInspectionByDate(orgId, patientId, date, projectId int64) (inspections []models.Inspection, err error) {
  34. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and status=1", patientId, orgId, projectId, date).Order("created_time desc").Find(&inspections).Error
  35. return
  36. }
  37. func GetAdvices(orgid int64, patientid int64, recorddate int64) (advcie []*models.DoctorAdvice, err error) {
  38. err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1", patientid, orgid, recorddate).Find(&advcie).Error
  39. return
  40. }
  41. func GetAdvicesByPrescription(orgid int64, patientid int64, recorddate int64) (models.DoctorAdvice, error) {
  42. advice := models.DoctorAdvice{}
  43. err = XTReadDB().Where("patient_id = ? and user_org_id = ? and record_date = ? and status =1 and is_prescription = 1", patientid, orgid, recorddate).Find(&advice).Error
  44. return advice, err
  45. }
  46. func UpdateDoctorAdvieById(id int64, prescription_number float64) (models.DoctorAdvice, error) {
  47. advice := models.DoctorAdvice{}
  48. err := XTWriteDB().Model(&advice).Where("id=? and status= 1", id).Updates(map[string]interface{}{"prescribing_number": prescription_number}).Error
  49. return advice, err
  50. }
  51. func UpdateDoctorAdvieByIdOne(id int64, prescription_number float64, single_dose float64) (models.DoctorAdvice, error) {
  52. advice := models.DoctorAdvice{}
  53. err := XTWriteDB().Model(&advice).Where("id=? and status= 1 ", id).Updates(map[string]interface{}{"prescribing_number": prescription_number, "single_dose": single_dose}).Error
  54. return advice, err
  55. }
  56. func CreatePatientInspection(inspectins []models.Inspection) (err error) {
  57. if len(inspectins) == 0 {
  58. err = errors.New("Inspections Cant be nil.")
  59. return
  60. }
  61. thisSQL := "INSERT INTO xt_inspection (patient_id, org_id, project_id, item_id, item_name, project_name, inspect_type, inspect_value, inspect_date, status, created_time, updated_time) VALUES "
  62. insertParams := make([]string, 0)
  63. insertData := make([]interface{}, 0)
  64. for _, inspectin := range inspectins {
  65. insertParams = append(insertParams, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
  66. insertData = append(insertData, inspectin.PatientId)
  67. insertData = append(insertData, inspectin.OrgId)
  68. insertData = append(insertData, inspectin.ProjectId)
  69. insertData = append(insertData, inspectin.ItemId)
  70. insertData = append(insertData, inspectin.ItemName)
  71. insertData = append(insertData, inspectin.ProjectName)
  72. insertData = append(insertData, inspectin.InspectType)
  73. insertData = append(insertData, inspectin.InspectValue)
  74. insertData = append(insertData, inspectin.InspectDate)
  75. insertData = append(insertData, 1)
  76. insertData = append(insertData, inspectin.CreatedTime)
  77. insertData = append(insertData, inspectin.UpdatedTime)
  78. }
  79. thisSQL += strings.Join(insertParams, ", ")
  80. err = writeDb.Exec(thisSQL, insertData...).Error
  81. return
  82. }
  83. func SavePatientInspection(inspectin models.Inspection) (err error) {
  84. err = writeDb.Save(&inspectin).Error
  85. return
  86. }
  87. func DeleteInspectionTwo(id int64) {
  88. err = writeDb.Model(&models.Inspection{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
  89. return
  90. }
  91. func EditPatientInspection(add []models.Inspection, edit []models.Inspection, noDeleteIDs []int64, patientId, orgId, projectId, date int64) (err error) {
  92. if len(add) == 0 && len(edit) == 0 && len(noDeleteIDs) == 0 {
  93. err = errors.New(" Cant be nil.")
  94. return
  95. }
  96. tx := writeDb.Begin()
  97. if len(noDeleteIDs) > 0 {
  98. err = tx.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and id NOT IN (?) and status=1", patientId, orgId, projectId, date, noDeleteIDs).Update(map[string]interface{}{"Status": 0, "UpdatedTime": time.Now().Unix()}).Error
  99. if err != nil {
  100. tx.Rollback()
  101. return
  102. }
  103. }
  104. if len(edit) > 0 {
  105. for _, item := range edit {
  106. fmt.Println("o----------------------", item.ItemId)
  107. fmt.Println("value----------------------", item.InspectValue)
  108. err = tx.Save(&item).Error
  109. if err != nil {
  110. tx.Rollback()
  111. return
  112. }
  113. }
  114. }
  115. if len(add) > 0 {
  116. thisSQL := "INSERT INTO xt_inspection (patient_id, org_id, project_id, item_id, item_name, project_name, inspect_type, inspect_value, inspect_date, status, created_time, updated_time) VALUES "
  117. insertParams := make([]string, 0)
  118. insertData := make([]interface{}, 0)
  119. for _, inspectin := range add {
  120. insertParams = append(insertParams, "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
  121. insertData = append(insertData, inspectin.PatientId)
  122. insertData = append(insertData, inspectin.OrgId)
  123. insertData = append(insertData, inspectin.ProjectId)
  124. insertData = append(insertData, inspectin.ItemId)
  125. insertData = append(insertData, inspectin.ItemName)
  126. insertData = append(insertData, inspectin.ProjectName)
  127. insertData = append(insertData, inspectin.InspectType)
  128. insertData = append(insertData, inspectin.InspectValue)
  129. insertData = append(insertData, inspectin.InspectDate)
  130. insertData = append(insertData, 1)
  131. insertData = append(insertData, inspectin.CreatedTime)
  132. insertData = append(insertData, inspectin.UpdatedTime)
  133. }
  134. thisSQL += strings.Join(insertParams, ", ")
  135. err = tx.Exec(thisSQL, insertData...).Error
  136. if err != nil {
  137. tx.Rollback()
  138. return
  139. }
  140. }
  141. tx.Commit()
  142. return
  143. }
  144. func DeletePatientInspection(orgId, patientId, projectId, date int64) (err error) {
  145. err = writeDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id =? and inspect_date =? and status=1", patientId, orgId, projectId, date).Update(map[string]interface{}{"Status": 0, "UpdatedTime": time.Now().Unix()}).Error
  146. return
  147. }
  148. func GetPatientInspections(orgId, patientId, projectId, page int64) (inspections []models.Inspection, total int64, date int64, err error) {
  149. var projectCount models.UserInspectionProjectCount
  150. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Order("inspect_date desc").Scan(&projectCount).Error
  151. if err != nil {
  152. return
  153. }
  154. total = projectCount.Count
  155. if total == 0 || page > total {
  156. return
  157. }
  158. var Id models.InspectionDate
  159. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1", patientId, orgId, projectId).Select("inspect_date").Group("inspect_date").Order("inspect_date desc").Offset(page - 1).Limit(1).Scan(&Id).Error
  160. if err != nil {
  161. return
  162. }
  163. if Id.InspectDate == 0 {
  164. return
  165. }
  166. date = Id.InspectDate
  167. inspections, err = GetPatientInspectionByDate(orgId, patientId, Id.InspectDate, projectId)
  168. if err != nil {
  169. return
  170. }
  171. return
  172. }
  173. type DateViewModel struct {
  174. inspect_date int64 `gorm:"column:inspect_date" json:"inspect_date"`
  175. project_id int64 `gorm:"column:project_id" json:"project_id"`
  176. }
  177. func FindLastRecordDate(orgId int64, patientId int64, project_id int64) (inspections models.Inspection, err error) {
  178. err = readDb.Raw("SELECT max(inspect_date) as inspect_date,project_id FROM `xt_inspection` WHERE (status = 1 AND org_id = ? AND project_id = ? AND patient_id = ?) ORDER BY `xt_inspection`.`id` ASC LIMIT 1", orgId, project_id, patientId).Scan(&inspections).Error
  179. return
  180. }
  181. func UpDateInfectiousRecordTime(orgId int64, patientId int64, time int64, remind_cycle int64) (err error) {
  182. err = writeDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgId, patientId).Updates(map[string]interface{}{"infectious_next_record_time": time, "remind_cycle": remind_cycle}).Error
  183. return
  184. }
  185. func CreateRemind(remind models.XtCheckRemind) (err error) {
  186. err = writeDb.Create(&remind).Error
  187. return
  188. }
  189. func UpDateCheckRemindRecordTime(orgId int64, patientId int64, time int64, project_id int64, remind_cycle int64) (err error) {
  190. err = writeDb.Model(&models.XtCheckRemind{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? and project_id = ?", orgId, patientId, project_id).Updates(map[string]interface{}{"last_remind_date": time, "remind_cycle": remind_cycle}).Error
  191. return
  192. }
  193. func UpDateCheckRemindRecordTimeTwo(orgId int64, patientId int64, time int64, project_id int64) (err error) {
  194. err = writeDb.Model(&models.XtCheckRemind{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? and project_id = ?", orgId, patientId, project_id).Updates(map[string]interface{}{"last_remind_date": time}).Error
  195. return
  196. }
  197. func GetCheckRemindRecordTime(orgId int64, patientId int64, project_id int64) (remind models.XtCheckRemind, err error) {
  198. err = writeDb.Model(&models.XtCheckRemind{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? and project_id = ?", orgId, patientId, project_id).First(&remind).Error
  199. return
  200. }
  201. func GetAllPatientInspection(orgId, patientId, page int64, projectId int64, start_time int64, end_time int64) (inspections []models.Inspection, date int64, err error) {
  202. //var projectCount models.UserInspectionProjectCount
  203. //err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id in (?) and status=1", patientId, orgId,projectId).Select("count(distinct inspect_date) as count, project_id, patient_id").Scan(&projectCount).Error
  204. //
  205. //if err != nil {
  206. // return
  207. //}
  208. //
  209. //total = projectCount.Count
  210. //if total == 0 || page > total {
  211. // return
  212. //}
  213. var Id models.InspectionDate
  214. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and org_id=? and project_id=? and status=1 and inspect_date >= ? and inspect_date <= ?", patientId, orgId, projectId, start_time, end_time).Select("inspect_date").Group("inspect_date").Order("inspect_date desc").Offset(page - 1).Limit(1).Scan(&Id).Error
  215. if err != nil {
  216. return
  217. }
  218. if Id.InspectDate == 0 {
  219. return
  220. }
  221. date = Id.InspectDate
  222. inspections, err = GetPatientInspectionByDate(orgId, patientId, Id.InspectDate, projectId)
  223. if err != nil {
  224. return
  225. }
  226. return
  227. }
  228. func GetAllInspectionReference(orgId int64) (inspectionReference []*models.InspectionReference, err error) {
  229. err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? AND status = 1", orgId).Find(&inspectionReference).Error
  230. return
  231. }
  232. func GetInspectionReferenceByOrgId(orgid int64) (insepciton []*models.XtInspectionReference, err error) {
  233. err = readDb.Model(&insepciton).Where("org_id = ? and status = 1 and project_name = '传染病检查'", orgid).Find(&insepciton).Error
  234. return insepciton, err
  235. }
  236. func GetInspectionReferenceById(id int64) (insepciton models.XtInspectionReference, err error) {
  237. err = readDb.Model(&insepciton).Where("id = ?", id).First(&insepciton).Error
  238. return insepciton, err
  239. }
  240. func GetInspectionReferenceTwo(project_id int64) (reference []*models.InspectionReference, err error) {
  241. err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and status = 1", project_id).Order("project_id").Find(&reference).Error
  242. return
  243. }
  244. func GetInspectionReferenceThree(project_id int64, item_id int64) (reference models.InspectionReference, err error) {
  245. err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and id = ? and status = 1 and org_id = 0", project_id, item_id).Order("project_id").Find(&reference).Error
  246. return
  247. }
  248. func GetInspectionReferenceFour(project_id int64, item_id int64, org_id int64) (reference models.InspectionReference, err error) {
  249. err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and item_id = ? and status = 1 and org_id = ?", project_id, item_id, org_id).Order("project_id").Find(&reference).Error
  250. return
  251. }
  252. func GetInspectionTwo(startime int64, endtime int64, orgid int64, projectid int64, itemid int64) (inspection []*models.Inspection, total int64, err error) {
  253. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  254. db = db.Where("project_id = ? and item_id = ?", projectid, itemid)
  255. if startime > 0 {
  256. db = db.Where("x.inspect_date >= ?", startime)
  257. }
  258. if endtime > 0 {
  259. db = db.Where("x.inspect_date<=?", endtime)
  260. }
  261. if orgid > 0 {
  262. db = db.Where("x.org_id = ?", orgid)
  263. }
  264. if projectid > 0 {
  265. db = db.Where("x.project_id = ?", projectid)
  266. }
  267. err = db.Count(&total).Order("x.inspect_date desc").Group("x.id").
  268. Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.created_time").Find(&inspection).Error
  269. return inspection, total, err
  270. }
  271. // 查出日期差小于3天的数据
  272. func GetAllInspectionRemind(org_id int64, patient_id int64) (check []models.XtCheckRemind, err error) {
  273. err = readDb.Model(&models.XtCheckRemind{}).Preload("InspectionReference", "status = 1").Where("patient_id = ? and status = 1 and user_org_id = ? and DATEDIFF(FROM_UNIXTIME(last_remind_date),NOW()) < 3 and last_remind_date <> 0", patient_id, org_id).Find(&check).Error
  274. return
  275. }
  276. func GetLastInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
  277. inspection := models.Inspection{}
  278. err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date < ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
  279. return inspection, err
  280. }
  281. func GetNextInspection(patientid int64, date int64, projectid int64, orgid int64) (models.Inspection, error) {
  282. inspection := models.Inspection{}
  283. err := XTReadDB().Group("inspect_date").Order("inspect_date asc").Where("patient_id = ? and inspect_date > ? and project_id =? and status=1 and org_id= ?", patientid, date, projectid, orgid).Limit(1).Find(&inspection).Error
  284. return inspection, err
  285. }
  286. func GetLastInspectionDetail(patientid int64, date int64, projectid int64, orgid int64) (inspection []*models.Inspections, err error) {
  287. db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
  288. if patientid > 0 {
  289. db = db.Where("x.patient_id = ?", patientid)
  290. }
  291. if date > 0 {
  292. db = db.Where("x.inspect_date = ?", date)
  293. }
  294. if orgid > 0 {
  295. db = db.Where("x.org_id = ?", orgid)
  296. }
  297. if projectid > 0 {
  298. db = db.Where("x.project_id = ?", projectid)
  299. }
  300. err = db.Order("inspect_date asc").Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
  301. return inspection, err
  302. }
  303. func GetInsepctionConfigurationList(orgid int64) (standard []*models.QualityControlStandard, err error) {
  304. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  305. db = db.Where("x.user_org_id = ? and x.is_status =1", orgid)
  306. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").
  307. Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor and s.project_id = x.inspection_major").Where("s.org_id = ? and s.status = 1", orgid).Scan(&standard).Error
  308. return standard, err
  309. }
  310. func GetInspectionGroup(patient_id int64, org_id int64) (inspection []*models.NewInspection, err error) {
  311. db := XTReadDB().Table("xt_inspection").Where("status =1")
  312. if patient_id > 0 {
  313. db = db.Where("patient_id = ?", patient_id)
  314. }
  315. if org_id > 0 {
  316. db = db.Where("org_id = ?", org_id)
  317. }
  318. err = db.Order("inspect_date asc").Group("project_id").Scan(&inspection).Error
  319. return inspection, err
  320. }
  321. func GetLastInspectionProject(patient_id int64, org_id int64, project_id int64) (models.XtInspection, error) {
  322. inspection := models.XtInspection{}
  323. err := XTReadDB().Where("patient_id = ? and org_id = ? and project_id = ? and status=1", patient_id, org_id, project_id).Last(&inspection).Error
  324. return inspection, err
  325. }
  326. func GetInspectionByProjectId(patient_id int64, org_id int64, project_id int64) (inspection []*models.NewInspection, err error) {
  327. db := XTReadDB().Table("xt_inspection").Where("status =1")
  328. if patient_id > 0 {
  329. db = db.Where("patient_id = ?", patient_id)
  330. }
  331. if org_id > 0 {
  332. db = db.Where("org_id = ?", org_id)
  333. }
  334. if project_id > 0 {
  335. db = db.Where("project_id = ?", project_id)
  336. }
  337. err = db.Order("id asc").Group("inspect_date").Scan(&inspection).Error
  338. return inspection, err
  339. }
  340. func GetInSpctionRerefce(project_id int64, user_org_id int64) (inspct []*models.InspectionReference, err error) {
  341. err = XTReadDB().Where("project_id = ? and (org_id = ? or org_id=0) and status =1", project_id, user_org_id).Find(&inspct).Error
  342. return inspct, err
  343. }
  344. func GetInspectionGroupByRecordDate(patient_id int64, project_id int64, org_id int64) (inspetion []*models.Inspection, err error) {
  345. err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ? and status=1", patient_id, project_id, org_id).Order("inspect_date desc").Limit(10).Group("inspect_date").Find(&inspetion).Error
  346. return inspetion, err
  347. }
  348. func GetInspectionByProject(patient_id int64, project_id int64, org_id int64, record_date int64) (inspection []*models.Inspection, err error) {
  349. err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ? and status=1 and inspect_date =?", patient_id, project_id, org_id, record_date).Order("id desc").Group("item_id").Find(&inspection).Error
  350. return inspection, err
  351. }
  352. func GetNewInspectionList(patient_id int64, project_id int64, user_org_id int64) (inspection []*models.Inspection, err error) {
  353. err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ?", patient_id, project_id, user_org_id).Find(&inspection).Error
  354. return inspection, err
  355. }
  356. func GetNewGroupInspectionList(patient_id int64, project_id int64, user_org_id int64) (inspection []*models.Inspection, err error) {
  357. err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ?", patient_id, project_id, user_org_id).Group("item_id").Find(&inspection).Error
  358. return inspection, err
  359. }
  360. func GetNewGroupInspectionInspectionList(patient_id int64, project_id int64, user_org_id int64) (inspection []*models.Inspection, err error) {
  361. err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ?", patient_id, project_id, user_org_id).Group("inspect_date").Order("inspect_date asc").Find(&inspection).Error
  362. return inspection, err
  363. }
  364. func GetNewInspectionDetailList(project_id int64, inspect_value int64, patient_id int64) (inpection []*models.Inspection, err error) {
  365. err = XTReadDB().Where("project_id =? and inspect_date = ? and patient_id = ?", project_id, inspect_value, patient_id).Find(&inpection).Error
  366. return inpection, err
  367. }