XMLWAN 4 years ago
parent
commit
ddf436e9d4

+ 22 - 8
controllers/new_mobile_api_controllers/common_api_controller.go View File

423
 	//fmt.Println("org", orgid)
423
 	//fmt.Println("org", orgid)
424
 	page, _ := this.GetInt64("page")
424
 	page, _ := this.GetInt64("page")
425
 	limit, _ := this.GetInt64("limit")
425
 	limit, _ := this.GetInt64("limit")
426
-	checkList, total, err := service.GetAllCheckList(orgid, page, limit)
427
-	if err != nil {
428
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
429
-		return
426
+	major, _ := service.GetInspectionMajor(orgid)
427
+	if len(major) == 0 {
428
+		checklist, total, err := service.GetAllChekcListTwo(orgid, page, limit)
429
+		if err != nil {
430
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
431
+			return
432
+		}
433
+		this.ServeSuccessJSON(map[string]interface{}{
434
+			"checklist": checklist,
435
+			"total":     total,
436
+		})
437
+	} else {
438
+		checkList, total, err := service.GetAllCheckList(orgid, page, limit)
439
+		if err != nil {
440
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
441
+			return
442
+		}
443
+		this.ServeSuccessJSON(map[string]interface{}{
444
+			"checklist": checkList,
445
+			"total":     total,
446
+		})
430
 	}
447
 	}
431
-	this.ServeSuccessJSON(map[string]interface{}{
432
-		"checklist": checkList,
433
-		"total":     total,
434
-	})
448
+
435
 }
449
 }
436
 
450
 
437
 func (this *CommonApiController) GetCheckdetail() {
451
 func (this *CommonApiController) GetCheckdetail() {

+ 48 - 3
service/common_service.go View File

153
 	return err
153
 	return err
154
 }
154
 }
155
 
155
 
156
+func GetAllChekcListTwo(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
157
+	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
158
+	table := XTReadDB().Table("xt_inspection_reference as r")
159
+	fmt.Println(table)
160
+	if orgid > 0 {
161
+		db = db.Where("x.user_org_id = ?", orgid)
162
+	}
163
+	offset := (page - 1) * limit
164
+	err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
165
+		Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
166
+	return check, total, err
167
+}
168
+
156
 func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
169
 func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
157
 
170
 
158
 	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
171
 	db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
163
 	}
176
 	}
164
 	offset := (page - 1) * limit
177
 	offset := (page - 1) * limit
165
 	err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
178
 	err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
166
-		Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
179
+		Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Where("r.org_id = ? and r.status = 1", orgid).Offset(offset).Limit(limit).Scan(&check).Error
167
 	return check, total, err
180
 	return check, total, err
168
 }
181
 }
169
 
182
 
2354
 	fmt.Println(d)
2367
 	fmt.Println(d)
2355
 
2368
 
2356
 	if orgid > 0 {
2369
 	if orgid > 0 {
2357
-		db = db.Where("x.org_id = ?", orgid)
2370
+		db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
2358
 	}
2371
 	}
2359
 	if lapstor == 0 {
2372
 	if lapstor == 0 {
2360
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
2373
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
2372
 		db = db.Where("x.inspect_date <=?", endtime)
2385
 		db = db.Where("x.inspect_date <=?", endtime)
2373
 	}
2386
 	}
2374
 	offset := (page - 1) * limit
2387
 	offset := (page - 1) * limit
2375
-	err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0 )").Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
2388
+	err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as r on x.item_id = r.inspection_minor ").Where("r.user_org_id = ? and r.status = 1", orgid).Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
2376
 
2389
 
2377
 	return inspection, total, err
2390
 	return inspection, total, err
2378
 }
2391
 }
2379
 
2392
 
2393
+//func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
2394
+//
2395
+//	db := readDb.Table("xt_inspection as x").Where("x.status =1")
2396
+//	table := readDb.Table("xt_patients as s")
2397
+//	fmt.Println(table)
2398
+//	d := readDb.Table(" xt_inspection_reference as r")
2399
+//	fmt.Println(d)
2400
+//
2401
+//	if orgid > 0 {
2402
+//		db = db.Where("x.org_id = ?", orgid)
2403
+//	}
2404
+//	if lapstor == 0 {
2405
+//		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
2406
+//	}
2407
+//	if lapstor == 1 {
2408
+//		db = db.Where("s.lapseto = 1")
2409
+//	}
2410
+//	if lapstor == 2 {
2411
+//		db = db.Where("s.lapseto = 2")
2412
+//	}
2413
+//	if startime > 0 {
2414
+//		db = db.Where("x.inspect_date >=?", startime)
2415
+//	}
2416
+//	if endtime > 0 {
2417
+//		db = db.Where("x.inspect_date <=?", endtime)
2418
+//	}
2419
+//	offset := (page - 1) * limit
2420
+//	err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0 )").Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
2421
+//
2422
+//	return inspection, total, err
2423
+//}
2424
+
2380
 func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
2425
 func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
2381
 
2426
 
2382
 	db := readDb.Table("xt_inspection as x").Where("x.status =1")
2427
 	db := readDb.Table("xt_inspection as x").Where("x.status =1")