patient_service.go 55KB

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