Bläddra i källkod

患者检验检查统计开发

XMLWAN 4 år sedan
förälder
incheckning
f1d598b614

+ 24 - 8
controllers/new_mobile_api_controllers/common_api_controller.go Visa fil

@@ -42,14 +42,30 @@ func (this *CommonApiController) GetInspectionMajor() {
42 42
 
43 43
 func (this *CommonApiController) GetInspectionMinor() {
44 44
 	id, _ := this.GetInt64("id")
45
-	minor, err := service.GetInspectionMinor(id)
46
-	if err != nil {
47
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
48
-		return
45
+	adminInfo := this.GetAdminUserInfo()
46
+	orgId := adminInfo.CurrentOrgId
47
+	//查询该机构是否存在小项
48
+	major, _ := service.GetInspectionMajor(orgId)
49
+	if len(major) == 0 {
50
+		minor, err := service.GetInspectionMinor(id, 0)
51
+		if err != nil {
52
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
53
+			return
54
+		}
55
+		this.ServeSuccessJSON(map[string]interface{}{
56
+			"inspection": minor,
57
+		})
58
+	} else {
59
+		minor, err := service.GetInspectionMinor(id, orgId)
60
+		if err != nil {
61
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
62
+			return
63
+		}
64
+		this.ServeSuccessJSON(map[string]interface{}{
65
+			"inspection": minor,
66
+		})
49 67
 	}
50
-	this.ServeSuccessJSON(map[string]interface{}{
51
-		"inspection": minor,
52
-	})
68
+
53 69
 }
54 70
 
55 71
 func (this *CommonApiController) GetInspectionRange() {
@@ -438,7 +454,7 @@ func (this *CommonApiController) GetTotalInfectiouscount() {
438 454
 	//统计透析总人数
439 455
 	total := service.GetPatientTotalCount(orgid)
440 456
 	//统计透析人数传染病所占比例
441
-	count, err := service.GetPatientInfectiousCount(orgid)
457
+	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
442 458
 	//统计其他
443 459
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
444 460
 	if err != nil {

+ 1 - 1
controllers/new_mobile_api_controllers/new_common_api_controller.go Visa fil

@@ -94,7 +94,7 @@ func (this *NewCommonApiController) GetMobileTotalInfectiousCout() {
94 94
 	//统计透析总人数
95 95
 	total := service.GetPatientTotalCount(orgid)
96 96
 	//统计透析人数传染病所占比例
97
-	count, err := service.GetPatientInfectiousCount(orgid)
97
+	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
98 98
 	//统计其他
99 99
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
100 100
 	if err != nil {

+ 31 - 14
service/common_service.go Visa fil

@@ -13,9 +13,9 @@ func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference
13 13
 	return inspection, err
14 14
 }
15 15
 
16
-func GetInspectionMinor(projectid int64) (inspection []*models.XtInspectionReference, err error) {
16
+func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
17 17
 
18
-	err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1", projectid).Find(&inspection).Error
18
+	err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
19 19
 	return inspection, err
20 20
 }
21 21
 
@@ -160,14 +160,19 @@ func DeleteCheck(id int64) error {
160 160
 	return err
161 161
 }
162 162
 
163
-func GetDialysiTotal(startime int64, endtime int64, orgid int64) (prescription []*models.DialysisPrescription, total int64, err error) {
164
-	err = XTReadDB().Model(&prescription).Where("record_date >= ? and record_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&prescription).Error
165
-	return prescription, total, err
163
+func GetDialysiTotal(startime int64, endtime int64, orgid int64) (order []*models.DialysisOrder, total int64, err error) {
164
+	err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
165
+	return order, total, err
166
+
166 167
 }
167 168
 
168 169
 func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
169
-	err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
170
+	//err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
171
+	//return counts, err
172
+
173
+	err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
170 174
 	return counts, err
175
+
171 176
 }
172 177
 
173 178
 func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
@@ -225,9 +230,9 @@ func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64
225 230
 //	return counts, err
226 231
 //}
227 232
 
228
-func GetPatientInfectiousCount(orgid int64) (counts []*models.PatientContagionsCountStruct, err error) {
233
+func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
229 234
 
230
-	err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and s.is_infectious = 2", orgid).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
235
+	err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and s.is_infectious = 2 and s.created_time>=? and s.created_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
231 236
 	return counts, err
232 237
 }
233 238
 
@@ -242,12 +247,11 @@ func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err
242 247
 	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
243 248
 	 SELECT
244 249
 	 CASE
245
-	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=20 THEN '20'
246
-	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>20 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=40 THEN '40'
247
-	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>40 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=60 THEN '60'
248
-	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>60 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=80 THEN '80'
249
-	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>80 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=150 THEN '150'
250
-	  ELSE '-1'
250
+	  WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
251
+    WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
252
+    WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
253
+    WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
254
+    ELSE '150'
251 255
 	 END
252 256
 	 AS nnd FROM xt_patients as s  where s.user_org_id=? and s.status=1
253 257
 	 )a GROUP BY nnd`, orgid).Scan(&counts)
@@ -320,6 +324,19 @@ func GetDialysisAgeData(orgID int64) (counts []*models.DialysisAgePieDataStruct,
320 324
 	err = readDb.Raw(countSQL, countParams...).Scan(&counts).Error
321 325
 	return
322 326
 
327
+	//readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
328
+	// SELECT
329
+	// CASE
330
+	//  WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0
331
+	//  WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '0~12' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12
332
+	//  WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '12~36' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36
333
+	//  WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '36~60' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60
334
+	//  ELSE '150'
335
+	// END
336
+	// AS nnd FROM xt_patients as p  where p.user_org_id=? and p.status=1
337
+	// )a GROUP BY nnd`, orgID).Scan(&counts)
338
+	//return
339
+
323 340
 }
324 341
 
325 342
 func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {