Browse Source

患者检验检查统计开发

XMLWAN 4 years ago
parent
commit
7085aac183

+ 4 - 4
controllers/base_api_controller.go View File

@@ -79,7 +79,7 @@ func (this *BaseAuthAPIController) Prepare() {
79 79
 		userAdmin.ModifyTime = 1530786071
80 80
 		var subscibe models.ServeSubscibe
81 81
 		subscibe.ID = 1
82
-		subscibe.OrgId = 9841
82
+		subscibe.OrgId = 7957
83 83
 		subscibe.PeriodStart = 1538035409
84 84
 		subscibe.PeriodEnd = 1569571409
85 85
 		subscibe.State = 1
@@ -89,7 +89,7 @@ func (this *BaseAuthAPIController) Prepare() {
89 89
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
90 90
 		subscibes[4] = &subscibe
91 91
 		var adminUserInfo service.AdminUserInfo
92
-		adminUserInfo.CurrentOrgId = 9841
92
+		adminUserInfo.CurrentOrgId = 7957
93 93
 		adminUserInfo.CurrentAppId = 18
94 94
 		adminUserInfo.AdminUser = &userAdmin
95 95
 		adminUserInfo.Subscibes = subscibes
@@ -329,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
329 329
 		userAdmin.ModifyTime = 1530786071
330 330
 		var subscibe models.ServeSubscibe
331 331
 		subscibe.ID = 1
332
-		subscibe.OrgId = 9841
332
+		subscibe.OrgId = 7957
333 333
 		subscibe.PeriodStart = 1538035409
334 334
 		subscibe.PeriodEnd = 1569571409
335 335
 		subscibe.State = 1
@@ -339,7 +339,7 @@ func (this *BaseServeAPIController) Prepare() {
339 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342
-		adminUserInfo.CurrentOrgId = 9841
342
+		adminUserInfo.CurrentOrgId = 7957
343 343
 		adminUserInfo.CurrentAppId = 18
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes

+ 49 - 17
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -21,7 +21,7 @@ func (this *CommonApiController) GetInspectionMajor() {
21 21
 	adminInfo := this.GetAdminUserInfo()
22 22
 	orgid := adminInfo.CurrentOrgId
23 23
 	major, err := service.GetInspectionMajor(orgid)
24
-	fmt.Println("major====================================", major)
24
+
25 25
 	if len(major) == 0 {
26 26
 		major, _ := service.GetInspectionMajor(0)
27 27
 		if err != nil {
@@ -99,7 +99,13 @@ func (this *CommonApiController) SaveConfiguration() {
99 99
 	sort := dataBody["sort"].(string)
100 100
 	sorts, err := strconv.ParseInt(sort, 10, 64)
101 101
 	fmt.Println("sort", sort)
102
-
102
+	checktype := int64(dataBody["check_type"].(float64))
103
+	fmt.Println("检查类型", checktype)
104
+	rangvalue := dataBody["range_value"].(string)
105
+	fmt.Println("rangvalue", rangvalue)
106
+	if rangvalue == "0" {
107
+		rangvalue = ""
108
+	}
103 109
 	_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
104 110
 	if errcode == gorm.ErrRecordNotFound {
105 111
 		standard := models.XtQualityControlStandard{
@@ -110,6 +116,8 @@ func (this *CommonApiController) SaveConfiguration() {
110 116
 			Sort:            sorts,
111 117
 			UserOrgId:       orgid,
112 118
 			Status:          1,
119
+			RangeType:       checktype,
120
+			RangeValue:      rangvalue,
113 121
 			CreatedTime:     time.Now().Unix(),
114 122
 		}
115 123
 		fmt.Println(standard)
@@ -185,6 +193,12 @@ func (this *CommonApiController) UpdateConfiguration() {
185 193
 	fmt.Println("largerange", largerange)
186 194
 	sort := int64(dataBody["sort"].(float64))
187 195
 	fmt.Println("排序", sort)
196
+	rangvalue := dataBody["range_value"].(string)
197
+	fmt.Println("范围", rangvalue)
198
+	if rangvalue == "0" {
199
+		rangvalue = ""
200
+	}
201
+	rangtype := int64(dataBody["check_type"].(float64))
188 202
 	adminInfo := this.GetAdminUserInfo()
189 203
 	orgId := adminInfo.CurrentOrgId
190 204
 	configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
@@ -199,6 +213,8 @@ func (this *CommonApiController) UpdateConfiguration() {
199 213
 		MinRange:        minrange,
200 214
 		LargeRange:      largerange,
201 215
 		Sort:            sort,
216
+		RangeValue:      rangvalue,
217
+		RangeType:       rangtype,
202 218
 	}
203 219
 	err = service.UpdarteConfiguration(&standard, id)
204 220
 	if err != nil {
@@ -396,19 +412,24 @@ func (this *CommonApiController) GetDialysisModeType() {
396 412
 }
397 413
 
398 414
 func (this *CommonApiController) GetTotalLapseCount() {
415
+	timeLayout := "2006-01-02"
416
+	loc, _ := time.LoadLocation("Local")
399 417
 	adminUser := this.GetAdminUserInfo()
400 418
 	orgid := adminUser.CurrentOrgId
401
-	startime, _ := this.GetInt64("startime")
402
-	fmt.Println("startime", startime)
403
-	endtime, _ := this.GetInt64("endtime")
404
-	fmt.Println("endtime", endtime)
405
-
419
+	startime := this.GetString("startime")
420
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
421
+	startnunix := startTimes.Unix()
422
+	//fmt.Println("开始时间==========",startnunix)
423
+	endtime := this.GetString("endtime")
424
+	endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 23:59:59", loc)
425
+	endunix := endtimes.Unix()
426
+	//fmt.Println("结束日期========",endunix)
406 427
 	//统计一个月内转出的病人
407 428
 	//patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
408 429
 	//统计该机构的转出人数
409
-	patients, err := service.GetTotalRollOutPatients(orgid, startime, endtime)
430
+	patients, err := service.GetTotalRollOutPatients(orgid, startnunix, endunix)
410 431
 	//统计该机构转出病人
411
-	patienttwo, err := service.GetTotalRollOutPatientsTwo(orgid, startime, endtime)
432
+	patienttwo, err := service.GetTotalRollOutPatientsTwo(orgid, startnunix, endunix)
412 433
 	//统计总共病人
413 434
 	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
414 435
 	count := service.GetPatientTotalCount(orgid)
@@ -449,14 +470,18 @@ func (this *CommonApiController) GetTotalInfectiouscount() {
449 470
 	adminUser := this.GetAdminUserInfo()
450 471
 	orgid := adminUser.CurrentOrgId
451 472
 	fmt.Println("orgid", orgid)
452
-	startime, _ := this.GetInt64("startime")
453
-	fmt.Println("开始时间", startime)
454
-	endtime, _ := this.GetInt64("endtime")
455
-	fmt.Println("结束时间", endtime)
473
+	timeLayout := "2006-01-02"
474
+	loc, _ := time.LoadLocation("Local")
475
+	startime := this.GetString("startime")
476
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
477
+	startnunix := startTimes.Unix()
478
+	endtime := this.GetString("endtime")
479
+	endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 23:59:59", loc)
480
+	endunix := endtimes.Unix()
456 481
 	//统计透析总人数
457 482
 	total := service.GetPatientTotalCount(orgid)
458 483
 	//统计透析人数传染病所占比例
459
-	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
484
+	count, err := service.GetPatientInfectiousCount(orgid, startnunix, endunix)
460 485
 	//统计其他
461 486
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
462 487
 	if err != nil {
@@ -559,7 +584,7 @@ func (this *CommonApiController) GetDialysislist() {
559 584
 	fmt.Println("limit", limit)
560 585
 	adminUser := this.GetAdminUserInfo()
561 586
 	orgId := adminUser.CurrentOrgId
562
-
587
+	count, _ := service.TotalDialysisCount(statime, entime, orgId)
563 588
 	dialysislist, total, err := service.GetDialysisList(statime, entime, page, limit, orgId)
564 589
 	prescriptionList, _ := service.GetAllDialysisList(statime, entime, orgId)
565 590
 	list, totallist, _ := service.GetDialysisPatientList(statime, entime, page, limit, orgId)
@@ -574,6 +599,7 @@ func (this *CommonApiController) GetDialysislist() {
574 599
 		"list":             list,
575 600
 		"totallist":        totallist,
576 601
 		"prescriptionList": prescriptionList,
602
+		"count":            count,
577 603
 	})
578 604
 }
579 605
 
@@ -933,13 +959,17 @@ func (this *CommonApiController) GetFirstQuarter() {
933 959
 	fmt.Println("结束日期", entime)
934 960
 	//group, parseDateErr := service.GetItemNameGroup(orgid, statime, entime)
935 961
 	//quarter, err := service.GetFirstQuarter(orgid, statime, entime)
962
+	//统计数值类型的数据
936 963
 	count, err := service.GetQuarterTotalCount(orgid, statime, entime, lapseto)
964
+	//统计rang_type== 2
965
+	countwo, _ := service.GetQuarterTotalCountTwo(orgid, statime, entime, lapseto)
937 966
 	if err != nil {
938 967
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
939 968
 		return
940 969
 	}
941 970
 	this.ServeSuccessJSON(map[string]interface{}{
942
-		"count": count,
971
+		"count":   count,
972
+		"countwo": countwo,
943 973
 	})
944 974
 }
945 975
 
@@ -1005,12 +1035,14 @@ func (this *CommonApiController) GetProjectList() {
1005 1035
 	fourQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", fourQuarterEndStr)
1006 1036
 	fourQuarterEndStrUnix := fourQuarterEnds.Unix()
1007 1037
 	fmt.Println("第四季度结束时间", fourQuarterEndStrUnix)
1038
+	rangetype, parseDateErr := this.GetInt64("range_type")
1008 1039
 	//按季度统计
1009
-	if itemtype == 1 {
1040
+	if rangetype == 1 {
1010 1041
 		//统计总共
1011 1042
 		list, err := service.GetProjectList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1012 1043
 		//统计达标个数
1013 1044
 		standList, err := service.GetProjectStandList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1045
+
1014 1046
 		if err != nil {
1015 1047
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1016 1048
 			return

+ 15 - 3
models/common_models.go View File

@@ -11,6 +11,8 @@ type QualityControlStandard struct {
11 11
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
12 12
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
13 13
 	LargeRange      string `gorm:"column:large_range" json:"large_range" form:"large_range"`
14
+	RangeType       int64  `gorm:"column:range_type" json:"range_type" form:"range_type"`
15
+	RangeValue      string `gorm:"column:range_value" json:"range_value" form:"range_value"`
14 16
 	Unit            string `gorm:"column:unit" json:"unit" form:"unit"`
15 17
 	ProjectName     string `gorm:"column:project_name" json:"project_name" form:"project_name"`
16 18
 	ItemName        string `gorm:"column:item_name" json:"item_name" form:"item_name"`
@@ -27,6 +29,8 @@ type XtQualityControlStandard struct {
27 29
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
28 30
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
29 31
 	LargeRange      string `gorm:"column:large_range" json:"large_range" form:"large_range"`
32
+	RangeType       int64  `gorm:"column:range_type" json:"range_type" form:"range_type"`
33
+	RangeValue      string `gorm:"column:range_value" json:"range_value" form:"range_value"`
30 34
 }
31 35
 
32 36
 func (XtQualityControlStandard) TableName() string {
@@ -308,6 +312,7 @@ type VmPatientInspectionTwo struct {
308 312
 	ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
309 313
 	Total  int64
310 314
 	Count  int64
315
+	Sort   int64 `gorm:"column:sort" json:"sort" form:"sort"`
311 316
 }
312 317
 
313 318
 type VmPatientInspection struct {
@@ -383,9 +388,11 @@ type PatientInspectionProjectCount struct {
383 388
 }
384 389
 
385 390
 type ProjectCountOne struct {
386
-	Total   string
387
-	Count   int64
388
-	NoCount int64
391
+	Total      string
392
+	Count      int64
393
+	NoCount    int64
394
+	MinRange   string `gorm:"column:min_range" json:"min_range" form:"min_range"`
395
+	LargeRange string `gorm:"column:large_range" json:"large_range" form:"large_range"`
389 396
 }
390 397
 
391 398
 type ProjectCount struct {
@@ -421,6 +428,11 @@ func (PatientInspectionCount) TableName() string {
421 428
 	return "xt_inspection"
422 429
 }
423 430
 
431
+type BloodDialysisOrderCount struct {
432
+	PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
433
+	Count     int64
434
+}
435
+
424 436
 type BloodDialysisOrder struct {
425 437
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
426 438
 	DialysisDate       int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`

+ 48 - 10
service/common_service.go View File

@@ -10,7 +10,7 @@ import (
10 10
 
11 11
 func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
12 12
 
13
-	err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1 and range_type = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
13
+	err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
14 14
 	return inspection, err
15 15
 }
16 16
 
@@ -78,7 +78,7 @@ func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReferenc
78 78
 
79 79
 func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
80 80
 
81
-	err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "updated_time": time.Now().Unix()}).Error
81
+	err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "range_value": st.RangeValue, "range_type": st.RangeType, "updated_time": time.Now().Unix()}).Error
82 82
 	return err
83 83
 }
84 84
 
@@ -297,6 +297,14 @@ func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error
297 297
 	return patients, err
298 298
 }
299 299
 
300
+func TotalDialysisCount(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
301
+
302
+	db := XTReadDB().Table("xt_dialysis_order as o")
303
+
304
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ?", startime, endtime, orgid).Group("o.patient_id").Scan(&order).Error
305
+	return order, err
306
+}
307
+
300 308
 func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
301 309
 
302 310
 	db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
@@ -750,7 +758,7 @@ func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard,
750 758
 	table := XTReadDB().Table("xt_inspection_reference as s")
751 759
 	fmt.Println(table)
752 760
 
753
-	err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
761
+	err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name,x.range_value,x.range_type").
754 762
 		Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
755 763
 	return standard, err
756 764
 }
@@ -811,10 +819,10 @@ func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto in
811 819
 	fmt.Println(table)
812 820
 	d := XTReadDB().Table("xt_patients as s")
813 821
 	fmt.Println(d)
814
-	//d2 := XTReadDB().Table("xt_quality_control_standard as p")
815
-	//fmt.Println(d2)
822
+	q := XTReadDB().Table("x.xt_quality_control_standard as q")
823
+	fmt.Println(q)
816 824
 	if orgid > 0 {
817
-		db = db.Where("x.org_id = ? and x.inspect_value <> 0", orgid)
825
+		db = db.Where("x.org_id = ? and x.inspect_value <> 0 and r.range_type = 1", orgid)
818 826
 	}
819 827
 	if startime > 0 {
820 828
 		db = db.Where("x.inspect_date >=?", startime)
@@ -828,7 +836,35 @@ func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto in
828 836
 	if lapseto > 0 {
829 837
 		db = db.Where("s.lapseto = ?", lapseto)
830 838
 	}
831
-	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>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id", 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_patients as  s on s.id = x.patient_id").Scan(&inspection).Error
839
+	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_patients as  s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
840
+	return inspection, err
841
+}
842
+
843
+func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspectionTwo, err error) {
844
+
845
+	db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
846
+	table := XTReadDB().Table("xt_inspection_reference as r")
847
+	fmt.Println(table)
848
+	d := XTReadDB().Table("xt_patients as s")
849
+	fmt.Println(d)
850
+	q := XTReadDB().Table("x.xt_quality_control_standard as q")
851
+	fmt.Println(q)
852
+	if orgid > 0 {
853
+		db = db.Where("x.org_id = ?  and r.range_type = 2", orgid)
854
+	}
855
+	if startime > 0 {
856
+		db = db.Where("x.inspect_date >=?", startime)
857
+	}
858
+	if endtime > 0 {
859
+		db = db.Where("x.inspect_date <=?", endtime)
860
+	}
861
+	if lapseto == 0 {
862
+		db = db.Where("s.lapseto = 1 or s.lapseto = 2")
863
+	}
864
+	if lapseto > 0 {
865
+		db = db.Where("s.lapseto = ?", lapseto)
866
+	}
867
+	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_patients as  s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
832 868
 	return inspection, err
833 869
 }
834 870
 
@@ -847,7 +883,7 @@ func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64,
847 883
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
848 884
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
849 885
 			" ELSE '其他'" +
850
-			"END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
886
+			"END AS nnd FROM xt_inspection as x  left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and x.inspect_value <> 0"
851 887
 		countParams := make([]interface{}, 0)
852 888
 		countParams = append(countParams, firststart)
853 889
 		countParams = append(countParams, firstend)
@@ -992,16 +1028,18 @@ func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime in
992 1028
 		fmt.Println("d", d)
993 1029
 		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
994 1030
 		table := XTReadDB().Table("xt_inspection_reference as r")
1031
+		//q := XTReadDB().Table("xt_quality_control_standard as q")
1032
+		//fmt.Println("q",q)
995 1033
 		fmt.Println(table)
996 1034
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
997 1035
 			"SELECT " +
998 1036
 			"CASE " +
999 1037
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '第一季度'" +
1000
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
1038
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <=  r.range_max+0 THEN '第二季度'" +
1001 1039
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
1002 1040
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
1003 1041
 			" ELSE '其他'" +
1004
-			"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1042
+			"END AS nnd FROM xt_inspection as x  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) left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= range_max+0)"
1005 1043
 		countParams := make([]interface{}, 0)
1006 1044
 		countParams = append(countParams, firststart)
1007 1045
 		countParams = append(countParams, firstend)