Browse Source

库存调拨修改

28169 2 years ago
parent
commit
495b498b72

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

@@ -840,6 +840,30 @@ func (c *DialysisAPIController) PostDoubleCheck() {
840 840
 		doubleCheck.Modifier = modifier
841 841
 
842 842
 		err := service.AddSigleDoubleCheck(&doubleCheck)
843
+
844
+		//针对长沙南雅
845
+		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
846
+			//查询未核对的医嘱
847
+			doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
848
+			if len(doctorList) > 0 && modifier > 0 {
849
+				for _, advice := range doctorList {
850
+					service.UpdateDoctorAdviceList(advice.ID, modifier)
851
+					key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
852
+					redis := service.RedisClient()
853
+					//清空key 值
854
+					redis.Set(key, "", time.Second)
855
+					keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
856
+					redis.Set(keyTwo, "", time.Second)
857
+					theTime := time.Now()
858
+					recordDate := theTime.Format("2006-01-02")
859
+					keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
860
+					redis.Set(keyFour, "", time.Second)
861
+					defer redis.Close()
862
+				}
863
+			}
864
+
865
+		}
866
+
843 867
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
844 868
 		redis := service.RedisClient()
845 869
 

+ 16 - 0
models/schedule_models.go View File

@@ -631,3 +631,19 @@ type ScheduleNewPatients struct {
631 631
 func (ScheduleNewPatients) TableName() string {
632 632
 	return "xt_schedule"
633 633
 }
634
+
635
+type MySchedule struct {
636
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
637
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
638
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
639
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
640
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
641
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
642
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
643
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
644
+	Count        int64
645
+}
646
+
647
+func (MySchedule) TableName() string {
648
+	return "xt_schedule"
649
+}

+ 53 - 40
service/dialysis_service.go View File

@@ -10,7 +10,7 @@ import (
10 10
 	"time"
11 11
 )
12 12
 
13
-//GetPatientList 返回患者的列表
13
+// GetPatientList 返回患者的列表
14 14
 func GetSchedualPatientList(orgID int64, schedulDate int64, schedulType int64, partitionType int64, keywords string, page int64, limit int64) (schedule []*models.DialysisSchedule, err error) {
15 15
 	var total int64
16 16
 	//if len(keywords) > 0 {
@@ -62,7 +62,7 @@ func GetSchedualPatientList(orgID int64, schedulDate int64, schedulType int64, p
62 62
 	return schedule, errors
63 63
 }
64 64
 
65
-//用户基本信息
65
+// 用户基本信息
66 66
 func FindPatientInfoById(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) {
67 67
 	err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB {
68 68
 		return db.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).Where("patient_id = ? AND user_org_id = ? AND schedule_date = ? ", id, orgID, time)
@@ -70,31 +70,31 @@ func FindPatientInfoById(orgID int64, id int64, time int64) (patient models.Sche
70 70
 	return
71 71
 }
72 72
 
73
-//透析处方
73
+// 透析处方
74 74
 func FindPatientPrescribeById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescription, err error) {
75 75
 	err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id=? and status=1 and  record_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
76 76
 	return
77 77
 }
78 78
 
79
-//透析方案中的透析处方
79
+// 透析方案中的透析处方
80 80
 func FindDialysisSolution(orgID int64, patientsId int64) (patient models.DialysisSolution, err error) {
81 81
 	err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id=? and status=1", patientsId, orgID).Last(&patient).Error
82 82
 	return
83 83
 }
84 84
 
85
-//透析方案中的透析模式
85
+// 透析方案中的透析模式
86 86
 func FindTreatmentModeById(modeId int64) (mode models.TreatmentMode, err error) {
87 87
 	err = readDb.Model(&models.TreatmentMode{}).Where("id = ? AND status=1", modeId).First(&mode).Error
88 88
 	return
89 89
 }
90 90
 
91
-//接诊评估
91
+// 接诊评估
92 92
 func FindReceiverTreatmentAccessRecordById(orgID int64, patientsId int64, recordDate int64) (receiveTreatmentAsses models.ReceiveTreatmentAsses, err error) {
93 93
 	err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ?", patientsId, orgID, recordDate).First(&receiveTreatmentAsses).Error
94 94
 	return
95 95
 }
96 96
 
97
-//透前评估
97
+// 透前评估
98 98
 func FindPredialysisEvaluationById(orgID int64, patientsId int64, recordDate int64) (patient models.PredialysisEvaluation, err error) {
99 99
 	err = readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ?", patientsId, orgID, recordDate).First(&patient).Error
100 100
 	return
@@ -106,7 +106,7 @@ func FindPredialysisName(id int64, orgid int64) (models.Dataconfig, error) {
106 106
 	return dataconfig, err
107 107
 }
108 108
 
109
-//临时医嘱
109
+// 临时医嘱
110 110
 func FindDoctorAdviceById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
111 111
 	err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? AND  advice_type = 2", patientsId, orgID, recordDate).Find(&patient).Error
112 112
 	return
@@ -128,7 +128,7 @@ func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.Dialysi
128 128
 	return order, total, err
129 129
 }
130 130
 
131
-//临时医嘱
131
+// 临时医嘱
132 132
 func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
133 133
 	err = readDb.Model(&models.DoctorAdvice{}).
134 134
 		Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate).
@@ -137,13 +137,13 @@ func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64)
137 137
 	return
138 138
 }
139 139
 
140
-//双人核对
140
+// 双人核对
141 141
 func FindDoubleCheckById(orgID int64, patientsId int64, recordDate int64) (patient models.DoubleCheck, err error) {
142 142
 	err = readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id=? and status=1 and check_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
143 143
 	return
144 144
 }
145 145
 
146
-//透析监测
146
+// 透析监测
147 147
 func FindAllMonitorRecord(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
148 148
 	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error
149 149
 	return
@@ -154,37 +154,37 @@ func FindAllMonitor(orgID int64, patientsId int64, recordDate int64) (record []*
154 154
 	return
155 155
 }
156 156
 
157
-//透后评估
157
+// 透后评估
158 158
 func FindAssessmentAfterDislysisById(orgID int64, patientsId int64, recordDate int64) (patient models.AssessmentAfterDislysis, err error) {
159 159
 	err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date =?", patientsId, orgID, recordDate).First(&patient).Error
160 160
 	return
161 161
 }
162 162
 
163
-//治疗小结
163
+// 治疗小结
164 164
 func FindTreatmentSummaryById(orgID int64, patientsId int64, recordDate int64) (patient models.TreatmentSummary, err error) {
165 165
 	err = readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
166 166
 	return
167 167
 }
168 168
 
169
-//机构叫号配置
169
+// 机构叫号配置
170 170
 func FindQueueCallInfo(orgID int64) (queueConfig models.QueueCallConfig, err error) {
171 171
 	err = readDb.Model(&models.QueueCallConfig{}).Where("org_id=? ", orgID).First(&queueConfig).Error
172 172
 	return
173 173
 }
174 174
 
175
-//修改机构叫号配置
175
+// 修改机构叫号配置
176 176
 func UpDateQueueCallInfo(queueConfig models.QueueCallConfig) error {
177 177
 	err := writeDb.Save(&queueConfig).Error
178 178
 	return err
179 179
 }
180 180
 
181
-//所有设备信息
181
+// 所有设备信息
182 182
 func FindAllDeviceInfo(orgID int64) (device []*models.Device, err error) {
183 183
 	err = readDb.Model(&models.Device{}).Where("org_id=? and status=1 and device_type = 1", orgID).Find(&device).Error
184 184
 	return device, err
185 185
 }
186 186
 
187
-//所有设备区域
187
+// 所有设备区域
188 188
 func GetAllDeviceZone(orgId int64) (error, []*models.DeviceZone) {
189 189
 	var zone []*models.DeviceZone
190 190
 	err := readDb.Model(&zone).Where("org_id = ? AND status = 1", orgId).Find(&zone).Error
@@ -192,7 +192,7 @@ func GetAllDeviceZone(orgId int64) (error, []*models.DeviceZone) {
192 192
 	return err, zone
193 193
 }
194 194
 
195
-//获取所有子药物
195
+// 获取所有子药物
196 196
 func FindAllSubDoctorAdvice(id int64, parentId int64) (error, []models.DoctorAdvice) {
197 197
 	var subAdvies []models.DoctorAdvice
198 198
 	err := readDb.Model(&subAdvies).Where("patient_id = ? AND parent_id = ?", id, parentId).Find(&subAdvies).Error
@@ -272,7 +272,7 @@ func AddSigleDoubleCheck(check *models.DoubleCheck) (err error) {
272 272
 	return errors
273 273
 }
274 274
 
275
-//修改透析处方
275
+// 修改透析处方
276 276
 func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error {
277 277
 	tx := writeDb.Begin()
278 278
 	err := writeDb.Save(&dialysisPrescription).Error
@@ -283,25 +283,25 @@ func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescriptio
283 283
 	return err
284 284
 }
285 285
 
286
-//修改接诊评估
286
+// 修改接诊评估
287 287
 func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error {
288 288
 	err := writeDb.Save(receiveTreatmentAsses).Error
289 289
 	return err
290 290
 }
291 291
 
292
-//修改透前评估
292
+// 修改透前评估
293 293
 func UpadatePredialysisEvaluation(predialysisEvaluation *models.PredialysisEvaluation) error {
294 294
 	err := writeDb.Save(&predialysisEvaluation).Error
295 295
 	return err
296 296
 }
297 297
 
298
-//修改双人核对
298
+// 修改双人核对
299 299
 func UpdateDoubleCheck(check *models.DoubleCheck) error {
300 300
 	err := writeDb.Save(&check).Error
301 301
 	return err
302 302
 }
303 303
 
304
-//修改透后评估
304
+// 修改透后评估
305 305
 func UpdateAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) error {
306 306
 	err := writeDb.Save(&assessmentAfterDislysis).Error
307 307
 	return err
@@ -330,21 +330,21 @@ func UpdatePredialysisEvaluationFour(predialysisevaluation *models.PredialysisEv
330 330
 	return err
331 331
 }
332 332
 
333
-//修改
333
+// 修改
334 334
 func UpdateSummeRecord(treatmentSummary *models.TreatmentSummary) error {
335 335
 	err := writeDb.Save(&treatmentSummary).Error
336 336
 	return err
337 337
 }
338 338
 
339
-// func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
340
-// 	tx := writeDb.Begin()
341
-// 	err := tx.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1, "checker": m.Checker}).Error
342
-// 	if err != nil {
343
-// 		tx.Rollback()
344
-// 	}
345
-// 	tx.Commit()
346
-// 	return err
347
-// }
339
+//	func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
340
+//		tx := writeDb.Begin()
341
+//		err := tx.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1, "checker": m.Checker}).Error
342
+//		if err != nil {
343
+//			tx.Rollback()
344
+//		}
345
+//		tx.Commit()
346
+//		return err
347
+//	}
348 348
 func ExceDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error {
349 349
 	err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND (id = ? Or parent_id=?)  AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error
350 350
 	return err
@@ -412,7 +412,7 @@ func UpdateSolution(solution *models.DialysisSolution) {
412 412
 
413 413
 }
414 414
 
415
-//创建长期处方
415
+// 创建长期处方
416 416
 func CreateSolution(solution *models.DialysisSolution) {
417 417
 	writeDb.Create(&solution)
418 418
 }
@@ -442,7 +442,7 @@ func SavePrescriptionAndCreateSolution(solution *models.DialysisSolution, prescr
442 442
 	return
443 443
 }
444 444
 
445
-//透析处方
445
+// 透析处方
446 446
 func FindDialysisPrescriptionByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DialysisPrescription) {
447 447
 	dialysisPrescription := models.DialysisPrescription{}
448 448
 	err := readDb.Model(&dialysisPrescription).Where("patient_id = ? AND  record_date = ? AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).Find(&dialysisPrescription).Error
@@ -455,14 +455,14 @@ func FindReceiveTreatmentAssesByReordDate(id int64, recordDate int64, orgId int6
455 455
 	return err, &receiveTreatmentAsses
456 456
 }
457 457
 
458
-//透前评估
458
+// 透前评估
459 459
 func FindPredialysisEvaluationByReordDate(id int64, recordDate int64, orgId int64) (error, *models.PredialysisEvaluation) {
460 460
 	dialysisEvaluation := models.PredialysisEvaluation{}
461 461
 	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? AND  assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&dialysisEvaluation).Error
462 462
 	return err, &dialysisEvaluation
463 463
 }
464 464
 
465
-//双人核对
465
+// 双人核对
466 466
 func FindDoubleCheckByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoubleCheck) {
467 467
 	check := models.DoubleCheck{}
468 468
 	err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? AND  check_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&check).Error
@@ -571,7 +571,7 @@ func UpdateSolutionByPatientId(id int64) error {
571 571
 
572 572
 }
573 573
 
574
-//更新透析处方记录ID
574
+// 更新透析处方记录ID
575 575
 func UpDateRecordIdToDialysisPrescription(patientId int64, orgId int64, recordTime int64, recordId int64) error {
576 576
 	errors := writeDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"record_id": recordId}).Error
577 577
 	return errors
@@ -612,7 +612,7 @@ func UpDateRecordIdToDoctorAdvice(patientId int64, orgId int64, recordTime int64
612 612
 	return errors
613 613
 }
614 614
 
615
-//透析处方
615
+// 透析处方
616 616
 func FindPatientPrescribeWidyDevideById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescriptionAddtional, err error) {
617 617
 	err = readDb.Preload("Device", "status = 1 AND org_id = ?", orgID).
618 618
 		Model(&models.DialysisPrescriptionAddtional{}).
@@ -687,7 +687,7 @@ func FindDoctorName(adminid int64, appid int64, orgid int64) (models.App_Roles,
687 687
 	return role, err
688 688
 }
689 689
 
690
-/////////////// 新 18-10-22
690
+// ///////////// 新 18-10-22
691 691
 func GetDialysisScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
692 692
 	var vms []*MDialysisScheduleVM
693 693
 	db := readDb.
@@ -2051,3 +2051,16 @@ func GetFiledConfig(orgid int64) (models.FiledConfig, error) {
2051 2051
 	err := XTReadDB().Where("filed_name = 'dialyzer_perfusion_apparatus' and org_id = ? and module =1 and is_show = 1", orgid).First(&config).Error
2052 2052
 	return config, err
2053 2053
 }
2054
+
2055
+func GetDoctorAdviceCheckList(patient_id int64, advice_date int64, user_org_id int64) (doctor []*models.DoctorAdvice, err error) {
2056
+
2057
+	err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id =? and status= 1 and check_state= 0", patient_id, advice_date, user_org_id).Find(&doctor).Error
2058
+	return doctor, err
2059
+}
2060
+
2061
+func UpdateDoctorAdviceList(id int64, checker int64) error {
2062
+
2063
+	advice := models.DoctorAdvice{}
2064
+	err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
2065
+	return err
2066
+}

+ 25 - 0
service/schedule_service.go View File

@@ -129,6 +129,31 @@ func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, schedule
129 129
 	return
130 130
 }
131 131
 
132
+func GetScheduleTotalCount(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.MySchedule, err error) {
133
+
134
+	db := readDb.Table("xt_schedule as s").Where("status= 1 and (mode_id = 2 or mode_id= 3)")
135
+	if len(schIds) > 0 {
136
+		db = db.Where("s.partition_id in (?)", schIds)
137
+	}
138
+	if scheduletype > 0 {
139
+		db = db.Where("s.schedule_type = ?", scheduletype)
140
+	}
141
+	if orgID > 0 {
142
+		db = db.Where("s.user_org_id = ?", orgID)
143
+	}
144
+	if start > 0 {
145
+		db = db.Where("s.schedule_date>=?", start)
146
+	}
147
+	if end > 0 {
148
+		db = db.Where("s.schedule_date<=?", end)
149
+	}
150
+
151
+	err = db.Select("Count(id) as count,schedule_date,mode_id,user_org_id,schedule_week,schedule_type").Group("schedule_date,schedule_type,mode_id").Find(&schedules).Error
152
+
153
+	return schedules, err
154
+
155
+}
156
+
132 157
 func GetWeekScheduleThree(orgID int64, start, end int64, schIds []string, scheduletype int64, WeekDayIds []string) (schedules []*models.Schedule, err error) {
133 158
 
134 159
 	db := readDb.Table("xt_schedule as s")