Browse Source

患者检验检查统计开发

XMLWAN 4 years ago
parent
commit
1632043c9e

+ 236 - 2
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -18,8 +18,19 @@ type CommonApiController struct {
18 18
 }
19 19
 
20 20
 func (this *CommonApiController) GetInspectionMajor() {
21
-
22
-	major, err := service.GetInspectionMajor(0)
21
+	adminInfo := this.GetAdminUserInfo()
22
+	orgid := adminInfo.CurrentOrgId
23
+	major, err := service.GetInspectionMajor(orgid)
24
+	if len(major) == 0 {
25
+		major, _ := service.GetInspectionMajor(0)
26
+		if err != nil {
27
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
28
+			return
29
+		}
30
+		this.ServeSuccessJSON(map[string]interface{}{
31
+			"inspection": major,
32
+		})
33
+	}
23 34
 	if err != nil {
24 35
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
25 36
 		return
@@ -786,6 +797,7 @@ func (this *CommonApiController) GetPatientList() {
786 797
 	page, _ := this.GetInt64("page")
787 798
 	fmt.Println("page", page)
788 799
 	patientInfo, total, err := service.GetPatientListData(orgid, statime, entime, limit, page)
800
+	info, _ := service.GetPatientListInfo(orgid, statime, entime)
789 801
 	if err != nil {
790 802
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
791 803
 		return
@@ -793,5 +805,227 @@ func (this *CommonApiController) GetPatientList() {
793 805
 	this.ServeSuccessJSON(map[string]interface{}{
794 806
 		"patientInfo": patientInfo,
795 807
 		"total":       total,
808
+		"list":        info,
809
+	})
810
+}
811
+
812
+func (this *CommonApiController) GetPatientDetailCheck() {
813
+	adminUser := this.GetAdminUserInfo()
814
+	orgid := adminUser.CurrentOrgId
815
+	id, _ := this.GetInt64("id")
816
+	startime := this.GetString("startime")
817
+	endtime := this.GetString("endtime")
818
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
819
+	fmt.Println("parseDateErr", parseDateErr)
820
+	statime := startDate.Unix()
821
+	fmt.Println("开始时间", statime)
822
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
823
+	entime := endDate.Unix()
824
+	fmt.Println("结束日期", entime)
825
+	checkDetail, err := service.GetPatientDetailCheck(id, orgid, statime, entime)
826
+	if err != nil {
827
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
828
+		return
829
+	}
830
+	this.ServeSuccessJSON(map[string]interface{}{
831
+		"checkDetail": checkDetail,
832
+	})
833
+}
834
+
835
+func (this *CommonApiController) GetSearchDetailCheck() {
836
+	adminUser := this.GetAdminUserInfo()
837
+	orgid := adminUser.CurrentOrgId
838
+	keyword := this.GetString("keyword")
839
+	startime := this.GetString("startime")
840
+	endtime := this.GetString("endtime")
841
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
842
+	fmt.Println("parseDateErr", parseDateErr)
843
+	statime := startDate.Unix()
844
+	fmt.Println("开始时间", statime)
845
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
846
+	entime := endDate.Unix()
847
+	fmt.Println("结束日期", entime)
848
+	checkDetail, err := service.GetSearchDetailCheck(orgid, keyword, statime, entime)
849
+	if err != nil {
850
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
851
+		return
852
+	}
853
+	this.ServeSuccessJSON(map[string]interface{}{
854
+		"checkDetail": checkDetail,
855
+	})
856
+}
857
+
858
+func (this *CommonApiController) GetNormData() {
859
+	orgid := this.GetAdminUserInfo().CurrentOrgId
860
+	//获取系统数据
861
+	normdata, err := service.GetNormDataByOrgId(orgid)
862
+	if len(normdata) == 0 {
863
+		normdata, err := service.GetNormData(0)
864
+		if err != nil {
865
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
866
+			return
867
+		}
868
+		this.ServeSuccessJSON(map[string]interface{}{
869
+			"normdata": normdata,
870
+		})
871
+	}
872
+	if err != nil {
873
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
874
+		return
875
+	}
876
+	this.ServeSuccessJSON(map[string]interface{}{
877
+		"normdata": normdata,
878
+	})
879
+}
880
+
881
+func (this *CommonApiController) GetFirstQuarter() {
882
+	orgid := this.GetAdminUserInfo().CurrentOrgId
883
+	lapseto, _ := this.GetInt64("lapseto")
884
+	fmt.Println("转归", lapseto)
885
+	startime := this.GetString("startime")
886
+	fmt.Println("startime", startime)
887
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
888
+	fmt.Println("parseDateErr", parseDateErr)
889
+	statime := startDate.Unix()
890
+	fmt.Println("开始时间", statime)
891
+	endtime := this.GetString("endtime")
892
+	fmt.Println("endtime", endtime)
893
+	endTimeYMDHmsStr := endtime + " 23:59:59"
894
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
895
+	entime := endDate.Unix()
896
+	fmt.Println("结束日期", entime)
897
+	//group, parseDateErr := service.GetItemNameGroup(orgid, statime, entime)
898
+	//quarter, err := service.GetFirstQuarter(orgid, statime, entime)
899
+	count, err := service.GetQuarterTotalCount(orgid, statime, entime, lapseto)
900
+	if err != nil {
901
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
902
+		return
903
+	}
904
+	this.ServeSuccessJSON(map[string]interface{}{
905
+		"count": count,
796 906
 	})
797 907
 }
908
+
909
+func (this *CommonApiController) GetProjectList() {
910
+	startime := this.GetString("startime")
911
+	fmt.Println("startime", startime)
912
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
913
+	fmt.Println("parseDateErr", parseDateErr)
914
+	statime := startDate.Unix()
915
+	fmt.Println("开始时间", statime)
916
+	endtime := this.GetString("endtime")
917
+	fmt.Println("endtime", endtime)
918
+	endTimeYMDHmsStr := endtime + " 23:59:59"
919
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
920
+	entime := endDate.Unix()
921
+	fmt.Println("结束日期", entime)
922
+	adminInfo := this.GetAdminUserInfo()
923
+	orgid := adminInfo.CurrentOrgId
924
+	fmt.Println("orgid", orgid)
925
+	lapseto, _ := this.GetInt64("lapseto")
926
+	fmt.Println("lapseto", lapseto)
927
+	itemtype, _ := this.GetInt64("itemtype")
928
+	fmt.Println("type", itemtype)
929
+	modetype, _ := this.GetInt64("modetype")
930
+	fmt.Println("modetype", modetype)
931
+
932
+	firstQuarterStart := this.GetString("first_quarter_start")
933
+	firstQuarterStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", firstQuarterStart)
934
+	firstQuarterStartUnix := firstQuarterStartStr.Unix()
935
+	fmt.Println("第一季度开始时间", firstQuarterStartUnix)
936
+	fisrtQuarterEnd := this.GetString("first_qurter_end")
937
+	fisrtQuarterEndStr := fisrtQuarterEnd + " 23:59:59"
938
+	fisrtQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", fisrtQuarterEndStr)
939
+	fisrtQuarterEndStrUnix := fisrtQuarterEnds.Unix()
940
+	fmt.Println("第一季度结束时间", fisrtQuarterEndStrUnix)
941
+
942
+	secondeQuarterStart := this.GetString("second_qurter_start")
943
+	secondeQuarterStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", secondeQuarterStart)
944
+	secondeQuarterStartUnix := secondeQuarterStartStr.Unix()
945
+	fmt.Println("第二季度开始时间", secondeQuarterStartUnix)
946
+	secondQuarterEnd := this.GetString("second_qurter_end")
947
+	secondQuarterEndStr := secondQuarterEnd + " 23:59:59"
948
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
949
+	secondQuarterEndStrUnix := secondQuarterEnds.Unix()
950
+	fmt.Println("第二季度结束时间", secondQuarterEndStrUnix)
951
+
952
+	threeQuarterStart := this.GetString("three_qurter_start")
953
+	threeQuarterStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", threeQuarterStart)
954
+	threeQuarterStartUnix := threeQuarterStartStr.Unix()
955
+	fmt.Println("第三季度开始时间", threeQuarterStartUnix)
956
+	threeQuarterEnd := this.GetString("three_qurter_end")
957
+	threeQuarterEndStr := threeQuarterEnd + " 23:59:59"
958
+	threeQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", threeQuarterEndStr)
959
+	threeQuarterEndStrUnix := threeQuarterEnds.Unix()
960
+	fmt.Println("第三季度结束时间", threeQuarterEndStrUnix)
961
+
962
+	fourQuarterStart := this.GetString("four_qurter_start")
963
+	fourQuarterStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", fourQuarterStart)
964
+	fourQuarterStartUnix := fourQuarterStartStr.Unix()
965
+	fmt.Println("第四季度开始时间", fourQuarterStartUnix)
966
+	fourQuarterEnd := this.GetString("four_qurter_end")
967
+	fourQuarterEndStr := fourQuarterEnd + " 23:59:59"
968
+	fourQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", fourQuarterEndStr)
969
+	fourQuarterEndStrUnix := fourQuarterEnds.Unix()
970
+	fmt.Println("第四季度结束时间", fourQuarterEndStrUnix)
971
+	//按季度统计
972
+	if itemtype == 1 {
973
+		//统计总共
974
+		list, err := service.GetProjectList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
975
+		//统计达标个数
976
+		standList, err := service.GetProjectStandList(orgid, lapseto, modetype, statime, entime, firstQuarterStartUnix, fisrtQuarterEndStrUnix, secondeQuarterStartUnix, secondQuarterEndStrUnix, threeQuarterStartUnix, threeQuarterEndStrUnix, fourQuarterStartUnix, fourQuarterEndStrUnix)
977
+		if err != nil {
978
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
979
+			return
980
+		}
981
+
982
+		this.ServeSuccessJSON(map[string]interface{}{
983
+			"list":      list,
984
+			"standList": standList,
985
+		})
986
+	}
987
+
988
+}
989
+
990
+func (this *CommonApiController) GetMonthProjectList() {
991
+	adminUser := this.GetAdminUserInfo()
992
+	orgid := adminUser.CurrentOrgId
993
+	fmt.Println("orgid", orgid)
994
+
995
+	lapseto, _ := this.GetInt64("lapseto")
996
+	fmt.Println("lapseto", lapseto)
997
+	itemtype, _ := this.GetInt64("itemtype")
998
+	fmt.Println("itemtype", itemtype)
999
+	modetype, _ := this.GetInt64("modetype")
1000
+	fmt.Println("modetype", modetype)
1001
+	januaryStart := this.GetString("januaryStart")
1002
+	fmt.Println("一月始", januaryStart)
1003
+	januaryStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", januaryStart)
1004
+	januaryStartStrUnix := januaryStartStr.Unix()
1005
+	fmt.Println("一月使", januaryStartStrUnix)
1006
+	januaryEnd := this.GetString("januaryEnd")
1007
+	fmt.Println("一月末", januaryEnd)
1008
+	januaryEndStr := januaryEnd + " 23:59:59"
1009
+	januaryEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", januaryEndStr)
1010
+	januaryEndStrUnix := januaryEndStrs.Unix()
1011
+	fmt.Println("一月末", januaryEndStrUnix)
1012
+
1013
+	febStart := this.GetString("febStart")
1014
+	fmt.Println("二月始", febStart)
1015
+	febEnd := this.GetString("febEnd")
1016
+	fmt.Println("二月末", febEnd)
1017
+	febEndStr := febEnd + " 23:59:59"
1018
+	febEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", febEndStr)
1019
+	febEndStrUnix := febEndStrs.Unix()
1020
+	fmt.Println("二月末", febEndStrUnix)
1021
+
1022
+	marchStart := this.GetString("marchStart")
1023
+	fmt.Println("三月始", marchStart)
1024
+	marchEnd := this.GetString("marchEnd")
1025
+	fmt.Println("三月末", febEnd)
1026
+	marchEndStr := marchEnd + " 23:59:59"
1027
+	marchEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", marchEndStr)
1028
+	marchEndStrUnix := marchEndStrs.Unix()
1029
+	fmt.Println("三月末", marchEndStrUnix)
1030
+
1031
+}

+ 6 - 0
controllers/new_mobile_api_controllers/common_api_router.go View File

@@ -39,4 +39,10 @@ func CommonApiControllersRegisterRouters() {
39 39
 	beego.Router("/com/api/getsearchpatientinfo", &CommonApiController{}, "Get:GetSearchPatientInfo")
40 40
 	beego.Router("/com/api/getallmajorInspection", &CommonApiController{}, "Get:GetAllMajorInspection")
41 41
 	beego.Router("/com/api/getpatientlist", &CommonApiController{}, "Get:GetPatientList")
42
+	beego.Router("/com/api/getPatientDetailCheck", &CommonApiController{}, "Get:GetPatientDetailCheck")
43
+	beego.Router("/com/api/searchdetailcheck", &CommonApiController{}, "Get:GetSearchDetailCheck")
44
+	beego.Router("/com/api/getnormdata", &CommonApiController{}, "Get:GetNormData")
45
+	beego.Router("/com/api/getfirstquarter", &CommonApiController{}, "Get:GetFirstQuarter")
46
+	beego.Router("/com/api/getprojectlist", &CommonApiController{}, "Get:GetProjectList")
47
+	beego.Router("/com/api/getmonthprojectlist", &CommonApiController{}, "Get:GetMonthProjectList")
42 48
 }

+ 61 - 0
models/common_models.go View File

@@ -304,6 +304,48 @@ type InspectionReferenceMaps struct {
304 304
 	CheckConfiguration []CheckConfiguration `gorm:"-" json:"inspection_reference" form:"inspection_reference"`
305 305
 }
306 306
 
307
+type VmPatientInspection struct {
308
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
309
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
310
+	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
311
+	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
312
+	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
313
+	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
314
+	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
315
+	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
316
+	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
317
+	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
318
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
319
+	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
320
+	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
321
+	Name         string `gorm:"column:name" json:"name" form:"name"`
322
+	RangMax      string `gorm:"column:range_max" json:"range_max" form:"range_max"`
323
+	RangMin      string `gorm:"column:range_min" json:"range_min" form:"range_min"`
324
+	Total        int64
325
+	Count        int64
326
+	Sort         int64 `gorm:"column:sort" json:"sort" form:"sort"`
327
+}
328
+
329
+type XtPatientInspection struct {
330
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
331
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
332
+	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
333
+	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
334
+	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
335
+	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
336
+	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
337
+	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
338
+	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
339
+	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
340
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
341
+	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
342
+	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
343
+	Name         string `gorm:"column:name" json:"name" form:"name"`
344
+	RangMax      string `gorm:"column:range_max" json:"range_max" form:"range_max"`
345
+	RangMin      string `gorm:"column:range_min" json:"range_min" form:"range_min"`
346
+	Count        int64
347
+}
348
+
307 349
 type PatientsInspection struct {
308 350
 	ID           int64  `gorm:"column:id" json:"id" form:"id"`
309 351
 	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
@@ -325,3 +367,22 @@ func (PatientsInspection) TableName() string {
325 367
 
326 368
 	return "xt_inspection"
327 369
 }
370
+
371
+type PatientInspectionProjectCount struct {
372
+	PatientId   int64
373
+	Count       int64
374
+	ProjectId   int64
375
+	ProjectName string
376
+	Name        string `gorm:"column:name" json:"name" form:"name"`
377
+}
378
+
379
+type ProjectCountOne struct {
380
+	Total   string
381
+	Count   int64
382
+	NoCount int64
383
+}
384
+
385
+type ProjectCount struct {
386
+	Total string
387
+	Count int64
388
+}

+ 1 - 0
models/inspection_models.go View File

@@ -74,6 +74,7 @@ type UserInspectionProjectCounts struct {
74 74
 	ProjectId           int64
75 75
 	ProjectName         string
76 76
 	InspectionFrequency string
77
+	Sort                int64
77 78
 }
78 79
 
79 80
 type UserDoctorAdvicesCount struct {

+ 471 - 1
service/common_service.go View File

@@ -520,7 +520,7 @@ func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (proj
520 520
 		db = db.Where("x.inspect_date <=?", endtime)
521 521
 	}
522 522
 
523
-	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left  join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
523
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left  join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
524 524
 	return
525 525
 }
526 526
 
@@ -610,3 +610,473 @@ func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64,
610 610
 	err = db.Group("x.patient_id").Select("x.id,x.patient_id,x.project_id,x.project_name,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
611 611
 	return inspection, total, err
612 612
 }
613
+
614
+func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
615
+
616
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
617
+	table := XTReadDB().Table("xt_inspection_reference as r")
618
+	fmt.Println(table)
619
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
620
+	pa := XTReadDB().Table("xt_patients as s")
621
+	fmt.Println(pa)
622
+	fmt.Println(d)
623
+	if orgid > 0 {
624
+		db = db.Where("x.org_id = ?", orgid)
625
+	}
626
+	if startime > 0 {
627
+		db = db.Where("x.inspect_date >=?", startime)
628
+	}
629
+	if endtime > 0 {
630
+		db = db.Where("x.inspect_date <=?", endtime)
631
+	}
632
+
633
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left  join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
634
+	return
635
+}
636
+
637
+func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
638
+
639
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
640
+	table := XTReadDB().Table("xt_inspection_reference as r")
641
+	fmt.Println(table)
642
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
643
+	pa := XTReadDB().Table("xt_patients as s")
644
+	fmt.Println(pa)
645
+	fmt.Println(d)
646
+	if id > 0 {
647
+		db = db.Where("s.id  = ?", id)
648
+	}
649
+	if orgid > 0 {
650
+		db = db.Where("x.org_id = ?", orgid)
651
+	}
652
+	if startime > 0 {
653
+		db = db.Where("x.inspect_date >=?", startime)
654
+	}
655
+	if endtime > 0 {
656
+		db = db.Where("x.inspect_date <=?", endtime)
657
+	}
658
+
659
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left  join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
660
+	return
661
+}
662
+
663
+func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
664
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
665
+	table := XTReadDB().Table("xt_inspection_reference as r")
666
+	fmt.Println(table)
667
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
668
+	pa := XTReadDB().Table("xt_patients as s")
669
+	fmt.Println(pa)
670
+	fmt.Println(d)
671
+	if len(keywords) > 0 {
672
+		likeKey := "%" + keywords + "%"
673
+		db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
674
+	}
675
+	if orgid > 0 {
676
+		db = db.Where("x.org_id = ?", orgid)
677
+	}
678
+	if startime > 0 {
679
+		db = db.Where("x.inspect_date >=?", startime)
680
+	}
681
+	if endtime > 0 {
682
+		db = db.Where("x.inspect_date <=?", endtime)
683
+	}
684
+
685
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left  join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
686
+	return
687
+}
688
+
689
+func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
690
+
691
+	db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
692
+	if orgid > 0 {
693
+		db = db.Where("x.user_org_id = ?", orgid)
694
+	}
695
+	table := XTReadDB().Table("xt_inspection_reference as s")
696
+	fmt.Println(table)
697
+
698
+	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").
699
+		Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
700
+	return standard, err
701
+}
702
+
703
+func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
704
+
705
+	db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
706
+	if orgid > 0 {
707
+		db = db.Where("x.user_org_id = ?", orgid)
708
+	}
709
+	table := XTReadDB().Table("xt_inspection_reference as s")
710
+	fmt.Println(table)
711
+
712
+	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").
713
+		Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
714
+	return standard, err
715
+}
716
+
717
+func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
718
+	db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
719
+	table := XTReadDB().Table("xt_inspection_reference as r")
720
+	fmt.Println(table)
721
+	if orgid > 0 {
722
+		db = db.Where("x.org_id = ?", orgid)
723
+	}
724
+	if startime > 0 {
725
+		db = db.Where("x.inspect_date >=?", startime)
726
+	}
727
+	if endtime > 0 {
728
+		db = db.Where("x.inspect_date <=?", endtime)
729
+	}
730
+	err = db.Group("x.item_id").Select("	count(x.item_id ) AS count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
731
+	return inspection, err
732
+}
733
+
734
+func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
735
+
736
+	db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
737
+	table := XTReadDB().Table("xt_inspection_reference as r")
738
+	fmt.Println(table)
739
+	if orgid > 0 {
740
+		db = db.Where("x.org_id = ?", orgid)
741
+	}
742
+	if startime > 0 {
743
+		db = db.Where("x.inspect_date >=?", startime)
744
+	}
745
+	if endtime > 0 {
746
+		db = db.Where("x.inspect_date <=?", endtime)
747
+	}
748
+	err = db.Group("x.item_id").Select("count(x.item_id) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Where("x.inspect_value+0 >= r.range_min+0 and x.inspect_value+0 <= r.range_max+0").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
749
+	return inspection, err
750
+}
751
+
752
+func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspection, err error) {
753
+
754
+	db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
755
+	table := XTReadDB().Table("xt_inspection_reference as r")
756
+	fmt.Println(table)
757
+	d := XTReadDB().Table("xt_patients as s")
758
+	fmt.Println(d)
759
+	d2 := XTReadDB().Table("xt_quality_control_standard as p")
760
+	fmt.Println(d2)
761
+	if orgid > 0 {
762
+		db = db.Where("x.org_id = ?", orgid)
763
+	}
764
+	if startime > 0 {
765
+		db = db.Where("x.inspect_date >=?", startime)
766
+	}
767
+	if endtime > 0 {
768
+		db = db.Where("x.inspect_date <=?", endtime)
769
+	}
770
+	if lapseto > 0 {
771
+		d = d.Where("s.lapseto = ?", lapseto)
772
+	}
773
+	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.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as  s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
774
+	return inspection, err
775
+}
776
+
777
+func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
778
+
779
+	if lapseto == 0 {
780
+		d := XTReadDB().Table("xt_patients as s")
781
+		fmt.Println("d", d)
782
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
783
+
784
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
785
+			"SELECT " +
786
+			"CASE " +
787
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第一季度'" +
788
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第二季度'" +
789
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
790
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
791
+			" ELSE '其他'" +
792
+			"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)"
793
+		countParams := make([]interface{}, 0)
794
+		countParams = append(countParams, firststart)
795
+		countParams = append(countParams, firstend)
796
+		countParams = append(countParams, sencondstart)
797
+		countParams = append(countParams, sencondend)
798
+		countParams = append(countParams, threestart)
799
+		countParams = append(countParams, threeend)
800
+		countParams = append(countParams, fourstart)
801
+		countParams = append(countParams, fourend)
802
+		if orgid > 0 {
803
+			db = db.Where("x.org_id=?", orgid)
804
+			countSQL += " AND x.org_id=?"
805
+			countParams = append(countParams, orgid)
806
+
807
+		}
808
+		if modetype > 0 {
809
+			db = db.Where("x.item_id = ?", modetype)
810
+			countSQL += " AND x.item_id=?"
811
+			countParams = append(countParams, modetype)
812
+		}
813
+		if startime > 0 {
814
+			db = db.Where("x.inspect_date >= ?", startime)
815
+			countSQL += " AND x.inspect_date >=?"
816
+			countParams = append(countParams, startime)
817
+		}
818
+		if endtime > 0 {
819
+			db = db.Where("x.inspect_date <= ?", endtime)
820
+			countSQL += " AND x.inspect_date <=?"
821
+			countParams = append(countParams, endtime)
822
+		}
823
+		countSQL += ")a GROUP BY nnd"
824
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
825
+	}
826
+
827
+	if lapseto == 1 {
828
+		d := XTReadDB().Table("xt_patients as s")
829
+		fmt.Println("d", d)
830
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
831
+
832
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
833
+			"SELECT " +
834
+			"CASE " +
835
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第一季度'" +
836
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第二季度'" +
837
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
838
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
839
+			"ELSE '其他'" +
840
+			"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)"
841
+		countParams := make([]interface{}, 0)
842
+		countParams = append(countParams, firststart)
843
+		countParams = append(countParams, firstend)
844
+		countParams = append(countParams, sencondstart)
845
+		countParams = append(countParams, sencondend)
846
+		countParams = append(countParams, threestart)
847
+		countParams = append(countParams, threeend)
848
+		countParams = append(countParams, fourstart)
849
+		countParams = append(countParams, fourend)
850
+		if orgid > 0 {
851
+			db = db.Where("x.org_id=?", orgid)
852
+			countSQL += " AND x.org_id=?"
853
+			countParams = append(countParams, orgid)
854
+
855
+		}
856
+		if modetype > 0 {
857
+			db = db.Where("x.item_id = ?", modetype)
858
+			countSQL += " AND x.item_id=?"
859
+			countParams = append(countParams, modetype)
860
+		}
861
+
862
+		if startime > 0 {
863
+			db = db.Where("x.inspect_date >= ?", startime)
864
+			countSQL += " AND x.inspect_date >=?"
865
+			countParams = append(countParams, startime)
866
+		}
867
+		if endtime > 0 {
868
+			db = db.Where("x.inspect_date <= ?", endtime)
869
+			countSQL += " AND x.inspect_date <=?"
870
+			countParams = append(countParams, endtime)
871
+		}
872
+
873
+		countSQL += ")a GROUP BY nnd"
874
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
875
+	}
876
+
877
+	if lapseto == 2 {
878
+		d := XTReadDB().Table("xt_patients as s")
879
+		fmt.Println("d", d)
880
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
881
+
882
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
883
+			"SELECT " +
884
+			"CASE " +
885
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第一季度'" +
886
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第二季度'" +
887
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第三季度'" +
888
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '第四季度'" +
889
+			" ELSE '其他'" +
890
+			"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 = 2)"
891
+		countParams := make([]interface{}, 0)
892
+		countParams = append(countParams, firststart)
893
+		countParams = append(countParams, firstend)
894
+		countParams = append(countParams, sencondstart)
895
+		countParams = append(countParams, sencondend)
896
+		countParams = append(countParams, threestart)
897
+		countParams = append(countParams, threeend)
898
+		countParams = append(countParams, fourstart)
899
+		countParams = append(countParams, fourend)
900
+		if orgid > 0 {
901
+			db = db.Where("x.org_id=?", orgid)
902
+			countSQL += " AND x.org_id=?"
903
+			countParams = append(countParams, orgid)
904
+
905
+		}
906
+		if modetype > 0 {
907
+			db = db.Where("x.item_id = ?", modetype)
908
+			countSQL += " AND x.item_id=?"
909
+			countParams = append(countParams, modetype)
910
+		}
911
+
912
+		if startime > 0 {
913
+			db = db.Where("x.inspect_date >= ?", startime)
914
+			countSQL += " AND x.inspect_date >=?"
915
+			countParams = append(countParams, startime)
916
+		}
917
+		if endtime > 0 {
918
+			db = db.Where("x.inspect_date <= ?", endtime)
919
+			countSQL += " AND x.inspect_date <=?"
920
+			countParams = append(countParams, endtime)
921
+		}
922
+
923
+		countSQL += ")a GROUP BY nnd"
924
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
925
+
926
+	}
927
+	return
928
+}
929
+
930
+func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
931
+
932
+	if lapseto == 0 {
933
+		d := XTReadDB().Table("xt_patients as s")
934
+		fmt.Println("d", d)
935
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
936
+		table := XTReadDB().Table("xt_inspection_reference as r")
937
+		fmt.Println(table)
938
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
939
+			"SELECT " +
940
+			"CASE " +
941
+			" 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 '第一季度'" +
942
+			" 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 '第二季度'" +
943
+			" 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 '第三季度'" +
944
+			" 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 '第四季度'" +
945
+			" ELSE '其他'" +
946
+			"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)"
947
+		countParams := make([]interface{}, 0)
948
+		countParams = append(countParams, firststart)
949
+		countParams = append(countParams, firstend)
950
+		countParams = append(countParams, sencondstart)
951
+		countParams = append(countParams, sencondend)
952
+		countParams = append(countParams, threestart)
953
+		countParams = append(countParams, threeend)
954
+		countParams = append(countParams, fourstart)
955
+		countParams = append(countParams, fourend)
956
+		if orgid > 0 {
957
+			db = db.Where("x.org_id=?", orgid)
958
+			countSQL += " AND x.org_id=?"
959
+			countParams = append(countParams, orgid)
960
+
961
+		}
962
+		if modetype > 0 {
963
+			db = db.Where("x.item_id = ?", modetype)
964
+			countSQL += " AND x.item_id=?"
965
+			countParams = append(countParams, modetype)
966
+		}
967
+		if startime > 0 {
968
+			db = db.Where("x.inspect_date >= ? ", startime)
969
+			countSQL += " AND x.inspect_date >=?"
970
+			countParams = append(countParams, startime)
971
+		}
972
+		if endtime > 0 {
973
+			db = db.Where("x.inspect_date <= ?", endtime)
974
+			countSQL += " AND x.inspect_date <=?"
975
+			countParams = append(countParams, endtime)
976
+		}
977
+
978
+		countSQL += ")a GROUP BY nnd"
979
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
980
+	}
981
+
982
+	if lapseto == 1 {
983
+		d := XTReadDB().Table("xt_patients as s")
984
+		fmt.Println("d", d)
985
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
986
+		table := XTReadDB().Table("xt_inspection_reference as r")
987
+		fmt.Println(table)
988
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
989
+			"SELECT " +
990
+			"CASE " +
991
+			" 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 '第一季度'" +
992
+			" 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 '第二季度'" +
993
+			" 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 '第三季度'" +
994
+			" 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 '第四季度'" +
995
+			" ELSE '其他'" +
996
+			"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) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
997
+		countParams := make([]interface{}, 0)
998
+		countParams = append(countParams, firststart)
999
+		countParams = append(countParams, firstend)
1000
+		countParams = append(countParams, sencondstart)
1001
+		countParams = append(countParams, sencondend)
1002
+		countParams = append(countParams, threestart)
1003
+		countParams = append(countParams, threeend)
1004
+		countParams = append(countParams, fourstart)
1005
+		countParams = append(countParams, fourend)
1006
+		if orgid > 0 {
1007
+			db = db.Where("x.org_id=?", orgid)
1008
+			countSQL += " AND x.org_id=?"
1009
+			countParams = append(countParams, orgid)
1010
+
1011
+		}
1012
+		if modetype > 0 {
1013
+			db = db.Where("x.item_id = ?", modetype)
1014
+			countSQL += " AND x.item_id=?"
1015
+			countParams = append(countParams, modetype)
1016
+		}
1017
+		if startime > 0 {
1018
+			db = db.Where("x.inspect_date >= ? ", startime)
1019
+			countSQL += " AND x.inspect_date >=?"
1020
+			countParams = append(countParams, startime)
1021
+		}
1022
+		if endtime > 0 {
1023
+			db = db.Where("x.inspect_date <= ?", endtime)
1024
+			countSQL += " AND x.inspect_date <=?"
1025
+			countParams = append(countParams, endtime)
1026
+		}
1027
+
1028
+		countSQL += ")a GROUP BY nnd"
1029
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1030
+	}
1031
+
1032
+	if lapseto == 2 {
1033
+		d := XTReadDB().Table("xt_patients as s")
1034
+		fmt.Println("d", d)
1035
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1036
+		table := XTReadDB().Table("xt_inspection_reference as r")
1037
+		fmt.Println(table)
1038
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1039
+			"SELECT " +
1040
+			"CASE " +
1041
+			" 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 '第一季度'" +
1042
+			" 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 '第二季度'" +
1043
+			" 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 '第三季度'" +
1044
+			" 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 '第四季度'" +
1045
+			" ELSE '其他'" +
1046
+			"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 = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1047
+		countParams := make([]interface{}, 0)
1048
+		countParams = append(countParams, firststart)
1049
+		countParams = append(countParams, firstend)
1050
+		countParams = append(countParams, sencondstart)
1051
+		countParams = append(countParams, sencondend)
1052
+		countParams = append(countParams, threestart)
1053
+		countParams = append(countParams, threeend)
1054
+		countParams = append(countParams, fourstart)
1055
+		countParams = append(countParams, fourend)
1056
+		if orgid > 0 {
1057
+			db = db.Where("x.org_id=?", orgid)
1058
+			countSQL += " AND x.org_id=?"
1059
+			countParams = append(countParams, orgid)
1060
+
1061
+		}
1062
+		if modetype > 0 {
1063
+			db = db.Where("x.item_id = ?", modetype)
1064
+			countSQL += " AND x.item_id=?"
1065
+			countParams = append(countParams, modetype)
1066
+		}
1067
+		if startime > 0 {
1068
+			db = db.Where("x.inspect_date >= ? ", startime)
1069
+			countSQL += " AND x.inspect_date >=?"
1070
+			countParams = append(countParams, startime)
1071
+		}
1072
+		if endtime > 0 {
1073
+			db = db.Where("x.inspect_date <= ?", endtime)
1074
+			countSQL += " AND x.inspect_date <=?"
1075
+			countParams = append(countParams, endtime)
1076
+		}
1077
+
1078
+		countSQL += ")a GROUP BY nnd"
1079
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1080
+	}
1081
+	return
1082
+}