mainqaq пре 2 година
родитељ
комит
20ee98baa1
2 измењених фајлова са 160 додато и 70 уклоњено
  1. 159 69
      service/pharmacy_service.go
  2. 1 1
      service/warhouse_service.go

+ 159 - 69
service/pharmacy_service.go Прегледај датотеку

@@ -40,19 +40,35 @@ func SavePharmacy() (err error) {
40 40
 
41 41
 //查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42 42
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
43
+	//orgid = 9675
43 44
 	InitDrugidIsNil(orgid, stime, etime)
44 45
 	var tmp []*models.TmpTTT
45
-	err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
46
-		"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
47
-		"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
48
-		"union "+
49
-		"select distinct patient_id from xt_doctor_advice where "+
50
-		"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
51
-		"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
52
-		stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
53
-	if err != nil {
54
-		return
46
+	if is_medicine == 0 {
47
+		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
48
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
49
+			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
50
+			"union "+
51
+			"select distinct patient_id from xt_doctor_advice where "+
52
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
53
+			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
54
+			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
55
+		if err != nil {
56
+			return
57
+		}
58
+	} else {
59
+		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
60
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
61
+			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
62
+			"union "+
63
+			"select distinct patient_id from xt_doctor_advice where "+
64
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
65
+			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
66
+			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
67
+		if err != nil {
68
+			return
69
+		}
55 70
 	}
71
+
56 72
 	return len(tmp), err
57 73
 
58 74
 }
@@ -63,32 +79,62 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
63 79
 	//病人
64 80
 	var tmp []*models.TmpTTT
65 81
 	//tmp := make([]string,0)
66
-	if keyword != "" {
67
-		keyword = "%" + keyword + "%"
68
-		err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
69
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
70
-			"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
71
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
72
-			"union "+
73
-			"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
74
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
75
-			"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
76
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
77
-			stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
82
+	if is_medicine == 0 {
83
+		if keyword != "" {
84
+			keyword = "%" + keyword + "%"
85
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
86
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
87
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
88
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
89
+				"union "+
90
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
91
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
92
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
93
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
94
+				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
95
+		} else {
96
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
97
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
98
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
99
+				"union "+
100
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
101
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
102
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
103
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
104
+		}
105
+
106
+		if err != nil {
107
+			return
108
+		}
78 109
 	} else {
79
-		err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
80
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
81
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
82
-			"union "+
83
-			"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
84
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
85
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
86
-			stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
87
-	}
110
+		if keyword != "" {
111
+			keyword = "%" + keyword + "%"
112
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
113
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
114
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
115
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
116
+				"union "+
117
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
118
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
119
+				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
120
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1))a order by dispensing_time desc ",
121
+				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
122
+		} else {
123
+			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
124
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
125
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
126
+				"union "+
127
+				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
128
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
129
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1))a order by dispensing_time desc",
130
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
131
+		}
88 132
 
89
-	if err != nil {
90
-		return
133
+		if err != nil {
134
+			return
135
+		}
91 136
 	}
137
+
92 138
 	tmp_s := make([]int64, 0)
93 139
 	s_map := make(map[int64]int64)
94 140
 	for _, v := range tmp {
@@ -123,11 +169,20 @@ func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
123 169
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
124 170
 	InitDrugidIsNil(orgid, stime, etime)
125 171
 	var tmp []*models.HisDoctorAdviceInfoL
126
-	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
127
-		"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
128
-	if err != nil {
129
-		return pp, err
172
+	if is_medicine == 0 {
173
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
174
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
175
+		if err != nil {
176
+			return pp, err
177
+		}
178
+	} else {
179
+		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
180
+			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
181
+		if err != nil {
182
+			return pp, err
183
+		}
130 184
 	}
185
+
131 186
 	for _, v := range tmp {
132 187
 		pp = append(pp, &models.PharmacyContent{
133 188
 			Name:         v.AdviceName,
@@ -143,11 +198,20 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
143 198
 	}
144 199
 
145 200
 	var tmp_advice []*models.XtDoctorAdviceL
146
-	err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
147
-		"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
148
-	if err != nil {
149
-		return pp, err
201
+	if is_medicine == 0 {
202
+		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
203
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
204
+		if err != nil {
205
+			return pp, err
206
+		}
207
+	} else {
208
+		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
209
+			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
210
+		if err != nil {
211
+			return pp, err
212
+		}
150 213
 	}
214
+
151 215
 	for _, v := range tmp_advice {
152 216
 		pp = append(pp, &models.PharmacyContent{
153 217
 			Name:         v.AdviceName,
@@ -267,7 +331,7 @@ func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword strin
267 331
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
268 332
 	var tmp []*models.HisDoctorAdviceInfoL
269 333
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
270
-		"status = 1 and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", patient_id, orgid, record_date, orgid).Find(&tmp).Error
334
+		"status = 1 and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", patient_id, orgid, record_date, orgid).Find(&tmp).Error
271 335
 	if err != nil {
272 336
 		return
273 337
 	}
@@ -286,7 +350,7 @@ func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.Pr
286 350
 
287 351
 	var tmp_advice []*models.XtDoctorAdviceL
288 352
 	err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
289
-		"status = 1 and (advice_type = 2 or advice_type = 3) and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", patient_id, orgid, record_date, orgid).Find(&tmp_advice).Error
353
+		"status = 1 and (advice_type = 2 or advice_type = 3) and patient_id = ? and user_org_id = ? and dispensing_time = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", patient_id, orgid, record_date, orgid).Find(&tmp_advice).Error
290 354
 	if err != nil {
291 355
 		return
292 356
 	}
@@ -341,30 +405,56 @@ func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDru
341 405
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
342 406
 	InitDrugidIsNil(orgid, stime, etime)
343 407
 	var tmp []*models.TmpLLL
344
-	if keyword != "" {
345
-		keyword = "%" + keyword + "%"
346
-		err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
347
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
348
-			"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
349
-			"union "+
350
-			"select distinct drug_id from xt_doctor_advice where "+
351
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
352
-			"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
353
-			stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
408
+	if is_medicine == 0 {
409
+		if keyword != "" {
410
+			keyword = "%" + keyword + "%"
411
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
412
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
413
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
414
+				"union "+
415
+				"select distinct drug_id from xt_doctor_advice where "+
416
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
417
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
418
+				stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
419
+		} else {
420
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
421
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
422
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
423
+				"union "+
424
+				"select distinct drug_id from xt_doctor_advice where "+
425
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
426
+				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
427
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
428
+		}
429
+		if err != nil {
430
+			return
431
+		}
354 432
 	} else {
355
-		err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
356
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
357
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
358
-			"union "+
359
-			"select distinct drug_id from xt_doctor_advice where "+
360
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
361
-			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
362
-			stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
433
+		if keyword != "" {
434
+			keyword = "%" + keyword + "%"
435
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
436
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
437
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1) "+
438
+				"union "+
439
+				"select distinct drug_id from xt_doctor_advice where "+
440
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
441
+				"drug_id in (select id from xt_base_drug where org_id = ? and drug_name like ? and is_pharmacy = 1)",
442
+				stime, etime, orgid, is_medicine, orgid, keyword, stime, etime, orgid, is_medicine, orgid, keyword).Scan(&tmp).Error
443
+		} else {
444
+			err = XTReadDB().Raw("select distinct drug_id from his_doctor_advice_info where "+
445
+				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
446
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
447
+				"union "+
448
+				"select distinct drug_id from xt_doctor_advice where "+
449
+				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
450
+				"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
451
+				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
452
+		}
453
+		if err != nil {
454
+			return
455
+		}
363 456
 	}
364 457
 
365
-	if err != nil {
366
-		return
367
-	}
368 458
 	for _, v := range tmp {
369 459
 		name, specifications := FindDrugSpecifications(v.DrugId)
370 460
 		number, errs := GetInventoryQuantity(orgid, v.DrugId)
@@ -607,7 +697,7 @@ func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error)
607 697
 	var xids []*models.TmpID
608 698
 	//var hid,xid []int64//查询已发药的药品
609 699
 	err = tx.Raw("select id,dispensing_time from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
610
-		"and user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
700
+		"and user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
611 701
 	if err != nil {
612 702
 		return
613 703
 	}
@@ -655,7 +745,7 @@ func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error)
655 745
 	}
656 746
 
657 747
 	err = tx.Raw("select id,dispensing_time from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
658
-		"user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
748
+		"user_org_id = ? and patient_id = ? and is_medicine = 1 and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
659 749
 	if err != nil {
660 750
 		return
661 751
 	}
@@ -700,7 +790,7 @@ func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error)
700 790
 
701 791
 	//删除掉发药明细
702 792
 	for k, _ := range map_time {
703
-		err = tx.Model(&models.Pharmary{}).Where("user_org_id = ? and record_date = ? ", orgid, k).Updates(map[string]interface{}{
793
+		err = tx.Model(&models.Pharmary{}).Where("user_org_id = ? and record_date = ? and patient_id = ? ", orgid, k, patient_id).Updates(map[string]interface{}{
704 794
 			"status": 0,
705 795
 			"mtime":  time.Now().Unix(),
706 796
 		}).Error
@@ -954,10 +1044,10 @@ func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name str
954 1044
 	var tmp []*models.TmpAdviceDoctor
955 1045
 	//var tmp []int64
956 1046
 	err = XTReadDB().Raw("select distinct advice_doctor from his_doctor_advice_info where "+
957
-		"status = 1 and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
1047
+		"status = 1 and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
958 1048
 		"union "+
959 1049
 		"select distinct advice_doctor from xt_doctor_advice where "+
960
-		"status = 1 and (advice_type = 2 or advice_type = 3) and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
1050
+		"status = 1 and (advice_type = 2 or advice_type = 3) and dispensing_time = ? and user_org_id = ? and is_medicine = 1 and patient_id = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
961 1051
 		recordtime, orgid, id, orgid, recordtime, orgid, id, orgid).Scan(&tmp).Error
962 1052
 	if err != nil || len(tmp) == 0 {
963 1053
 		return

+ 1 - 1
service/warhouse_service.go Прегледај датотеку

@@ -268,7 +268,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
268 268
 				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
269 269
 			}
270 270
 
271
-			if minNumber == 0 && maxNumber != 1 {
271
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
272 272
 				if warehouse.StockMinNumber > 0 {
273 273
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
274 274
 				}