Browse Source

历史排班

28169 1 year ago
parent
commit
58058d6b24

+ 41 - 0
controllers/dialysis_api_controller.go View File

@@ -121,6 +121,8 @@ func DialysisApiRegistRouters() {
121 121
 	beego.Router("/api/patient/checkdialysisinformation", &DialysisApiController{}, "Get:CheckDialysisInformation")
122 122
 
123 123
 	beego.Router("/api/dialysis/patientsflow", &DialysisApiController{}, "Get:GetDialysisPatientsFlow")
124
+
125
+	beego.Router("/api/patient/getlongdialysisadvicetoday", &DialysisApiController{}, "Get:GetLongDialysisAdviceToday")
124 126
 }
125 127
 
126 128
 func (c *DialysisApiController) GetQueueCall() {
@@ -2455,6 +2457,7 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2455 2457
 				newprescribe.RecordDate = recordDate.Unix()
2456 2458
 				newprescribe.DewaterAmount = dewater_amount
2457 2459
 				newprescribe.TargetUltrafiltration = dewater_amount
2460
+				newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2458 2461
 				newprescribe.Status = 1
2459 2462
 
2460 2463
 				err := service.AddSigleRecord(&newprescribe)
@@ -2513,6 +2516,7 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2513 2516
 					newprescribe.Status = 1
2514 2517
 					newprescribe.Creater = adminUserInfo.AdminUser.Id
2515 2518
 					newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
2519
+					newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2516 2520
 
2517 2521
 					err := service.AddSigleRecord(&newprescribe)
2518 2522
 					key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
@@ -2710,6 +2714,7 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2710 2714
 			newprescribe.RecordDate = recordDate.Unix()
2711 2715
 			newprescribe.DewaterAmount = dewater_amount
2712 2716
 			newprescribe.TargetUltrafiltration = dewater_amount
2717
+			newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2713 2718
 			newprescribe.Status = 1
2714 2719
 
2715 2720
 			err := service.AddSigleRecord(&newprescribe)
@@ -2765,6 +2770,7 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
2765 2770
 				newprescribe.RecordDate = recordDate.Unix()
2766 2771
 				newprescribe.DewaterAmount = dewater_amount
2767 2772
 				newprescribe.TargetUltrafiltration = dewater_amount
2773
+				newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2768 2774
 				newprescribe.Status = 1
2769 2775
 
2770 2776
 				err := service.AddSigleRecord(&newprescribe)
@@ -6839,3 +6845,38 @@ func (this *DialysisApiController) SaveInformation() {
6839 6845
 	}
6840 6846
 
6841 6847
 }
6848
+
6849
+func (this *DialysisApiController) GetLongDialysisAdviceToday() {
6850
+
6851
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6852
+
6853
+	schedule_type, _ := this.GetInt64("schedule_type")
6854
+
6855
+	partion_type := this.GetString("partion_type")
6856
+	var ids []string
6857
+	ids = strings.Split(partion_type, ",")
6858
+	start_time := this.GetString("selected_date")
6859
+	timeLayout := "2006-01-02"
6860
+	loc, _ := time.LoadLocation("Local")
6861
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6862
+
6863
+	list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
6864
+
6865
+	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
6866
+	_, config := service.FindXTHisRecordByOrgId(orgId)
6867
+	appId := this.GetAdminUserInfo().CurrentAppId
6868
+	doctorList, _ := service.GetAllAdminUsers(orgId, appId)
6869
+	if err == nil {
6870
+		this.ServeSuccessJSON(map[string]interface{}{
6871
+			"list":       list,
6872
+			"drug":       drug,
6873
+			"config":     config,
6874
+			"doctorList": doctorList,
6875
+		})
6876
+		return
6877
+
6878
+	} else {
6879
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
6880
+		return
6881
+	}
6882
+}

+ 45 - 0
controllers/doctors_api_controller.go View File

@@ -65,6 +65,8 @@ func DoctorApiRegistRouters() {
65 65
 	beego.Router("/api/patient/getfirstdetailbyid", &DoctorsApiController{}, "Get:GetFirstDetailById")
66 66
 	beego.Router("/api/patient/updatefirstdisease", &DoctorsApiController{}, "Post:UpdateFirstDisease")
67 67
 	beego.Router("/api/patient/deletefirstdisease", &DoctorsApiController{}, "Get:DeleteFirstDisease")
68
+
69
+	beego.Router("/api/schedule/new/long/advices", &DoctorsApiController{}, "Get:GetLongScheduleAdvicesList")
68 70
 }
69 71
 
70 72
 func (c *DoctorsApiController) ScheduleAdvices() {
@@ -1626,3 +1628,46 @@ func (c *DoctorsApiController) DeleteFirstDisease() {
1626 1628
 	c.ServeSuccessJSON(returnData)
1627 1629
 	return
1628 1630
 }
1631
+
1632
+func (c *DoctorsApiController) GetLongScheduleAdvicesList() {
1633
+
1634
+	schedualDate := c.GetString("date")
1635
+	adviceType, _ := c.GetInt("advice_type")
1636
+	patientType, _ := c.GetInt("patient_type")
1637
+	delivery_way := c.GetString("delivery_way")
1638
+	schedule_type, _ := c.GetInt64("schedule_type")
1639
+	partition_type, _ := c.GetInt64("partition_type")
1640
+	patient_id, _ := c.GetInt64("patient_id")
1641
+	excution_way, _ := c.GetInt64("excution_way")
1642
+	cost_type, _ := c.GetInt64("cost_type")
1643
+	execution_frequency := c.GetString("execution_frequency")
1644
+
1645
+	date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
1646
+	if parseDateErr != nil {
1647
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1648
+		return
1649
+	}
1650
+
1651
+	adminUserInfo := c.GetAdminUserInfo()
1652
+	orgID := adminUserInfo.CurrentOrgId
1653
+
1654
+	scheduals, err := service.MobileGetLongScheduleDoctorAdvices(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way, schedule_type, partition_type, patient_id, excution_way, cost_type, execution_frequency)
1655
+
1656
+	adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
1657
+	if err != nil {
1658
+		c.ErrorLog("获取排班信息失败:%v", err)
1659
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1660
+	} else {
1661
+		filtedScheduals := []*service.MScheduleDoctorAdviceVM{}
1662
+		for _, schedual := range scheduals {
1663
+			if len(schedual.DoctorAdvices) > 0 {
1664
+				filtedScheduals = append(filtedScheduals, schedual)
1665
+			}
1666
+		}
1667
+		c.ServeSuccessJSON(map[string]interface{}{
1668
+			"scheduals": filtedScheduals,
1669
+			"adminUser": adminUser,
1670
+		})
1671
+	}
1672
+
1673
+}

+ 3 - 0
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -379,6 +379,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
379 379
 			newprescribe.DewaterAmount = dewater_amount
380 380
 			newprescribe.TargetUltrafiltration = dewater_amount
381 381
 			newprescribe.PrescriptionWater = dewater_amount
382
+			newprescribe.Chaptalization = dialysisSolution.Chaptalization
382 383
 			newprescribe.Status = 1
383 384
 			if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
384 385
 				newprescribe.Remark = dialysisSolution.Remark
@@ -465,6 +466,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
465 466
 				newprescribe.PrescriptionWater = dewater_amount
466 467
 				newprescribe.Status = 1
467 468
 				newprescribe.Remark = lastDialysisPrescribe.Remark
469
+				newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
468 470
 				if adminUserInfo.Org.Id == 10340 {
469 471
 					newprescribe.TargetUltrafiltration = 0
470 472
 				}
@@ -530,6 +532,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
530 532
 				newprescribe.RecordDate = theAssessmentDateTime
531 533
 				newprescribe.DewaterAmount = dewater_amount
532 534
 				newprescribe.TargetUltrafiltration = dewater_amount
535
+				newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
533 536
 				newprescribe.Status = 1
534 537
 
535 538
 				if adminUserInfo.Org.Id == 10340 {

+ 1 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -4245,6 +4245,7 @@ func (this *DialysisAPIController) ModifyStartDialysisOrder() {
4245 4245
 	difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
4246 4246
 	new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
4247 4247
 	quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
4248
+	fmt.Println("quality_nurse_id", quality_nurse_id)
4248 4249
 	patient_id, _ := this.GetInt64("patient_id")
4249 4250
 	record_date, _ := this.GetInt64("record_date")
4250 4251
 	puncture_needle := this.GetString("puncture_needle")

+ 5 - 1
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -2172,6 +2172,7 @@ func (c *PatientApiController) EditAssessmentBeforeDislysis() {
2172 2172
 	// 计算透析处方的相关超滤量
2173 2173
 	schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
2174 2174
 	lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
2175
+
2175 2176
 	var lastDialysisPrescribe *models.DialysisPrescription
2176 2177
 	var dialysisSolution *models.DialysisSolution
2177 2178
 	var dialysisPrescribe *models.DialysisPrescription
@@ -2253,6 +2254,7 @@ func (c *PatientApiController) EditAssessmentBeforeDislysis() {
2253 2254
 		newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
2254 2255
 		newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
2255 2256
 		newprescribe.Remark = lastDialysisPrescription.Remark
2257
+		newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2256 2258
 		_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
2257 2259
 		newprescribe.ID = dialysisPrescription.ID
2258 2260
 
@@ -2373,6 +2375,7 @@ func (c *PatientApiController) EditAssessmentBeforeDislysis() {
2373 2375
 			newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
2374 2376
 			newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
2375 2377
 			newprescribe.Remark = lastDialysisPrescription.Remark
2378
+			newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2376 2379
 			_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
2377 2380
 			newprescribe.ID = dialysisPrescription.ID
2378 2381
 			if dialysisPrescription.ID == 0 {
@@ -2486,6 +2489,7 @@ func (c *PatientApiController) EditAssessmentBeforeDislysis() {
2486 2489
 			newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
2487 2490
 			newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
2488 2491
 			newprescribe.Remark = lastDialysisPrescription.Remark
2492
+			newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
2489 2493
 			_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
2490 2494
 			newprescribe.ID = dialysisPrescription.ID
2491 2495
 			if dialysisPrescription.ID == 0 {
@@ -3207,6 +3211,7 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
3207 3211
 
3208 3212
 	if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
3209 3213
 		is_infect, _ := dataBody["is_infect"].(string)
3214
+		fmt.Println("is_infect================", is_infect)
3210 3215
 		infect, _ := strconv.ParseInt(is_infect, 10, 64)
3211 3216
 		evaluation.IsInfect = infect
3212 3217
 	}
@@ -3417,7 +3422,6 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
3417 3422
 		befor_symptoms := dataBody["befor_symptoms"].(string)
3418 3423
 		evaluation.BeforSymptoms = befor_symptoms
3419 3424
 
3420
-		fmt.Println("befor_symptomsss23333333333333333333333333", befor_symptoms)
3421 3425
 	}
3422 3426
 	return
3423 3427
 }

+ 1 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go View File

@@ -890,6 +890,7 @@ func (c *StaffScheduleApiController) GetSolutionSchedule() {
890 890
 	loc, _ := time.LoadLocation("Local")
891 891
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
892 892
 	schedule, _ := service.GetSolutionScheduleBySchedule(orgId, zoneid, classtype, theTime.Unix())
893
+
893 894
 	c.ServeSuccessJSON(map[string]interface{}{
894 895
 		"schedule": schedule,
895 896
 	})

+ 5 - 4
models/patient_models.go View File

@@ -1663,10 +1663,11 @@ func (DialysisPrescriptionTwenty) TableName() string {
1663 1663
 }
1664 1664
 
1665 1665
 type DialysisPrescriptionThrity struct {
1666
-	ID        int64  `gorm:"column:id" json:"id"`
1667
-	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id"`
1668
-	PatientId int64  `gorm:"column:patient_id" json:"patient_id"`
1669
-	Remark    string `gorm:"column:remark" json:"remark" form:"remark"`
1666
+	ID             int64  `gorm:"column:id" json:"id"`
1667
+	UserOrgId      int64  `gorm:"column:user_org_id" json:"user_org_id"`
1668
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id"`
1669
+	Remark         string `gorm:"column:remark" json:"remark" form:"remark"`
1670
+	Chaptalization string `gorm:"column:chaptalization" json:"chaptalization" form:"chaptalization"`
1670 1671
 }
1671 1672
 
1672 1673
 func (DialysisPrescriptionThrity) TableName() string {

+ 24 - 0
models/schedule_models.go View File

@@ -710,3 +710,27 @@ type ScheduleConfig struct {
710 710
 func (ScheduleConfig) TableName() string {
711 711
 	return "xt_schedule_config"
712 712
 }
713
+
714
+type VmLongBloodSchedule struct {
715
+	ID              int64                      `gorm:"column:id" json:"id" form:"id"`
716
+	UserOrgId       int64                      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
717
+	PartitionId     int64                      `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
718
+	BedId           int64                      `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
719
+	PatientId       int64                      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
720
+	ScheduleDate    int64                      `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
721
+	ScheduleType    int64                      `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
722
+	ScheduleWeek    int64                      `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
723
+	ModeId          int64                      `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
724
+	Status          int64                      `gorm:"column:status" json:"status" form:"status"`
725
+	CreatedTime     int64                      `gorm:"column:created_time" json:"created_time" form:"created_time"`
726
+	UpdatedTime     int64                      `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
727
+	IsExport        int64                      `gorm:"column:is_export" json:"is_export" form:"is_export"`
728
+	DeviceNumber    *NewMDeviceNumberVM        `gorm:"ForeignKey:BedId" json:"device_number"`
729
+	SchedualPatient *NewMSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
730
+	XtDoctorAdvice  []*XtDoctorAdvice          `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"xt_doctor_advice"`
731
+	HisDoctorAdvice []*HisDoctorAdviceFourty   `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_doctor_advice"`
732
+}
733
+
734
+func (VmLongBloodSchedule) TableName() string {
735
+	return "xt_schedule"
736
+}

+ 28 - 0
service/dialysis_solution_service.go View File

@@ -556,3 +556,31 @@ func GetHisDialysisGoodCountTwo(orgID int64, schedule_type int64, partition_id [
556 556
 
557 557
 	return schedule, err
558 558
 }
559
+
560
+func GetLongDialysisAdviceToday(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmLongBloodSchedule, err error) {
561
+
562
+	db := XTReadDB().Model(&models.VmLongBloodSchedule{}).Where("status = 1")
563
+
564
+	if scheduleDate > 0 {
565
+		db = db.Where("schedule_date = ?", scheduleDate)
566
+	}
567
+	if schedule_type > 0 {
568
+		db = db.Where("schedule_type = ?", schedule_type)
569
+	}
570
+	if len(partition_id) > 0 {
571
+		db = db.Where("partition_id in(?)", partition_id)
572
+	}
573
+
574
+	if orgID > 0 {
575
+		db = db.Where("user_org_id  = ?", orgID)
576
+	}
577
+	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
578
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
579
+		Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ?  and advice_type = 1", orgID).
580
+		Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
581
+			return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
582
+		}).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
583
+
584
+	return schedule, err
585
+
586
+}

+ 303 - 0
service/mobile_dialysis_service.go View File

@@ -7237,3 +7237,306 @@ func GetPatientDryWeight(org_id int64, patient_id int64) (weight []*models.SgjPa
7237 7237
 
7238 7238
 	return weight, err
7239 7239
 }
7240
+
7241
+func MobileGetLongScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
7242
+
7243
+	var vms []*MScheduleDoctorAdviceVM
7244
+	adviceWhere := ""
7245
+	adviceCondition := []interface{}{}
7246
+	if adviceType == 1 {
7247
+		if patientType == 0 {
7248
+			if patient_id > 0 {
7249
+				if execution_state > 0 {
7250
+					if cost_type > 0 {
7251
+						if len(execution_frequency) > 0 {
7252
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and patient_id = ? and execution_state = ? and is_settle = ? and execution_frequency = ?"
7253
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
7254
+						} else {
7255
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and is_settle = ?"
7256
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
7257
+						}
7258
+
7259
+					} else {
7260
+						if len(execution_frequency) > 0 {
7261
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_state = ? and execution_frequency = ?"
7262
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
7263
+						} else {
7264
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and patient_id = ? and execution_state = ?"
7265
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
7266
+						}
7267
+
7268
+					}
7269
+
7270
+				} else {
7271
+					if cost_type > 0 {
7272
+						if len(execution_frequency) > 0 {
7273
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and patient_id = ? and is_settle = ? and execution_frequency = ?"
7274
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
7275
+						} else {
7276
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and patient_id = ? and is_settle = ? "
7277
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
7278
+						}
7279
+
7280
+					} else {
7281
+						if len(execution_frequency) > 0 {
7282
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? and execution_frequency = ?"
7283
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
7284
+						} else {
7285
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 and patient_id = ? "
7286
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
7287
+						}
7288
+
7289
+					}
7290
+
7291
+				}
7292
+
7293
+			} else {
7294
+				if execution_state > 0 {
7295
+					if cost_type > 0 {
7296
+						if len(execution_frequency) > 0 {
7297
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and execution_state = ? and is_settle = ? and execution_frequency = ?"
7298
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
7299
+						} else {
7300
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and execution_state = ? and is_settle = ?"
7301
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
7302
+						}
7303
+
7304
+					} else {
7305
+						if len(execution_frequency) > 0 {
7306
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and execution_state = ? and execution_frequency = ?"
7307
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
7308
+						} else {
7309
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and execution_state = ?"
7310
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
7311
+						}
7312
+
7313
+					}
7314
+
7315
+				} else {
7316
+					if cost_type > 0 {
7317
+						adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  and is_settle = ? "
7318
+						adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
7319
+					} else {
7320
+						adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1   "
7321
+						adviceCondition = append(adviceCondition, adviceWhere, orgID)
7322
+					}
7323
+
7324
+				}
7325
+
7326
+			}
7327
+
7328
+		} else if patientType == 1 {
7329
+			if patient_id > 0 {
7330
+				if execution_state > 0 {
7331
+					if cost_type > 0 {
7332
+						if len(execution_frequency) > 0 {
7333
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and patient_id = ? and execution_state = ? and  is_settle = ? and execution_frequency = ?"
7334
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type, execution_frequency)
7335
+						} else {
7336
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and patient_id = ? and execution_state = ? and  is_settle = ?"
7337
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, cost_type)
7338
+						}
7339
+
7340
+					} else {
7341
+						if len(execution_frequency) > 0 {
7342
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and execution_state = ? and execution_frequency = ?"
7343
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state, execution_frequency)
7344
+						} else {
7345
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and patient_id = ? and execution_state = ?"
7346
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_state)
7347
+						}
7348
+
7349
+					}
7350
+
7351
+				} else {
7352
+					if cost_type > 0 {
7353
+						if len(execution_frequency) > 0 {
7354
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and patient_id = ? and is_settle = ?and execution_frequency = ?"
7355
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type, execution_frequency)
7356
+						} else {
7357
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ? and is_settle = ?"
7358
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, cost_type)
7359
+						}
7360
+
7361
+					} else {
7362
+						if len(execution_frequency) > 0 {
7363
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and patient_id = ? and execution_frequency = ?"
7364
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id, execution_frequency)
7365
+						} else {
7366
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and patient_id = ?"
7367
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, patient_id)
7368
+						}
7369
+
7370
+					}
7371
+
7372
+				}
7373
+
7374
+			} else {
7375
+				if execution_state > 0 {
7376
+					if cost_type > 0 {
7377
+						if len(execution_frequency) > 0 {
7378
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? and execution_state=? and is_settle = ?and execution_frequency = ?"
7379
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type, execution_frequency)
7380
+						} else {
7381
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and execution_state=? and is_settle = ?"
7382
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, cost_type)
7383
+						}
7384
+
7385
+					} else {
7386
+						if len(execution_frequency) > 0 {
7387
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and execution_state=?and execution_frequency = ?"
7388
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state, execution_frequency)
7389
+						} else {
7390
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and execution_state=?"
7391
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_state)
7392
+						}
7393
+
7394
+					}
7395
+
7396
+				} else {
7397
+					if cost_type > 0 {
7398
+						if len(execution_frequency) > 0 {
7399
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and  is_settle = ? and execution_frequency = ?"
7400
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type, execution_frequency)
7401
+						} else {
7402
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and  is_settle = ? "
7403
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, cost_type)
7404
+						}
7405
+
7406
+					} else {
7407
+						if len(execution_frequency) > 0 {
7408
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND advice_doctor = ? and execution_frequency = ?"
7409
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId, execution_frequency)
7410
+						} else {
7411
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND advice_doctor = ? "
7412
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, adminUserId)
7413
+						}
7414
+
7415
+					}
7416
+
7417
+				}
7418
+
7419
+			}
7420
+
7421
+		} else if patientType == 2 {
7422
+			if patient_id > 0 {
7423
+				if execution_state > 0 {
7424
+					if cost_type > 0 {
7425
+						if len(execution_frequency) > 0 {
7426
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?and execution_frequency = ?"
7427
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type, execution_frequency)
7428
+						} else {
7429
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and execution_state = ? and is_settle = ?"
7430
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, cost_type)
7431
+						}
7432
+
7433
+					} else {
7434
+						if len(execution_frequency) > 0 {
7435
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and execution_state = ? and execution_frequency = ?"
7436
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state, execution_frequency)
7437
+						} else {
7438
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and execution_state = ?"
7439
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_state)
7440
+						}
7441
+
7442
+					}
7443
+
7444
+				} else {
7445
+					if cost_type > 0 {
7446
+						if len(execution_frequency) > 0 {
7447
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and is_settle = ? and execution_frequency = ?"
7448
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type, execution_frequency)
7449
+						} else {
7450
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ? and is_settle = ?"
7451
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, cost_type)
7452
+						}
7453
+
7454
+					} else {
7455
+						if len(execution_frequency) > 0 {
7456
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and patient_id = ?  and execution_frequency = ?"
7457
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id, execution_frequency)
7458
+						} else {
7459
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and patient_id = ?"
7460
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, patient_id)
7461
+						}
7462
+
7463
+					}
7464
+
7465
+				}
7466
+			} else {
7467
+				if execution_state > 0 {
7468
+
7469
+					if cost_type > 0 {
7470
+						if len(execution_frequency) > 0 {
7471
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ? and execution_frequency = ?"
7472
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type, execution_frequency)
7473
+						} else {
7474
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1AND execution_staff = 0 and execution_state = ? and is_settle = ?"
7475
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, cost_type)
7476
+						}
7477
+
7478
+					} else {
7479
+						if len(execution_frequency) > 0 {
7480
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_state = ? and execution_frequency = ?"
7481
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state, execution_frequency)
7482
+						} else {
7483
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and execution_state = ?"
7484
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_state)
7485
+						}
7486
+
7487
+					}
7488
+
7489
+				} else {
7490
+
7491
+					if cost_type > 0 {
7492
+						if len(execution_frequency) > 0 {
7493
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and is_settle = ? and execution_frequency = ?"
7494
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type, execution_frequency)
7495
+						} else {
7496
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0 and is_settle = ?"
7497
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, cost_type)
7498
+						}
7499
+
7500
+					} else {
7501
+						if len(execution_frequency) > 0 {
7502
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND execution_staff = 0 and execution_frequency = ?"
7503
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, execution_frequency)
7504
+						} else {
7505
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1  AND execution_staff = 0"
7506
+							adviceCondition = append(adviceCondition, adviceWhere, orgID)
7507
+						}
7508
+
7509
+					}
7510
+
7511
+				}
7512
+
7513
+			}
7514
+
7515
+		}
7516
+
7517
+	}
7518
+
7519
+	db := readDb.Table("xt_schedule")
7520
+	if scheduleType > 0 {
7521
+		db = db.Where("schedule_type = ?", scheduleType)
7522
+	}
7523
+	if partitonType > 0 {
7524
+		db = db.Where("partition_id = ?", partitonType)
7525
+	}
7526
+	db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
7527
+		Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
7528
+			return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
7529
+		}).
7530
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
7531
+		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
7532
+		Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
7533
+		Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
7534
+		Preload("DoctorAdvices", adviceCondition...).
7535
+		Where("status = 1 AND user_org_id = ?", orgID)
7536
+	if scheduleDate != 0 {
7537
+		db = db.Where("schedule_date = ?", scheduleDate)
7538
+	}
7539
+
7540
+	err := db.Find(&vms).Error
7541
+	return vms, err
7542
+}