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
f64746571c

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

@@ -21,6 +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
 	if len(major) == 0 {
25 26
 		major, _ := service.GetInspectionMajor(0)
26 27
 		if err != nil {
@@ -708,23 +709,22 @@ func (this *CommonApiController) GetInspectionTatolCount() {
708 709
 	startime := this.GetString("startime")
709 710
 	fmt.Println(startime)
710 711
 	endtime := this.GetString("endtime")
712
+	fmt.Print("endtime", endtime)
713
+	patientid, _ := this.GetInt64("patientid")
711 714
 	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
712 715
 	fmt.Println("parseDateErr", parseDateErr)
713 716
 	statime := startDate.Unix()
714
-	//fmt.Println("开始时间", statime)
715
-	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
716
-	//entime := endDate.Unix()
717
-	endTimeYMDHmsStr := endtime + " 23:59:59"
718
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
719
-	entime := endDate.Unix()
720
-	fmt.Println("结束日期", entime)
717
+	secondQuarterEndStr := endtime + " 23:59:59"
718
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
719
+	entime := secondQuarterEnds.Unix()
720
+
721 721
 	references, err := service.GetInspectionTotalCount(orgid)
722 722
 	if err != nil {
723 723
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
724 724
 		return
725 725
 	}
726 726
 
727
-	counts, err := service.GetInspectionProjectCount(orgid, statime, entime)
727
+	counts, err := service.GetInspectionProjectCount(orgid, statime, entime, patientid)
728 728
 
729 729
 	this.ServeSuccessJSON(map[string]interface{}{
730 730
 		"Inspection": references,
@@ -743,9 +743,9 @@ func (this *CommonApiController) GetInspectionDetailById() {
743 743
 	fmt.Println("parseDateErr", parseDateErr)
744 744
 	statime := startDate.Unix()
745 745
 	fmt.Println("开始时间", statime)
746
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
747
-	entime := endDate.Unix()
748
-	fmt.Println("结束日期", entime)
746
+	secondQuarterEndStr := endtime + " 23:59:59"
747
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
748
+	entime := secondQuarterEnds.Unix()
749 749
 	patientdetail, err := service.GetInspectionDetailById(id, orgId, statime, entime)
750 750
 	if err != nil {
751 751
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -768,9 +768,12 @@ func (this *CommonApiController) GetSearchPatientInfo() {
768 768
 	fmt.Println("parseDateErr", parseDateErr)
769 769
 	statime := startDate.Unix()
770 770
 	fmt.Println("开始时间", statime)
771
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
772
-	entime := endDate.Unix()
773
-	fmt.Println("结束日期", entime)
771
+	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
772
+	//entime := endDate.Unix()
773
+	//fmt.Println("结束日期", entime)
774
+	secondQuarterEndStr := endtime + " 23:59:59"
775
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
776
+	entime := secondQuarterEnds.Unix()
774 777
 	PatientsInfo, err := service.GetSearchPatientInfo(orgId, patientid, statime, entime)
775 778
 	if err != nil {
776 779
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -825,7 +828,8 @@ func (this *CommonApiController) GetPatientList() {
825 828
 	page, _ := this.GetInt64("page")
826 829
 	fmt.Println("page", page)
827 830
 	patientInfo, total, err := service.GetPatientListData(orgid, statime, entime, limit, page)
828
-	info, _ := service.GetPatientListInfo(orgid, statime, entime)
831
+
832
+	info, _ := service.GetPatientListInfo(orgid, statime, entime, limit, page)
829 833
 	if err != nil {
830 834
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
831 835
 		return
@@ -847,9 +851,12 @@ func (this *CommonApiController) GetPatientDetailCheck() {
847 851
 	fmt.Println("parseDateErr", parseDateErr)
848 852
 	statime := startDate.Unix()
849 853
 	fmt.Println("开始时间", statime)
850
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
854
+	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
855
+	//entime := endDate.Unix()
856
+	//fmt.Println("结束日期", entime)
857
+	endTimeYMDHmsStr := endtime + " 23:59:59"
858
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endTimeYMDHmsStr)
851 859
 	entime := endDate.Unix()
852
-	fmt.Println("结束日期", entime)
853 860
 	checkDetail, err := service.GetPatientDetailCheck(id, orgid, statime, entime)
854 861
 	if err != nil {
855 862
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 1 - 0
controllers/new_mobile_api_controllers/index_evaluation_api_controller.go View File

@@ -240,6 +240,7 @@ func (this *IndexEvaluationApiController) GetPatientInspectionBarChartData() {
240 240
 func (this *IndexEvaluationApiController) GetDialysisProcessIndexChartData() {
241 241
 	adminUserInfo := this.GetMobileAdminUserInfo()
242 242
 	statistics_type, _ := this.GetInt("statistics_type")
243
+	fmt.Println("startisct=====================", statistics_type)
243 244
 	start_time := this.GetString("start_time")
244 245
 	end_time := this.GetString("end_time")
245 246
 	patient_id, _ := this.GetInt64("patient_id")

+ 28 - 15
controllers/new_mobile_api_controllers/new_common_api_controller.go View File

@@ -316,17 +316,21 @@ func (this *NewCommonApiController) GetMobileInspectionList() {
316 316
 	fmt.Println("parseDateErr", parseDateErr)
317 317
 	statime := startDate.Unix()
318 318
 	fmt.Println("开始时间", statime)
319
-	endtimeStr := endtime + " 23:59:59"
320
-	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
321
-	entime := endtimeStrs.Unix()
322
-	fmt.Println("结束日期", entime)
319
+	//endtimeStr := endtime + " 23:59:59"
320
+	//endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
321
+	//entime := endtimeStrs.Unix()
322
+	secondQuarterEndStr := endtime + " 23:59:59"
323
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
324
+	entime := secondQuarterEnds.Unix()
325
+	fmt.Println("结束日期==========", entime)
326
+	patientid, _ := this.GetInt64("patientid")
323 327
 	references, err := service.GetInspectionTotalCount(orgid)
324 328
 	if err != nil {
325 329
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
326 330
 		return
327 331
 	}
328 332
 
329
-	counts, err := service.GetInspectionProjectCount(orgid, statime, entime)
333
+	counts, err := service.GetInspectionProjectCount(orgid, statime, entime, patientid)
330 334
 
331 335
 	this.ServeSuccessJSON(map[string]interface{}{
332 336
 		"Inspection": references,
@@ -345,9 +349,12 @@ func (this *NewCommonApiController) GetPatientInspectionDetail() {
345 349
 	fmt.Println("parseDateErr", parseDateErr)
346 350
 	statime := startDate.Unix()
347 351
 	fmt.Println("开始时间", statime)
348
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
349
-	entime := endDate.Unix()
350
-	fmt.Println("结束日期", entime)
352
+	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
353
+	//entime := endDate.Unix()
354
+	//fmt.Println("结束日期", entime)
355
+	secondQuarterEndStr := endtime + " 23:59:59"
356
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
357
+	entime := secondQuarterEnds.Unix()
351 358
 	patientdetail, err := service.GetInspectionDetailById(id, orgId, statime, entime)
352 359
 	if err != nil {
353 360
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -370,9 +377,12 @@ func (this *NewCommonApiController) GetSeachPatientDetail() {
370 377
 	fmt.Println("parseDateErr", parseDateErr)
371 378
 	statime := startDate.Unix()
372 379
 	fmt.Println("开始时间", statime)
373
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
374
-	entime := endDate.Unix()
375
-	fmt.Println("结束日期", entime)
380
+	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
381
+	//entime := endDate.Unix()
382
+	//fmt.Println("结束日期", entime)
383
+	secondQuarterEndStr := endtime + " 23:59:59"
384
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
385
+	entime := secondQuarterEnds.Unix()
376 386
 	PatientsInfo, err := service.GetSearchPatientInfo(orgId, patientid, statime, entime)
377 387
 	if err != nil {
378 388
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -719,7 +729,7 @@ func (this *NewCommonApiController) GetMobilePatient() {
719 729
 	page, _ := this.GetInt64("page")
720 730
 	fmt.Println("page", page)
721 731
 	patientInfo, total, err := service.GetPatientListData(orgid, statime, entime, limit, page)
722
-	info, _ := service.GetPatientListInfo(orgid, statime, entime)
732
+	info, _ := service.GetPatientListInfo(orgid, statime, entime, limit, page)
723 733
 	if err != nil {
724 734
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
725 735
 		return
@@ -742,9 +752,12 @@ func (this *NewCommonApiController) GetMobilePatientDetailCheck() {
742 752
 	fmt.Println("parseDateErr", parseDateErr)
743 753
 	statime := startDate.Unix()
744 754
 	fmt.Println("开始时间", statime)
745
-	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
746
-	entime := endDate.Unix()
747
-	fmt.Println("结束日期", entime)
755
+	//endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
756
+	//entime := endDate.Unix()
757
+	//fmt.Println("结束日期", entime)
758
+	secondQuarterEndStr := endtime + " 23:59:59"
759
+	secondQuarterEnds, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", secondQuarterEndStr)
760
+	entime := secondQuarterEnds.Unix()
748 761
 	checkDetail, err := service.GetPatientDetailCheck(id, orgid, statime, entime)
749 762
 	if err != nil {
750 763
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 28 - 5
service/common_service.go View File

@@ -4,12 +4,13 @@ import (
4 4
 	"XT_New/models"
5 5
 	"fmt"
6 6
 	"github.com/jinzhu/gorm"
7
+	"strconv"
7 8
 	"time"
8 9
 )
9 10
 
10 11
 func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
11 12
 
12
-	err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
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 14
 	return inspection, err
14 15
 }
15 16
 
@@ -532,7 +533,7 @@ func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfigur
532 533
 	return configuration, err
533 534
 }
534 535
 
535
-func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
536
+func GetInspectionProjectCount(orgid int64, startime int64, endtime int64, patientid int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
536 537
 
537 538
 	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
538 539
 	table := XTReadDB().Table("xt_inspection_reference as r")
@@ -548,8 +549,11 @@ func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (proj
548 549
 	if endtime > 0 {
549 550
 		db = db.Where("x.inspect_date <=?", endtime)
550 551
 	}
552
+	if patientid > 0 {
553
+		db = db.Where("x.patient_id = ?", patientid)
554
+	}
551 555
 
552
-	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
556
+	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("x.project_id,x.patient_id").Scan(&projectCounts).Error
553 557
 	return
554 558
 }
555 559
 
@@ -643,7 +647,9 @@ func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64,
643 647
 	return inspection, total, err
644 648
 }
645 649
 
646
-func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
650
+func GetPatientListInfo(orgid int64, startime int64, endtime int64, limit int64, page int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
651
+
652
+	patients, _, err := GetPatientListData(orgid, startime, endtime, limit, page)
647 653
 
648 654
 	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
649 655
 	table := XTReadDB().Table("xt_inspection_reference as r")
@@ -662,7 +668,24 @@ func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCoun
662 668
 		db = db.Where("x.inspect_date <=?", endtime)
663 669
 	}
664 670
 
665
-	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
671
+	//if len(ds) > 0 {
672
+	//  for _, d := range ds {
673
+	//    dates = append(dates, d.Date)
674
+	//  }
675
+	//
676
+	//  db = db.Where("o.dialysis_date IN (?)", dates)
677
+	//
678
+	////}
679
+
680
+	selectContent := "CASE"
681
+	dates := make([]string, 0)
682
+	for _, item := range patients {
683
+		selectContent = selectContent + " WHEN x.patient_id =" + strconv.FormatInt(item.PatientId, 10) + " THEN " + "'" + item.Name + "'"
684
+		dates = append(dates, strconv.FormatInt(item.PatientId, 10))
685
+	}
686
+	db = db.Where("x.patient_id in(?)", dates)
687
+	err = db.Select(selectContent + "ELSE '未知' END AS name,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("x.project_id,x.patient_id").Scan(&projectCounts).Error
688
+	//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
666 689
 	return
667 690
 }
668 691
 

+ 2 - 3
service/statistics_service/index_evaluation_service.go View File

@@ -111,11 +111,10 @@ func GetDialysisProcessIndexOtherChartData(user_org_id int64, patient_id int64,
111 111
 			selectContent = selectContent + " WHEN p.anticoagulant =" + strconv.Itoa(item.Value) + " THEN " + "'" + item.Name + "'"
112 112
 
113 113
 		}
114
-		fmt.Println(selectContent)
114
+		fmt.Println("selectContent 是什么=============================================", selectContent)
115 115
 		tempErr = db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? and p.status=1 and  p.record_date >= ? and p.record_date <= ? AND p.patient_id = ? ", user_org_id, start_time, end_time, patient_id).
116 116
 			Select(selectContent +
117
-				" ELSE '未知' END AS name, COUNT(*) AS total",
118
-			).Group("p.anticoagulant").Scan(&items).Error
117
+				" ELSE '未知' END AS name, COUNT(*) AS total").Group("p.anticoagulant").Scan(&items).Error
119 118
 
120 119
 		break
121 120
 	}