Browse Source

患者检验检查统计开发

XMLWAN 4 years ago
parent
commit
e675c8c23b

+ 75 - 0
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -669,3 +669,78 @@ func (this *CommonApiController) GetStatistics() {
669 669
 		"total":      total,
670 670
 	})
671 671
 }
672
+
673
+func (this *CommonApiController) GetInspectionTatolCount() {
674
+	adminUser := this.GetAdminUserInfo()
675
+	orgid := adminUser.CurrentOrgId
676
+	startime := this.GetString("startime")
677
+	fmt.Println(startime)
678
+	endtime := this.GetString("endtime")
679
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
680
+	fmt.Println("parseDateErr", parseDateErr)
681
+	statime := startDate.Unix()
682
+	fmt.Println("开始时间", statime)
683
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
684
+	entime := endDate.Unix()
685
+	fmt.Println("结束日期", entime)
686
+	references, err := service.GetInspectionTotalCount(orgid)
687
+	if err != nil {
688
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
689
+		return
690
+	}
691
+
692
+	counts, err := service.GetInspectionProjectCount(orgid, statime, entime)
693
+
694
+	this.ServeSuccessJSON(map[string]interface{}{
695
+		"Inspection": references,
696
+		"counts":     counts,
697
+	})
698
+}
699
+
700
+func (this *CommonApiController) GetInspectionDetailById() {
701
+	adminUser := this.GetAdminUserInfo()
702
+	orgId := adminUser.CurrentOrgId
703
+	id, _ := this.GetInt64("id")
704
+	fmt.Println("id", id)
705
+	startime := this.GetString("startime")
706
+	endtime := this.GetString("endtime")
707
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
708
+	fmt.Println("parseDateErr", parseDateErr)
709
+	statime := startDate.Unix()
710
+	fmt.Println("开始时间", statime)
711
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
712
+	entime := endDate.Unix()
713
+	fmt.Println("结束日期", entime)
714
+	patientdetail, err := service.GetInspectionDetailById(id, orgId, statime, entime)
715
+	if err != nil {
716
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
717
+		return
718
+	}
719
+	this.ServeSuccessJSON(map[string]interface{}{
720
+		"patientdetail": patientdetail,
721
+	})
722
+}
723
+
724
+func (this *CommonApiController) GetSearchPatientInfo() {
725
+	adminUser := this.GetAdminUserInfo()
726
+	orgId := adminUser.CurrentOrgId
727
+	keyword := this.GetString("keyword")
728
+	fmt.Println("keyword", keyword)
729
+	startime := this.GetString("startime")
730
+	endtime := this.GetString("endtime")
731
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
732
+	fmt.Println("parseDateErr", parseDateErr)
733
+	statime := startDate.Unix()
734
+	fmt.Println("开始时间", statime)
735
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
736
+	entime := endDate.Unix()
737
+	fmt.Println("结束日期", entime)
738
+	PatientsInfo, err := service.GetSearchPatientInfo(orgId, keyword, statime, entime)
739
+	if err != nil {
740
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
741
+		return
742
+	}
743
+	this.ServeSuccessJSON(map[string]interface{}{
744
+		"PatientsInfo": PatientsInfo,
745
+	})
746
+}

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

@@ -34,4 +34,7 @@ func CommonApiControllersRegisterRouters() {
34 34
 	beego.Router("/com/api/getdialysisdetailbyid", &CommonApiController{}, "Get:GetDialysisDetailById")
35 35
 	beego.Router("/com/api/getprescriptionbyname", &CommonApiController{}, "Get:GetPrescritionByName")
36 36
 	beego.Router("/com/api/getstatistics", &CommonApiController{}, "Get:GetStatistics")
37
+	beego.Router("/com/api/getinspectiontotalcount", &CommonApiController{}, "Get:GetInspectionTatolCount")
38
+	beego.Router("/com/api/getinspectionDetailById", &CommonApiController{}, "Get:GetInspectionDetailById")
39
+	beego.Router("/com/api/getsearchpatientinfo", &CommonApiController{}, "Get:GetSearchPatientInfo")
37 40
 }

+ 14 - 0
models/common_models.go View File

@@ -289,3 +289,17 @@ type DialysisTotalDataStruct struct {
289 289
 	Number string `json:"number"`
290 290
 	ModeID string `json:"mode_id"`
291 291
 }
292
+
293
+type UserInspectionProjectCount struct {
294
+	PatientId int64
295
+	Count     int64
296
+	ProjectId int64
297
+}
298
+
299
+type InspectionReferenceMaps struct {
300
+	ProjectName        string               `gorm:"-" json:"project_name" form:"project_name"`
301
+	Project            string               `gorm:"-" json:"project" form:"project"`
302
+	ProjectId          int64                `gorm:"-" json:"project_id" form:"project_id"`
303
+	Count              int64                `gorm:"-" json:"count" form:"count"`
304
+	CheckConfiguration []CheckConfiguration `gorm:"-" json:"inspection_reference" form:"inspection_reference"`
305
+}

+ 6 - 4
models/inspection_models.go View File

@@ -68,10 +68,12 @@ func (InspectionReference) TableName() string {
68 68
 	return "xt_inspection_reference"
69 69
 }
70 70
 
71
-type UserInspectionProjectCount struct {
72
-	PatientId int64
73
-	Count     int64
74
-	ProjectId int64
71
+type UserInspectionProjectCounts struct {
72
+	PatientId           int64
73
+	Count               int64
74
+	ProjectId           int64
75
+	ProjectName         string
76
+	InspectionFrequency string
75 77
 }
76 78
 
77 79
 type UserDoctorAdvicesCount struct {

+ 83 - 0
service/common_service.go View File

@@ -490,3 +490,86 @@ func GetStatistics(orgID int64, startime int64, endtime int64, lapseto int64, li
490 490
 	err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, mode_id").Find(&dtd).Error
491 491
 	return
492 492
 }
493
+
494
+func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
495
+	var count int
496
+	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
497
+	table := XTReadDB().Table("xt_inspection_reference as s")
498
+	if orgid > 0 {
499
+		db = db.Where("x.user_org_id = ?", orgid)
500
+	}
501
+	fmt.Println(table)
502
+	err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,s.project_name").Joins("left join xt_inspection_reference as s on s.project_id = x.inspection_major").Count(&count).Order("x.sort asc").Scan(&configuration).Error
503
+	return configuration, err
504
+}
505
+
506
+func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
507
+
508
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
509
+	table := XTReadDB().Table("xt_inspection_reference as r")
510
+	fmt.Println(table)
511
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
512
+	fmt.Println(d)
513
+	if orgid > 0 {
514
+		db = db.Where("x.org_id = ?", orgid)
515
+	}
516
+	if startime > 0 {
517
+		db = db.Where("x.inspect_date >=?", startime)
518
+	}
519
+	if endtime > 0 {
520
+		db = db.Where("x.inspect_date <=?", endtime)
521
+	}
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
524
+	return
525
+}
526
+
527
+func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
528
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
529
+	table := XTReadDB().Table("xt_inspection_reference as r")
530
+	fmt.Println(table)
531
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
532
+	fmt.Println(d)
533
+	if id > 0 {
534
+		db = db.Where("x.patient_id=?", id)
535
+	}
536
+	if orgid > 0 {
537
+		db = db.Where("x.org_id = ?", orgid)
538
+	}
539
+	if startime > 0 {
540
+		db = db.Where("x.inspect_date >=?", startime)
541
+	}
542
+	if endtime > 0 {
543
+		db = db.Where("x.inspect_date <=?", endtime)
544
+	}
545
+
546
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency").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
547
+	return
548
+}
549
+
550
+func GetSearchPatientInfo(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
551
+
552
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
553
+	table := XTReadDB().Table("xt_inspection_reference as r")
554
+	fmt.Println(table)
555
+	d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
556
+	fmt.Println(d)
557
+	p := XTReadDB().Table("xt_patients as p")
558
+	fmt.Println(p)
559
+	if len(keywords) > 0 {
560
+		likeKey := "%" + keywords + "%"
561
+		db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
562
+	}
563
+	if orgid > 0 {
564
+		db = db.Where("x.org_id = ?", orgid)
565
+	}
566
+	if startime > 0 {
567
+		db = db.Where("x.inspect_date >=?", startime)
568
+	}
569
+	if endtime > 0 {
570
+		db = db.Where("x.inspect_date <=?", endtime)
571
+	}
572
+
573
+	err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency").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 p on p.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
574
+	return
575
+}