Browse Source

更新数据

XMLWAN 5 years ago
parent
commit
419ce93966

+ 114 - 4
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go View File

@@ -603,9 +603,9 @@ func (this *NewDialysisApiController) GetDoctorAdvices() {
603 603
 	limit, _ := this.GetInt64("limit")
604 604
 	page, _ := this.GetInt64("page")
605 605
 	fmt.Println("病人ID", newPatientInfo.BloodId)
606
-	advice, total, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
607
-	one, t, date, err := service.GetNewDoctorAdviceOne(newPatientInfo.BloodId, page, orgid)
608
-	fmt.Print(one, t, date, err)
606
+	advice, _, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
607
+	one, total, err := service.GetNewDoctorAdviceOne(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
608
+	fmt.Print(one, total, err)
609 609
 	if err != nil {
610 610
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
611 611
 		return
@@ -1563,8 +1563,8 @@ func (this *NewDialysisApiController) GetInspection() {
1563 1563
 
1564 1564
 func (this *NewDialysisApiController) GetMyInformation() {
1565 1565
 	id, _ := this.GetInt64("id")
1566
-	fmt.Println("id--------------", id)
1567 1566
 	roleInfo, err := service.GetPosition(id)
1567
+
1568 1568
 	if err != nil {
1569 1569
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1570 1570
 		return
@@ -2040,11 +2040,121 @@ func (this *NewDialysisApiController) GetOrgInformation() {
2040 2040
 	adminUser := this.GetMobileAdminUserInfo()
2041 2041
 	id := adminUser.Org.Id
2042 2042
 	information, err := service.GetOrgInformation(id)
2043
+	name, err := service.GetShortName(information.OrgType)
2044
+	typeName, err := service.GetTypeName(name.Pid)
2045
+	//获取省
2046
+	province, err := service.GetOrgProvince(information.Province)
2047
+	cityes, err := service.GetOrgProvince(information.City)
2048
+	district, err := service.GetOrgProvince(information.District)
2049
+	fmt.Print("err", err)
2043 2050
 	if err != nil {
2044 2051
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2045 2052
 		return
2046 2053
 	}
2047 2054
 	this.ServeSuccessJSON(map[string]interface{}{
2048 2055
 		"information": information,
2056
+		"name":        name,
2057
+		"typeName":    typeName,
2058
+		"province":    province,
2059
+		"city":        cityes,
2060
+		"district":    district,
2061
+	})
2062
+}
2063
+
2064
+func (this *NewDialysisApiController) GetAllOrgType() {
2065
+
2066
+	orgType, _ := service.GetAllOrgType()
2067
+	returnData := make(map[string]interface{}, 0)
2068
+	returnData["orgType"] = orgType
2069
+	this.ServeSuccessJSON(returnData)
2070
+}
2071
+
2072
+func (this *NewDialysisApiController) EditOrg() {
2073
+	id, _ := this.GetInt64("id")
2074
+	fmt.Println("id", id)
2075
+	name := this.GetString("org_name")
2076
+	fmt.Println("name", name)
2077
+	provinceName := this.GetString("provinces_name")
2078
+	fmt.Println("provinceName", provinceName)
2079
+	cityName := this.GetString("city_name")
2080
+	fmt.Println("cityName", cityName)
2081
+	districtName := this.GetString("district_name")
2082
+	fmt.Println("districtName", districtName)
2083
+	address := this.GetString("address")
2084
+	fmt.Println("address", address)
2085
+	org_type := this.GetString("org_type")
2086
+	fmt.Println("org_type", org_type)
2087
+	contactName := this.GetString("contact_name")
2088
+	fmt.Println("contactName", contactName)
2089
+	orgPhone := this.GetString("telephone")
2090
+	fmt.Println("orgPhone", orgPhone)
2091
+	provinceID := 0
2092
+	cityID := 0
2093
+	districtID := 0
2094
+	province, getProvinceErr := service.GetProvinceWithName(provinceName)
2095
+	if getProvinceErr != nil {
2096
+		utils.ErrorLog("查询省名失败:%v", getProvinceErr)
2097
+		this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2098
+		this.ServeJSON()
2099
+		return
2100
+	} else if province != nil {
2101
+		provinceID = int(province.ID)
2102
+		city, getCityErr := service.GetCityWithName(province.ID, cityName)
2103
+		if getCityErr != nil {
2104
+			utils.ErrorLog("查询城市名失败:%v", getCityErr)
2105
+			this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2106
+			this.ServeJSON()
2107
+			return
2108
+		} else if city != nil {
2109
+			cityID = int(city.ID)
2110
+			district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
2111
+			if getDistrictErr != nil {
2112
+				utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
2113
+				this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2114
+				this.ServeJSON()
2115
+				return
2116
+			} else if district != nil {
2117
+				districtID = int(district.ID)
2118
+			}
2119
+		}
2120
+	}
2121
+
2122
+	orgType := service.GetOrgTypeByName(org_type)
2123
+	fmt.Println(provinceID, cityID, districtID)
2124
+	org := models.SgjUserOrg{
2125
+		OrgName:      name,
2126
+		OrgShortName: name,
2127
+		Province:     int64(provinceID),
2128
+		City:         int64(cityID),
2129
+		District:     int64(districtID),
2130
+		Address:      address,
2131
+		OrgType:      orgType.ID,
2132
+		Telephone:    orgPhone,
2133
+		ContactName:  contactName,
2134
+	}
2135
+
2136
+	fmt.Println("org", org)
2137
+	err := service.UpdateOrg(id, org)
2138
+	if err != nil {
2139
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2140
+		return
2141
+	}
2142
+	this.ServeSuccessJSON(map[string]interface{}{
2143
+		"org": org,
2144
+	})
2145
+}
2146
+
2147
+func (this *NewDialysisApiController) GetMyInforName() {
2148
+
2149
+	id, _ := this.GetInt64("id")
2150
+	Rolename, err := service.GetMyInfoName(id)
2151
+	Username, err := service.GetAdminName(Rolename.AdminUserId)
2152
+	if err != nil {
2153
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
2154
+		return
2155
+	}
2156
+	this.ServeSuccessJSON(map[string]interface{}{
2157
+		"Rolename": Rolename,
2158
+		"Username": Username,
2049 2159
 	})
2050 2160
 }

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

@@ -132,4 +132,7 @@ func NewMobileAPIControllersRegisterRouters() {
132 132
 	beego.Router("/m/api/patient/getallorganization", &NewDialysisApiController{}, "Get:GetAllOrganization")
133 133
 	beego.Router("/m/api/patient/getmyorganazition", &NewDialysisApiController{}, "Get:GetMyOrganazition")
134 134
 	beego.Router("/m/api/org/getorginformation", &NewDialysisApiController{}, "Get:GetOrgInformation")
135
+	beego.Router("/m/api/patient/getallorgtype", &NewDialysisApiController{}, "Get:GetAllOrgType")
136
+	beego.Router("/m/api/patient/editorg", &NewDialysisApiController{}, "Get:EditOrg")
137
+	beego.Router("/m/api/patient/getmyinforname", &NewDialysisApiController{}, "Get:GetMyInforName")
135 138
 }

+ 32 - 0
models/org_models.go View File

@@ -150,3 +150,35 @@ type SgjUserOrg struct {
150 150
 func (SgjUserOrg) TableName() string {
151 151
 	return "sgj_user_org"
152 152
 }
153
+
154
+type SgjUserDistrict struct {
155
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
156
+	Name      string `gorm:"column:name" json:"name" form:"name"`
157
+	Level     int64  `gorm:"column:level" json:"level" form:"level"`
158
+	Upid      int64  `gorm:"column:upid" json:"upid" form:"upid"`
159
+	Path      string `gorm:"column:path" json:"path" form:"path"`
160
+	Namepath  string `gorm:"column:namepath" json:"namepath" form:"namepath"`
161
+	Initial   string `gorm:"column:initial" json:"initial" form:"initial"`
162
+	Longitude string `gorm:"column:longitude" json:"longitude" form:"longitude"`
163
+	Latitude  string `gorm:"column:latitude" json:"latitude" form:"latitude"`
164
+	Adcode    int64  `gorm:"column:adcode" json:"adcode" form:"adcode"`
165
+}
166
+
167
+func (SgjUserDistrict) TableName() string {
168
+	return "sgj_user_district"
169
+}
170
+
171
+type SgjUserOrgType struct {
172
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
173
+	Name        string `gorm:"column:name" json:"name" form:"name"`
174
+	ShortName   string `gorm:"column:short_name" json:"short_name" form:"short_name"`
175
+	Pid         int64  `gorm:"column:pid" json:"pid" form:"pid"`
176
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
177
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
178
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
179
+	SortNo      int64  `gorm:"column:sort_no" json:"sort_no" form:"sort_no"`
180
+}
181
+
182
+func (SgjUserOrgType) TableName() string {
183
+	return "sgj_user_org_type"
184
+}

+ 66 - 30
service/patientmanage_service.go View File

@@ -504,39 +504,31 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
504 504
 
505 505
 }
506 506
 
507
-func GetNewDoctorAdviceOne(patientID int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, date int64, err error) {
508
-
509
-	var advicesCount models.UserDoctorAdvicesCount
510
-
511
-	err = XTReadDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status =1", patientID, orgID).Select("count(distinct record_date) as count,patient_id").Scan(&advicesCount).Error
512
-
513
-	if err != nil {
514
-		return
507
+func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
508
+	db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
509
+	table := UserReadDB().Table("sgj_user_admin_role as r")
510
+	fmt.Println("table", table)
511
+	if orgID > 0 {
512
+		db = db.Where("x.user_org_id=?", orgID)
515 513
 	}
516
-	total = advicesCount.Count
517
-	if total == 0 || page > total {
518
-		return
514
+	if patientID > 0 {
515
+		db = db.Where("x.patient_id = ?", patientID)
519 516
 	}
520
-
521
-	var Id models.AdviceDate
522
-
523
-	err = XTReadDB().Model(models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Select("record_date").Group("record_date").Order("created_time desc").Offset(page - 1).Limit(10).Scan(&Id).Error
524
-	if err != nil {
525
-		return
517
+	if advice_type > 0 {
518
+		db = db.Where("x.advice_type = ?", advice_type)
519
+	} else if advice_type == 0 {
520
+		db = db.Where("x.advice_type in (?)", []int{1, 3})
526 521
 	}
527
-
528
-	if Id.RecordDate == 0 {
529
-		return
522
+	if start > 0 {
523
+		db = db.Where("x.start_time>=?", start)
530 524
 	}
531
-
532
-	date = Id.RecordDate
533
-	fmt.Println("结构是==============", Id.RecordDate)
534
-	doctoradvice, err = GetAdvices(orgID, patientID, Id.RecordDate)
535
-	if err != nil {
536
-		return
525
+	if end > 0 {
526
+		db = db.Where("start_time<=?", end)
537 527
 	}
528
+	offset := (page - 1) * limit
529
+	err = db.Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc").Scan(&doctoradvice).Error
530
+	fmt.Print("错误是什么东西", err)
538 531
 	return
539
-
540 532
 }
541 533
 
542 534
 func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
@@ -1064,7 +1056,7 @@ func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZone
1064 1056
 		db = db.Where("x.org_id = ?", orgid)
1065 1057
 	}
1066 1058
 	offset := (page - 1) * limit
1067
-	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id").Scan(&zone).Error
1059
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id AND n.status = 1").Scan(&zone).Error
1068 1060
 	return zone, total, err
1069 1061
 }
1070 1062
 
@@ -1087,7 +1079,7 @@ func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGr
1087 1079
 		db = db.Where("x.org_id = ?", orgid)
1088 1080
 	}
1089 1081
 	offset := (page - 1) * limit
1090
-	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id").Scan(&group).Error
1082
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id And n.status = 1").Scan(&group).Error
1091 1083
 	return group, total, err
1092 1084
 }
1093 1085
 
@@ -1121,7 +1113,7 @@ func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.Device
1121 1113
 		db = db.Where("x.org_id = ?", orgid)
1122 1114
 	}
1123 1115
 	offset := (page - 1) * limit
1124
-	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
1116
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime asc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
1125 1117
 
1126 1118
 	return number, total, err
1127 1119
 }
@@ -1178,3 +1170,47 @@ func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
1178 1170
 	err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
1179 1171
 	return org, err
1180 1172
 }
1173
+
1174
+func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
1175
+
1176
+	orgType := models.SgjUserOrgType{}
1177
+	err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
1178
+	return orgType, err
1179
+}
1180
+
1181
+func GetTypeName(id int64) (models.SgjUserOrgType, error) {
1182
+	orgType := models.SgjUserOrgType{}
1183
+	err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
1184
+	return orgType, err
1185
+}
1186
+
1187
+func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
1188
+
1189
+	district := models.SgjUserDistrict{}
1190
+	err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
1191
+	return district, err
1192
+}
1193
+
1194
+func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
1195
+
1196
+	err = UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Find(&orgType).Error
1197
+	return
1198
+}
1199
+
1200
+func UpdateOrg(id int64, org models.SgjUserOrg) error {
1201
+
1202
+	err := UserWriteDB().Model(&org).Where("id = ?", id).Update(map[string]interface{}{"org_name": org.OrgName, "org_short_name": org.OrgShortName, "province": org.Province, "city": org.City, "district": org.District, "address": org.Address, "org_type": org.OrgType, "telephone": org.Telephone, "contact_name": org.ContactName, "mtime": time.Now().Unix()}).Error
1203
+	return err
1204
+}
1205
+
1206
+func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
1207
+	role := models.SgjUserAdminRole{}
1208
+	err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
1209
+	return role, err
1210
+}
1211
+
1212
+func GetAdminName(id int64) (models.AdminUser, error) {
1213
+	user := models.AdminUser{}
1214
+	err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
1215
+	return user, err
1216
+}