patient_service.go 54KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. package service
  2. import (
  3. "XT_New/models"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. )
  10. //GetPatientList 返回患者的列表
  11. func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bindingState, lapseto, source, startTime, endTime, contagion, reimbursementWay, isscheduling, isprescription int64, isStartTime, isEndTime bool) (patients []*models.Patients, total int64, err error) {
  12. db := readDb.Table("xt_patients as p").Where("p.status=1")
  13. if orgID > 0 {
  14. db = db.Where("p.user_org_id=?", orgID)
  15. }
  16. if len(keywords) > 0 {
  17. likeKey := "%" + keywords + "%"
  18. db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  19. }
  20. if schedulType > 0 {
  21. db = db.Joins("JOIN xt_schedule as s ON s.patient_id=p.id")
  22. db = db.Where("s.status=1 and s.schedule_type=?", schedulType)
  23. }
  24. if contagion > 0 {
  25. db = db.Joins("JOIN xt_patients_infectious_diseases as xpid ON xpid.patient_id=p.id")
  26. db = db.Where("xpid.disease_id=? and xpid.status=1", contagion)
  27. }
  28. if isscheduling == 1 {
  29. db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
  30. } else if isscheduling == 2 {
  31. db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.status=1").QueryExpr())
  32. }
  33. if isprescription == 1 {
  34. db = db.Where("EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
  35. } else if isprescription == 2 {
  36. db = db.Where("NOT EXISTS (?)", readDb.Table("xt_dialysis_prescription as xdp").Where("xdp.patient_id=p.id and xdp.status=1").QueryExpr())
  37. }
  38. if bindingState > 0 {
  39. db = db.Where("p.binding_state=?", bindingState)
  40. }
  41. if lapseto > 0 {
  42. db = db.Where("p.lapseto=?", lapseto)
  43. }
  44. if source > 0 {
  45. db = db.Where("p.source=?", source)
  46. }
  47. if reimbursementWay > 0 {
  48. db = db.Where("p.reimbursement_way_id = ?", reimbursementWay)
  49. }
  50. if isStartTime {
  51. db = db.Where("p.created_time>=?", startTime)
  52. }
  53. if isEndTime {
  54. db = db.Where("p.created_time<=?", endTime)
  55. }
  56. offset := (page - 1) * limit
  57. err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
  58. return
  59. }
  60. //GetAllPatientList 返回全部患者的列表
  61. func GetAllPatientList(orgID int64) (patients []*models.Patients, total int64, err error) {
  62. db := readDb.Table("xt_patients as p").Where("p.user_org_id=? and p.status=1", orgID)
  63. err = db.Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time").Count(&total).Find(&patients).Error
  64. return
  65. }
  66. func GetPatientListByUpdateTime(orgID int64, syncTime int64, force int64) (patients []*models.PatientListForFace, total int64, err error) {
  67. db := readDb.Model(&models.PatientListForFace{}).Where("user_org_id=? and status=1", orgID)
  68. if force == 0 {
  69. db = db.Where("updated_time >= ?", syncTime)
  70. }
  71. err = db.Count(&total).Find(&patients).Error
  72. return
  73. }
  74. func GetPatientCount(orgID int64) (total int64) {
  75. readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
  76. return
  77. }
  78. func GetLapsetoPatientCount(orgID int64, lapseto int64) (total int64) {
  79. readDb.Model(&models.Patients{}).Where("user_org_id=? and lapseto=? and status=1", orgID, lapseto).Count(&total)
  80. return
  81. }
  82. func ChechLastDialysisNo(orgID int64) (dialysisNo int64) {
  83. var patient models.Patients
  84. err := readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=?", orgID).Order("dialysis_no desc").First(&patient).Error
  85. if err != nil {
  86. return
  87. }
  88. if patient.ID == 0 {
  89. return
  90. }
  91. dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
  92. return
  93. }
  94. func FindPatientByDialysisNo(orgID int64, dialysisNo string) (patient models.Patients, err error) {
  95. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=?", orgID, dialysisNo).First(&patient).Error
  96. return
  97. }
  98. func FindPatientByIdCardNo(orgID int64, idCardNo string) (patient models.Patients, err error) {
  99. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
  100. return
  101. }
  102. func FindPatientByMobile(orgID int64, mobile string) (patient models.Patients, err error) {
  103. err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
  104. return
  105. }
  106. func FindPatientById(orgID int64, id int64) (patient models.Patients, err error) {
  107. err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  108. return
  109. }
  110. func FindPatientByIdTwo(orgID int64, id int64) (patient models.XtPatientsNew, err error) {
  111. err = readDb.Model(&models.XtPatientsNew{}).Where("blood_id = ? and user_org_id = ? and status =1", id, orgID).First(&patient).Error
  112. return
  113. }
  114. func FindPatientByIdWithDiseases(orgID int64, id int64) (patient models.Patients, err error) {
  115. err = readDb.Model(&models.Patients{}).Preload("Contagions", "status = 1").Preload("Diseases", "status = 1").Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error
  116. return
  117. }
  118. func FindPatientWithDeviceByNo(orgID int64, no string, time int64) (patient models.SchedualPatient2, err error) {
  119. err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
  120. return db.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  121. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  122. Where("user_org_id = ? AND schedule_date = ? ", orgID, time)
  123. }).Preload("InfectiousDiseases", "status = 1").Where("user_org_id=? and dialysis_no = ? and status=1", orgID, no).First(&patient).Error
  124. return
  125. }
  126. func CreatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  127. user, _ := GetSgjUserByMobild(patient.Phone)
  128. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  129. utx := writeDb.Begin()
  130. btx := writeUserDb.Begin()
  131. if user.ID == 0 {
  132. user.Mobile = patient.Phone
  133. user.Avatar = patient.Avatar
  134. user.AvatarThumb = patient.Avatar
  135. user.Birthday = patient.Birthday
  136. user.Username = patient.Name
  137. user.Gender = patient.Gender
  138. user.Sources = 11
  139. user.Introduce = patient.Remark
  140. user.Status = 1
  141. user.UpdatedTime = patient.UpdatedTime
  142. user.CreatedTime = patient.CreatedTime
  143. err = btx.Create(&user).Error
  144. if err != nil {
  145. utx.Rollback()
  146. btx.Rollback()
  147. return
  148. }
  149. }
  150. patient.UserId = user.ID
  151. if customer == nil {
  152. err = btx.Create(&models.SgjCustomer{
  153. UserOrgId: patient.UserOrgId,
  154. UserId: user.ID,
  155. Mobile: patient.Phone,
  156. Name: patient.Name,
  157. Gender: patient.Gender,
  158. Birthday: patient.Birthday,
  159. Sources: 11,
  160. Status: 1,
  161. CreatedTime: patient.CreatedTime,
  162. UpdatedTime: patient.UpdatedTime,
  163. Avatar: patient.Avatar,
  164. Remark: patient.Remark,
  165. }).Error
  166. if err != nil {
  167. utx.Rollback()
  168. btx.Rollback()
  169. return
  170. }
  171. }
  172. err = utx.Create(patient).Error
  173. if err != nil {
  174. utx.Rollback()
  175. btx.Rollback()
  176. return
  177. }
  178. var lapseto models.PatientLapseto
  179. lapseto.PatientId = patient.ID
  180. lapseto.LapsetoType = patient.Lapseto
  181. lapseto.CreatedTime = patient.CreatedTime
  182. lapseto.UpdatedTime = patient.CreatedTime
  183. lapseto.Status = 1
  184. lapseto.LapsetoTime = patient.CreatedTime
  185. err = utx.Create(&lapseto).Error
  186. if err != nil {
  187. utx.Rollback()
  188. btx.Rollback()
  189. return
  190. }
  191. if len(contagions) > 0 {
  192. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  193. insertParams := make([]string, 0)
  194. insertData := make([]interface{}, 0)
  195. for _, contagion := range contagions {
  196. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  197. insertData = append(insertData, patient.ID)
  198. insertData = append(insertData, contagion)
  199. insertData = append(insertData, 1)
  200. insertData = append(insertData, patient.CreatedTime)
  201. insertData = append(insertData, patient.UpdatedTime)
  202. }
  203. thisSQL += strings.Join(insertParams, ", ")
  204. err = utx.Exec(thisSQL, insertData...).Error
  205. if err != nil {
  206. utx.Rollback()
  207. btx.Rollback()
  208. return
  209. }
  210. }
  211. if len(diseases) > 0 {
  212. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  213. insertParams := make([]string, 0)
  214. insertData := make([]interface{}, 0)
  215. for _, disease := range diseases {
  216. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  217. insertData = append(insertData, patient.ID)
  218. insertData = append(insertData, disease)
  219. insertData = append(insertData, 1)
  220. insertData = append(insertData, patient.CreatedTime)
  221. insertData = append(insertData, patient.UpdatedTime)
  222. }
  223. thisSQL += strings.Join(insertParams, ", ")
  224. err = utx.Exec(thisSQL, insertData...).Error
  225. if err != nil {
  226. utx.Rollback()
  227. btx.Rollback()
  228. return
  229. }
  230. }
  231. utx.Commit()
  232. btx.Commit()
  233. return
  234. }
  235. func GetLastPatientData(orgid int64) (models.Patients, error) {
  236. patients := models.Patients{}
  237. err := XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgid).Last(&patients).Error
  238. return patients, err
  239. }
  240. func CreatePatientsNew(patientsNew *models.XtPatientsNew) error {
  241. err := XTWriteDB().Model(&patientsNew).Create(&patientsNew).Error
  242. return err
  243. }
  244. func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
  245. utx := writeDb.Begin()
  246. err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"Lapseto": patient.Lapseto}).Error
  247. //err = utx.Model(&models.PatientLapseto{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto_type": patient.Lapseto, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
  248. if err != nil {
  249. utx.Rollback()
  250. return
  251. }
  252. err = utx.Create(lapseto).Error
  253. if err != nil {
  254. utx.Rollback()
  255. return
  256. }
  257. // 删除排班和排班模板信息
  258. if lapseto.LapsetoType == 2 {
  259. now := time.Now()
  260. deleteScheduleErr := utx.Model(&models.PatientSchedule{}).Where("patient_id = ? AND schedule_date >= ? AND status = 1", patient.ID, lapseto.LapsetoTime).Updates(map[string]interface{}{
  261. "status": 0,
  262. "updated_time": now.Unix(),
  263. }).Error
  264. if deleteScheduleErr != nil {
  265. utx.Rollback()
  266. err = deleteScheduleErr
  267. return
  268. }
  269. deleteSchTempItemErr := utx.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND status = 1", patient.ID).Updates(map[string]interface{}{
  270. "status": 0,
  271. "mtime": now.Unix(),
  272. }).Error
  273. if deleteSchTempItemErr != nil {
  274. utx.Rollback()
  275. err = deleteSchTempItemErr
  276. return
  277. }
  278. }
  279. utx.Commit()
  280. return
  281. }
  282. func UpdatePatient(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  283. // if len(contagions) > 0 || len(diseases) > 0 {
  284. utx := writeDb.Begin()
  285. err = utx.Save(patient).Error
  286. if err != nil {
  287. utx.Rollback()
  288. return
  289. }
  290. err = utx.Model(&models.InfectiousDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
  291. fmt.Println("err", err)
  292. if err != nil {
  293. utx.Rollback()
  294. return
  295. }
  296. if len(contagions) > 0 && patient.IsInfectious == 2 {
  297. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  298. insertParams := make([]string, 0)
  299. insertData := make([]interface{}, 0)
  300. for _, contagion := range contagions {
  301. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  302. insertData = append(insertData, patient.ID)
  303. insertData = append(insertData, contagion)
  304. insertData = append(insertData, 1)
  305. insertData = append(insertData, patient.CreatedTime)
  306. insertData = append(insertData, patient.UpdatedTime)
  307. }
  308. thisSQL += strings.Join(insertParams, ", ")
  309. err = utx.Exec(thisSQL, insertData...).Error
  310. if err != nil {
  311. utx.Rollback()
  312. return
  313. }
  314. }
  315. err = utx.Model(&models.ChronicDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
  316. if err != nil {
  317. utx.Rollback()
  318. return
  319. }
  320. if len(diseases) > 0 {
  321. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  322. insertParams := make([]string, 0)
  323. insertData := make([]interface{}, 0)
  324. for _, disease := range diseases {
  325. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  326. insertData = append(insertData, patient.ID)
  327. insertData = append(insertData, disease)
  328. insertData = append(insertData, 1)
  329. insertData = append(insertData, patient.CreatedTime)
  330. insertData = append(insertData, patient.UpdatedTime)
  331. }
  332. thisSQL += strings.Join(insertParams, ", ")
  333. err = utx.Exec(thisSQL, insertData...).Error
  334. if err != nil {
  335. utx.Rollback()
  336. return
  337. }
  338. }
  339. utx.Commit()
  340. // } else {
  341. // err = writeDb.Save(patient).Error
  342. // }
  343. return
  344. }
  345. func UpdatePatientLapseto(patientid int64, lapseto models.PatientLapseto) error {
  346. err := XTWriteDB().Model(&lapseto).Where("patient_id = ?", patientid).Updates(map[string]interface{}{"lapseto_type": lapseto.LapsetoType, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
  347. return err
  348. }
  349. func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
  350. err := XTWriteDB().Model(&patientsNew).Where("blood_id = ?", id).Update(map[string]interface{}{"user_org_id": patientsNew.UserOrgId, "user_id": patientsNew.UserId, "avatar": patientsNew.Avatar, "patient_type": patientsNew.Avatar, "dialysis_no": patientsNew.DialysisNo, "admission_number": patientsNew.AdmissionNumber, "source": patientsNew.Source, "lapseto": patientsNew.Lapseto, "partition_id": patientsNew.PartitionId, "bed_id": patientsNew.BedId, "name": patientsNew.Name, "alias": patientsNew.Alias, "gender": patientsNew.Gender, "marital_status": patientsNew.MaritalStatus, "id_card_no": patientsNew.IdCardNo, "birthday": patientsNew.Birthday, "reimbursement_way_id": patientsNew.ReimbursementWayId, "health_care_type": patientsNew.HealthCareType, "health_care_no": patientsNew.HealthCareType, "health_care_due_date": patientsNew.HealthCareType, "height": patientsNew.Height, "blood_type": patientsNew.BloodType, "rh": patientsNew.Rh, "health_care_due_alert_date": patientsNew.HealthCareDueAlertDate, "education_level": patientsNew.EducationLevel, "profession": patientsNew.Profession, "phone": patientsNew.Phone, "home_telephone": patientsNew.HomeTelephone, "relative_phone": patientsNew.RelativePhone, "relative_relations": patientsNew.RelativeRelations, "home_address": patientsNew.HomeAddress, "work_unit": patientsNew.WorkUnit, "unit_address": patientsNew.UnitAddress, "children": patientsNew.Children, "receiving_date": patientsNew.ReceivingDate, "is_hospital_first_dialysis": patientsNew.IsHospitalFirstDialysis, "first_dialysis_date": patientsNew.FirstDialysisDate, "first_dialysis_hospital": patientsNew.FirstDialysisHospital, "predialysis_condition": patientsNew.PredialysisCondition, "pre_hospital_dialysis_frequency": patientsNew.PreHospitalDialysisFrequency, "pre_hospital_dialysis_times": patientsNew.PreHospitalDialysisFrequency, "hospital_first_dialysis_date": patientsNew.HospitalFirstDialysisDate, "induction_period": patientsNew.InductionPeriod, "initial_dialysis": patientsNew.InitialDialysis, "total_dialysis": patientsNew.TotalDialysis, "attending_doctor_id": patientsNew.AttendingDoctorId, "head_nurse_id": patientsNew.HeadNurseId, "evaluate": patientsNew.Evaluate, "diagnose": patientsNew.Diagnose, "remark": patientsNew.Remark, "registrars_id": patientsNew.RegistrarsId, "registrars": patientsNew.Registrars, "qr_code": patientsNew.QrCode, "binding_state": patientsNew.BindingState, "patient_complains": patientsNew.PatientComplains, "present_history": patientsNew.PresentHistory, "past_history": patientsNew.PastHistory, "temperature": patientsNew.Temperature,
  351. "pulse": patientsNew.Pulse, "respiratory": patientsNew.Respiratory, "sbp": patientsNew.Sbp, "dbp": patientsNew.Dbp, "nation": patientsNew.Nation, "native_place": patientsNew.NativePlace, "age": patientsNew.Age, "infectious_next_record_time": patientsNew.InfectiousNextRecordTime, "is_infectious": patientsNew.IsInfectious, "remind_cycle": patientsNew.RemindCycle, "response_result": patientsNew.ResponseResult, "is_open_remind": patientsNew.IsOpenRemind, "first_treatment_date": patientsNew.FirstTreatmentDate, "dialysis_age": patientsNew.DialysisAge, "expense_kind": patientsNew.ExpenseKind, "tell_phone": patientsNew.ExpenseKind, "contact_name": patientsNew.ContactName, "blood_patients": patientsNew.BloodPatients, "slow_patients": patientsNew.SlowPatients, "member_patients": patientsNew.MemberPatients, "ecommer_patients": patientsNew.EcommerPatients}).Error
  352. return err
  353. }
  354. func GetLastInfectionRecord(id int64, org_id int64, project_id int64, date int64) (inspection models.Inspection, err error) {
  355. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? AND inspect_date = ? ", id, org_id, project_id, date).Last(&inspection).Error
  356. return
  357. }
  358. func GetAllInfectionRecord(date int64, org_id int64, patient_id int64, project_id int64) (inspection []*models.Inspection, err error) {
  359. err = readDb.Model(&models.Inspection{}).Where("patient_id=? and status=1 and org_id = ? and project_id = ? and inspect_date = ?", patient_id, org_id, project_id, date).Find(&inspection).Error
  360. return
  361. }
  362. func GetPatientDiseases(id int64) []int64 {
  363. var dis []models.ChronicDiseases
  364. ids := make([]int64, 0)
  365. err := readDb.Model(&models.ChronicDiseases{}).Where("patient_id=? and status=1", id).Find(&dis).Error
  366. if err != nil || len(dis) == 0 {
  367. return ids
  368. }
  369. for _, item := range dis {
  370. ids = append(ids, item.DiseaseId)
  371. }
  372. return ids
  373. }
  374. func GetPatientContagions(id int64) []int64 {
  375. var cis []models.InfectiousDiseases
  376. ids := make([]int64, 0)
  377. err := readDb.Model(&models.InfectiousDiseases{}).Where("patient_id=? and status=1", id).Find(&cis).Error
  378. if err != nil || len(cis) == 0 {
  379. return ids
  380. }
  381. for _, item := range cis {
  382. ids = append(ids, item.DiseaseId)
  383. }
  384. return ids
  385. }
  386. func FindPatientDialysisSolutionByMode(orgID int64, patientID, modeId int64) (solution models.DialysisSolution, err error) {
  387. err = readDb.Model(&models.DialysisSolution{}).Where("user_org_id=? and patient_id=? and mode_id=? and parent_id=0 and status=1", orgID, patientID, modeId).First(&solution).Error
  388. return
  389. }
  390. func FindPatientDialysisSolution(orgID int64, id int64) (solution models.DialysisSolution, err error) {
  391. err = readDb.Model(&models.DialysisSolution{}).Where("id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  392. return
  393. }
  394. func FindPatientDialysisSolutionChild(orgID int64, id int64) (solution models.DialysisSolution, err error) {
  395. err = readDb.Model(&models.DialysisSolution{}).Where("parent_id = ? and status=1 and user_org_id=?", id, orgID).First(&solution).Error
  396. return
  397. }
  398. func CreatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
  399. err = writeDb.Create(solution).Error
  400. return
  401. }
  402. func UpdatePatientDialysisSolution(solution *models.DialysisSolution) (err error) {
  403. err = writeDb.Save(solution).Error
  404. return
  405. }
  406. //GetPatientDialysisSolutionList 返回患者透析方案的列表
  407. func GetPatientDialysisSolutionList(orgID int64, patientID int64, page, limit int64) (solutions []*models.DialysisSolution, total int64, err error) {
  408. offset := (page - 1) * limit
  409. db := readDb.Table("xt_dialysis_solution as ds").Where("ds.status=1")
  410. if orgID > 0 {
  411. db = db.Where("ds.user_org_id=?", orgID)
  412. }
  413. if patientID > 0 {
  414. db = db.Where("ds.patient_id=?", patientID)
  415. }
  416. db = db.Count(&total).Offset(offset).Limit(limit)
  417. err = db.Order("id desc").Find(&solutions).Error
  418. if err != nil {
  419. return
  420. }
  421. if len(solutions) > 0 {
  422. nilNameIds := make([]int64, 0)
  423. for _, solution := range solutions {
  424. if len(solution.ModeName) == 0 {
  425. nilNameIds = append(nilNameIds, solution.ModeId)
  426. }
  427. }
  428. if len(nilNameIds) > 0 {
  429. var modes []*models.TreatmentMode
  430. err = readDb.Model(&models.TreatmentMode{}).Where("id IN (?)", nilNameIds).Find(&modes).Error
  431. if err != nil {
  432. return
  433. }
  434. modesMap := make(map[int64]models.TreatmentMode, 0)
  435. for _, mode := range modes {
  436. modesMap[mode.ID] = *mode
  437. }
  438. for index, solution := range solutions {
  439. if _, exixt := modesMap[solution.ModeId]; exixt && len(solution.ModeName) == 0 {
  440. solutions[index].ModeName = modesMap[solution.ModeId].Name
  441. }
  442. }
  443. }
  444. }
  445. return
  446. }
  447. //GetPatientDryWeightAdjustList 返回患者调整干体重的列表
  448. func GetPatientDryWeightAdjustList(orgID int64, patientID int64, page int64, limit int64) (weights []*models.DryWeightAdjust, total int64, err error) {
  449. db := readDb.Table("xt_dry_weight_adjust as dwa").Where("dwa.status=1")
  450. if orgID > 0 {
  451. db = db.Where("dwa.user_org_id=?", orgID)
  452. }
  453. if patientID > 0 {
  454. db = db.Where("dwa.patient_id=?", patientID)
  455. }
  456. db = db.Select("dwa.id, dwa.user_org_id, dwa.patient_id, dwa.weight, dwa.adjusted_value, dwa.doctor, dwa.registrars_id, dwa.remark, dwa.status, dwa.created_time, dwa.updated_time").Count(&total).Order("id desc")
  457. if page > 0 && limit > 0 {
  458. offset := (page - 1) * limit
  459. db = db.Offset(offset).Limit(limit)
  460. }
  461. err = db.Find(&weights).Error
  462. return
  463. }
  464. func CreateDryWeightAdjust(m *models.DryWeightAdjust) (err error) {
  465. err = writeDb.Create(m).Error
  466. return
  467. }
  468. func FindPatientLastDryWeightAdjust(orgID int64, id int64) (weight models.DryWeightAdjust, err error) {
  469. err = readDb.Model(&models.DryWeightAdjust{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
  470. return
  471. }
  472. func CreateDoctorAdvice(m *models.DoctorAdvice) (err error) {
  473. return writeDb.Create(m).Error
  474. }
  475. func GetMaxAdviceGroupID(orgId int64) (group int64) {
  476. var advice models.DoctorAdvice
  477. err := readDb.Table("xt_doctor_advice").Where("user_org_id=?", orgId).Select("max(groupno) as groupno").First(&advice).Error
  478. if err != nil {
  479. fmt.Println(err)
  480. group = 0
  481. }
  482. group = advice.GroupNo
  483. return
  484. }
  485. func CreateGroupAdvice(orgId int64, group int64, advices []*models.GroupAdvice) (err error) {
  486. if group == 0 {
  487. group = GetMaxAdviceGroupID(orgId) + 1
  488. }
  489. tx := writeDb.Begin()
  490. defer func() {
  491. if r := recover(); r != nil {
  492. tx.Rollback()
  493. }
  494. }()
  495. for _, advice := range advices {
  496. advice.GroupNo = group
  497. if err = tx.Create(advice).Error; err != nil {
  498. tx.Rollback()
  499. return
  500. }
  501. }
  502. tx.Commit()
  503. return
  504. }
  505. func CreateMGroupAdvice(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) {
  506. if groupNo <= 0 {
  507. group := GetMaxAdviceGroupID(orgId)
  508. groupNo = group + 1
  509. }
  510. tx := writeDb.Begin()
  511. defer func() {
  512. if r := recover(); r != nil {
  513. tx.Rollback()
  514. }
  515. }()
  516. for _, advice := range advices {
  517. advice.GroupNo = groupNo
  518. if err = tx.Create(advice).Error; err != nil {
  519. tx.Rollback()
  520. return
  521. }
  522. list = append(list, advice)
  523. if len(advice.Children) > 0 {
  524. for _, child := range advice.Children {
  525. child.GroupNo = groupNo
  526. child.ParentId = advice.ID
  527. fmt.Println(child)
  528. if err = tx.Create(&child).Error; err != nil {
  529. tx.Rollback()
  530. return
  531. }
  532. list = append(list, child)
  533. }
  534. }
  535. }
  536. tx.Commit()
  537. return
  538. }
  539. func UpdateDoctorAdvice(m *models.DoctorAdvice) (err error) {
  540. return writeDb.Save(m).Error
  541. }
  542. func StopGroupAdvice(orgId int64, groupNo int64, m *models.DoctorAdvice) (err error) {
  543. err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? and groupno=?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime}).Error
  544. if err != nil {
  545. return
  546. }
  547. return
  548. }
  549. func StopDoctorAdvice(m *models.DoctorAdvice) (err error) {
  550. ut := writeDb.Begin()
  551. err = ut.Save(m).Error
  552. if err != nil {
  553. ut.Rollback()
  554. return
  555. }
  556. err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "StopState": 1, "StopReason": m.StopReason, "StopDoctor": m.StopDoctor, "StopTime": m.StopTime, "Modifier": m.Modifier}).Error
  557. if err != nil {
  558. ut.Rollback()
  559. return
  560. }
  561. ut.Commit()
  562. return
  563. }
  564. func DeleteSolution(m *models.DialysisSolution) (err error) {
  565. if m.ParentId > 0 {
  566. return writeDb.Save(m).Error
  567. } else {
  568. ut := writeDb.Begin()
  569. err = ut.Save(m).Error
  570. if err != nil {
  571. ut.Rollback()
  572. return
  573. }
  574. err = ut.Model(&models.DialysisSolution{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0}).Error
  575. if err != nil {
  576. ut.Rollback()
  577. return
  578. }
  579. ut.Commit()
  580. }
  581. return
  582. }
  583. func DeleteDoctorAdvice(m *models.DoctorAdvice) (err error) {
  584. if m.ParentId > 0 {
  585. return writeDb.Save(m).Error
  586. } else {
  587. ut := writeDb.Begin()
  588. err = ut.Save(m).Error
  589. if err != nil {
  590. ut.Rollback()
  591. return
  592. }
  593. err = ut.Model(&models.DoctorAdvice{}).Where("parent_id=?", m.ID).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0, "Modifier": m.Modifier}).Error
  594. if err != nil {
  595. ut.Rollback()
  596. return
  597. }
  598. ut.Commit()
  599. }
  600. return
  601. }
  602. func DeleteGroupAdvice(orgId int64, groupNo int64, admin_user_id int64) (err error) {
  603. err = writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ?", orgId, groupNo).Update(map[string]interface{}{"UpdatedTime": time.Now().Unix(), "Status": 0, "Modifier": admin_user_id}).Error
  604. if err != nil {
  605. return
  606. }
  607. return
  608. }
  609. func FindDoctorAdvice(orgID, id int64) (advice models.DoctorAdvice, err error) {
  610. err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? and user_org_id=? and status = 1", id, orgID).First(&advice).Error
  611. return
  612. }
  613. func FindDoctorAdviceByGroupNo(orgID, groupNo int64) (advice models.DoctorAdvice, err error) {
  614. err = readDb.Model(&models.DoctorAdvice{}).Where("groupno = ? and user_org_id=? and status = 1", groupNo, orgID).First(&advice).Error
  615. return
  616. }
  617. func GetDoctorAdviceList(orgID, patientID, advice_type, stop, start, end int64, keywords string) (advices []*models.DoctorAdvices, total int64, err error) {
  618. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  619. table := UserReadDB().Table("sgj_user_admin_role as r")
  620. fmt.Print("table", table)
  621. if orgID > 0 {
  622. db = db.Where("x.user_org_id=?", orgID)
  623. }
  624. if patientID > 0 {
  625. db = db.Where("x.patient_id = ?", patientID)
  626. }
  627. if advice_type > 0 {
  628. db = db.Where("x.advice_type = ?", advice_type)
  629. } else if advice_type == 0 {
  630. db = db.Where("x.advice_type in (?)", []int{1, 3})
  631. }
  632. if stop == 1 {
  633. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  634. } else if stop == 2 {
  635. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  636. }
  637. if start != 0 {
  638. db = db.Where("x.start_time>=?", start)
  639. }
  640. if end != 0 {
  641. db = db.Where("start_time<=?", end)
  642. }
  643. if len(keywords) > 0 {
  644. likeKey := "%" + keywords + "%"
  645. db = db.Where("x.advice_name LIKE ?", likeKey)
  646. }
  647. err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
  648. fmt.Print("err", err)
  649. return
  650. }
  651. func GetDoctorAdviceListOne(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.DoctorAdvices, total int64, err error) {
  652. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  653. table := UserReadDB().Table("sgj_user_admin_role as r")
  654. fmt.Print("table", table)
  655. if orgID > 0 {
  656. db = db.Where("x.user_org_id=?", orgID)
  657. }
  658. if patientID > 0 {
  659. db = db.Where("x.patient_id = ?", patientID)
  660. }
  661. if advice_type == 1 && advice_type > 0 {
  662. db = db.Where("x.advice_type = ?", advice_type)
  663. }
  664. if advice_type == 3 && advice_type > 0 {
  665. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  666. }
  667. if stop == 1 {
  668. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  669. } else if stop == 2 {
  670. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  671. }
  672. if start != 0 {
  673. db = db.Where("x.start_time>=?", start)
  674. }
  675. if end != 0 {
  676. db = db.Where("start_time<=?", end)
  677. }
  678. if len(keywords) > 0 {
  679. likeKey := "%" + keywords + "%"
  680. db = db.Where("x.advice_name LIKE ?", likeKey)
  681. }
  682. offset := (page - 1) * limit
  683. err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
  684. fmt.Print("err", err)
  685. return
  686. }
  687. func GetDoctorAdviceListTwo(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64) (advices []*models.DoctorAdvices, total int64, err error) {
  688. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  689. table := UserReadDB().Table("sgj_user_admin_role as r")
  690. fmt.Println(table)
  691. if orgID > 0 {
  692. db = db.Where("x.user_org_id=?", orgID)
  693. }
  694. if patientID > 0 {
  695. db = db.Where("x.patient_id = ?", patientID)
  696. }
  697. if advice_type == 1 {
  698. db = db.Where("x.advice_type = ?", advice_type)
  699. }
  700. if advice_type == 3 {
  701. db = db.Where("x.advice_type <> 1")
  702. }
  703. if stop == 1 {
  704. db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
  705. } else if stop == 2 {
  706. db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
  707. }
  708. if start != 0 {
  709. db = db.Where("x.start_time>=?", start)
  710. }
  711. if end != 0 {
  712. db = db.Where("start_time<=?", end)
  713. }
  714. if len(keywords) > 0 {
  715. likeKey := "%" + keywords + "%"
  716. db = db.Where("x.advice_name LIKE ?", likeKey)
  717. }
  718. offset := (page - 1) * limit
  719. err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
  720. fmt.Print("错误是什么", err)
  721. return
  722. }
  723. func GetDoctorAdvicePageList(orgID, patientID, advice_type, stop, start, end int64, keywords string, page, limit int64) (advices []*models.DoctorAdvice, total int64, err error) {
  724. offset := (page - 1) * limit
  725. db := readDb.Model(&models.DoctorAdvice{}).Where("status=1")
  726. if orgID > 0 {
  727. db = db.Where("user_org_id=?", orgID)
  728. }
  729. if patientID > 0 {
  730. db = db.Where("patient_id = ?", patientID)
  731. }
  732. if advice_type > 0 {
  733. db = db.Where("advice_type = ?", advice_type)
  734. }
  735. if stop == 1 {
  736. db = db.Where("(stop_state=? or execution_state=?) and parent_id=0", stop, stop)
  737. } else if stop == 2 {
  738. db = db.Where("stop_state=? and execution_state=?", stop, stop)
  739. }
  740. if start != 0 {
  741. db = db.Where("start_time>=?", start)
  742. }
  743. if end != 0 {
  744. db = db.Where("start_time<=?", end)
  745. }
  746. if len(keywords) > 0 {
  747. likeKey := "%" + keywords + "%"
  748. db = db.Where("advice_name LIKE ?", likeKey)
  749. }
  750. err = db.Count(&total).Select("id,user_org_id,patient_id,advice_type,advice_date,start_time,advice_name,advice_desc,reminder_date,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker IF(parent_id>0, parent_id, id) as advice_order").Order("advice_order desc, id").Offset(offset).Limit(limit).Scan(&advices).Error
  751. return
  752. }
  753. func CreateSubDoctorAdvice(advices []*models.DoctorAdvice) (err error) {
  754. if len(advices) > 0 {
  755. utx := writeDb.Begin()
  756. if len(advices) > 0 {
  757. thisSQL := "INSERT INTO xt_doctor_advice (single_dose_unit, prescribing_number, prescribing_number_unit, advice_name, advice_desc,single_dose,created_time,updated_time,patient_id,parent_id,user_org_id,record_date,advice_type,drug_spec_unit) VALUES "
  758. insertParams := make([]string, 0)
  759. insertData := make([]interface{}, 0)
  760. for _, advice := range advices {
  761. insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
  762. insertData = append(insertData, advice.SingleDoseUnit)
  763. insertData = append(insertData, advice.PrescribingNumber)
  764. insertData = append(insertData, advice.PrescribingNumberUnit)
  765. insertData = append(insertData, advice.AdviceName)
  766. insertData = append(insertData, advice.AdviceDesc)
  767. insertData = append(insertData, advice.SingleDose)
  768. insertData = append(insertData, advice.CreatedTime)
  769. insertData = append(insertData, advice.UpdatedTime)
  770. insertData = append(insertData, advice.PatientId)
  771. insertData = append(insertData, advice.ParentId)
  772. insertData = append(insertData, advice.UserOrgId)
  773. insertData = append(insertData, advice.RecordDate)
  774. insertData = append(insertData, 2)
  775. insertData = append(insertData, advice.DrugSpecUnit)
  776. }
  777. thisSQL += strings.Join(insertParams, ", ")
  778. err = utx.Exec(thisSQL, insertData...).Error
  779. if err != nil {
  780. utx.Rollback()
  781. return
  782. }
  783. }
  784. utx.Commit()
  785. }
  786. return
  787. }
  788. func GetPatientDialysisRecord(orgID, patientID int64, page, limit, start, end, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
  789. offset := (page - 1) * limit
  790. var total int64
  791. var err error
  792. var orders []*models.PatientDialysisRecord
  793. // err = readDb.Table("xt_dialysis_order as do").
  794. // Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  795. // Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  796. // Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  797. // Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  798. // Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
  799. // Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
  800. // Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select(" do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time, s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
  801. db := readDb.Table("xt_dialysis_order as do").
  802. Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  803. Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  804. Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
  805. return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  806. return readUserDb.Where("status = 1")
  807. })
  808. }).
  809. Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  810. Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  811. Preload("Device", "org_id=? and status=1", orgID).
  812. Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  813. return readUserDb.Where("org_id=? and status = 1", orgID)
  814. }).
  815. Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
  816. Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
  817. Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
  818. if start != 0 {
  819. db = db.Where("do.dialysis_date>=?", start)
  820. }
  821. if end != 0 {
  822. db = db.Where("do.dialysis_date<=?", end)
  823. }
  824. if mode_id > 0 {
  825. db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.record_id=do.id")
  826. db = db.Where("dp.mode_id=?", mode_id)
  827. }
  828. err = db.Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select("do.bed_id, do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time,do.start_nurse,do.finish_nurse ,s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
  829. if len(orders) > 0 {
  830. ids := make([]int64, 0)
  831. for _, order := range orders {
  832. dialyzer := order.DialysisPrescription.Dialyzer
  833. ids = append(ids, dialyzer)
  834. }
  835. if len(ids) > 0 {
  836. var dialyzers []*models.DeviceNumber
  837. err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
  838. if err != nil {
  839. return nil, 0, err
  840. }
  841. dialyzerMap := make(map[int64]models.DeviceNumber, 0)
  842. for _, item := range dialyzers {
  843. dialyzerMap[item.ID] = *item
  844. }
  845. for orderIndex, order := range orders {
  846. if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
  847. orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
  848. }
  849. }
  850. }
  851. }
  852. return orders, total, err
  853. }
  854. func GetPatientTreatmentSummaryList(orgID, patientID, page, limit, start, end int64) (list []*models.TreatmentSummary, total int, err error) {
  855. offset := (page - 1) * limit
  856. fmt.Println(offset)
  857. fmt.Println(limit)
  858. db := readDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? and patient_id=?", orgID, patientID)
  859. if start != 0 {
  860. db = db.Where("assessment_date >= ?", start)
  861. }
  862. if end != 0 {
  863. db = db.Where("assessment_date <= ?", end)
  864. }
  865. db = db.Where("status=1")
  866. err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc, id desc").Find(&list).Error
  867. return
  868. }
  869. func GetPatientScheduleList(orgID int64, patientID int64, page int64, limit int64, start int64) (schedules []*models.PatientSchedule, err error) {
  870. offset := (page - 1) * limit
  871. err = readDb.Table("xt_schedule as s").
  872. Preload("DeviceZone", "org_id=? and status=1", orgID).
  873. Preload("DeviceNumber", "org_id=? and status=1", orgID).
  874. Preload("TreatmentMode", "status=1").
  875. Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, start).
  876. Limit(limit).Offset(offset).Find(&schedules).Error
  877. return
  878. }
  879. func GetMonitorRecord(orgID int64, date int64, partition int64) ([]*models.MonitorDialysisSchedule, error) {
  880. var mds []*models.MonitorDialysisSchedule
  881. db := readDb.
  882. Model(&models.MonitorDialysisSchedule{}).
  883. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  884. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  885. Preload("TreatmentMode", "status = 1").
  886. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  887. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  888. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  889. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  890. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  891. Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
  892. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID).
  893. Where("status = 1 AND user_org_id = ?", orgID)
  894. if date != 0 {
  895. db = db.Where("schedule_date = ? ", date)
  896. }
  897. if partition != 0 {
  898. db = db.Where("partition_id = ? ", partition)
  899. }
  900. err := db.Find(&mds).Error
  901. return mds, err
  902. }
  903. func MobileGetMonitorsWithPatient(orgID int64, keyword string, page int) ([]*models.MonitorDialysisSchedule, error) {
  904. var patients []*models.Patients
  905. getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
  906. if getPatientErr != nil {
  907. return nil, getPatientErr
  908. }
  909. patientIDs := make([]int64, len(patients))
  910. for index, patient := range patients {
  911. patientIDs[index] = patient.ID
  912. }
  913. db := readDb.
  914. Model(&models.MonitorDialysisSchedule{}).
  915. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  916. Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  917. Preload("TreatmentMode", "status = 1").
  918. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  919. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  920. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  921. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  922. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  923. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID).
  924. Where("status = 1 AND user_org_id = ? AND patient_id in (?)", orgID, patientIDs)
  925. var schedules []*models.MonitorDialysisSchedule
  926. err := db.Offset(20 * (page - 1)).Limit(20).Order("schedule_date desc").Find(&schedules).Error
  927. return schedules, err
  928. }
  929. func GetPatientByKeyWord(orgID int64, keywords string) (patient []*models.Patients, err error) {
  930. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID)
  931. if len(keywords) > 0 {
  932. likekey := "%" + keywords + "%"
  933. err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
  934. } else {
  935. err = db.Find(&patient).Error
  936. }
  937. return
  938. }
  939. func FindDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice models.DoctorAdvice, err error) {
  940. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).First(&advice).Error
  941. return
  942. }
  943. func FindOldDoctorAdvice(orgID int64, advice_id int64) (advice models.DoctorAdvice, err error) {
  944. err = readDb.Model(&models.DoctorAdvice{}).Where("id = ? AND user_org_id=? AND status = 1", advice_id, orgID).First(&advice).Error
  945. return
  946. }
  947. func UpdateAdviceGroupStartTime(orgID int64, groupNO int64, startTime int64, admin_user_id int64) error {
  948. now := time.Now().Unix()
  949. err := writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND status = 1 AND execution_state <> 1 AND check_state <> 1 AND groupno = ? AND admin_user_id = ?", orgID, groupNO, admin_user_id).Updates(map[string]interface{}{
  950. "start_time": startTime,
  951. "updated_time": now,
  952. "modifier": admin_user_id,
  953. }).Error
  954. return err
  955. }
  956. func QueryPatientById(id int64) *models.Patients {
  957. var pat models.Patients
  958. err := readDb.Model(&models.Patients{}).Where("id=?", id).First(&pat).Error
  959. if err != nil {
  960. }
  961. return &pat
  962. }
  963. func FindAllDoctorAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  964. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1", orgID, groupno).Find(&advice).Error
  965. return
  966. }
  967. func FindDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) {
  968. err = readDb.Model(&models.DoctorAdvice{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error
  969. return
  970. }
  971. func BatchDeleteDoctorAdvice(ids []string, user_id int64) (err error) {
  972. ut := writeDb.Begin()
  973. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix(), "modifier": user_id}).Error
  974. if err != nil {
  975. ut.Rollback()
  976. return
  977. }
  978. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", ids).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix(), "modifier": user_id}).Error
  979. if err != nil {
  980. ut.Rollback()
  981. return
  982. }
  983. ut.Commit()
  984. return err
  985. }
  986. func FindAdviceByGoroupNo(orgID int64, groupno int64) (advice []models.DoctorAdvice, err error) {
  987. err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND groupno = ? AND status = 1 AND parent_id = 0", orgID, groupno).Find(&advice).Error
  988. return
  989. }
  990. func UpdateDoctorAdviceAndSubAdvice(m *models.DoctorAdvice) (err error) {
  991. ut := writeDb.Begin()
  992. err = ut.Save(m).Error
  993. if err != nil {
  994. ut.Rollback()
  995. return
  996. }
  997. err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?)", m.ID).Updates(map[string]interface{}{"start_time": m.StartTime, "groupno": m.GroupNo, "mtime": time.Now().Unix()}).Error
  998. if err != nil {
  999. ut.Rollback()
  1000. return
  1001. }
  1002. ut.Commit()
  1003. return err
  1004. }
  1005. func GetAllWaitRemindPatient(org_id int64, page int64, limit int64) (total int64, patient []*models.Patients, err error) {
  1006. type Total struct {
  1007. Count int64
  1008. }
  1009. var totals Total
  1010. offset := (page - 1) * limit
  1011. err = readDb.Raw("select * from xt_patients where user_org_id = ? AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Offset(offset).Limit(limit).Scan(&patient).Error
  1012. readDb.Raw("select Count(id) as count from xt_patients where user_org_id = ? AND infectious_next_record_time > 0 AND status = 1 AND date_sub(DATE_FORMAT(date(from_unixtime(`xt_patients`.`infectious_next_record_time`)),'%Y-%m-%d'), interval 7 day) <= now() Order by infectious_next_record_time", org_id).Scan(&totals)
  1013. return totals.Count, patient, err
  1014. }
  1015. func UpdatePatientRemindStatus(patient_id int64, remind int64, org_id int64) (err error) {
  1016. err = writeDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).Updates(map[string]interface{}{"is_open_remind": remind}).Error
  1017. return
  1018. }
  1019. func CreatePatientWeightAdjust(m *models.SgjPatientDryweight) (err error) {
  1020. err = writeDb.Create(m).Error
  1021. return
  1022. }
  1023. func FindLastDryWeightAdjust(orgID int64, id int64) (weight models.SgjPatientDryweight, err error) {
  1024. err = readDb.Model(&models.SgjPatientDryweight{}).Where("user_org_id=? and patient_id=? and status=1", orgID, id).Order("id desc").First(&weight).Error
  1025. return
  1026. }
  1027. func GetSchedualPatientByKeyWord(orgID int64, keywords string, date int64) (patient []*models.Patients, err error) {
  1028. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
  1029. if len(keywords) > 0 {
  1030. likekey := "%" + keywords + "%"
  1031. err = db.Where("(name LIKE ? OR dialysis_no LIKE ?) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = xt_patients.id AND d.user_org_id = xt_patients.user_org_id)", likekey, likekey, date).Find(&patient).Error
  1032. } else {
  1033. err = db.Find(&patient).Error
  1034. }
  1035. return
  1036. }
  1037. func GetPatientScheduleOne(patientid int64, nowdate int64, orgid int64) (models.XtSchedule, error) {
  1038. schedule := models.XtSchedule{}
  1039. err := XTReadDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status =1", patientid, nowdate, orgid).Find(&schedule).Error
  1040. return schedule, err
  1041. }
  1042. func CreateExportPatient(patient *models.Patients, contagions []int64, org_creator int64) (err error) {
  1043. user, _ := GetSgjUserByMobild(patient.Phone)
  1044. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  1045. utx := writeDb.Begin()
  1046. btx := writeUserDb.Begin()
  1047. if user.ID == 0 {
  1048. user.Mobile = patient.Phone
  1049. user.Avatar = patient.Avatar
  1050. user.AvatarThumb = patient.Avatar
  1051. user.Birthday = patient.Birthday
  1052. user.Username = patient.Name
  1053. user.Gender = patient.Gender
  1054. user.Sources = 11
  1055. user.Introduce = patient.Remark
  1056. user.Status = 1
  1057. user.UpdatedTime = patient.UpdatedTime
  1058. user.CreatedTime = patient.CreatedTime
  1059. err = btx.Create(&user).Error
  1060. if err != nil {
  1061. utx.Rollback()
  1062. btx.Rollback()
  1063. return
  1064. }
  1065. }
  1066. patient.UserId = user.ID
  1067. if customer == nil {
  1068. err = btx.Create(&models.SgjCustomer{
  1069. UserOrgId: patient.UserOrgId,
  1070. UserId: user.ID,
  1071. Mobile: patient.Phone,
  1072. Name: patient.Name,
  1073. Gender: patient.Gender,
  1074. Birthday: patient.Birthday,
  1075. Sources: 11,
  1076. Status: 1,
  1077. CreatedTime: patient.CreatedTime,
  1078. UpdatedTime: patient.UpdatedTime,
  1079. Avatar: patient.Avatar,
  1080. Remark: patient.Remark,
  1081. }).Error
  1082. if err != nil {
  1083. utx.Rollback()
  1084. btx.Rollback()
  1085. return
  1086. }
  1087. }
  1088. err = utx.Create(patient).Error
  1089. if err != nil {
  1090. utx.Rollback()
  1091. btx.Rollback()
  1092. return
  1093. }
  1094. if patient.DryWeight > 0 {
  1095. var dryWeight models.SgjPatientDryweight
  1096. dryWeight.PatientId = patient.ID
  1097. dryWeight.UserOrgId = patient.UserOrgId
  1098. dryWeight.Status = 1
  1099. dryWeight.AdjustedValue = "/"
  1100. dryWeight.Creator = org_creator
  1101. dryWeight.UserId = org_creator
  1102. dryWeight.Ctime = time.Now().Unix()
  1103. dryWeight.Mtime = time.Now().Unix()
  1104. dryWeight.DryWeight = patient.DryWeight
  1105. dryWeight.Remakes = ""
  1106. err = utx.Create(&dryWeight).Error
  1107. }
  1108. var lapseto models.PatientLapseto
  1109. lapseto.PatientId = patient.ID
  1110. lapseto.LapsetoType = patient.Lapseto
  1111. lapseto.CreatedTime = patient.CreatedTime
  1112. lapseto.UpdatedTime = patient.CreatedTime
  1113. lapseto.Status = 1
  1114. lapseto.LapsetoTime = patient.CreatedTime
  1115. err = utx.Create(&lapseto).Error
  1116. if err != nil {
  1117. utx.Rollback()
  1118. btx.Rollback()
  1119. return
  1120. }
  1121. if len(contagions) > 0 {
  1122. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  1123. insertParams := make([]string, 0)
  1124. insertData := make([]interface{}, 0)
  1125. for _, contagion := range contagions {
  1126. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  1127. insertData = append(insertData, patient.ID)
  1128. insertData = append(insertData, contagion)
  1129. insertData = append(insertData, 1)
  1130. insertData = append(insertData, patient.CreatedTime)
  1131. insertData = append(insertData, patient.UpdatedTime)
  1132. }
  1133. thisSQL += strings.Join(insertParams, ", ")
  1134. err = utx.Exec(thisSQL, insertData...).Error
  1135. if err != nil {
  1136. utx.Rollback()
  1137. btx.Rollback()
  1138. return
  1139. }
  1140. }
  1141. patientsNew := models.XtPatientsNew{
  1142. Name: patient.Name,
  1143. Gender: patient.Gender,
  1144. Phone: patient.Phone,
  1145. IdCardNo: patient.IdCardNo,
  1146. FirstDialysisDate: patient.FirstDialysisDate,
  1147. Source: patient.Source,
  1148. Lapseto: patient.Lapseto,
  1149. IsInfectious: patient.IsInfectious,
  1150. DialysisNo: patient.DialysisNo,
  1151. Height: patient.Height,
  1152. HomeAddress: patient.HomeAddress,
  1153. IsExcelExport: 1,
  1154. BloodPatients: 1,
  1155. Status: 1,
  1156. CreatedTime: time.Now().Unix(),
  1157. UserOrgId: patient.UserOrgId,
  1158. BloodId: patient.ID,
  1159. Avatar: "https://images.shengws.com/201809182128111.png",
  1160. }
  1161. err = utx.Create(&patientsNew).Error
  1162. if err != nil {
  1163. utx.Rollback()
  1164. btx.Rollback()
  1165. return
  1166. }
  1167. utx.Commit()
  1168. btx.Commit()
  1169. return
  1170. }
  1171. func FindPatientPhoneIsExist(phone string, org_id int64) (count int64) {
  1172. readDb.Model(&models.Patients{}).Where("user_org_id = ? AND phone = ? AND status = 1", org_id, phone).Count(&count)
  1173. return
  1174. }
  1175. func FindPatientIdCardNoIsExist(id_card_no string, org_id int64) (count int64) {
  1176. readDb.Model(&models.Patients{}).Where("user_org_id = ? AND id_card_no = ? AND status = 1", org_id, id_card_no).Count(&count)
  1177. return
  1178. }
  1179. func CreateExportErrLog(log *models.ExportErrLog) {
  1180. writeDb.Create(&log)
  1181. return
  1182. }
  1183. func FindPatientExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
  1184. err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 1", org_id, export_time).Find(&errLogs).Error
  1185. return
  1186. }
  1187. func CreateExportLog(log *models.ExportLog) {
  1188. writeDb.Create(&log)
  1189. }
  1190. func UpdateDoctorEditAdvice(advice models.XtDoctorAdvice, orgid int64, groupno int64, date int64, patientid int64) error {
  1191. err := XTWriteDB().Model(&advice).Where("user_org_id = ? and groupno = ? and advice_date = ? and patient_id = ?", orgid, groupno, date, patientid).Update(map[string]interface{}{"start_time": advice.StartTime, "updated_time": advice.UpdatedTime}).Error
  1192. return err
  1193. }
  1194. func GetPatientsByKey(orgID int64, keywords string) (patient []*models.Patients, err error) {
  1195. db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1 and lapseto = 1 ", orgID)
  1196. if len(keywords) > 0 {
  1197. likekey := "%" + keywords + "%"
  1198. err = db.Where("(name LIKE ? OR dialysis_no LIKE ?)", likekey, likekey).Find(&patient).Error
  1199. } else {
  1200. err = db.Find(&patient).Error
  1201. }
  1202. return
  1203. }