|
@@ -30,13 +30,13 @@ func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType in
|
30
|
30
|
Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
31
|
31
|
Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
32
|
32
|
Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
33
|
|
- Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2", orgID).
|
|
33
|
+ Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
|
34
|
34
|
Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
|
35
|
35
|
Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
|
36
|
|
- Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
|
|
36
|
+ Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
|
37
|
37
|
Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
38
|
|
- Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
|
39
|
|
- Preload("AssessmentAfterDislysis", "status = 1 AND user_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
|
40
|
|
41
|
41
|
|
42
|
42
|
|
|
@@ -115,13 +115,13 @@ type MDialysisScheduleVM struct {
|
115
|
115
|
|
116
|
116
|
SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
|
117
|
117
|
DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
118
|
|
- DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
|
119
|
|
- Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"prescription"`
|
120
|
|
- AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_before_dislysis"`
|
121
|
|
- AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_after_dislysis"`
|
|
118
|
+ DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
|
|
119
|
+ Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
|
|
120
|
+ AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
|
|
121
|
+ AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
|
122
|
122
|
|
123
|
|
- Advices []*VMDoctorAdvice `gorm:"ForeignKey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"doctor_advice"`
|
124
|
|
- TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"treatment_summary"`
|
|
123
|
+ Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
|
|
124
|
+ TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
|
125
|
125
|
}
|
126
|
126
|
|
127
|
127
|
func (MDialysisScheduleVM) TableName() string {
|
|
@@ -290,6 +290,8 @@ type VMDoctorAdvice struct {
|
290
|
290
|
Status int64 `gorm:"column:status" json:"status" form:"status"`
|
291
|
291
|
ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
|
292
|
292
|
RecordDate int64 `gorm:"column:record_date" json:"record_date"`
|
|
293
|
+ CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
|
|
294
|
+ CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
|
293
|
295
|
}
|
294
|
296
|
|
295
|
297
|
func (VMDoctorAdvice) TableName() string {
|
|
@@ -489,7 +491,7 @@ func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*
|
489
|
491
|
err := readDb.
|
490
|
492
|
Model(&models.DoctorAdvice{}).
|
491
|
493
|
Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
|
492
|
|
- 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,IF(parent_id>0, parent_id, id) as advice_order,groupno").
|
|
494
|
+ 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,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
|
493
|
495
|
Order("start_time asc, groupno desc, advice_order desc, id").
|
494
|
496
|
Scan(&records).Error
|
495
|
497
|
|
|
@@ -506,7 +508,7 @@ func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int
|
506
|
508
|
err := readDb.
|
507
|
509
|
Model(&models.DoctorAdvice{}).
|
508
|
510
|
Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
|
509
|
|
- 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, IF(parent_id > 0, parent_id, id) as advice_order").
|
|
511
|
+ 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").
|
510
|
512
|
Order("start_time asc, groupno desc, advice_order desc, id asc").
|
511
|
513
|
Scan(&records).Error
|
512
|
514
|
|
|
@@ -637,6 +639,19 @@ func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64)
|
637
|
639
|
return &record, nil
|
638
|
640
|
}
|
639
|
641
|
|
|
642
|
+func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
|
|
643
|
+ var schedule models.XtSchedule
|
|
644
|
+ err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
|
|
645
|
+ if err != nil {
|
|
646
|
+ if err == gorm.ErrRecordNotFound {
|
|
647
|
+ return nil, nil
|
|
648
|
+ } else {
|
|
649
|
+ return nil, err
|
|
650
|
+ }
|
|
651
|
+ }
|
|
652
|
+ return &schedule, nil
|
|
653
|
+}
|
|
654
|
+
|
640
|
655
|
|
641
|
656
|
func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
|
642
|
657
|
var record models.DialysisSolution
|
|
@@ -692,19 +707,20 @@ func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecor
|
692
|
707
|
}
|
693
|
708
|
|
694
|
709
|
type MScheduleDoctorAdviceVM struct {
|
695
|
|
- ID int64 `gorm:"column:id" json:"id"`
|
696
|
|
- UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
697
|
|
- PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
|
698
|
|
- BedId int64 `gorm:"column:bed_id" json:"bed_id"`
|
699
|
|
- PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
700
|
|
- ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
|
701
|
|
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
|
702
|
|
- ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
|
703
|
|
- Status int64 `gorm:"column:status" json:"status"`
|
704
|
|
- DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
|
705
|
|
- SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
|
706
|
|
- DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
707
|
|
- DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
|
|
710
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
711
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
|
712
|
+ PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
|
|
713
|
+ BedId int64 `gorm:"column:bed_id" json:"bed_id"`
|
|
714
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
715
|
+ ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
|
|
716
|
+ ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
|
|
717
|
+ ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
|
|
718
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
719
|
+ DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
|
|
720
|
+ SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
|
|
721
|
+ DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
|
722
|
+ DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
|
|
723
|
+ Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
|
708
|
724
|
}
|
709
|
725
|
|
710
|
726
|
func (MScheduleDoctorAdviceVM) TableName() string {
|
|
@@ -761,7 +777,7 @@ func (MDoctorAdviceVM) TableName() string {
|
761
|
777
|
return "xt_doctor_advice"
|
762
|
778
|
}
|
763
|
779
|
|
764
|
|
-func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64) ([]*MScheduleDoctorAdviceVM, error) {
|
|
780
|
+func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
|
765
|
781
|
var vms []*MScheduleDoctorAdviceVM
|
766
|
782
|
adviceWhere := ""
|
767
|
783
|
fmt.Println("advicetype", adviceType)
|
|
@@ -810,13 +826,26 @@ func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType
|
810
|
826
|
adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
|
811
|
827
|
}
|
812
|
828
|
|
813
|
|
- } else if adviceType == 2 {
|
|
829
|
+ } else if adviceType == 2 && len(deliverWay) > 0 {
|
|
830
|
+ if patientType == 0 {
|
|
831
|
+ adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
|
|
832
|
+ adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
|
|
833
|
+
|
|
834
|
+ } else if patientType == 1 {
|
|
835
|
+ adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
|
|
836
|
+ adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
|
|
837
|
+ } else if patientType == 2 {
|
|
838
|
+ adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
|
|
839
|
+ adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
|
|
840
|
+ }
|
|
841
|
+
|
|
842
|
+ } else if adviceType == 2 && len(deliverWay) <= 0 {
|
814
|
843
|
if patientType == 0 {
|
815
|
|
- adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? "
|
|
844
|
+ adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
|
816
|
845
|
adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
|
817
|
846
|
|
818
|
847
|
} else if patientType == 1 {
|
819
|
|
- adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? "
|
|
848
|
+ adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
|
820
|
849
|
adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
|
821
|
850
|
} else if patientType == 2 {
|
822
|
851
|
adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
|
|
@@ -833,6 +862,7 @@ func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType
|
833
|
862
|
}).
|
834
|
863
|
Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
835
|
864
|
Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
|
865
|
+ Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
|
836
|
866
|
Preload("DoctorAdvices", adviceCondition...).
|
837
|
867
|
Where("status = 1 AND user_org_id = ?", orgID)
|
838
|
868
|
if scheduleDate != 0 {
|
|
@@ -1056,7 +1086,7 @@ func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
|
1056
|
1086
|
func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
|
1057
|
1087
|
tx := writeDb.Begin()
|
1058
|
1088
|
updateTime := time.Now().Unix()
|
1059
|
|
- err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType}).Error
|
|
1089
|
+ err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse}).Error
|
1060
|
1090
|
if err != nil {
|
1061
|
1091
|
tx.Rollback()
|
1062
|
1092
|
return err
|
|
@@ -1173,6 +1203,19 @@ func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int6
|
1173
|
1203
|
return &record, nil
|
1174
|
1204
|
}
|
1175
|
1205
|
|
|
1206
|
+func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
|
|
1207
|
+ var record models.DialysisOrder
|
|
1208
|
+ err := readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? and user_org_id = ? and status = 1 and dialysis_date < ?", patientID, orgID, maxDate).Order("dialysis_date desc").First(&record).Error
|
|
1209
|
+ if err != nil {
|
|
1210
|
+ if err == gorm.ErrRecordNotFound {
|
|
1211
|
+ return nil, nil
|
|
1212
|
+ } else {
|
|
1213
|
+ return nil, err
|
|
1214
|
+ }
|
|
1215
|
+ }
|
|
1216
|
+ return &record, nil
|
|
1217
|
+}
|
|
1218
|
+
|
1176
|
1219
|
func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
|
1177
|
1220
|
var record models.MonitoringRecord
|
1178
|
1221
|
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
|
|
@@ -1301,7 +1344,7 @@ func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64,
|
1301
|
1344
|
}
|
1302
|
1345
|
|
1303
|
1346
|
func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
|
1304
|
|
- err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
|
|
1347
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count<>0", orgID, patient_id, recordDate).Find(&consumables).Error
|
1305
|
1348
|
return
|
1306
|
1349
|
}
|
1307
|
1350
|
|
|
@@ -1392,7 +1435,7 @@ type MDialysisGoodsVM struct {
|
1392
|
1435
|
|
1393
|
1436
|
DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
1394
|
1437
|
SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
|
1395
|
|
- AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordTime" json:"good_user"`
|
|
1438
|
+ AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
|
1396
|
1439
|
LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
|
1397
|
1440
|
DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
|
1398
|
1441
|
LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
|
|
@@ -1433,7 +1476,7 @@ type DialysisGoodsDetailDate struct {
|
1433
|
1476
|
RecordTime int64
|
1434
|
1477
|
}
|
1435
|
1478
|
|
1436
|
|
-func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
|
|
1479
|
+func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
|
1437
|
1480
|
var vms []*MDialysisGoodsVM
|
1438
|
1481
|
var total int64
|
1439
|
1482
|
|
|
@@ -1446,7 +1489,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
|
1446
|
1489
|
return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
|
1447
|
1490
|
}).
|
1448
|
1491
|
Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
|
1449
|
|
- return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0 ", orgID, scheduleDate)
|
|
1492
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ? ", orgID, scheduleDate, end_time)
|
1450
|
1493
|
}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
|
1451
|
1494
|
if scheduleDate != 0 {
|
1452
|
1495
|
db = db.Where("schedule_date = ?", scheduleDate)
|
|
@@ -1470,9 +1513,12 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
|
1470
|
1513
|
}
|
1471
|
1514
|
|
1472
|
1515
|
func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
|
|
1516
|
+
|
1473
|
1517
|
var Id []*DialysisGoodsDetailDate
|
|
1518
|
+
|
1474
|
1519
|
err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
|
1475
|
1520
|
if len(Id) > 0 {
|
|
1521
|
+
|
1476
|
1522
|
err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
|
1477
|
1523
|
}
|
1478
|
1524
|
return
|
|
@@ -1492,14 +1538,14 @@ func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (li
|
1492
|
1538
|
db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
|
1493
|
1539
|
db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
|
1494
|
1540
|
db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
|
1495
|
|
- return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgID).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.org_id = ? ", start_time, end_time, orgID)
|
|
1541
|
+ return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.sys_record_time >= ? AND xt_warehouse_out_info.sys_record_time <= ?", orgID, start_time, end_time)
|
1496
|
1542
|
})
|
1497
|
1543
|
db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
|
1498
|
1544
|
err = db.Order("ctime desc").Find(&list).Error
|
1499
|
1545
|
return
|
1500
|
1546
|
}
|
1501
|
1547
|
|
1502
|
|
-func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
|
|
1548
|
+func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
|
1503
|
1549
|
var vms []*MDialysisGoodsVM
|
1504
|
1550
|
var total int64
|
1505
|
1551
|
|
|
@@ -1512,7 +1558,7 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
|
1512
|
1558
|
return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
|
1513
|
1559
|
}).
|
1514
|
1560
|
Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
|
1515
|
|
- return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0", orgID, scheduleDate)
|
|
1561
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=? AND count > 0", orgID, scheduleDate, end_time)
|
1516
|
1562
|
}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
|
1517
|
1563
|
|
1518
|
1564
|
if scheduleDate != 0 {
|
|
@@ -1543,3 +1589,84 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
|
1543
|
1589
|
|
1544
|
1590
|
return vms, err, total
|
1545
|
1591
|
}
|
|
1592
|
+
|
|
1593
|
+func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
|
|
1594
|
+
|
|
1595
|
+ var Id []*DialysisGoodsDetailDate
|
|
1596
|
+
|
|
1597
|
+ err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
|
|
1598
|
+ if len(Id) > 0 {
|
|
1599
|
+
|
|
1600
|
+ err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
|
|
1601
|
+ }
|
|
1602
|
+ return
|
|
1603
|
+}
|
|
1604
|
+
|
|
1605
|
+func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
|
|
1606
|
+ var Id []*DialysisGoodsDate
|
|
1607
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
|
|
1608
|
+ if len(Id) > 0 {
|
|
1609
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
|
|
1610
|
+ }
|
|
1611
|
+ return
|
|
1612
|
+}
|
|
1613
|
+
|
|
1614
|
+func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
|
|
1615
|
+
|
|
1616
|
+ evaluation := models.PredialysisEvaluation{}
|
|
1617
|
+
|
|
1618
|
+ err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
|
|
1619
|
+ if err == gorm.ErrRecordNotFound {
|
|
1620
|
+ return nil, err
|
|
1621
|
+ }
|
|
1622
|
+ if err != nil {
|
|
1623
|
+ return nil, err
|
|
1624
|
+ }
|
|
1625
|
+ return &evaluation, nil
|
|
1626
|
+}
|
|
1627
|
+
|
|
1628
|
+func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
|
|
1629
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
|
|
1630
|
+ return
|
|
1631
|
+
|
|
1632
|
+}
|
|
1633
|
+
|
|
1634
|
+func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
|
|
1635
|
+
|
|
1636
|
+ prescription := models.DialysisPrescription{}
|
|
1637
|
+ err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
|
|
1638
|
+ if err == gorm.ErrRecordNotFound {
|
|
1639
|
+ return nil, err
|
|
1640
|
+ }
|
|
1641
|
+ if err != nil {
|
|
1642
|
+ return nil, err
|
|
1643
|
+ }
|
|
1644
|
+ return &prescription, nil
|
|
1645
|
+}
|
|
1646
|
+
|
|
1647
|
+type HisMScheduleDoctorAdviceVM struct {
|
|
1648
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1649
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
|
1650
|
+ PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
|
|
1651
|
+ BedId int64 `gorm:"column:bed_id" json:"bed_id"`
|
|
1652
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
1653
|
+ ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
|
|
1654
|
+ ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
|
|
1655
|
+ ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
|
|
1656
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
1657
|
+ DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
|
|
1658
|
+ SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
|
|
1659
|
+ DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
|
1660
|
+ Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
|
|
1661
|
+ HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
|
|
1662
|
+}
|
|
1663
|
+
|
|
1664
|
+func (HisMScheduleDoctorAdviceVM) TableName() string {
|
|
1665
|
+ return "xt_schedule"
|
|
1666
|
+}
|
|
1667
|
+
|
|
1668
|
+func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
|
|
1669
|
+ config := models.XtHisConfig{}
|
|
1670
|
+ err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
|
|
1671
|
+ return config, err
|
|
1672
|
+}
|