|
@@ -46,11 +46,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
|
46
|
46
|
var tmp []*models.TmpTTT
|
47
|
47
|
if is_medicine == 0 {
|
48
|
48
|
err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
|
49
|
|
- "status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
|
|
49
|
+ "status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
|
50
|
50
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
|
51
|
51
|
"union "+
|
52
|
52
|
"select distinct patient_id from xt_doctor_advice where "+
|
53
|
|
- "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
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
|
54
|
54
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
|
55
|
55
|
stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
|
56
|
56
|
if err != nil {
|
|
@@ -58,11 +58,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
|
58
|
58
|
}
|
59
|
59
|
} else {
|
60
|
60
|
err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
|
61
|
|
- "status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
|
|
61
|
+ "status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
|
62
|
62
|
"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
|
63
|
63
|
"union "+
|
64
|
64
|
"select distinct patient_id from xt_doctor_advice where "+
|
65
|
|
- "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
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
|
66
|
66
|
"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
|
67
|
67
|
stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
|
68
|
68
|
if err != nil {
|
|
@@ -74,6 +74,52 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
|
74
|
74
|
|
75
|
75
|
}
|
76
|
76
|
|
|
77
|
+func GetTodayAdviceCount(stime, etime, orgid, is_medicine int64) (num int, err error) {
|
|
78
|
+
|
|
79
|
+ //orgid = 9675
|
|
80
|
+ InitDrugidIsNil(orgid, stime, etime)
|
|
81
|
+ var tmp []*models.TmpTTT
|
|
82
|
+ if is_medicine == 0 {
|
|
83
|
+ err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=0 group by patient_id",
|
|
84
|
+ stime, etime, orgid).Scan(&tmp).Error
|
|
85
|
+ if err != nil {
|
|
86
|
+ return
|
|
87
|
+ }
|
|
88
|
+ } else {
|
|
89
|
+ err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=1 group by patient_id",
|
|
90
|
+ stime, etime, orgid).Scan(&tmp).Error
|
|
91
|
+ if err != nil {
|
|
92
|
+ return
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ return len(tmp), err
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+func GetTodayAdviceCountOne(stime int64, etime int64, orgid int64, is_medicine int64) (advice []*models.HisDoctorAdviceInfo, err error) {
|
|
100
|
+
|
|
101
|
+ db := XTReadDB().Model(&advice).Where("status=1 and is_medicine = ?", is_medicine)
|
|
102
|
+ if stime > 0 {
|
|
103
|
+ db = db.Where("advice_date>=?", stime)
|
|
104
|
+ }
|
|
105
|
+ if etime > 0 {
|
|
106
|
+ db = db.Where("advice_date<=?", stime)
|
|
107
|
+ }
|
|
108
|
+ if orgid > 0 {
|
|
109
|
+ db = db.Where("user_org_id = ?", orgid)
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ err = db.Group("patient_id").Find(&advice).Error
|
|
113
|
+ return advice, err
|
|
114
|
+}
|
|
115
|
+
|
|
116
|
+func GetPatientByAdviceId(patient_id int64) (models.TmpPatientOne, error) {
|
|
117
|
+
|
|
118
|
+ patient := models.TmpPatientOne{}
|
|
119
|
+ err = XTReadDB().Where("id = ?", patient_id).Find(&patient).Error
|
|
120
|
+ return patient, err
|
|
121
|
+}
|
|
122
|
+
|
77
|
123
|
// (改)
|
78
|
124
|
func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
|
79
|
125
|
InitDrugidIsNil(orgid, stime, etime)
|
|
@@ -84,22 +130,22 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
|
84
|
130
|
if keyword != "" {
|
85
|
131
|
keyword = "%" + keyword + "%"
|
86
|
132
|
err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
|
87
|
|
- "status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
|
|
133
|
+ "status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
|
88
|
134
|
"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
|
89
|
135
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
|
90
|
136
|
"union "+
|
91
|
137
|
"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
|
92
|
|
- "status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
|
|
138
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
|
93
|
139
|
"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
|
94
|
140
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
|
95
|
141
|
stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
|
96
|
142
|
} else {
|
97
|
143
|
err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
|
98
|
|
- "status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
|
|
144
|
+ "status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
|
99
|
145
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
|
100
|
146
|
"union "+
|
101
|
147
|
"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
|
102
|
|
- "status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
|
|
148
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
|
103
|
149
|
"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
|
104
|
150
|
stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
|
105
|
151
|
}
|
|
@@ -172,13 +218,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
|
172
|
218
|
var tmp []*models.HisDoctorAdviceInfoL
|
173
|
219
|
if is_medicine == 0 {
|
174
|
220
|
err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
|
175
|
|
- "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
|
|
221
|
+ "status = 1 and advice_date >= ? and advice_date <= ? 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
|
176
|
222
|
if err != nil {
|
177
|
223
|
return pp, err
|
178
|
224
|
}
|
179
|
225
|
} else {
|
180
|
226
|
err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
|
181
|
|
- "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
|
|
227
|
+ "status = 1 and advice_date >= ? and advice_date <= ? 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
|
182
|
228
|
if err != nil {
|
183
|
229
|
return pp, err
|
184
|
230
|
}
|
|
@@ -201,13 +247,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
|
201
|
247
|
var tmp_advice []*models.XtDoctorAdviceL
|
202
|
248
|
if is_medicine == 0 {
|
203
|
249
|
err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
|
204
|
|
- "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
|
|
250
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? 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
|
205
|
251
|
if err != nil {
|
206
|
252
|
return pp, err
|
207
|
253
|
}
|
208
|
254
|
} else {
|
209
|
255
|
err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
|
210
|
|
- "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
|
|
256
|
+ "status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? 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
|
211
|
257
|
if err != nil {
|
212
|
258
|
return pp, err
|
213
|
259
|
}
|
|
@@ -580,7 +626,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
|
580
|
626
|
time_now := time.Now().Unix()
|
581
|
627
|
var hids []*models.TmpID
|
582
|
628
|
var xids []*models.TmpID
|
583
|
|
- err = tx.Raw("select id from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
|
|
629
|
+ err = tx.Raw("select id from his_doctor_advice_info where status = 1 and advice_date >= ? and advice_date <= ? "+
|
584
|
630
|
"and user_org_id = ? and patient_id = ? and is_medicine = 0 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
|
585
|
631
|
if err != nil {
|
586
|
632
|
return
|
|
@@ -629,7 +675,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
|
629
|
675
|
return err1
|
630
|
676
|
}
|
631
|
677
|
|
632
|
|
- err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
|
|
678
|
+ err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and "+
|
633
|
679
|
"user_org_id = ? and patient_id = ? and is_medicine = 0 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
|
634
|
680
|
if err != nil {
|
635
|
681
|
return
|
|
@@ -1911,3 +1957,24 @@ func GetAllValidDeviceZones02(orgID int64) ([]*models.DeviceZone, error) {
|
1911
|
1957
|
}
|
1912
|
1958
|
return zones, nil
|
1913
|
1959
|
}
|
|
1960
|
+
|
|
1961
|
+func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
|
|
1962
|
+
|
|
1963
|
+ db := XTReadDB().Model(&advice).Where("status= 1")
|
|
1964
|
+
|
|
1965
|
+ if orgid > 0 {
|
|
1966
|
+ db = db.Where("user_org_id = ?", orgid)
|
|
1967
|
+ }
|
|
1968
|
+ if patient_id > 0 {
|
|
1969
|
+ db = db.Where("patient_id = ?", patient_id)
|
|
1970
|
+ }
|
|
1971
|
+ if stime > 0 {
|
|
1972
|
+ db = db.Where("advice_date >=?", stime)
|
|
1973
|
+ }
|
|
1974
|
+ if etime > 0 {
|
|
1975
|
+ db = db.Where("advice_date<=?", etime)
|
|
1976
|
+ }
|
|
1977
|
+ err = db.Find(&advice).Error
|
|
1978
|
+
|
|
1979
|
+ return advice, err
|
|
1980
|
+}
|