|
@@ -5,6 +5,8 @@ import (
|
5
|
5
|
"fmt"
|
6
|
6
|
"github.com/jinzhu/gorm"
|
7
|
7
|
"time"
|
|
8
|
+ "encoding/json"
|
|
9
|
+ "strconv"
|
8
|
10
|
)
|
9
|
11
|
|
10
|
12
|
// func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
|
|
@@ -23,21 +25,21 @@ import (
|
23
|
25
|
// return vms, err
|
24
|
26
|
// }
|
25
|
27
|
|
26
|
|
-func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVM, error) {
|
27
|
|
- var vms []*MDialysisScheduleVM
|
|
28
|
+func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
|
|
29
|
+ var vms []*MDialysisScheduleVMForList
|
28
|
30
|
db := readDb.
|
29
|
31
|
Table("xt_schedule as sch").
|
30
|
|
- Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
31
|
|
- Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
32
|
|
- Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
33
|
|
- Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
|
34
|
|
- Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
|
35
|
|
- Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
|
36
|
|
- Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
|
37
|
|
- Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
38
|
|
- Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
|
39
|
|
- Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
|
40
|
|
- Preload("HisAdvices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
|
|
32
|
+ // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
|
33
|
+ // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
34
|
+ // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
|
35
|
+ // Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
|
|
36
|
+ // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
|
|
37
|
+ // Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
|
|
38
|
+ // Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
|
|
39
|
+ // Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
40
|
+ // Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
|
|
41
|
+ // Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
|
|
42
|
+ // Preload("HisAdvices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
|
41
|
43
|
// Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
|
42
|
44
|
// return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
|
43
|
45
|
// }).
|
|
@@ -127,6 +129,32 @@ func (MDialysisScheduleVM) TableName() string {
|
127
|
129
|
return "xt_schedule"
|
128
|
130
|
}
|
129
|
131
|
|
|
132
|
+type MDialysisScheduleVMForList struct {
|
|
133
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
134
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
|
135
|
+ PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
|
|
136
|
+ BedId int64 `gorm:"column:bed_id" json:"bed_id"`
|
|
137
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
138
|
+ ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
|
|
139
|
+ ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
|
|
140
|
+ ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
|
|
141
|
+ ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
|
|
142
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
143
|
+ SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
|
|
144
|
+ DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
|
|
145
|
+ DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
|
|
146
|
+ Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
|
|
147
|
+ AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
|
|
148
|
+ AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
|
|
149
|
+ HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
|
|
150
|
+ Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
|
|
151
|
+ TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
|
|
152
|
+}
|
|
153
|
+
|
|
154
|
+func (MDialysisScheduleVMForList) TableName() string {
|
|
155
|
+ return "xt_schedule"
|
|
156
|
+}
|
|
157
|
+
|
130
|
158
|
type MDeviceNumberVM struct {
|
131
|
159
|
models.DeviceNumber
|
132
|
160
|
|
|
@@ -312,6 +340,19 @@ func (VMHisDoctorAdviceInfo) TableName() string {
|
312
|
340
|
return "his_doctor_advice_info"
|
313
|
341
|
}
|
314
|
342
|
|
|
343
|
+type VMAssessmentAfterDislysis struct {
|
|
344
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
345
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
|
346
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
347
|
+ AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
|
|
348
|
+ WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
|
|
349
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
350
|
+}
|
|
351
|
+
|
|
352
|
+func (VMAssessmentAfterDislysis) TableName() string {
|
|
353
|
+ return "xt_assessment_after_dislysis"
|
|
354
|
+}
|
|
355
|
+
|
315
|
356
|
// 获取透析记录
|
316
|
357
|
func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
|
317
|
358
|
var record models.DialysisOrder
|
|
@@ -342,21 +383,45 @@ func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
|
342
|
383
|
|
343
|
384
|
// 用户排班信息
|
344
|
385
|
func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
|
|
386
|
+ redis := RedisClient()
|
|
387
|
+ defer redis.Close()
|
345
|
388
|
var vm MDialysisScheduleVM
|
346
|
|
- err := readDb.
|
|
389
|
+
|
|
390
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
391
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
|
|
392
|
+ schedual_detail_str, _ := redis.Get(key).Result()
|
|
393
|
+
|
|
394
|
+ if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
395
|
+ err := readDb.
|
347
|
396
|
Table("xt_schedule").
|
348
|
397
|
// Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
349
|
398
|
Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
399
|
+ Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
350
|
400
|
Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
|
351
|
401
|
First(&vm).Error
|
352
|
|
- if err != nil {
|
353
|
|
- if err == gorm.ErrRecordNotFound {
|
354
|
|
- return nil, nil
|
|
402
|
+
|
|
403
|
+ if err != nil {
|
|
404
|
+ if err == gorm.ErrRecordNotFound {
|
|
405
|
+ return nil, nil
|
|
406
|
+ } else {
|
|
407
|
+ return nil, err
|
|
408
|
+ }
|
355
|
409
|
} else {
|
356
|
|
- return nil, err
|
|
410
|
+ if vm.ID > 0 {
|
|
411
|
+ //缓存数据
|
|
412
|
+ schedual_detail_str, err := json.Marshal(vm)
|
|
413
|
+ if err == nil {
|
|
414
|
+ redis.Set(key, schedual_detail_str, time.Second*60*60*18)
|
|
415
|
+ }
|
|
416
|
+ } else {
|
|
417
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
418
|
+ }
|
|
419
|
+ return &vm, nil
|
357
|
420
|
}
|
|
421
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
422
|
+ json.Unmarshal([]byte(schedual_detail_str), &vm)
|
|
423
|
+ return &vm, nil
|
358
|
424
|
}
|
359
|
|
- return &vm, err
|
360
|
425
|
}
|
361
|
426
|
|
362
|
427
|
// 用户排班信息
|
|
@@ -457,44 +522,110 @@ func (MPatient) TableName() string {
|
457
|
522
|
// 接诊评估
|
458
|
523
|
func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
|
459
|
524
|
var record models.ReceiveTreatmentAsses
|
460
|
|
- err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
|
461
|
|
- if err != nil {
|
462
|
|
- if err == gorm.ErrRecordNotFound {
|
463
|
|
- return nil, nil
|
|
525
|
+ redis := RedisClient()
|
|
526
|
+ defer redis.Close()
|
|
527
|
+
|
|
528
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
529
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
|
|
530
|
+ receive_treatment_asses_str, _ := redis.Get(key).Result()
|
|
531
|
+
|
|
532
|
+ if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
533
|
+ err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
534
|
+ if err != nil {
|
|
535
|
+ if err == gorm.ErrRecordNotFound {
|
|
536
|
+ return nil, nil
|
|
537
|
+ } else {
|
|
538
|
+ return nil, err
|
|
539
|
+ }
|
464
|
540
|
} else {
|
465
|
|
- return nil, err
|
|
541
|
+ if record.ID > 0 {
|
|
542
|
+ //缓存数据
|
|
543
|
+ receive_treatment_asses_str, err := json.Marshal(record)
|
|
544
|
+ if err == nil {
|
|
545
|
+ redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
|
|
546
|
+ }
|
|
547
|
+ } else {
|
|
548
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
549
|
+ }
|
|
550
|
+ return &record, nil
|
466
|
551
|
}
|
|
552
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
553
|
+ json.Unmarshal([]byte(receive_treatment_asses_str), &record)
|
|
554
|
+ return &record, nil
|
467
|
555
|
}
|
468
|
|
- return &record, nil
|
469
|
556
|
}
|
470
|
557
|
|
471
|
558
|
// 透前评估
|
472
|
559
|
func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
|
473
|
|
- fmt.Println("recordDate", recordDate)
|
|
560
|
+
|
474
|
561
|
var record models.PredialysisEvaluation
|
475
|
|
- err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
476
|
|
- if err != nil {
|
477
|
|
- if err == gorm.ErrRecordNotFound {
|
478
|
|
- return nil, nil
|
|
562
|
+ redis := RedisClient()
|
|
563
|
+ defer redis.Close()
|
|
564
|
+
|
|
565
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
566
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
|
|
567
|
+ assessment_before_dislysis_str, _ := redis.Get(key).Result()
|
|
568
|
+
|
|
569
|
+ if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
570
|
+ err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
571
|
+ if err != nil {
|
|
572
|
+ if err == gorm.ErrRecordNotFound {
|
|
573
|
+ return nil, nil
|
|
574
|
+ } else {
|
|
575
|
+ return nil, err
|
|
576
|
+ }
|
479
|
577
|
} else {
|
480
|
|
- return nil, err
|
|
578
|
+ if record.ID > 0 {
|
|
579
|
+ //缓存数据
|
|
580
|
+ assessment_before_dislysis_str, err := json.Marshal(record)
|
|
581
|
+ if err == nil {
|
|
582
|
+ redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
|
|
583
|
+ }
|
|
584
|
+ } else {
|
|
585
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
586
|
+ }
|
|
587
|
+ return &record, nil
|
481
|
588
|
}
|
|
589
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
590
|
+ json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
|
|
591
|
+ return &record, nil
|
482
|
592
|
}
|
483
|
|
- return &record, nil
|
484
|
593
|
}
|
485
|
594
|
|
486
|
595
|
// 获取 maxDate 之前一次的透前评估记录
|
487
|
596
|
func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
|
488
|
597
|
var record models.PredialysisEvaluation
|
489
|
|
- err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
|
490
|
|
- if err != nil {
|
491
|
|
- if err == gorm.ErrRecordNotFound {
|
492
|
|
- return nil, nil
|
|
598
|
+ redis := RedisClient()
|
|
599
|
+ defer redis.Close()
|
|
600
|
+
|
|
601
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
602
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
|
|
603
|
+ assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
|
|
604
|
+
|
|
605
|
+ if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
606
|
+ err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
|
|
607
|
+ if err != nil {
|
|
608
|
+ if err == gorm.ErrRecordNotFound {
|
|
609
|
+ return nil, nil
|
|
610
|
+ } else {
|
|
611
|
+ return nil, err
|
|
612
|
+ }
|
493
|
613
|
} else {
|
494
|
|
- return nil, err
|
|
614
|
+ if record.ID > 0 {
|
|
615
|
+ //缓存数据
|
|
616
|
+ assessment_before_dislysis_last_str, err := json.Marshal(record)
|
|
617
|
+ if err == nil {
|
|
618
|
+ redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
|
|
619
|
+ }
|
|
620
|
+ } else {
|
|
621
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
622
|
+ }
|
|
623
|
+ return &record, nil
|
495
|
624
|
}
|
|
625
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
626
|
+ json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
|
|
627
|
+ return &record, nil
|
496
|
628
|
}
|
497
|
|
- return &record, nil
|
498
|
629
|
}
|
499
|
630
|
|
500
|
631
|
// 临时医嘱
|
|
@@ -517,57 +648,150 @@ func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*
|
517
|
648
|
|
518
|
649
|
func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
|
519
|
650
|
var records []*models.DoctorAdvice
|
520
|
|
- // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
|
|
651
|
+ redis := RedisClient()
|
|
652
|
+ defer redis.Close()
|
521
|
653
|
|
522
|
|
- err := readDb.
|
|
654
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
655
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
|
|
656
|
+ doctor_advices_str, _ := redis.Get(key).Result()
|
|
657
|
+
|
|
658
|
+ if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
659
|
+ err := readDb.
|
523
|
660
|
Model(&models.DoctorAdvice{}).
|
524
|
661
|
Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
|
525
|
662
|
Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, 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, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
|
526
|
663
|
Order("start_time asc, groupno desc, advice_order desc, id asc").
|
527
|
664
|
Scan(&records).Error
|
528
|
|
-
|
529
|
|
- if err != nil {
|
530
|
|
- return nil, err
|
|
665
|
+ if err != nil {
|
|
666
|
+ if err == gorm.ErrRecordNotFound {
|
|
667
|
+ return nil, nil
|
|
668
|
+ } else {
|
|
669
|
+ return nil, err
|
|
670
|
+ }
|
|
671
|
+ } else {
|
|
672
|
+ if len(records) > 0 {
|
|
673
|
+ //缓存数据
|
|
674
|
+ doctor_advices_str, err := json.Marshal(records)
|
|
675
|
+ if err == nil {
|
|
676
|
+ redis.Set(key, doctor_advices_str, time.Second*60*60*18)
|
|
677
|
+ }
|
|
678
|
+ } else {
|
|
679
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
680
|
+ }
|
|
681
|
+ return records, nil
|
|
682
|
+ }
|
|
683
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
684
|
+ json.Unmarshal([]byte(doctor_advices_str), &records)
|
|
685
|
+ return records, nil
|
531
|
686
|
}
|
532
|
|
- return records, nil
|
533
|
687
|
}
|
534
|
688
|
|
535
|
689
|
// 透析记录
|
536
|
690
|
func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
|
537
|
691
|
var record models.DialysisOrder
|
538
|
|
- err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
|
539
|
|
- if err != nil {
|
540
|
|
- if err == gorm.ErrRecordNotFound {
|
541
|
|
- return nil, nil
|
|
692
|
+ redis := RedisClient()
|
|
693
|
+ defer redis.Close()
|
|
694
|
+
|
|
695
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
696
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
|
|
697
|
+ dialysis_order_str, _ := redis.Get(key).Result()
|
|
698
|
+
|
|
699
|
+ if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
700
|
+ err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
|
|
701
|
+ if err != nil {
|
|
702
|
+ if err == gorm.ErrRecordNotFound {
|
|
703
|
+ return nil, nil
|
|
704
|
+ } else {
|
|
705
|
+ return nil, err
|
|
706
|
+ }
|
542
|
707
|
} else {
|
543
|
|
- return nil, err
|
|
708
|
+ if record.ID > 0 {
|
|
709
|
+ //缓存数据
|
|
710
|
+ dialysis_order_str, err := json.Marshal(record)
|
|
711
|
+ if err == nil {
|
|
712
|
+ redis.Set(key, dialysis_order_str, time.Second*60*60*18)
|
|
713
|
+ }
|
|
714
|
+ } else {
|
|
715
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
716
|
+ }
|
|
717
|
+ return &record, nil
|
544
|
718
|
}
|
|
719
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
720
|
+ json.Unmarshal([]byte(dialysis_order_str), &record)
|
|
721
|
+ return &record, nil
|
545
|
722
|
}
|
546
|
|
- return &record, nil
|
547
|
723
|
}
|
548
|
724
|
|
549
|
725
|
// 双人核对
|
550
|
726
|
func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
|
551
|
727
|
var record models.DoubleCheck
|
552
|
|
- err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
|
553
|
|
- if err != nil {
|
554
|
|
- if err == gorm.ErrRecordNotFound {
|
555
|
|
- return nil, nil
|
|
728
|
+ redis := RedisClient()
|
|
729
|
+ defer redis.Close()
|
|
730
|
+
|
|
731
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
732
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
|
|
733
|
+ double_check_str, _ := redis.Get(key).Result()
|
|
734
|
+
|
|
735
|
+ if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
736
|
+ err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
737
|
+ if err != nil {
|
|
738
|
+ if err == gorm.ErrRecordNotFound {
|
|
739
|
+ return nil, nil
|
|
740
|
+ } else {
|
|
741
|
+ return nil, err
|
|
742
|
+ }
|
556
|
743
|
} else {
|
557
|
|
- return nil, err
|
|
744
|
+ if record.ID > 0 {
|
|
745
|
+ //缓存数据
|
|
746
|
+ double_check_str, err := json.Marshal(record)
|
|
747
|
+ if err == nil {
|
|
748
|
+ redis.Set(key, double_check_str, time.Second*60*60*18)
|
|
749
|
+ }
|
|
750
|
+ } else {
|
|
751
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
752
|
+ }
|
|
753
|
+ return &record, nil
|
558
|
754
|
}
|
|
755
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
756
|
+ json.Unmarshal([]byte(double_check_str), &record)
|
|
757
|
+ return &record, nil
|
559
|
758
|
}
|
560
|
|
- return &record, nil
|
561
|
759
|
}
|
562
|
760
|
|
563
|
761
|
// 透析监测记录
|
564
|
762
|
func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
|
565
|
763
|
var records []*models.MonitoringRecord
|
566
|
|
- err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
|
567
|
|
- if err != nil {
|
568
|
|
- return nil, err
|
|
764
|
+ redis := RedisClient()
|
|
765
|
+ defer redis.Close()
|
|
766
|
+
|
|
767
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
768
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
|
|
769
|
+ monitor_records_str, _ := redis.Get(key).Result()
|
|
770
|
+
|
|
771
|
+ if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
772
|
+ err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
|
|
773
|
+ if err != nil {
|
|
774
|
+ if err == gorm.ErrRecordNotFound {
|
|
775
|
+ return nil, nil
|
|
776
|
+ } else {
|
|
777
|
+ return nil, err
|
|
778
|
+ }
|
|
779
|
+ } else {
|
|
780
|
+ if len(records) > 0 {
|
|
781
|
+ //缓存数据
|
|
782
|
+ monitor_records_str, err := json.Marshal(records)
|
|
783
|
+ if err == nil {
|
|
784
|
+ redis.Set(key, monitor_records_str, time.Second*60*60*18)
|
|
785
|
+ }
|
|
786
|
+ } else {
|
|
787
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
788
|
+ }
|
|
789
|
+ return records, nil
|
|
790
|
+ }
|
|
791
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
792
|
+ json.Unmarshal([]byte(monitor_records_str), &records)
|
|
793
|
+ return records, nil
|
569
|
794
|
}
|
570
|
|
- return records, nil
|
571
|
795
|
}
|
572
|
796
|
|
573
|
797
|
func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
|
|
@@ -581,43 +805,109 @@ func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64)
|
581
|
805
|
|
582
|
806
|
func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
|
583
|
807
|
var record models.MonitoringRecord
|
584
|
|
- err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
|
585
|
|
- if err != nil {
|
586
|
|
- if err == gorm.ErrRecordNotFound {
|
587
|
|
- return nil, nil
|
|
808
|
+ redis := RedisClient()
|
|
809
|
+ defer redis.Close()
|
|
810
|
+
|
|
811
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
812
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
|
|
813
|
+ monitor_record_last_str, _ := redis.Get(key).Result()
|
|
814
|
+
|
|
815
|
+ if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
816
|
+ err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
|
|
817
|
+ if err != nil {
|
|
818
|
+ if err == gorm.ErrRecordNotFound {
|
|
819
|
+ return nil, nil
|
|
820
|
+ } else {
|
|
821
|
+ return nil, err
|
|
822
|
+ }
|
588
|
823
|
} else {
|
589
|
|
- return nil, err
|
|
824
|
+ if record.ID > 0 {
|
|
825
|
+ //缓存数据
|
|
826
|
+ monitor_record_last_str, err := json.Marshal(record)
|
|
827
|
+ if err == nil {
|
|
828
|
+ redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
|
|
829
|
+ }
|
|
830
|
+ } else {
|
|
831
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
832
|
+ }
|
|
833
|
+ return &record, nil
|
590
|
834
|
}
|
|
835
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
836
|
+ json.Unmarshal([]byte(monitor_record_last_str), &record)
|
|
837
|
+ return &record, nil
|
591
|
838
|
}
|
592
|
|
- return &record, nil
|
593
|
839
|
}
|
594
|
840
|
|
595
|
841
|
// 透后评估
|
596
|
842
|
func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
|
597
|
843
|
var record models.AssessmentAfterDislysis
|
598
|
|
- err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
599
|
|
- if err != nil {
|
600
|
|
- if err == gorm.ErrRecordNotFound {
|
601
|
|
- return nil, nil
|
|
844
|
+ redis := RedisClient()
|
|
845
|
+ defer redis.Close()
|
|
846
|
+
|
|
847
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
848
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
|
|
849
|
+ assessment_after_dislysis_str, _ := redis.Get(key).Result()
|
|
850
|
+
|
|
851
|
+ if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
852
|
+ err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
853
|
+ if err != nil {
|
|
854
|
+ if err == gorm.ErrRecordNotFound {
|
|
855
|
+ return nil, nil
|
|
856
|
+ } else {
|
|
857
|
+ return nil, err
|
|
858
|
+ }
|
602
|
859
|
} else {
|
603
|
|
- return nil, err
|
|
860
|
+ if record.ID > 0 {
|
|
861
|
+ //缓存数据
|
|
862
|
+ assessment_after_dislysis_str, err := json.Marshal(record)
|
|
863
|
+ if err == nil {
|
|
864
|
+ redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
|
|
865
|
+ }
|
|
866
|
+ } else {
|
|
867
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
868
|
+ }
|
|
869
|
+ return &record, nil
|
604
|
870
|
}
|
|
871
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
872
|
+ json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
|
|
873
|
+ return &record, nil
|
605
|
874
|
}
|
606
|
|
- return &record, nil
|
607
|
875
|
}
|
608
|
876
|
|
609
|
877
|
// 获取 maxDate 之前一次的透后评估记录
|
610
|
878
|
func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
|
611
|
879
|
var record models.AssessmentAfterDislysis
|
612
|
|
- err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
|
613
|
|
- if err != nil {
|
614
|
|
- if err == gorm.ErrRecordNotFound {
|
615
|
|
- return nil, nil
|
|
880
|
+ redis := RedisClient()
|
|
881
|
+ defer redis.Close()
|
|
882
|
+
|
|
883
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
884
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
|
|
885
|
+ assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
|
|
886
|
+
|
|
887
|
+ if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
888
|
+ err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
|
|
889
|
+ if err != nil {
|
|
890
|
+ if err == gorm.ErrRecordNotFound {
|
|
891
|
+ return nil, nil
|
|
892
|
+ } else {
|
|
893
|
+ return nil, err
|
|
894
|
+ }
|
616
|
895
|
} else {
|
617
|
|
- return nil, err
|
|
896
|
+ if record.ID > 0 {
|
|
897
|
+ //缓存数据
|
|
898
|
+ assessment_after_dislysis_last_str, err := json.Marshal(record)
|
|
899
|
+ if err == nil {
|
|
900
|
+ redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
|
|
901
|
+ }
|
|
902
|
+ } else {
|
|
903
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
904
|
+ }
|
|
905
|
+ return &record, nil
|
618
|
906
|
}
|
|
907
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
908
|
+ json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
|
|
909
|
+ return &record, nil
|
619
|
910
|
}
|
620
|
|
- return &record, nil
|
621
|
911
|
}
|
622
|
912
|
func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
|
623
|
913
|
dislysis := models.AssessmentAfterDislysis{}
|
|
@@ -628,15 +918,37 @@ func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.Assessme
|
628
|
918
|
// 治疗小结
|
629
|
919
|
func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
|
630
|
920
|
var record models.TreatmentSummary
|
631
|
|
- err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
632
|
|
- if err != nil {
|
633
|
|
- if err == gorm.ErrRecordNotFound {
|
634
|
|
- return nil, nil
|
|
921
|
+ redis := RedisClient()
|
|
922
|
+ defer redis.Close()
|
|
923
|
+
|
|
924
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
925
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
|
|
926
|
+ treatment_summary_str, _ := redis.Get(key).Result()
|
|
927
|
+
|
|
928
|
+ if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
929
|
+ err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
930
|
+ if err != nil {
|
|
931
|
+ if err == gorm.ErrRecordNotFound {
|
|
932
|
+ return nil, nil
|
|
933
|
+ } else {
|
|
934
|
+ return nil, err
|
|
935
|
+ }
|
635
|
936
|
} else {
|
636
|
|
- return nil, err
|
|
937
|
+ if record.ID > 0 {
|
|
938
|
+ //缓存数据
|
|
939
|
+ treatment_summary_str, err := json.Marshal(record)
|
|
940
|
+ if err == nil {
|
|
941
|
+ redis.Set(key, treatment_summary_str, time.Second*60*60*18)
|
|
942
|
+ }
|
|
943
|
+ } else {
|
|
944
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
945
|
+ }
|
|
946
|
+ return &record, nil
|
637
|
947
|
}
|
|
948
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
949
|
+ json.Unmarshal([]byte(treatment_summary_str), &record)
|
|
950
|
+ return &record, nil
|
638
|
951
|
}
|
639
|
|
- return &record, nil
|
640
|
952
|
}
|
641
|
953
|
|
642
|
954
|
// 透析处方
|
|
@@ -1450,56 +1762,144 @@ func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
|
1450
|
1762
|
|
1451
|
1763
|
func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
|
1452
|
1764
|
var record models.SgjPatientDryweight
|
1453
|
|
- err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
|
1454
|
|
- if err != nil {
|
1455
|
|
- if err == gorm.ErrRecordNotFound {
|
1456
|
|
- return nil, nil
|
|
1765
|
+ redis := RedisClient()
|
|
1766
|
+ defer redis.Close()
|
|
1767
|
+
|
|
1768
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
1769
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":last_dry_weight"
|
|
1770
|
+ last_dry_weight_str, _ := redis.Get(key).Result()
|
|
1771
|
+
|
|
1772
|
+ if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
1773
|
+ err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
|
|
1774
|
+ if err != nil {
|
|
1775
|
+ if err == gorm.ErrRecordNotFound {
|
|
1776
|
+ return nil, nil
|
|
1777
|
+ } else {
|
|
1778
|
+ return nil, err
|
|
1779
|
+ }
|
1457
|
1780
|
} else {
|
1458
|
|
- return nil, err
|
|
1781
|
+ if record.ID > 0 {
|
|
1782
|
+ //缓存数据
|
|
1783
|
+ last_dry_weight_str, err := json.Marshal(record)
|
|
1784
|
+ if err == nil {
|
|
1785
|
+ redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
|
|
1786
|
+ }
|
|
1787
|
+ } else {
|
|
1788
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
1789
|
+ }
|
|
1790
|
+ return &record, nil
|
1459
|
1791
|
}
|
|
1792
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
1793
|
+ json.Unmarshal([]byte(last_dry_weight_str), &record)
|
|
1794
|
+ return &record, nil
|
1460
|
1795
|
}
|
1461
|
|
- return &record, nil
|
1462
|
1796
|
}
|
1463
|
1797
|
|
1464
|
1798
|
// 透析方案
|
1465
|
1799
|
func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
|
1466
|
1800
|
var record models.DialysisSolution
|
1467
|
|
- err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
|
1468
|
|
- if err != nil {
|
1469
|
|
- if err == gorm.ErrRecordNotFound {
|
1470
|
|
- return nil, nil
|
|
1801
|
+ redis := RedisClient()
|
|
1802
|
+ defer redis.Close()
|
|
1803
|
+
|
|
1804
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
1805
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
|
|
1806
|
+ dialysis_solution_str, _ := redis.Get(key).Result()
|
|
1807
|
+
|
|
1808
|
+ if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
1809
|
+ err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
|
|
1810
|
+ if err != nil {
|
|
1811
|
+ if err == gorm.ErrRecordNotFound {
|
|
1812
|
+ return nil, nil
|
|
1813
|
+ } else {
|
|
1814
|
+ return nil, err
|
|
1815
|
+ }
|
1471
|
1816
|
} else {
|
1472
|
|
- return nil, err
|
|
1817
|
+ if record.ID > 0 {
|
|
1818
|
+ //缓存数据
|
|
1819
|
+ dialysis_solution_str, err := json.Marshal(record)
|
|
1820
|
+ if err == nil {
|
|
1821
|
+ redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
|
|
1822
|
+ }
|
|
1823
|
+ } else {
|
|
1824
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
1825
|
+ }
|
|
1826
|
+ return &record, nil
|
1473
|
1827
|
}
|
|
1828
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
1829
|
+ json.Unmarshal([]byte(dialysis_solution_str), &record)
|
|
1830
|
+ return &record, nil
|
1474
|
1831
|
}
|
1475
|
|
- return &record, nil
|
1476
|
1832
|
}
|
1477
|
1833
|
|
1478
|
1834
|
// 透析处方
|
1479
|
1835
|
func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
|
1480
|
1836
|
var record models.DialysisPrescription
|
1481
|
|
- err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
|
1482
|
|
- if err != nil {
|
1483
|
|
- if err == gorm.ErrRecordNotFound {
|
1484
|
|
- return nil, nil
|
|
1837
|
+ redis := RedisClient()
|
|
1838
|
+ defer redis.Close()
|
|
1839
|
+
|
|
1840
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
1841
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
|
|
1842
|
+ dialysis_prescribe_str, _ := redis.Get(key).Result()
|
|
1843
|
+
|
|
1844
|
+ if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
1845
|
+ err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
|
|
1846
|
+ if err != nil {
|
|
1847
|
+ if err == gorm.ErrRecordNotFound {
|
|
1848
|
+ return nil, nil
|
|
1849
|
+ } else {
|
|
1850
|
+ return nil, err
|
|
1851
|
+ }
|
1485
|
1852
|
} else {
|
1486
|
|
- return nil, err
|
|
1853
|
+ if record.ID > 0 {
|
|
1854
|
+ //缓存数据
|
|
1855
|
+ dialysis_prescribe_str, err := json.Marshal(record)
|
|
1856
|
+ if err == nil {
|
|
1857
|
+ redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
|
|
1858
|
+ }
|
|
1859
|
+ } else {
|
|
1860
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
1861
|
+ }
|
|
1862
|
+ return &record, nil
|
1487
|
1863
|
}
|
|
1864
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
1865
|
+ json.Unmarshal([]byte(dialysis_prescribe_str), &record)
|
|
1866
|
+ return &record, nil
|
1488
|
1867
|
}
|
1489
|
|
- return &record, nil
|
1490
|
1868
|
}
|
1491
|
1869
|
|
1492
|
1870
|
func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
|
1493
|
1871
|
var record models.DialysisPrescription
|
1494
|
|
- err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
|
1495
|
|
- if err != nil {
|
1496
|
|
- if err == gorm.ErrRecordNotFound {
|
1497
|
|
- return nil, nil
|
|
1872
|
+ redis := RedisClient()
|
|
1873
|
+ defer redis.Close()
|
|
1874
|
+
|
|
1875
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
1876
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
|
|
1877
|
+ dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
|
|
1878
|
+
|
|
1879
|
+ if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
1880
|
+ err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
|
|
1881
|
+ if err != nil {
|
|
1882
|
+ if err == gorm.ErrRecordNotFound {
|
|
1883
|
+ return nil, nil
|
|
1884
|
+ } else {
|
|
1885
|
+ return nil, err
|
|
1886
|
+ }
|
1498
|
1887
|
} else {
|
1499
|
|
- return nil, err
|
|
1888
|
+ if record.ID > 0 {
|
|
1889
|
+ //缓存数据
|
|
1890
|
+ dialysis_prescribe_by_mode_str, err := json.Marshal(record)
|
|
1891
|
+ if err == nil {
|
|
1892
|
+ redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
|
|
1893
|
+ }
|
|
1894
|
+ } else {
|
|
1895
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
1896
|
+ }
|
|
1897
|
+ return &record, nil
|
1500
|
1898
|
}
|
|
1899
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
1900
|
+ json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
|
|
1901
|
+ return &record, nil
|
1501
|
1902
|
}
|
1502
|
|
- return &record, nil
|
1503
|
1903
|
}
|
1504
|
1904
|
|
1505
|
1905
|
func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
|
|
@@ -1515,17 +1915,39 @@ func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.Dialy
|
1515
|
1915
|
return &record, nil
|
1516
|
1916
|
}
|
1517
|
1917
|
|
1518
|
|
-func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
|
|
1918
|
+func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64,mode_id int64) (*models.DialysisPrescription, error) {
|
1519
|
1919
|
var record models.DialysisPrescription
|
1520
|
|
- err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
|
1521
|
|
- if err != nil {
|
1522
|
|
- if err == gorm.ErrRecordNotFound {
|
1523
|
|
- return nil, nil
|
|
1920
|
+ redis := RedisClient()
|
|
1921
|
+ defer redis.Close()
|
|
1922
|
+
|
|
1923
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
1924
|
+ key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_last"
|
|
1925
|
+ dialysis_prescribe_last_str, _ := redis.Get(key).Result()
|
|
1926
|
+
|
|
1927
|
+ if len(dialysis_prescribe_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
1928
|
+ err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? AND record_date < ?", patientID, orgID, mode_id,recordDate).Last(&record).Error
|
|
1929
|
+ if err != nil {
|
|
1930
|
+ if err == gorm.ErrRecordNotFound {
|
|
1931
|
+ return nil, nil
|
|
1932
|
+ } else {
|
|
1933
|
+ return nil, err
|
|
1934
|
+ }
|
1524
|
1935
|
} else {
|
1525
|
|
- return nil, err
|
|
1936
|
+ if record.ID > 0 {
|
|
1937
|
+ //缓存数据
|
|
1938
|
+ dialysis_prescribe_last_str, err := json.Marshal(record)
|
|
1939
|
+ if err == nil {
|
|
1940
|
+ redis.Set(key, dialysis_prescribe_last_str, time.Second*60*60*18)
|
|
1941
|
+ }
|
|
1942
|
+ } else {
|
|
1943
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
1944
|
+ }
|
|
1945
|
+ return &record, nil
|
1526
|
1946
|
}
|
|
1947
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
1948
|
+ json.Unmarshal([]byte(dialysis_prescribe_last_str), &record)
|
|
1949
|
+ return &record, nil
|
1527
|
1950
|
}
|
1528
|
|
- return &record, nil
|
1529
|
1951
|
}
|
1530
|
1952
|
|
1531
|
1953
|
func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
|
|
@@ -1666,15 +2088,37 @@ func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight
|
1666
|
2088
|
|
1667
|
2089
|
func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
|
1668
|
2090
|
var record models.SystemPrescription
|
1669
|
|
- err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
|
1670
|
|
- if err != nil {
|
1671
|
|
- if err == gorm.ErrRecordNotFound {
|
1672
|
|
- return nil, nil
|
|
2091
|
+ redis := RedisClient()
|
|
2092
|
+ defer redis.Close()
|
|
2093
|
+
|
|
2094
|
+ // cur_date := time.Now().Format("2006-01-02")
|
|
2095
|
+ key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
|
|
2096
|
+ system_dialysis_prescribe_str, _ := redis.Get(key).Result()
|
|
2097
|
+
|
|
2098
|
+ if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
2099
|
+ err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
|
|
2100
|
+ if err != nil {
|
|
2101
|
+ if err == gorm.ErrRecordNotFound {
|
|
2102
|
+ return nil, nil
|
|
2103
|
+ } else {
|
|
2104
|
+ return nil, err
|
|
2105
|
+ }
|
1673
|
2106
|
} else {
|
1674
|
|
- return nil, err
|
|
2107
|
+ if record.ID > 0 {
|
|
2108
|
+ //缓存数据
|
|
2109
|
+ system_dialysis_prescribe_str, err := json.Marshal(record)
|
|
2110
|
+ if err == nil {
|
|
2111
|
+ redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
|
|
2112
|
+ }
|
|
2113
|
+ } else {
|
|
2114
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
2115
|
+ }
|
|
2116
|
+ return &record, nil
|
1675
|
2117
|
}
|
|
2118
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
2119
|
+ json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
|
|
2120
|
+ return &record, nil
|
1676
|
2121
|
}
|
1677
|
|
- return &record, nil
|
1678
|
2122
|
}
|
1679
|
2123
|
|
1680
|
2124
|
func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
|
|
@@ -2007,9 +2451,35 @@ func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models
|
2007
|
2451
|
}
|
2008
|
2452
|
|
2009
|
2453
|
func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
|
2010
|
|
- err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
|
2011
|
|
- return
|
2012
|
|
-
|
|
2454
|
+ redis := RedisClient()
|
|
2455
|
+ defer redis.Close()
|
|
2456
|
+ key := strconv.FormatInt(orgid, 10) + ":"+ strconv.FormatInt(patientid, 10) + ":"+ strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
|
|
2457
|
+ his_doctor_advice_str, _ := redis.Get(key).Result()
|
|
2458
|
+
|
|
2459
|
+ if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
|
|
2460
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
|
|
2461
|
+ if err != nil {
|
|
2462
|
+ if err == gorm.ErrRecordNotFound {
|
|
2463
|
+ return his, nil
|
|
2464
|
+ } else {
|
|
2465
|
+ return his, err
|
|
2466
|
+ }
|
|
2467
|
+ } else {
|
|
2468
|
+ if len(his) > 0 {
|
|
2469
|
+ //缓存数据
|
|
2470
|
+ his_doctor_advice_str, err := json.Marshal(his)
|
|
2471
|
+ if err == nil {
|
|
2472
|
+ redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
|
|
2473
|
+ }
|
|
2474
|
+ } else {
|
|
2475
|
+ redis.Set(key, " ", time.Second*60*60*18)
|
|
2476
|
+ }
|
|
2477
|
+ return his, nil
|
|
2478
|
+ }
|
|
2479
|
+ } else { //缓存数据了数据,将redis缓存的json字符串转为map
|
|
2480
|
+ json.Unmarshal([]byte(his_doctor_advice_str), &his)
|
|
2481
|
+ return his, nil
|
|
2482
|
+ }
|
2013
|
2483
|
}
|
2014
|
2484
|
|
2015
|
2485
|
func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
|