Browse Source

患者检验检查统计开发

XMLWAN 4 years ago
parent
commit
7bc795110c

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

@@ -744,3 +744,54 @@ func (this *CommonApiController) GetSearchPatientInfo() {
744 744
 		"PatientsInfo": PatientsInfo,
745 745
 	})
746 746
 }
747
+
748
+func (this *CommonApiController) GetAllMajorInspection() {
749
+	adminUser := this.GetAdminUserInfo()
750
+	orgid := adminUser.CurrentOrgId
751
+	inspection, err := service.GetMajorInspectionByOrgid(orgid)
752
+	if len(inspection) == 0 {
753
+		inspect, err := service.GetDefaultByOrgId(0)
754
+		if err != nil {
755
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
756
+			return
757
+		}
758
+		this.ServeSuccessJSON(map[string]interface{}{
759
+			"inspection": inspect,
760
+		})
761
+	} else {
762
+		if err != nil {
763
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
764
+			return
765
+		}
766
+		this.ServeSuccessJSON(map[string]interface{}{
767
+			"inspection": inspection,
768
+		})
769
+	}
770
+}
771
+
772
+func (this *CommonApiController) GetPatientList() {
773
+	adminUser := this.GetAdminUserInfo()
774
+	orgid := adminUser.CurrentOrgId
775
+	startime := this.GetString("startime")
776
+	endtime := this.GetString("endtime")
777
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
778
+	fmt.Println("parseDateErr", parseDateErr)
779
+	statime := startDate.Unix()
780
+	fmt.Println("开始时间", statime)
781
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
782
+	entime := endDate.Unix()
783
+	fmt.Println("结束日期", entime)
784
+	limit, _ := this.GetInt64("limit")
785
+	fmt.Println("limit", limit)
786
+	page, _ := this.GetInt64("page")
787
+	fmt.Println("page", page)
788
+	patientInfo, total, err := service.GetPatientListData(orgid, statime, entime, limit, page)
789
+	if err != nil {
790
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
791
+		return
792
+	}
793
+	this.ServeSuccessJSON(map[string]interface{}{
794
+		"patientInfo": patientInfo,
795
+		"total":       total,
796
+	})
797
+}

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

@@ -37,4 +37,6 @@ func CommonApiControllersRegisterRouters() {
37 37
 	beego.Router("/com/api/getinspectiontotalcount", &CommonApiController{}, "Get:GetInspectionTatolCount")
38 38
 	beego.Router("/com/api/getinspectionDetailById", &CommonApiController{}, "Get:GetInspectionDetailById")
39 39
 	beego.Router("/com/api/getsearchpatientinfo", &CommonApiController{}, "Get:GetSearchPatientInfo")
40
+	beego.Router("/com/api/getallmajorInspection", &CommonApiController{}, "Get:GetAllMajorInspection")
41
+	beego.Router("/com/api/getpatientlist", &CommonApiController{}, "Get:GetPatientList")
40 42
 }

+ 22 - 0
models/common_models.go View File

@@ -303,3 +303,25 @@ type InspectionReferenceMaps struct {
303 303
 	Count              int64                `gorm:"-" json:"count" form:"count"`
304 304
 	CheckConfiguration []CheckConfiguration `gorm:"-" json:"inspection_reference" form:"inspection_reference"`
305 305
 }
306
+
307
+type PatientsInspection 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
+}
323
+
324
+func (PatientsInspection) TableName() string {
325
+
326
+	return "xt_inspection"
327
+}

+ 37 - 0
service/common_service.go View File

@@ -573,3 +573,40 @@ func GetSearchPatientInfo(orgid int64, keywords string, startime int64, endtime
573 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 574
 	return
575 575
 }
576
+
577
+func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
578
+
579
+	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
580
+	table := XTReadDB().Table("xt_inspection_reference ar r")
581
+	fmt.Println(table)
582
+	err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
583
+	return checkconfiguration, err
584
+}
585
+
586
+func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
587
+
588
+	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
589
+	table := XTReadDB().Table("xt_inspection_reference ar r")
590
+	fmt.Println(table)
591
+	err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
592
+	return checkconfiguration, err
593
+}
594
+
595
+func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
596
+
597
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
598
+	table := XTReadDB().Table("xt_patients as s")
599
+	fmt.Println("table", table)
600
+	if orgid > 0 {
601
+		db = db.Where("x.org_id = ?", orgid)
602
+	}
603
+	if startime > 0 {
604
+		db = db.Where("x.inspect_date >= ?", startime)
605
+	}
606
+	if endtime > 0 {
607
+		db = db.Where("x.inspect_date <=?", endtime)
608
+	}
609
+	offset := (page - 1) * limit
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
+	return inspection, total, err
612
+}