|
@@ -2,6 +2,10 @@ package service
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"XT_New/models"
|
|
5
|
+ "fmt"
|
|
6
|
+ "strconv"
|
|
7
|
+ "strings"
|
|
8
|
+ "time"
|
5
|
9
|
|
6
|
10
|
"github.com/jinzhu/gorm"
|
7
|
11
|
)
|
|
@@ -227,15 +231,12 @@ func GetSchedualPatientsByKeywords(keywords string, org_id int64) (schedule []*m
|
227
|
231
|
|
228
|
232
|
}
|
229
|
233
|
|
230
|
|
-func GetWeekDaySchedule(orgID int64, scheduleDate int64) (schedules []*models.WeekSchedule, err error) {
|
|
234
|
+func GetWeekDaySchedule(orgID int64, scheduleDate int64, scheduleDates *time.Time) (schedules []*models.WeekSchedule, err error) {
|
231
|
235
|
|
232
|
236
|
err = readDb.
|
233
|
237
|
Table("xt_schedule as s").
|
234
|
238
|
Preload("DeviceZone", "status = 1 ").
|
235
|
239
|
Preload("DeviceNumber", "status = 1 ").
|
236
|
|
- Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
|
237
|
|
- return db.Where("status = 1 AND advice_type = 1").Preload("ChildDoctorAdvice", "status = 1")
|
238
|
|
- }).
|
239
|
240
|
Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
|
240
|
241
|
return db.Where("status = 1").Order("id desc")
|
241
|
242
|
}).
|
|
@@ -244,5 +245,106 @@ func GetWeekDaySchedule(orgID int64, scheduleDate int64) (schedules []*models.We
|
244
|
245
|
Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
|
245
|
246
|
Order("schedule_type").
|
246
|
247
|
Find(&schedules).Error
|
|
248
|
+
|
|
249
|
+ for _, item := range schedules {
|
|
250
|
+ _, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
|
|
251
|
+ if config.IsOpenRemind > 0 {
|
|
252
|
+
|
|
253
|
+ var advice_three []*models.DoctorAdvice
|
|
254
|
+ advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
|
|
255
|
+ advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
|
|
256
|
+ for _, advice := range advices {
|
|
257
|
+ advice.IsCheck = 1
|
|
258
|
+ if advice.FrequencyType == 3 {
|
|
259
|
+ week := int(scheduleDates.Weekday())
|
|
260
|
+ fmt.Println(advice.WeekDay)
|
|
261
|
+ switch week {
|
|
262
|
+ case 1:
|
|
263
|
+ if strings.Index(advice.WeekDay, "周一") > -1 {
|
|
264
|
+ advice_three = append(advice_three, advice)
|
|
265
|
+ }
|
|
266
|
+ break
|
|
267
|
+ case 2:
|
|
268
|
+ if strings.Index(advice.WeekDay, "周二") > -1 {
|
|
269
|
+ advice_three = append(advice_three, advice)
|
|
270
|
+ }
|
|
271
|
+ break
|
|
272
|
+ case 3:
|
|
273
|
+ if strings.Index(advice.WeekDay, "周三") > -1 {
|
|
274
|
+ advice_three = append(advice_three, advice)
|
|
275
|
+ }
|
|
276
|
+ break
|
|
277
|
+ case 4:
|
|
278
|
+ if strings.Index(advice.WeekDay, "周四") > -1 {
|
|
279
|
+ advice_three = append(advice_three, advice)
|
|
280
|
+ }
|
|
281
|
+ break
|
|
282
|
+ case 5:
|
|
283
|
+ if strings.Index(advice.WeekDay, "周五") > -1 {
|
|
284
|
+ advice_three = append(advice_three, advice)
|
|
285
|
+ }
|
|
286
|
+ break
|
|
287
|
+ case 6:
|
|
288
|
+ if strings.Index(advice.WeekDay, "周六") > -1 {
|
|
289
|
+ advice_three = append(advice_three, advice)
|
|
290
|
+ }
|
|
291
|
+ break
|
|
292
|
+ case 0:
|
|
293
|
+ if strings.Index(advice.WeekDay, "周日") > -1 {
|
|
294
|
+ advice_three = append(advice_three, advice)
|
|
295
|
+ }
|
|
296
|
+ break
|
|
297
|
+ }
|
|
298
|
+ } else if advice.FrequencyType == 1 {
|
|
299
|
+ advice_three = append(advice_three, advice)
|
|
300
|
+ }
|
|
301
|
+ }
|
|
302
|
+
|
|
303
|
+ for _, advice := range advices_two {
|
|
304
|
+ now := scheduleDates.Unix()
|
|
305
|
+ dayStr := strconv.FormatInt(advice.DayCount, 10)
|
|
306
|
+ dayStr2 := "-" + dayStr
|
|
307
|
+ count, _ := strconv.ParseInt(dayStr2, 10, 64)
|
|
308
|
+ oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
|
|
309
|
+ advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
|
|
310
|
+ if len(advices) == 0 {
|
|
311
|
+ advice_three = append(advice_three)
|
|
312
|
+ }
|
|
313
|
+ }
|
|
314
|
+ item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
|
|
315
|
+ }
|
|
316
|
+ }
|
|
317
|
+ return
|
|
318
|
+}
|
|
319
|
+
|
|
320
|
+func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
|
|
321
|
+ newArr = make([]*models.DoctorAdvice, 0)
|
|
322
|
+ for i := 0; i < len(arr); i++ {
|
|
323
|
+ repeat := false
|
|
324
|
+ for j := i + 1; j < len(arr); j++ {
|
|
325
|
+ if arr[i].ID == arr[j].ID {
|
|
326
|
+ repeat = true
|
|
327
|
+ break
|
|
328
|
+ }
|
|
329
|
+ }
|
|
330
|
+ if !repeat {
|
|
331
|
+ newArr = append(newArr, arr[i])
|
|
332
|
+ }
|
|
333
|
+ }
|
|
334
|
+ return
|
|
335
|
+}
|
|
336
|
+
|
|
337
|
+func GetLastLongAdviceByGroupNoOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
|
|
338
|
+ err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
|
|
339
|
+ return
|
|
340
|
+}
|
|
341
|
+
|
|
342
|
+func GetLastLongAdviceByGroupNoThreeOther(orgId int64, patient_id int64) (advice []*models.DoctorAdvice, err error) {
|
|
343
|
+ err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 ", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
|
|
344
|
+ return
|
|
345
|
+}
|
|
346
|
+
|
|
347
|
+func FindAllDoctorAdviceByTimeOther(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) {
|
|
348
|
+ err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2 AND frequency_type = 2 AND advice_date > ? AND advice_date < ? AND template_id = ? ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
|
247
|
349
|
return
|
248
|
350
|
}
|