Browse Source

医保对接

csx 3 years ago
parent
commit
bf4cefb682
1 changed files with 28 additions and 13 deletions
  1. 28 13
      service/common_service.go

+ 28 - 13
service/common_service.go View File

@@ -986,11 +986,15 @@ func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto in
986 986
 	if endtime > 0 {
987 987
 		db = db.Where("x.inspect_date <=?", endtime)
988 988
 	}
989
-	if lapseto > 0 {
990
-		db = db.Joins("inner join xt_patients as p On p.id = x.patient_id AND p.lapseto = ?", lapseto)
989
+	if lapseto > 0 && origin > 0 {
990
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
991
+	}
992
+	if lapseto > 0 && origin == 0 {
993
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
991 994
 	}
992
-	if origin > 0 {
993
-		db = db.Joins("inner join xt_patients as p On p.id = x.patient_id AND p.source = ?", origin)
995
+
996
+	if lapseto == 0 && origin > 0 {
997
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
994 998
 	}
995 999
 	err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=q.min_range+0 and x.inspect_value +0 <= q.large_range+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
996 1000
 	return inspection, err
@@ -1009,12 +1013,15 @@ func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto
1009 1013
 	if endtime > 0 {
1010 1014
 		db = db.Where("x.inspect_date <=?", endtime)
1011 1015
 	}
1012
-
1013
-	if lapseto > 0 {
1014
-		db = db.Joins("inner join xt_patients as p On p.id = x.patient_id AND p.lapseto = ?", lapseto)
1016
+	if lapseto > 0 && origin > 0 {
1017
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
1015 1018
 	}
1016
-	if origin > 0 {
1017
-		db = db.Joins("inner join xt_patients as p On p.id = x.patient_id AND p.source = ?", origin)
1019
+	if lapseto > 0 && origin == 0 {
1020
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
1021
+	}
1022
+
1023
+	if lapseto == 0 && origin > 0 {
1024
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
1018 1025
 	}
1019 1026
 	err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when q.range_value = x.inspect_value and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
1020 1027
 	return inspection, err
@@ -2842,10 +2849,14 @@ func GetSystolicBloodPressure(orgid int64, startime int64, endtime int64) (recor
2842 2849
 func GetSystolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
2843 2850
 
2844 2851
 	db := XTReadDB().Table("xt_monitoring_record as x")
2845
-	if lapseto > 0 {
2852
+	if lapseto > 0 && origin > 0 {
2853
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
2854
+	}
2855
+	if lapseto > 0 && origin == 0 {
2846 2856
 		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
2847 2857
 	}
2848
-	if origin > 0 {
2858
+
2859
+	if lapseto == 0 && origin > 0 {
2849 2860
 		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
2850 2861
 	}
2851 2862
 	err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
@@ -2868,10 +2879,14 @@ func GetDiastolicBloodPressure(orgid int64, startime int64, endtime int64) (reco
2868 2879
 
2869 2880
 func GetDiastolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
2870 2881
 	db := XTReadDB().Table("xt_monitoring_record as x")
2871
-	if lapseto > 0 {
2882
+	if lapseto > 0 && origin > 0 {
2883
+		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
2884
+	}
2885
+	if lapseto > 0 && origin == 0 {
2872 2886
 		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
2873 2887
 	}
2874
-	if origin > 0 {
2888
+
2889
+	if lapseto == 0 && origin > 0 {
2875 2890
 		db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
2876 2891
 	}
2877 2892
 	err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error