XMLWAN пре 4 година
родитељ
комит
fe8b7392c1

+ 93 - 0
controllers/dialysis_parameter_api_controller.go Прегледај датотеку

@@ -0,0 +1,93 @@
1
+package controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/service"
6
+	"fmt"
7
+	"github.com/astaxie/beego"
8
+	"strings"
9
+	"time"
10
+)
11
+
12
+type DialysisPrameterApiController struct {
13
+	BaseAuthAPIController
14
+}
15
+
16
+func DialysisPrameteRoutes() {
17
+	beego.Router("/api/dialysis/getdialysisparameters", &DialysisPrameterApiController{}, "Get:GetDialysisParameters")
18
+	beego.Router("/api/dialysis/getdialysisbatchparameters", &DialysisPrameterApiController{}, "Get:GetDialysisBatchParameters")
19
+	beego.Router("/api/dialysis/getwarehouseoutlist", &DialysisPrameterApiController{}, "Get:GetWareHouseOutList")
20
+}
21
+
22
+func (this *DialysisPrameterApiController) GetDialysisParameters() {
23
+	timeLayout := "2006-01-02"
24
+	loc, _ := time.LoadLocation("Local")
25
+	page, _ := this.GetInt64("page")
26
+	limit, _ := this.GetInt64("limit")
27
+	schedulType, _ := this.GetInt64("scheduleType")
28
+	start_time := this.GetString("start_time")
29
+	partitionType, _ := this.GetInt64("partitionType")
30
+	keywords := this.GetString("keyword")
31
+	adminUserInfo := this.GetAdminUserInfo()
32
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
33
+	fmt.Println("scheduletype", schedulType, start_time, partitionType, keywords, theTime.Unix())
34
+	if len(keywords) > 0 {
35
+		dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
36
+		if err == nil {
37
+			this.ServeSuccessJSON(map[string]interface{}{
38
+				"schedule": dialysisSchedule,
39
+				"total":    total,
40
+			})
41
+		} else {
42
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
43
+		}
44
+	} else {
45
+		dialysisSchedule, err, total := service.GetDialysisParameter(adminUserInfo.CurrentOrgId, theTime.Unix(), schedulType, partitionType, page, limit)
46
+		if err == nil {
47
+			this.ServeSuccessJSON(map[string]interface{}{
48
+				"schedule": dialysisSchedule,
49
+				"total":    total,
50
+			})
51
+		} else {
52
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
53
+		}
54
+	}
55
+
56
+}
57
+
58
+func (this *DialysisPrameterApiController) GetDialysisBatchParameters() {
59
+	adminUser := this.GetAdminUserInfo()
60
+	orgId := adminUser.CurrentOrgId
61
+	schIDStr := this.GetString("ids")
62
+	if len(schIDStr) == 0 {
63
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
64
+		return
65
+	}
66
+	idStrs := strings.Split(schIDStr, ",")
67
+
68
+	parameters, err := service.GetDialysisBatchParameters(idStrs, orgId)
69
+	if err == nil {
70
+		this.ServeSuccessJSON(map[string]interface{}{
71
+			"schedule": parameters,
72
+		})
73
+	}
74
+}
75
+
76
+func (this *DialysisPrameterApiController) GetWareHouseOutList() {
77
+
78
+	timeLayout := "2006-01-02"
79
+	loc, _ := time.LoadLocation("Local")
80
+	start_time := this.GetString("start_time")
81
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
82
+	end_time := this.GetString("end_time")
83
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
84
+	fmt.Println(start_time, end_time)
85
+	adminUserInfo := this.GetAdminUserInfo()
86
+	orgId := adminUserInfo.CurrentOrgId
87
+	wareoutlist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
88
+	if err == nil {
89
+		this.ServeSuccessJSON(map[string]interface{}{
90
+			"wareoutlist": wareoutlist,
91
+		})
92
+	}
93
+}

+ 58 - 0
models/dialysis_parameter_models.go Прегледај датотеку

@@ -0,0 +1,58 @@
1
+package models
2
+
3
+type DialysisParameter struct {
4
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
7
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
8
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
9
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
10
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
11
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
12
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
13
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
14
+	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
15
+	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
16
+
17
+	MonitorPatients MonitorPatients `gorm:"ForeignKey:PatientId" json:"patient"`
18
+	DeviceNumber    DeviceNumber    `gorm:"ForeignKey:BedId" json:"device_number"`
19
+	DeviceZone      DeviceZone      `gorm:"ForeignKey:PartitionId" json:"device_zone"`
20
+	TreatmentMode   TreatmentMode   `gorm:"ForeignKey:ModeId" json:"treatment_mode"`
21
+
22
+	DialysisOrder            MonitorDialysisOrder    `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
23
+	Prescription             DialysisPrescription    `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"prescription"`
24
+	AssessmentBeforeDislysis PredialysisEvaluation   `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_before_dislysis"`
25
+	AssessmentAfterDislysis  AssessmentAfterDislysis `gorm:"ForeignKey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"assessment_after_dislysis"`
26
+	MonitoringRecord         []MonitoringRecord      `gorm:"ForeignKey:MonitoringDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"monitoring_record"`
27
+}
28
+
29
+func (DialysisParameter) TableName() string {
30
+	return "xt_schedule"
31
+}
32
+
33
+type XtWarehouseOutInfo struct {
34
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
35
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
36
+	GoodId                  int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
37
+	GoodTypeId              int64   `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
38
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
39
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
40
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
41
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
42
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
43
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
44
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
45
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
46
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
47
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
48
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
49
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
50
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
51
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
52
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
53
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
54
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
55
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
56
+	TypeName                string  `gorm:"column:type_name" json:"type_name" form:"type_name"`
57
+	SpecificationName       string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
58
+}

+ 1 - 0
routers/router.go Прегледај датотеку

@@ -64,4 +64,5 @@ func init() {
64 64
 	//controllers.PatientRouters()
65 65
 	controllers.DoctorScheduleRouters()
66 66
 	new_m_api.StaffScheduleApiControllersRegisterRouters()
67
+	controllers.DialysisPrameteRoutes()
67 68
 }

+ 111 - 0
service/dialysis_parameter_service.go Прегледај датотеку

@@ -0,0 +1,111 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
6
+)
7
+
8
+func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, schedulDate int64) ([]*models.DialysisParameter, error, int64) {
9
+
10
+	var patients []*models.Patients
11
+	getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
12
+	if getPatientErr != nil {
13
+		return nil, getPatientErr, 0
14
+	}
15
+	patientIDs := make([]int64, len(patients))
16
+	for index, patient := range patients {
17
+		patientIDs[index] = patient.ID
18
+	}
19
+
20
+	db := readDb.
21
+		Model(&models.DialysisSchedule{}).
22
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
23
+		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
24
+		Preload("TreatmentMode", "status = 1").
25
+		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
26
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
27
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
28
+		Preload("MonitoringRecord", "status = 1 AND  user_org_id = ?", orgID).
29
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
30
+		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
31
+	db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
32
+	if schedulType > 0 {
33
+		db = db.Where("schedule_type = ?", schedulType)
34
+	}
35
+	if partitionType > 0 {
36
+		db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
37
+		// db = db.Where("partition_id = ?", partitionType)
38
+	}
39
+	if schedulDate > 0 {
40
+		db = db.Where("schedule_date = ?", schedulDate)
41
+	}
42
+	var schedules []*models.DialysisParameter
43
+	total := int64(0)
44
+	err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
45
+	return schedules, err, total
46
+}
47
+
48
+func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64) (schedule []*models.DialysisParameter, err error, total int64) {
49
+	db := readDb.
50
+		Model(&models.MonitorDialysisSchedule{}).
51
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
52
+		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
53
+		Preload("TreatmentMode", "status = 1").
54
+		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
55
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
56
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
57
+		Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
58
+			return db.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time asc")
59
+		}).
60
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
61
+		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
62
+	db = db.Where("xt_schedule.status = 1 AND user_org_id = ?", orgID)
63
+	if schedulDate > 0 {
64
+		db = db.Where("schedule_date = ?", schedulDate)
65
+	}
66
+	if schedulType > 0 {
67
+		db = db.Where("schedule_type = ?", schedulType)
68
+	}
69
+	if partitionType > 0 {
70
+		db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ? and xt_device_number.status = 1", partitionType)
71
+		// db = db.Where("partition_id = ?", partitionType)
72
+	}
73
+	offset := (page - 1) * limit
74
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
75
+	return schedule, err, total
76
+}
77
+
78
+func GetDialysisBatchParameters(schIDs []string, orgID int64) (schedule []*models.DialysisParameter, err error) {
79
+
80
+	db := readDb.
81
+		Model(&models.DialysisSchedule{}).
82
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
83
+		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
84
+		Preload("TreatmentMode", "status = 1").
85
+		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
86
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
87
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
88
+		Preload("MonitoringRecord", "status = 1 AND  user_org_id = ?", orgID).
89
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
90
+		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
91
+	db = db.Where("xt_schedule.status = 1 AND id in (?)", schIDs)
92
+	var schedules []*models.DialysisParameter
93
+	err = db.Order("schedule_date desc").Find(&schedules).Error
94
+	return schedules, err
95
+}
96
+
97
+func GetWareHouseOutList(startime int64, endtime int64, orgid int64) (warehouse []*models.XtWarehouseOutInfo, err error) {
98
+
99
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
100
+	if startime > 0 {
101
+		db = db.Where("x.sys_record_time >=?", startime)
102
+	}
103
+	if endtime > 0 {
104
+		db = db.Where("x.sys_record_time<=?", endtime)
105
+	}
106
+	if orgid > 0 {
107
+		db = db.Where("x.org_id = ?", orgid)
108
+	}
109
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.count,x.warehouse_out_order_number,x.sys_record_time,s.specification_name,t.type_name").Joins("left join xt_good_information as s on s.id = x.good_id").Where("s.status = 1 and s.org_id = ?", orgid).Joins("left join xt_goods_type as t on t.id = x.good_type_id").Order("x.id desc").Scan(&warehouse).Error
110
+	return warehouse, err
111
+}