陈少旭 2 mesi fa
parent
commit
95b2cbc875

+ 20 - 17
controllers/statistics_api_controller.go Vedi File

@@ -73,17 +73,17 @@ func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
73 73
 	//患者总数
74 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 78
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
79 79
 	max, _ := strconv.ParseFloat(config.LargeRange, 64)
80 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 87
 	c.ServeSuccessJSON(map[string]interface{}{
88 88
 		"patient_count":  patientCount,
89 89
 		"normal_total":   normalTotal,
@@ -125,10 +125,12 @@ func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
125 125
 	}
126 126
 
127 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 134
 	c.ServeSuccessJSON(map[string]interface{}{
133 135
 		"patient":     patient,
134 136
 		"reference":   reference,
@@ -167,7 +169,7 @@ func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
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 175
 	config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
@@ -176,24 +178,25 @@ func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
176 178
 
177 179
 	//max, _ := strconv.ParseFloat(reference.RangeMax, 64)
178 180
 	//min, _ := strconv.ParseFloat(reference.RangeMin, 64)
181
+	//config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
179 182
 
180 183
 	switch item_type {
181 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 186
 		c.ServeSuccessJSON(map[string]interface{}{
184 187
 			"list":      list,
185 188
 			"reference": reference,
186 189
 		})
187 190
 		break
188 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 193
 		c.ServeSuccessJSON(map[string]interface{}{
191 194
 			"list":      list,
192 195
 			"reference": reference,
193 196
 		})
194 197
 		break
195 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 200
 		c.ServeSuccessJSON(map[string]interface{}{
198 201
 			"list":      list,
199 202
 			"reference": reference,
@@ -289,7 +292,7 @@ func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
289 292
 			})
290 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 296
 			c.ServeSuccessJSON(map[string]interface{}{
294 297
 				"list":      list,
295 298
 				"reference": reference,
@@ -311,7 +314,7 @@ func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
311 314
 			})
312 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 318
 			c.ServeSuccessJSON(map[string]interface{}{
316 319
 				"list":      list,
317 320
 				"reference": reference,
@@ -331,7 +334,7 @@ func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
331 334
 				"list": list,
332 335
 			})
333 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 338
 			c.ServeSuccessJSON(map[string]interface{}{
336 339
 				"list":      list,
337 340
 				"reference": reference,
@@ -408,11 +411,11 @@ func (c *StatisticsApiController) GetAllInspectionStatistisc() {
408 411
 			"no_check_total": noCheckTotal,
409 412
 		})
410 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 419
 		c.ServeSuccessJSON(map[string]interface{}{
417 420
 			"patient_count":  patientCount,
418 421
 			"normal_total":   normalTotal,
@@ -483,7 +486,7 @@ func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
483 486
 		//获取配置
484 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 490
 		c.ServeSuccessJSON(map[string]interface{}{
488 491
 			"patient":     patient,
489 492
 			"reference":   reference,

+ 2 - 2
service/inspection_service.go Vedi File

@@ -279,8 +279,8 @@ func GetInspectionReferenceThree(project_id int64, item_id int64) (reference mod
279 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 284
 	return
285 285
 }
286 286
 

+ 16 - 18
service/patientmanage_service.go Vedi File

@@ -1965,28 +1965,28 @@ type InspectionCount struct {
1965 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 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 1971
 	for _, items := range count {
1972 1972
 		total = total + items.Count
1973 1973
 	}
1974 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 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 1979
 	for _, items := range count {
1980 1980
 		total = total + items.Count
1981 1981
 	}
1982 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 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 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 1991
 	if startime > 0 {
1992 1992
 		db = db.Where("x.inspect_date >= ?", startime)
@@ -1998,11 +1998,9 @@ func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, projec
1998 1998
 	if orgid > 0 {
1999 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 2005
 	if patient_id > 0 {
2008 2006
 		db = db.Where("x.patient_id = ?", patient_id)
@@ -2074,7 +2072,7 @@ func GetPatientURRByID(startime int64, endtime int64, orgid int64, patient_id in
2074 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 2076
 	db := XTReadDB().Table("xt_inspection as xti ")
2079 2077
 	if len(keyword) > 0 {
2080 2078
 		keyword = "%" + keyword + "%"
@@ -2082,10 +2080,10 @@ func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64,
2082 2080
 	} else {
2083 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 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 2087
 	db := XTReadDB().Table("xt_inspection as xti ")
2090 2088
 	if len(keyword) > 0 {
2091 2089
 		keyword = "%" + keyword + "%"
@@ -2094,11 +2092,11 @@ func GetUnusualInspectionPatientList(startime int64, endtime int64, orgid int64,
2094 2092
 
2095 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 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 2100
 	return patient, err
2103 2101
 }
2104 2102
 

+ 5 - 5
service/pharmacy_service.go Vedi File

@@ -1693,11 +1693,6 @@ func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error)
1693 1693
 		return
1694 1694
 	}
1695 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 1697
 		if orgid == 10206 {
1703 1698
 			list = append(list, &models.ReplacementDrugs{
@@ -1706,6 +1701,11 @@ func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error)
1706 1701
 			})
1707 1702
 
1708 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 1709
 			list = append(list, &models.ReplacementDrugs{
1710 1710
 				Id:   v.ID,
1711 1711
 				Name: v.DrugName + " " + v.Dose + v.DoseUnit + "*" + config.ToString(v.MinNumber) + v.MinUnit + "/" + v.PrescribingNumberUnit + " " + tmp.ManufacturerName,