|
@@ -6,7 +6,7 @@ import (
|
6
|
6
|
"time"
|
7
|
7
|
)
|
8
|
8
|
|
9
|
|
-func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.ChargePatient, err error) {
|
|
9
|
+func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargePatient, err error) {
|
10
|
10
|
if len(keyword) == 0 {
|
11
|
11
|
switch item_type {
|
12
|
12
|
case 0:
|
|
@@ -152,6 +152,150 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
|
152
|
152
|
return
|
153
|
153
|
}
|
154
|
154
|
|
|
155
|
+func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
|
|
156
|
+ if len(keyword) == 0 {
|
|
157
|
+ switch item_type {
|
|
158
|
+ case 0:
|
|
159
|
+ err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
|
|
160
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
161
|
+ Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
|
|
162
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
|
|
163
|
+ Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
|
|
164
|
+ Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
165
|
+ break
|
|
166
|
+ case 1:
|
|
167
|
+ err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
|
|
168
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
169
|
+ Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
|
|
170
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
|
|
171
|
+ Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
|
|
172
|
+ Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
173
|
+ break
|
|
174
|
+
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ } else {
|
|
178
|
+ keyword := "%" + keyword + "%"
|
|
179
|
+ switch item_type {
|
|
180
|
+ case 0:
|
|
181
|
+ err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
|
|
182
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
183
|
+ Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
|
|
184
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
|
|
185
|
+ Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
|
|
186
|
+ Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
187
|
+
|
|
188
|
+ break
|
|
189
|
+ case 1:
|
|
190
|
+ err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
|
|
191
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
192
|
+ Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
|
|
193
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
|
|
194
|
+ Joins(" JOIN xt_base_drug drug on a.drug_id = drug.id").
|
|
195
|
+ Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
196
|
+
|
|
197
|
+ break
|
|
198
|
+
|
|
199
|
+ }
|
|
200
|
+
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ return
|
|
204
|
+}
|
|
205
|
+func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
|
|
206
|
+ if len(keyword) == 0 {
|
|
207
|
+ switch item_type {
|
|
208
|
+ case 0:
|
|
209
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
210
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
211
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
|
|
212
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
213
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
214
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
|
|
215
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
216
|
+
|
|
217
|
+ //err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
|
|
218
|
+ // return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
|
|
219
|
+ // Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
|
|
220
|
+ // return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
|
|
221
|
+ // Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
|
|
222
|
+ // return db.Preload("Drug", "status = 1").Where("status = 1")
|
|
223
|
+ // }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
|
|
224
|
+ // return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
|
|
225
|
+ // return db.Select("id,project_name,unit").Where("status = 1 ")
|
|
226
|
+ // }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
|
|
227
|
+ // return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
|
|
228
|
+ // }).Where("status = 1 ")
|
|
229
|
+ // }).Where("status = 1")
|
|
230
|
+ // }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
|
|
231
|
+ //}).Where("p.status = 1 AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
|
|
232
|
+
|
|
233
|
+ break
|
|
234
|
+ case 2:
|
|
235
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
236
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
237
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
|
|
238
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
239
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
240
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
|
|
241
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
242
|
+
|
|
243
|
+ break
|
|
244
|
+ case 3:
|
|
245
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
246
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
247
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
|
|
248
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
249
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
250
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
|
|
251
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
252
|
+
|
|
253
|
+ break
|
|
254
|
+
|
|
255
|
+ }
|
|
256
|
+
|
|
257
|
+ } else {
|
|
258
|
+ keyword := "%" + keyword + "%"
|
|
259
|
+ switch item_type {
|
|
260
|
+ case 0:
|
|
261
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
262
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
263
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
|
|
264
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
265
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
266
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
|
|
267
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
268
|
+
|
|
269
|
+ break
|
|
270
|
+
|
|
271
|
+ case 2:
|
|
272
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
273
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
274
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
|
|
275
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
276
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
277
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
|
|
278
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
279
|
+
|
|
280
|
+ break
|
|
281
|
+ case 3:
|
|
282
|
+ err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type, (case p.type when 2 then project.project_name when 3 then good.good_name END) as item_name,(case p.type when 2 then '' when 3 then good.specification_name END) as specification_name, p.project_id as item_id").
|
|
283
|
+ Joins("JOIN his_order o ON oi.order_number = o.number and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
|
|
284
|
+ Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
|
|
285
|
+ Joins(" join xt_his_project project on p.project_id = project.id").
|
|
286
|
+ Joins(" join xt_good_information good on p.project_id = good.id").
|
|
287
|
+ Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
|
|
288
|
+ Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ? and oi.`upload_date` <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
|
|
289
|
+
|
|
290
|
+ break
|
|
291
|
+
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+ }
|
|
295
|
+
|
|
296
|
+ return
|
|
297
|
+}
|
|
298
|
+
|
155
|
299
|
func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.SettlePatient, err error) {
|
156
|
300
|
if len(keyword) == 0 {
|
157
|
301
|
switch item_type {
|