Browse Source

Merge branch 'xt_statistics_branch' of http://git.shengws.com/csx/XT_New into xt_statistics_branch

csx 4 years ago
parent
commit
3bb36351b0

+ 4 - 4
controllers/base_api_controller.go View File

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

+ 50 - 18
controllers/new_mobile_api_controllers/common_api_controller.go View File

21
 	adminInfo := this.GetAdminUserInfo()
21
 	adminInfo := this.GetAdminUserInfo()
22
 	orgid := adminInfo.CurrentOrgId
22
 	orgid := adminInfo.CurrentOrgId
23
 	major, err := service.GetInspectionMajor(orgid)
23
 	major, err := service.GetInspectionMajor(orgid)
24
-	fmt.Println("major====================================", major)
24
+
25
 	if len(major) == 0 {
25
 	if len(major) == 0 {
26
 		major, _ := service.GetInspectionMajor(0)
26
 		major, _ := service.GetInspectionMajor(0)
27
 		if err != nil {
27
 		if err != nil {
99
 	sort := dataBody["sort"].(string)
99
 	sort := dataBody["sort"].(string)
100
 	sorts, err := strconv.ParseInt(sort, 10, 64)
100
 	sorts, err := strconv.ParseInt(sort, 10, 64)
101
 	fmt.Println("sort", sort)
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
 	_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
109
 	_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
104
 	if errcode == gorm.ErrRecordNotFound {
110
 	if errcode == gorm.ErrRecordNotFound {
105
 		standard := models.XtQualityControlStandard{
111
 		standard := models.XtQualityControlStandard{
110
 			Sort:            sorts,
116
 			Sort:            sorts,
111
 			UserOrgId:       orgid,
117
 			UserOrgId:       orgid,
112
 			Status:          1,
118
 			Status:          1,
119
+			RangeType:       checktype,
120
+			RangeValue:      rangvalue,
113
 			CreatedTime:     time.Now().Unix(),
121
 			CreatedTime:     time.Now().Unix(),
114
 		}
122
 		}
115
 		fmt.Println(standard)
123
 		fmt.Println(standard)
185
 	fmt.Println("largerange", largerange)
193
 	fmt.Println("largerange", largerange)
186
 	sort := int64(dataBody["sort"].(float64))
194
 	sort := int64(dataBody["sort"].(float64))
187
 	fmt.Println("排序", sort)
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
 	adminInfo := this.GetAdminUserInfo()
202
 	adminInfo := this.GetAdminUserInfo()
189
 	orgId := adminInfo.CurrentOrgId
203
 	orgId := adminInfo.CurrentOrgId
190
 	configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
204
 	configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
199
 		MinRange:        minrange,
213
 		MinRange:        minrange,
200
 		LargeRange:      largerange,
214
 		LargeRange:      largerange,
201
 		Sort:            sort,
215
 		Sort:            sort,
216
+		RangeValue:      rangvalue,
217
+		RangeType:       rangtype,
202
 	}
218
 	}
203
 	err = service.UpdarteConfiguration(&standard, id)
219
 	err = service.UpdarteConfiguration(&standard, id)
204
 	if err != nil {
220
 	if err != nil {
396
 }
412
 }
397
 
413
 
398
 func (this *CommonApiController) GetTotalLapseCount() {
414
 func (this *CommonApiController) GetTotalLapseCount() {
415
+	timeLayout := "2006-01-02"
416
+	loc, _ := time.LoadLocation("Local")
399
 	adminUser := this.GetAdminUserInfo()
417
 	adminUser := this.GetAdminUserInfo()
400
 	orgid := adminUser.CurrentOrgId
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
 	//patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
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
 	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
434
 	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
414
 	count := service.GetPatientTotalCount(orgid)
435
 	count := service.GetPatientTotalCount(orgid)
449
 	adminUser := this.GetAdminUserInfo()
470
 	adminUser := this.GetAdminUserInfo()
450
 	orgid := adminUser.CurrentOrgId
471
 	orgid := adminUser.CurrentOrgId
451
 	fmt.Println("orgid", orgid)
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
 	total := service.GetPatientTotalCount(orgid)
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
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
486
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
462
 	if err != nil {
487
 	if err != nil {
559
 	fmt.Println("limit", limit)
584
 	fmt.Println("limit", limit)
560
 	adminUser := this.GetAdminUserInfo()
585
 	adminUser := this.GetAdminUserInfo()
561
 	orgId := adminUser.CurrentOrgId
586
 	orgId := adminUser.CurrentOrgId
562
-
587
+	count, _ := service.TotalDialysisCount(statime, entime, orgId)
563
 	dialysislist, total, err := service.GetDialysisList(statime, entime, page, limit, orgId)
588
 	dialysislist, total, err := service.GetDialysisList(statime, entime, page, limit, orgId)
564
 	prescriptionList, _ := service.GetAllDialysisList(statime, entime, orgId)
589
 	prescriptionList, _ := service.GetAllDialysisList(statime, entime, orgId)
565
 	list, totallist, _ := service.GetDialysisPatientList(statime, entime, page, limit, orgId)
590
 	list, totallist, _ := service.GetDialysisPatientList(statime, entime, page, limit, orgId)
574
 		"list":             list,
599
 		"list":             list,
575
 		"totallist":        totallist,
600
 		"totallist":        totallist,
576
 		"prescriptionList": prescriptionList,
601
 		"prescriptionList": prescriptionList,
602
+		"count":            count,
577
 	})
603
 	})
578
 }
604
 }
579
 
605
 
933
 	fmt.Println("结束日期", entime)
959
 	fmt.Println("结束日期", entime)
934
 	//group, parseDateErr := service.GetItemNameGroup(orgid, statime, entime)
960
 	//group, parseDateErr := service.GetItemNameGroup(orgid, statime, entime)
935
 	//quarter, err := service.GetFirstQuarter(orgid, statime, entime)
961
 	//quarter, err := service.GetFirstQuarter(orgid, statime, entime)
962
+	//统计数值类型的数据
936
 	count, err := service.GetQuarterTotalCount(orgid, statime, entime, lapseto)
963
 	count, err := service.GetQuarterTotalCount(orgid, statime, entime, lapseto)
964
+	//统计rang_type== 2
965
+	countwo, _ := service.GetQuarterTotalCountTwo(orgid, statime, entime, lapseto)
937
 	if err != nil {
966
 	if err != nil {
938
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
967
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
939
 		return
968
 		return
940
 	}
969
 	}
941
 	this.ServeSuccessJSON(map[string]interface{}{
970
 	this.ServeSuccessJSON(map[string]interface{}{
942
-		"count": count,
971
+		"count":   count,
972
+		"countwo": countwo,
943
 	})
973
 	})
944
 }
974
 }
945
 
975
 
1004
 	fourQuarterEndStr := fourQuarterEnd + " 23:59:59"
1034
 	fourQuarterEndStr := fourQuarterEnd + " 23:59:59"
1005
 	fourQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", fourQuarterEndStr)
1035
 	fourQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", fourQuarterEndStr)
1006
 	fourQuarterEndStrUnix := fourQuarterEnds.Unix()
1036
 	fourQuarterEndStrUnix := fourQuarterEnds.Unix()
1007
-	fmt.Println("第四季度结束时间", fourQuarterEndStrUnix)
1037
+	//fmt.Println("第四季度结束时间", fourQuarterEndStrUnix)
1038
+	rangetype, parseDateErr := this.GetInt64("range_type")
1008
 	//按季度统计
1039
 	//按季度统计
1009
-	if itemtype == 1 {
1040
+	if rangetype == 1 {
1010
 		//统计总共
1041
 		//统计总共
1011
 		list, err := service.GetProjectList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1042
 		list, err := service.GetProjectList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1012
 		//统计达标个数
1043
 		//统计达标个数
1013
 		standList, err := service.GetProjectStandList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1044
 		standList, err := service.GetProjectStandList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
1045
+
1014
 		if err != nil {
1046
 		if err != nil {
1015
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1047
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1016
 			return
1048
 			return

+ 15 - 3
models/common_models.go View File

11
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
11
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
12
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
12
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
13
 	LargeRange      string `gorm:"column:large_range" json:"large_range" form:"large_range"`
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
 	Unit            string `gorm:"column:unit" json:"unit" form:"unit"`
16
 	Unit            string `gorm:"column:unit" json:"unit" form:"unit"`
15
 	ProjectName     string `gorm:"column:project_name" json:"project_name" form:"project_name"`
17
 	ProjectName     string `gorm:"column:project_name" json:"project_name" form:"project_name"`
16
 	ItemName        string `gorm:"column:item_name" json:"item_name" form:"item_name"`
18
 	ItemName        string `gorm:"column:item_name" json:"item_name" form:"item_name"`
27
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
29
 	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
28
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
30
 	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
29
 	LargeRange      string `gorm:"column:large_range" json:"large_range" form:"large_range"`
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
 func (XtQualityControlStandard) TableName() string {
36
 func (XtQualityControlStandard) TableName() string {
308
 	ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
312
 	ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
309
 	Total  int64
313
 	Total  int64
310
 	Count  int64
314
 	Count  int64
315
+	Sort   int64 `gorm:"column:sort" json:"sort" form:"sort"`
311
 }
316
 }
312
 
317
 
313
 type VmPatientInspection struct {
318
 type VmPatientInspection struct {
383
 }
388
 }
384
 
389
 
385
 type ProjectCountOne struct {
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
 type ProjectCount struct {
398
 type ProjectCount struct {
421
 	return "xt_inspection"
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
 type BloodDialysisOrder struct {
436
 type BloodDialysisOrder struct {
425
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
437
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
426
 	DialysisDate       int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
438
 	DialysisDate       int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`

+ 48 - 10
service/common_service.go View File

10
 
10
 
11
 func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
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
 	return inspection, err
14
 	return inspection, err
15
 }
15
 }
16
 
16
 
78
 
78
 
79
 func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
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
 	return err
82
 	return err
83
 }
83
 }
84
 
84
 
297
 	return patients, err
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
 func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
308
 func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
301
 
309
 
302
 	db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
310
 	db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
750
 	table := XTReadDB().Table("xt_inspection_reference as s")
758
 	table := XTReadDB().Table("xt_inspection_reference as s")
751
 	fmt.Println(table)
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
 		Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
762
 		Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
755
 	return standard, err
763
 	return standard, err
756
 }
764
 }
811
 	fmt.Println(table)
819
 	fmt.Println(table)
812
 	d := XTReadDB().Table("xt_patients as s")
820
 	d := XTReadDB().Table("xt_patients as s")
813
 	fmt.Println(d)
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
 	if orgid > 0 {
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
 	if startime > 0 {
827
 	if startime > 0 {
820
 		db = db.Where("x.inspect_date >=?", startime)
828
 		db = db.Where("x.inspect_date >=?", startime)
828
 	if lapseto > 0 {
836
 	if lapseto > 0 {
829
 		db = db.Where("s.lapseto = ?", lapseto)
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
 	return inspection, err
868
 	return inspection, err
833
 }
869
 }
834
 
870
 
847
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
883
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
848
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
884
 			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
849
 			" ELSE '其他'" +
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
 		countParams := make([]interface{}, 0)
887
 		countParams := make([]interface{}, 0)
852
 		countParams = append(countParams, firststart)
888
 		countParams = append(countParams, firststart)
853
 		countParams = append(countParams, firstend)
889
 		countParams = append(countParams, firstend)
992
 		fmt.Println("d", d)
1028
 		fmt.Println("d", d)
993
 		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1029
 		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
994
 		table := XTReadDB().Table("xt_inspection_reference as r")
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
 		fmt.Println(table)
1033
 		fmt.Println(table)
996
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1034
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
997
 			"SELECT " +
1035
 			"SELECT " +
998
 			"CASE " +
1036
 			"CASE " +
999
 			" 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 '第一季度'" +
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
 			" 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 '第三季度'" +
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
 			" 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 '第四季度'" +
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
 			" ELSE '其他'" +
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
 		countParams := make([]interface{}, 0)
1043
 		countParams := make([]interface{}, 0)
1006
 		countParams = append(countParams, firststart)
1044
 		countParams = append(countParams, firststart)
1007
 		countParams = append(countParams, firstend)
1045
 		countParams = append(countParams, firstend)