|
@@ -204,19 +204,64 @@ func DeleteCheck(id int64) error {
|
204
|
204
|
return err
|
205
|
205
|
}
|
206
|
206
|
|
207
|
|
-func GetDialysiTotal(startime int64, endtime int64, orgid int64) (order []*models.DialysisOrder, total int64, err error) {
|
208
|
|
- err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
|
209
|
|
- return order, total, err
|
|
207
|
+//
|
|
208
|
+//func GetDialysiTotal(startime int64, endtime int64, orgid int64,lapsetotype int64,sourcetype int64) (order []*models.DialysisOrder, total int64, err error) {
|
|
209
|
+// err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
|
|
210
|
+// return order, total, err
|
|
211
|
+//}
|
|
212
|
+
|
|
213
|
+func GetDialysiTotal(startime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (models.PatientPrescriptionCountStruct, error) {
|
|
214
|
+ counts := models.PatientPrescriptionCountStruct{}
|
|
215
|
+
|
|
216
|
+ db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
|
|
217
|
+ table := XTReadDB().Table("xt_paitents as s").Where("s.status = 1")
|
|
218
|
+ fmt.Println(table)
|
|
219
|
+
|
|
220
|
+ if lapsetotype > 0 {
|
|
221
|
+ err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
222
|
+ }
|
|
223
|
+ if lapsetotype == 0 {
|
|
224
|
+ err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? ", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
225
|
+ }
|
|
226
|
+
|
|
227
|
+ if sourcetype > 0 {
|
|
228
|
+ err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
229
|
+ }
|
210
|
230
|
|
|
231
|
+ if sourcetype == 0 {
|
|
232
|
+ err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ?", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ return counts, err
|
211
|
236
|
}
|
212
|
237
|
|
213
|
|
-func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
|
214
|
|
- //err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
|
|
238
|
+func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
|
|
239
|
+
|
|
240
|
+ //err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
|
215
|
241
|
//return counts, err
|
216
|
242
|
|
217
|
|
- err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
|
|
243
|
+ db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
|
|
244
|
+ table := readDb.Table("xt_schedule as s").Where("s.status = 1")
|
|
245
|
+ fmt.Println(table)
|
|
246
|
+ p := readDb.Table("xt_patients as p").Where("p.status = 1")
|
|
247
|
+ fmt.Println(p)
|
|
248
|
+ if starttime > 0 {
|
|
249
|
+ db = db.Where("o.dialysis_date >=?", starttime)
|
|
250
|
+ }
|
|
251
|
+ if endtime > 0 {
|
|
252
|
+ db = db.Where("o.dialysis_date<=?", endtime)
|
|
253
|
+ }
|
|
254
|
+ if orgid > 0 {
|
|
255
|
+ db = db.Where("o.user_org_id = ?", orgid)
|
|
256
|
+ }
|
|
257
|
+ if lapsetotype > 0 {
|
|
258
|
+ db = db.Where("p.lapseto = ?", lapsetotype)
|
|
259
|
+ }
|
|
260
|
+ if sourcetype > 0 {
|
|
261
|
+ db = db.Where("p.source = ?", sourcetype)
|
|
262
|
+ }
|
|
263
|
+ err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id and s.schedule_date = o.dialysis_date and s.status= 1").Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
|
218
|
264
|
return counts, err
|
219
|
|
-
|
220
|
265
|
}
|
221
|
266
|
|
222
|
267
|
func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
|
|
@@ -228,22 +273,41 @@ func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*mod
|
228
|
273
|
return counts, total, err
|
229
|
274
|
}
|
230
|
275
|
|
231
|
|
-func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
|
|
276
|
+func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
|
|
277
|
+
|
|
278
|
+ db := XTReadDB().Table("xt_patients as x")
|
232
|
279
|
|
233
|
|
- db := XTReadDB().Table("x.patients as x")
|
234
|
|
- err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
|
|
280
|
+ if sourcetype == 0 {
|
|
281
|
+ err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
|
|
282
|
+ }
|
|
283
|
+ if sourcetype > 0 {
|
|
284
|
+ err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
|
|
285
|
+ }
|
235
|
286
|
return patients, err
|
236
|
287
|
}
|
237
|
288
|
|
238
|
|
-func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
|
|
289
|
+func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
|
|
290
|
+
|
|
291
|
+ db := XTReadDB().Table("xt_patients as x")
|
|
292
|
+ if sourcetype == 0 {
|
|
293
|
+ err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
|
239
|
294
|
|
240
|
|
- db := XTReadDB().Table("x.patients as x")
|
241
|
|
- err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
|
|
295
|
+ }
|
|
296
|
+ if sourcetype > 0 {
|
|
297
|
+ err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
|
|
298
|
+ }
|
242
|
299
|
return patients, err
|
243
|
300
|
}
|
244
|
301
|
|
245
|
|
-func GetPatientTotalCount(orgID int64) (total int64) {
|
246
|
|
- readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
|
|
302
|
+func GetPatientTotalCount(orgID int64, lapsetotype int64, sourcetype int64) (total int64) {
|
|
303
|
+ db := readDb.Table("xt_patients as x")
|
|
304
|
+ //if lapsetotype > 0 {
|
|
305
|
+ // db = db.Where("x.lapseto = ?", lapsetotype)
|
|
306
|
+ //}
|
|
307
|
+ //if sourcetype > 0 {
|
|
308
|
+ // db = db.Where("x.source = ?", sourcetype)
|
|
309
|
+ //}
|
|
310
|
+ db.Where("x.user_org_id=? and x.status=1", orgID).Count(&total)
|
247
|
311
|
return
|
248
|
312
|
}
|
249
|
313
|
|
|
@@ -263,9 +327,28 @@ func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialy
|
263
|
327
|
|
264
|
328
|
}
|
265
|
329
|
|
266
|
|
-func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64, err error) {
|
|
330
|
+func GetManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
|
267
|
331
|
|
268
|
|
- err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and gender = 1", orgid).Count(&total).Find(&patients).Error
|
|
332
|
+ db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
|
|
333
|
+ if lapsetotype > 0 {
|
|
334
|
+ db = db.Where("x.lapseto = ?", lapsetotype)
|
|
335
|
+ }
|
|
336
|
+ if sourcetype > 0 {
|
|
337
|
+ db = db.Where("x.source = ?", sourcetype)
|
|
338
|
+ }
|
|
339
|
+ err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 1", orgid).Count(&total).Find(&patients).Error
|
|
340
|
+ return patients, total, err
|
|
341
|
+}
|
|
342
|
+
|
|
343
|
+func GetWoManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
|
|
344
|
+ db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
|
|
345
|
+ if lapsetotype > 0 {
|
|
346
|
+ db = db.Where("x.lapseto = ?", lapsetotype)
|
|
347
|
+ }
|
|
348
|
+ if sourcetype > 0 {
|
|
349
|
+ db = db.Where("x.source = ?", sourcetype)
|
|
350
|
+ }
|
|
351
|
+ err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 2", orgid).Count(&total).Find(&patients).Error
|
269
|
352
|
return patients, total, err
|
270
|
353
|
}
|
271
|
354
|
|
|
@@ -274,10 +357,25 @@ func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64
|
274
|
357
|
// return counts, err
|
275
|
358
|
//}
|
276
|
359
|
|
277
|
|
-func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
|
|
360
|
+func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientContagionsCountStruct, err error) {
|
|
361
|
+
|
|
362
|
+ if lapsetotype == 0 {
|
|
363
|
+ err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
|
|
364
|
+ }
|
|
365
|
+ if sourcetype == 0 {
|
|
366
|
+ err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
|
|
367
|
+ }
|
|
368
|
+
|
|
369
|
+ if lapsetotype > 0 {
|
|
370
|
+ err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.lapseto = ?", orgid, startime, endtime, lapsetotype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
|
|
371
|
+ }
|
|
372
|
+
|
|
373
|
+ if sourcetype > 0 {
|
|
374
|
+ err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.source = ?", orgid, startime, endtime, sourcetype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
|
|
375
|
+ }
|
278
|
376
|
|
279
|
|
- err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
|
280
|
377
|
return counts, err
|
|
378
|
+
|
281
|
379
|
}
|
282
|
380
|
|
283
|
381
|
func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
|
|
@@ -286,9 +384,10 @@ func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, tota
|
286
|
384
|
return patients, total, err
|
287
|
385
|
}
|
288
|
386
|
|
289
|
|
-func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err error) {
|
|
387
|
+func GetTotalAgeCount(orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientAgeCountStruct, err error) {
|
290
|
388
|
|
291
|
|
- readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
389
|
+ if lapsetotype == 0 || sourcetype == 0 {
|
|
390
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
292
|
391
|
SELECT
|
293
|
392
|
CASE
|
294
|
393
|
WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
|
|
@@ -299,8 +398,39 @@ func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err
|
299
|
398
|
END
|
300
|
399
|
AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
|
301
|
400
|
)a GROUP BY nnd`, orgid).Scan(&counts)
|
302
|
|
- return
|
303
|
401
|
|
|
402
|
+ }
|
|
403
|
+
|
|
404
|
+ if lapsetotype > 0 {
|
|
405
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
406
|
+ SELECT
|
|
407
|
+ CASE
|
|
408
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
|
|
409
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
|
|
410
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
|
|
411
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
|
|
412
|
+ ELSE '150'
|
|
413
|
+ END
|
|
414
|
+ AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.lapseto = ?
|
|
415
|
+ )a GROUP BY nnd`, orgid, lapsetotype).Scan(&counts)
|
|
416
|
+
|
|
417
|
+ }
|
|
418
|
+
|
|
419
|
+ if sourcetype > 0 {
|
|
420
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
421
|
+ SELECT
|
|
422
|
+ CASE
|
|
423
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
|
|
424
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
|
|
425
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
|
|
426
|
+ WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
|
|
427
|
+ ELSE '150'
|
|
428
|
+ END
|
|
429
|
+ AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.source = ?
|
|
430
|
+ )a GROUP BY nnd`, orgid, sourcetype).Scan(&counts)
|
|
431
|
+
|
|
432
|
+ }
|
|
433
|
+ return
|
304
|
434
|
}
|
305
|
435
|
|
306
|
436
|
func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
|
|
@@ -320,18 +450,42 @@ func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err e
|
320
|
450
|
return patients, err
|
321
|
451
|
}
|
322
|
452
|
|
323
|
|
-func GetDialysisAgeData(orgID int64) (counts []*models.DialysisAgePieDataStruct, err error) {
|
|
453
|
+func GetDialysisAgeData(orgID int64, lapsetotype int64, sourcetype int64) (counts []*models.DialysisAgePieDataStruct, err error) {
|
324
|
454
|
|
325
|
|
- readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
326
|
|
- SELECT
|
327
|
|
- CASE
|
328
|
|
- WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
|
329
|
|
- WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
|
330
|
|
- WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
|
331
|
|
- WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
|
332
|
|
- END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0)a GROUP BY nnd`, orgID).Scan(&counts)
|
333
|
|
- return
|
|
455
|
+ if lapsetotype == 0 || sourcetype == 0 {
|
|
456
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
457
|
+ SELECT
|
|
458
|
+ CASE
|
|
459
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
|
|
460
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
|
|
461
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
|
|
462
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
|
|
463
|
+ END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0)a GROUP BY nnd`, orgID).Scan(&counts)
|
|
464
|
+ }
|
|
465
|
+
|
|
466
|
+ if lapsetotype > 0 {
|
|
467
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
468
|
+ SELECT
|
|
469
|
+ CASE
|
|
470
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
|
|
471
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
|
|
472
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
|
|
473
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
|
|
474
|
+ END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.lapseto = ?)a GROUP BY nnd`, orgID, lapsetotype).Scan(&counts)
|
|
475
|
+ }
|
|
476
|
+
|
|
477
|
+ if sourcetype > 0 {
|
|
478
|
+ readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
|
|
479
|
+ SELECT
|
|
480
|
+ CASE
|
|
481
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
|
|
482
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
|
|
483
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
|
|
484
|
+ WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
|
|
485
|
+ END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.source = ?)a GROUP BY nnd`, orgID, sourcetype).Scan(&counts)
|
|
486
|
+ }
|
334
|
487
|
|
|
488
|
+ return
|
335
|
489
|
}
|
336
|
490
|
|
337
|
491
|
func GetCurentOrgPatients(orgid int64) (patients []*models.BloodXtPatients, err error) {
|
|
@@ -3375,7 +3529,7 @@ func GetCountModeId(startime int64, endtime int64, modeid int64, orgid int64) (o
|
3375
|
3529
|
|
3376
|
3530
|
}
|
3377
|
3531
|
|
3378
|
|
-func GetCountRollout(orgid int64, startime int64, endtime int64) (lapseto []*models.BloodLapsetoCount, err error) {
|
|
3532
|
+func GetCountRollout(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (lapseto []*models.BloodLapsetoCount, err error) {
|
3379
|
3533
|
|
3380
|
3534
|
table := XTReadDB().Table("xt_patients as s")
|
3381
|
3535
|
fmt.Println(table)
|
|
@@ -3386,6 +3540,15 @@ func GetCountRollout(orgid int64, startime int64, endtime int64) (lapseto []*mod
|
3386
|
3540
|
if endtime > 0 {
|
3387
|
3541
|
db = db.Where("x.lapseto_time<=?", endtime)
|
3388
|
3542
|
}
|
3389
|
|
- err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ?", orgid).Scan(&lapseto).Error
|
|
3543
|
+ if lapsetotype == 0 || sourcetype == 0 {
|
|
3544
|
+ err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ?", orgid).Scan(&lapseto).Error
|
|
3545
|
+ }
|
|
3546
|
+
|
|
3547
|
+ if lapsetotype > 0 {
|
|
3548
|
+ err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.lapseto = ?", orgid, lapsetotype).Scan(&lapseto).Error
|
|
3549
|
+ }
|
|
3550
|
+ if sourcetype > 0 {
|
|
3551
|
+ err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.source = ?", orgid, sourcetype).Scan(&lapseto).Error
|
|
3552
|
+ }
|
3390
|
3553
|
return lapseto, err
|
3391
|
3554
|
}
|