Browse Source

提交代码

陈少旭 2 months ago
parent
commit
95b2cbc875

+ 20 - 17
controllers/statistics_api_controller.go View File

73
 	//患者总数
73
 	//患者总数
74
 	patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
74
 	patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
75
 	//获取配置
75
 	//获取配置
76
-	reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
76
+	reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
77
 	//获取数值在正常范围内的总数
77
 	//获取数值在正常范围内的总数
78
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
78
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
79
 	max, _ := strconv.ParseFloat(config.LargeRange, 64)
79
 	max, _ := strconv.ParseFloat(config.LargeRange, 64)
80
 	min, _ := strconv.ParseFloat(config.MinRange, 64)
80
 	min, _ := strconv.ParseFloat(config.MinRange, 64)
81
 
81
 
82
-	normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
82
+	normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
83
 	//获取数值异常的总数
83
 	//获取数值异常的总数
84
-	unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
84
+	unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
85
 	//获取没有检查的患者总数
85
 	//获取没有检查的患者总数
86
-	noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
86
+	noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
87
 	c.ServeSuccessJSON(map[string]interface{}{
87
 	c.ServeSuccessJSON(map[string]interface{}{
88
 		"patient_count":  patientCount,
88
 		"patient_count":  patientCount,
89
 		"normal_total":   normalTotal,
89
 		"normal_total":   normalTotal,
125
 	}
125
 	}
126
 
126
 
127
 	patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
127
 	patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
128
+	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
129
+
128
 	//获取配置
130
 	//获取配置
129
-	reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
131
+	reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
130
 	//获取数值在正常范围内的总数
132
 	//获取数值在正常范围内的总数
131
-	inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
133
+	inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
132
 	c.ServeSuccessJSON(map[string]interface{}{
134
 	c.ServeSuccessJSON(map[string]interface{}{
133
 		"patient":     patient,
135
 		"patient":     patient,
134
 		"reference":   reference,
136
 		"reference":   reference,
167
 	}
169
 	}
168
 
170
 
169
 	//获取配置
171
 	//获取配置
170
-	reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
172
+	reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
171
 	//获取数值在正常范围内的总数
173
 	//获取数值在正常范围内的总数
172
 
174
 
173
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
175
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
176
 
178
 
177
 	//max, _ := strconv.ParseFloat(reference.RangeMax, 64)
179
 	//max, _ := strconv.ParseFloat(reference.RangeMax, 64)
178
 	//min, _ := strconv.ParseFloat(reference.RangeMin, 64)
180
 	//min, _ := strconv.ParseFloat(reference.RangeMin, 64)
181
+	//config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
179
 
182
 
180
 	switch item_type {
183
 	switch item_type {
181
 	case 1:
184
 	case 1:
182
-		list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
185
+		list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
183
 		c.ServeSuccessJSON(map[string]interface{}{
186
 		c.ServeSuccessJSON(map[string]interface{}{
184
 			"list":      list,
187
 			"list":      list,
185
 			"reference": reference,
188
 			"reference": reference,
186
 		})
189
 		})
187
 		break
190
 		break
188
 	case 2:
191
 	case 2:
189
-		list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
192
+		list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
190
 		c.ServeSuccessJSON(map[string]interface{}{
193
 		c.ServeSuccessJSON(map[string]interface{}{
191
 			"list":      list,
194
 			"list":      list,
192
 			"reference": reference,
195
 			"reference": reference,
193
 		})
196
 		})
194
 		break
197
 		break
195
 	case 3:
198
 	case 3:
196
-		list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
199
+		list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
197
 		c.ServeSuccessJSON(map[string]interface{}{
200
 		c.ServeSuccessJSON(map[string]interface{}{
198
 			"list":      list,
201
 			"list":      list,
199
 			"reference": reference,
202
 			"reference": reference,
289
 			})
292
 			})
290
 		} else {
293
 		} else {
291
 
294
 
292
-			list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
295
+			list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
293
 			c.ServeSuccessJSON(map[string]interface{}{
296
 			c.ServeSuccessJSON(map[string]interface{}{
294
 				"list":      list,
297
 				"list":      list,
295
 				"reference": reference,
298
 				"reference": reference,
311
 			})
314
 			})
312
 		} else {
315
 		} else {
313
 
316
 
314
-			list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
317
+			list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
315
 			c.ServeSuccessJSON(map[string]interface{}{
318
 			c.ServeSuccessJSON(map[string]interface{}{
316
 				"list":      list,
319
 				"list":      list,
317
 				"reference": reference,
320
 				"reference": reference,
331
 				"list": list,
334
 				"list": list,
332
 			})
335
 			})
333
 		} else {
336
 		} else {
334
-			list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
337
+			list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
335
 			c.ServeSuccessJSON(map[string]interface{}{
338
 			c.ServeSuccessJSON(map[string]interface{}{
336
 				"list":      list,
339
 				"list":      list,
337
 				"reference": reference,
340
 				"reference": reference,
408
 			"no_check_total": noCheckTotal,
411
 			"no_check_total": noCheckTotal,
409
 		})
412
 		})
410
 	} else {
413
 	} else {
411
-		normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
414
+		normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
412
 		//获取数值异常的总数
415
 		//获取数值异常的总数
413
-		unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
416
+		unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
414
 		//获取没有检查的患者总数
417
 		//获取没有检查的患者总数
415
-		noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
418
+		noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
416
 		c.ServeSuccessJSON(map[string]interface{}{
419
 		c.ServeSuccessJSON(map[string]interface{}{
417
 			"patient_count":  patientCount,
420
 			"patient_count":  patientCount,
418
 			"normal_total":   normalTotal,
421
 			"normal_total":   normalTotal,
483
 		//获取配置
486
 		//获取配置
484
 		reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
487
 		reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
485
 		//获取数值在正常范围内的总数
488
 		//获取数值在正常范围内的总数
486
-		inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
489
+		inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
487
 		c.ServeSuccessJSON(map[string]interface{}{
490
 		c.ServeSuccessJSON(map[string]interface{}{
488
 			"patient":     patient,
491
 			"patient":     patient,
489
 			"reference":   reference,
492
 			"reference":   reference,

+ 2 - 2
service/inspection_service.go View File

279
 	return
279
 	return
280
 }
280
 }
281
 
281
 
282
-func GetInspectionReferenceFour(project_id int64, item_id int64) (reference models.InspectionReference, err error) {
283
-	err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and item_id = ? and status = 1", project_id, item_id).Order("project_id").Find(&reference).Error
282
+func GetInspectionReferenceFour(project_id int64, item_id int64, org_id int64) (reference models.InspectionReference, err error) {
283
+	err = readDb.Model(&models.InspectionReference{}).Where("project_id = ? and item_id = ? and status = 1 and org_id = ?", project_id, item_id, org_id).Order("project_id").Find(&reference).Error
284
 	return
284
 	return
285
 }
285
 }
286
 
286
 

+ 16 - 18
service/patientmanage_service.go View File

1965
 	Count int64
1965
 	Count int64
1966
 }
1966
 }
1967
 
1967
 
1968
-func GetNormalInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64) (total int64, err error) {
1968
+func GetNormalInspectionTotalByID(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64) (total int64, err error) {
1969
 	var count []*InspectionCount
1969
 	var count []*InspectionCount
1970
-	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, min_value).Scan(&count).Error
1970
+	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ?  and x.item_name = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ?  and xti.item_name = ?  and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, min_value).Scan(&count).Error
1971
 	for _, items := range count {
1971
 	for _, items := range count {
1972
 		total = total + items.Count
1972
 		total = total + items.Count
1973
 	}
1973
 	}
1974
 	return total, err2
1974
 	return total, err2
1975
 }
1975
 }
1976
-func GetUnusualInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64) (total int64, err error) {
1976
+func GetUnusualInspectionTotalByID(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64) (total int64, err error) {
1977
 	var count []*InspectionCount
1977
 	var count []*InspectionCount
1978
-	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
1978
+	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.org_id = ? and xti.item_name = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ?  and xti.item_name = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, orgid, item_name, startime, endtime, min_value).Scan(&count).Error
1979
 	for _, items := range count {
1979
 	for _, items := range count {
1980
 		total = total + items.Count
1980
 		total = total + items.Count
1981
 	}
1981
 	}
1982
 	return total, err2
1982
 	return total, err2
1983
 }
1983
 }
1984
-func GetPatientNotInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
1985
-	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
1984
+func GetPatientNotInspectionTotal(startime int64, endtime int64, orgid int64, item_name string) (total int64, err error) {
1985
+	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.item_name = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, item_name, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
1986
 	return total, err
1986
 	return total, err
1987
 }
1987
 }
1988
 
1988
 
1989
-func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, patient_id int64) (inspections []*models.Inspection, err error) {
1989
+func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, patient_id int64, item_name string) (inspections []*models.Inspection, err error) {
1990
 	db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
1990
 	db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
1991
 	if startime > 0 {
1991
 	if startime > 0 {
1992
 		db = db.Where("x.inspect_date >= ?", startime)
1992
 		db = db.Where("x.inspect_date >= ?", startime)
1998
 	if orgid > 0 {
1998
 	if orgid > 0 {
1999
 		db = db.Where("x.org_id = ?", orgid)
1999
 		db = db.Where("x.org_id = ?", orgid)
2000
 	}
2000
 	}
2001
-	if projectid > 0 {
2002
-		db = db.Where("x.reference_project_id = ?", projectid)
2003
-	}
2004
-	if item_id > 0 {
2005
-		db = db.Where("x.reference_item_id = ?", item_id)
2001
+
2002
+	if len(item_name) > 0 {
2003
+		db = db.Where("x.item_name = ?", item_name)
2006
 	}
2004
 	}
2007
 	if patient_id > 0 {
2005
 	if patient_id > 0 {
2008
 		db = db.Where("x.patient_id = ?", patient_id)
2006
 		db = db.Where("x.patient_id = ?", patient_id)
2074
 	return inspections, err
2072
 	return inspections, err
2075
 }
2073
 }
2076
 
2074
 
2077
-func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2075
+func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2078
 	db := XTReadDB().Table("xt_inspection as xti ")
2076
 	db := XTReadDB().Table("xt_inspection as xti ")
2079
 	if len(keyword) > 0 {
2077
 	if len(keyword) > 0 {
2080
 		keyword = "%" + keyword + "%"
2078
 		keyword = "%" + keyword + "%"
2082
 	} else {
2080
 	} else {
2083
 		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
2081
 		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
2084
 	}
2082
 	}
2085
-	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, min_value).Scan(&xti).Error
2083
+	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ? and xti.item_name = ?   and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, min_value).Scan(&xti).Error
2086
 	return xti, err2
2084
 	return xti, err2
2087
 }
2085
 }
2088
-func GetUnusualInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2086
+func GetUnusualInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2089
 	db := XTReadDB().Table("xt_inspection as xti ")
2087
 	db := XTReadDB().Table("xt_inspection as xti ")
2090
 	if len(keyword) > 0 {
2088
 	if len(keyword) > 0 {
2091
 		keyword = "%" + keyword + "%"
2089
 		keyword = "%" + keyword + "%"
2094
 
2092
 
2095
 		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
2093
 		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
2096
 	}
2094
 	}
2097
-	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
2095
+	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.item_name = ?   and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.org_id = ? and xti.item_name = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.item_name = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, item_name, startime, endtime, orgid, item_name, startime, endtime, max_value, orgid, item_name, startime, endtime, min_value).Scan(&xti).Error
2098
 	return xti, err2
2096
 	return xti, err2
2099
 }
2097
 }
2100
-func GetPatientNotInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, keyword string) (patient []*models.XtPatientsTen, err error) {
2101
-	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2098
+func GetPatientNotInspectionPatientList(startime int64, endtime int64, orgid int64, item_name string, keyword string) (patient []*models.XtPatientsTen, err error) {
2099
+	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.item_name = ?  and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, item_name, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2102
 	return patient, err
2100
 	return patient, err
2103
 }
2101
 }
2104
 
2102
 

+ 5 - 5
service/pharmacy_service.go View File

1693
 		return
1693
 		return
1694
 	}
1694
 	}
1695
 	for _, v := range lib {
1695
 	for _, v := range lib {
1696
-		var tmp models.Manufacturer
1697
-		err = readDb.Model(&models.Manufacturer{}).Where("id = ?", v.Manufacturer).Find(&tmp).Error
1698
-		if err != nil {
1699
-			return
1700
-		}
1701
 
1696
 
1702
 		if orgid == 10206 {
1697
 		if orgid == 10206 {
1703
 			list = append(list, &models.ReplacementDrugs{
1698
 			list = append(list, &models.ReplacementDrugs{
1706
 			})
1701
 			})
1707
 
1702
 
1708
 		} else {
1703
 		} else {
1704
+			var tmp models.Manufacturer
1705
+			err = readDb.Model(&models.Manufacturer{}).Where("id = ?", v.Manufacturer).Find(&tmp).Error
1706
+			if err != nil {
1707
+				return
1708
+			}
1709
 			list = append(list, &models.ReplacementDrugs{
1709
 			list = append(list, &models.ReplacementDrugs{
1710
 				Id:   v.ID,
1710
 				Id:   v.ID,
1711
 				Name: v.DrugName + " " + v.Dose + v.DoseUnit + "*" + config.ToString(v.MinNumber) + v.MinUnit + "/" + v.PrescribingNumberUnit + " " + tmp.ManufacturerName,
1711
 				Name: v.DrugName + " " + v.Dose + v.DoseUnit + "*" + config.ToString(v.MinNumber) + v.MinUnit + "/" + v.PrescribingNumberUnit + " " + tmp.ManufacturerName,