Browse Source

医保对接

csx 4 years ago
parent
commit
de413dfc5f

+ 2 - 0
controllers/dialysis_api_controller.go View File

1547
 func (c *DialysisApiController) GetAllDeviceZone() {
1547
 func (c *DialysisApiController) GetAllDeviceZone() {
1548
 	adminUserInfo := c.GetAdminUserInfo()
1548
 	adminUserInfo := c.GetAdminUserInfo()
1549
 	err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
1549
 	err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
1550
+	dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
1550
 	if err == nil {
1551
 	if err == nil {
1551
 		c.ServeSuccessJSON(map[string]interface{}{
1552
 		c.ServeSuccessJSON(map[string]interface{}{
1552
 			"zone": zone,
1553
 			"zone": zone,
1554
+			"dics": dics,
1553
 		})
1555
 		})
1554
 	}
1556
 	}
1555
 
1557
 

+ 3 - 3
controllers/doctors_api_controller.go View File

33
 	schedualDate := c.GetString("date")
33
 	schedualDate := c.GetString("date")
34
 	adviceType, _ := c.GetInt("advice_type")
34
 	adviceType, _ := c.GetInt("advice_type")
35
 	patientType, _ := c.GetInt("patient_type")
35
 	patientType, _ := c.GetInt("patient_type")
36
-
36
+	delivery_way := c.GetString("delivery_way")
37
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
37
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
38
 		adviceType = 0
38
 		adviceType = 0
39
 	}
39
 	}
52
 	adminUserInfo := c.GetAdminUserInfo()
52
 	adminUserInfo := c.GetAdminUserInfo()
53
 	orgID := adminUserInfo.CurrentOrgId
53
 	orgID := adminUserInfo.CurrentOrgId
54
 
54
 
55
-	scheduals, err := service.MobileGetScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id)
56
-	hisAdvices, _ := service.GetHisDoctorAdvices(orgID, date.Unix())
55
+	scheduals, err := service.MobileGetScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way)
56
+	hisAdvices, _ := service.GetHisDoctorAdvices(orgID, date.Unix(), delivery_way)
57
 	config, _ := service.GetHisDoctorConfig(orgID)
57
 	config, _ := service.GetHisDoctorConfig(orgID)
58
 	adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
58
 	adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
59
 	if err != nil {
59
 	if err != nil {

+ 3 - 3
controllers/mobile_api_controllers/doctor_advice_api_controller.go View File

19
 	schedualDate := this.GetString("date")
19
 	schedualDate := this.GetString("date")
20
 	adviceType, _ := this.GetInt("advice_type")
20
 	adviceType, _ := this.GetInt("advice_type")
21
 	patientType, _ := this.GetInt("patient_type")
21
 	patientType, _ := this.GetInt("patient_type")
22
-
22
+	delivery_way := this.GetString("delivery_way")
23
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
23
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
24
 		adviceType = 0
24
 		adviceType = 0
25
 	}
25
 	}
38
 	adminInfo := this.GetMobileAdminUserInfo()
38
 	adminInfo := this.GetMobileAdminUserInfo()
39
 	orgID := adminInfo.Org.Id
39
 	orgID := adminInfo.Org.Id
40
 
40
 
41
-	scheduals, err := service.MobileGetScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminInfo.AdminUser.Id)
41
+	scheduals, err := service.MobileGetScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminInfo.AdminUser.Id, delivery_way)
42
 	//获取his医嘱数据
42
 	//获取his医嘱数据
43
 	fmt.Println("date.un222222", date.Unix())
43
 	fmt.Println("date.un222222", date.Unix())
44
-	hisAdvices, _ := service.GetHisDoctorAdvices(orgID, date.Unix())
44
+	hisAdvices, _ := service.GetHisDoctorAdvices(orgID, date.Unix(), delivery_way)
45
 	config, _ := service.GetHisDoctorConfig(orgID)
45
 	config, _ := service.GetHisDoctorConfig(orgID)
46
 	adminUser, _ := service.GetAllAdminUsers(orgID, adminInfo.App.Id)
46
 	adminUser, _ := service.GetAllAdminUsers(orgID, adminInfo.App.Id)
47
 	if err != nil {
47
 	if err != nil {

+ 15 - 17
models/good_models.go View File

1
 package models
1
 package models
2
 
2
 
3
-import "XT/models"
4
-
5
 type GoodsType struct {
3
 type GoodsType struct {
6
 	ID             int64  `gorm:"column:id" json:"id"`
4
 	ID             int64  `gorm:"column:id" json:"id"`
7
 	TypeCode       string `gorm:"column:type_code" json:"type_code"`
5
 	TypeCode       string `gorm:"column:type_code" json:"type_code"`
75
 }
73
 }
76
 
74
 
77
 type GoodsTypeOne struct {
75
 type GoodsTypeOne struct {
78
-	ID             int64              `gorm:"column:id" json:"id"`
79
-	TypeCode       string             `gorm:"column:type_code" json:"type_code"`
80
-	TypeName       string             `gorm:"column:type_name" json:"type_name"`
81
-	Remark         string             `gorm:"column:remark" json:"remark"`
82
-	Ctime          int64              `gorm:"column:ctime" json:"ctime"`
83
-	Mtime          int64              `gorm:"column:mtime" json:"mtime"`
84
-	Creater        int64              `gorm:"column:creater" json:"creater"`
85
-	Modifier       int64              `gorm:"column:modifier" json:"modifier"`
86
-	OrgId          int64              `gorm:"column:org_id" json:"org_id"`
87
-	Status         int64              `gorm:"column:status" json:"status"`
88
-	Type           int64              `gorm:"column:type" json:"type"`
89
-	Number         int64              `gorm:"column:number" json:"number"`
90
-	OutStock       int64              `gorm:"column:out_stock" json:"out_stock" form:"out_stock"`
91
-	StockAttribute int64              `gorm:"column:stock_attribute" json:"stock_attribute" form:"stock_attribute"`
92
-	GoodInfo       []*models.GoodInfo `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"GoodInfo"`
76
+	ID             int64       `gorm:"column:id" json:"id"`
77
+	TypeCode       string      `gorm:"column:type_code" json:"type_code"`
78
+	TypeName       string      `gorm:"column:type_name" json:"type_name"`
79
+	Remark         string      `gorm:"column:remark" json:"remark"`
80
+	Ctime          int64       `gorm:"column:ctime" json:"ctime"`
81
+	Mtime          int64       `gorm:"column:mtime" json:"mtime"`
82
+	Creater        int64       `gorm:"column:creater" json:"creater"`
83
+	Modifier       int64       `gorm:"column:modifier" json:"modifier"`
84
+	OrgId          int64       `gorm:"column:org_id" json:"org_id"`
85
+	Status         int64       `gorm:"column:status" json:"status"`
86
+	Type           int64       `gorm:"column:type" json:"type"`
87
+	Number         int64       `gorm:"column:number" json:"number"`
88
+	OutStock       int64       `gorm:"column:out_stock" json:"out_stock" form:"out_stock"`
89
+	StockAttribute int64       `gorm:"column:stock_attribute" json:"stock_attribute" form:"stock_attribute"`
90
+	GoodInfo       []*GoodInfo `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"GoodInfo"`
93
 }
91
 }
94
 
92
 
95
 func (GoodsTypeOne) TableName() string {
93
 func (GoodsTypeOne) TableName() string {

+ 164 - 37
models/service/mobile_dialysis_service.go View File

30
 		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
30
 		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
31
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
31
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
32
 		Preload("DeviceNumber.Zone", "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", 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).
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).
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
 		Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
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
 		// Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
41
 		// Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
42
 		// 	return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
42
 		// 	return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
115
 
115
 
116
 	SchedualPatient          *MSchedualPatientVMList           `gorm:"ForeignKey:PatientId" json:"patient"`
116
 	SchedualPatient          *MSchedualPatientVMList           `gorm:"ForeignKey:PatientId" json:"patient"`
117
 	DeviceNumber             *MDeviceNumberVM                  `gorm:"ForeignKey:BedId" json:"device_number"`
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
 func (MDialysisScheduleVM) TableName() string {
127
 func (MDialysisScheduleVM) TableName() string {
290
 	Status         int64 `gorm:"column:status" json:"status" form:"status"`
290
 	Status         int64 `gorm:"column:status" json:"status" form:"status"`
291
 	ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
291
 	ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
292
 	RecordDate     int64 `gorm:"column:record_date" json:"record_date"`
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
 func (VMDoctorAdvice) TableName() string {
297
 func (VMDoctorAdvice) TableName() string {
489
 	err := readDb.
491
 	err := readDb.
490
 		Model(&models.DoctorAdvice{}).
492
 		Model(&models.DoctorAdvice{}).
491
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
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
 		Order("start_time asc, groupno desc, advice_order desc, id").
495
 		Order("start_time asc, groupno desc, advice_order desc, id").
494
 		Scan(&records).Error
496
 		Scan(&records).Error
495
 
497
 
506
 	err := readDb.
508
 	err := readDb.
507
 		Model(&models.DoctorAdvice{}).
509
 		Model(&models.DoctorAdvice{}).
508
 		Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and advice_type = 2", patientID, orgID, recordDate).
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
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
512
 		Order("start_time asc, groupno desc, advice_order desc, id asc").
511
 		Scan(&records).Error
513
 		Scan(&records).Error
512
 
514
 
637
 	return &record, nil
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
 func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
656
 func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
642
 	var record models.DialysisSolution
657
 	var record models.DialysisSolution
692
 }
707
 }
693
 
708
 
694
 type MScheduleDoctorAdviceVM struct {
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
 func (MScheduleDoctorAdviceVM) TableName() string {
726
 func (MScheduleDoctorAdviceVM) TableName() string {
761
 	return "xt_doctor_advice"
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
 	var vms []*MScheduleDoctorAdviceVM
781
 	var vms []*MScheduleDoctorAdviceVM
766
 	adviceWhere := ""
782
 	adviceWhere := ""
767
 	fmt.Println("advicetype", adviceType)
783
 	fmt.Println("advicetype", adviceType)
810
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
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
 		if patientType == 0 {
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
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
845
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
817
 
846
 
818
 		} else if patientType == 1 {
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
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
849
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
821
 		} else if patientType == 2 {
850
 		} else if patientType == 2 {
822
 			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
851
 			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
833
 		}).
862
 		}).
834
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
863
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
835
 		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
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
 		Preload("DoctorAdvices", adviceCondition...).
866
 		Preload("DoctorAdvices", adviceCondition...).
837
 		Where("status = 1 AND user_org_id = ?", orgID)
867
 		Where("status = 1 AND user_org_id = ?", orgID)
838
 	if scheduleDate != 0 {
868
 	if scheduleDate != 0 {
1056
 func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
1086
 func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
1057
 	tx := writeDb.Begin()
1087
 	tx := writeDb.Begin()
1058
 	updateTime := time.Now().Unix()
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
 	if err != nil {
1090
 	if err != nil {
1061
 		tx.Rollback()
1091
 		tx.Rollback()
1062
 		return err
1092
 		return err
1173
 	return &record, nil
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
 func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
1219
 func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
1177
 	var record models.MonitoringRecord
1220
 	var record models.MonitoringRecord
1178
 	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
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
 }
1344
 }
1302
 
1345
 
1303
 func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
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
 	return
1348
 	return
1306
 }
1349
 }
1307
 
1350
 
1392
 
1435
 
1393
 	DeviceNumber              *MDeviceNumberVM         `gorm:"ForeignKey:BedId" json:"device_number"`
1436
 	DeviceNumber              *MDeviceNumberVM         `gorm:"ForeignKey:BedId" json:"device_number"`
1394
 	SchedualPatient           *MSchedualPatientVMList  `gorm:"ForeignKey:PatientId" json:"patient"`
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
 	LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
1439
 	LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
1397
 	DialysisBeforePrepare     []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
1440
 	DialysisBeforePrepare     []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
1398
 	LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
1441
 	LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
1433
 	RecordTime int64
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
 	var vms []*MDialysisGoodsVM
1480
 	var vms []*MDialysisGoodsVM
1438
 	var total int64
1481
 	var total int64
1439
 
1482
 
1446
 			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)
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
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
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
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1493
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
1451
 	if scheduleDate != 0 {
1494
 	if scheduleDate != 0 {
1452
 		db = db.Where("schedule_date = ?", scheduleDate)
1495
 		db = db.Where("schedule_date = ?", scheduleDate)
1470
 }
1513
 }
1471
 
1514
 
1472
 func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
1515
 func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
1516
+
1473
 	var Id []*DialysisGoodsDetailDate
1517
 	var Id []*DialysisGoodsDetailDate
1518
+
1474
 	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
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
 	if len(Id) > 0 {
1520
 	if len(Id) > 0 {
1521
+
1476
 		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
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
 	return
1524
 	return
1492
 	db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
1538
 	db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
1493
 	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")
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
 	db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
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
 	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
1543
 	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
1498
 	err = db.Order("ctime desc").Find(&list).Error
1544
 	err = db.Order("ctime desc").Find(&list).Error
1499
 	return
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
 	var vms []*MDialysisGoodsVM
1549
 	var vms []*MDialysisGoodsVM
1504
 	var total int64
1550
 	var total int64
1505
 
1551
 
1512
 			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)
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
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
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
 		}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
1562
 		}).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
1517
 
1563
 
1518
 	if scheduleDate != 0 {
1564
 	if scheduleDate != 0 {
1543
 
1589
 
1544
 	return vms, err, total
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
+}

File diff suppressed because it is too large
+ 856 - 21
models/service/stock_service.go


+ 1 - 0
service/gdyb_service.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"XT_New/models"
4
 	"XT_New/models"
5
+	//"/models"
5
 	"bytes"
6
 	"bytes"
6
 	"crypto/sha256"
7
 	"crypto/sha256"
7
 	"encoding/hex"
8
 	"encoding/hex"

+ 3 - 4
service/his_service.go View File

581
 }
581
 }
582
 
582
 
583
 func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
583
 func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
584
-	err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
585
-	err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
586
-	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 4, "mtime": time.Now().Unix()}).Error
587
-	err = writeDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
584
+	err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
585
+	err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
586
+	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
588
 
587
 
589
 	return
588
 	return
590
 
589
 

+ 50 - 20
service/mobile_dialysis_service.go View File

777
 	return "xt_doctor_advice"
777
 	return "xt_doctor_advice"
778
 }
778
 }
779
 
779
 
780
-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) {
781
 	var vms []*MScheduleDoctorAdviceVM
781
 	var vms []*MScheduleDoctorAdviceVM
782
 	adviceWhere := ""
782
 	adviceWhere := ""
783
 	fmt.Println("advicetype", adviceType)
783
 	fmt.Println("advicetype", adviceType)
826
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
826
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
827
 		}
827
 		}
828
 
828
 
829
-	} else if adviceType == 2 {
829
+	} else if adviceType == 2 && len(deliverWay) > 0 {
830
 		if patientType == 0 {
830
 		if patientType == 0 {
831
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?  "
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 {
843
+		if patientType == 0 {
844
+			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
832
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
845
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
833
 
846
 
834
 		} else if patientType == 1 {
847
 		} else if patientType == 1 {
835
-			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 = ?"
836
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
849
 			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
837
 		} else if patientType == 2 {
850
 		} else if patientType == 2 {
838
 			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
851
 			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
860
 	return vms, err
873
 	return vms, err
861
 }
874
 }
862
 
875
 
863
-func GetHisDoctorAdvices(orgID int64, scheduleDate int64) ([]*HisMScheduleDoctorAdviceVM, error) {
876
+func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string) ([]*HisMScheduleDoctorAdviceVM, error) {
864
 
877
 
865
 	var vms []*HisMScheduleDoctorAdviceVM
878
 	var vms []*HisMScheduleDoctorAdviceVM
866
-
867
-	db := readDb.
868
-		Table("xt_schedule").
869
-		Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
870
-		Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
871
-			return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
872
-		}).
873
-		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
874
-		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
875
-		Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
876
-		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
877
-		Where("status = 1 AND user_org_id = ?", orgID)
878
-	if scheduleDate != 0 {
879
-		db = db.Where("schedule_date = ?", scheduleDate)
879
+	if len(deliverWay) > 0 {
880
+		db := readDb.
881
+			Table("xt_schedule").
882
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
883
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
884
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
885
+			}).
886
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
887
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
888
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
889
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
890
+			Where("status = 1 AND user_org_id = ?", orgID)
891
+		if scheduleDate != 0 {
892
+			db = db.Where("schedule_date = ?", scheduleDate)
893
+		}
894
+		err = db.Find(&vms).Error
895
+	} else {
896
+		db := readDb.
897
+			Table("xt_schedule").
898
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
899
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
900
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
901
+			}).
902
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
903
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
904
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
905
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
906
+			Where("status = 1 AND user_org_id = ?", orgID)
907
+		if scheduleDate != 0 {
908
+			db = db.Where("schedule_date = ?", scheduleDate)
909
+		}
910
+		err = db.Find(&vms).Error
880
 	}
911
 	}
881
 
912
 
882
-	err := db.Find(&vms).Error
883
 	return vms, err
913
 	return vms, err
884
 }
914
 }
885
 
915