浏览代码

Merge branch 'xt_statistics_branch' of http://git.shengws.com/csx/XT_New into xt_statistics_branch

csx 5 年前
父节点
当前提交
2c1f98cedc

+ 119 - 12
controllers/new_mobile_api_controllers/common_api_controller.go 查看文件

42
 
42
 
43
 func (this *CommonApiController) GetInspectionMinor() {
43
 func (this *CommonApiController) GetInspectionMinor() {
44
 	id, _ := this.GetInt64("id")
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
 func (this *CommonApiController) GetInspectionRange() {
71
 func (this *CommonApiController) GetInspectionRange() {
389
 	//统计一个月内转出的病人
405
 	//统计一个月内转出的病人
390
 	//patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
406
 	//patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
391
 	//统计该机构的转出人数
407
 	//统计该机构的转出人数
392
-	patients, total, err := service.GetTotalRollOutPatients(orgid)
408
+	patients, err := service.GetTotalRollOutPatients(orgid, startime, endtime)
409
+	//统计该机构转出病人
410
+	patienttwo, err := service.GetTotalRollOutPatientsTwo(orgid, startime, endtime)
393
 	//统计总共病人
411
 	//统计总共病人
394
 	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
412
 	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
395
 	count := service.GetPatientTotalCount(orgid)
413
 	count := service.GetPatientTotalCount(orgid)
398
 		return
416
 		return
399
 	}
417
 	}
400
 	this.ServeSuccessJSON(map[string]interface{}{
418
 	this.ServeSuccessJSON(map[string]interface{}{
401
-		"patients": patients,
402
-		"total":    total,
403
-		"count":    count,
419
+		"patients":   patients,
420
+		"count":      count,
421
+		"patienttwo": patienttwo,
404
 	})
422
 	})
405
 }
423
 }
406
 
424
 
436
 	//统计透析总人数
454
 	//统计透析总人数
437
 	total := service.GetPatientTotalCount(orgid)
455
 	total := service.GetPatientTotalCount(orgid)
438
 	//统计透析人数传染病所占比例
456
 	//统计透析人数传染病所占比例
439
-	count, err := service.GetPatientInfectiousCount(orgid)
457
+	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
440
 	//统计其他
458
 	//统计其他
441
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
459
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
442
 	if err != nil {
460
 	if err != nil {
1145
 	monthlist, err := service.GetMonthProjectList(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1163
 	monthlist, err := service.GetMonthProjectList(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1146
 	//统计不合格
1164
 	//统计不合格
1147
 	monthNolist, err := service.GetMonthProjectListTwo(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1165
 	monthNolist, err := service.GetMonthProjectListTwo(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1166
+	fmt.Println("monthnolist=====", monthNolist)
1148
 	if err != nil {
1167
 	if err != nil {
1149
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1168
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1150
 		return
1169
 		return
1194
 		"control":  control,
1213
 		"control":  control,
1195
 	})
1214
 	})
1196
 }
1215
 }
1216
+
1217
+func (this *CommonApiController) GetCartogramList() {
1218
+	adminUser := this.GetAdminUserInfo()
1219
+	orgid := adminUser.CurrentOrgId
1220
+	lapstor, _ := this.GetInt64("lapstor")
1221
+	fmt.Println("lapstor", lapstor)
1222
+	startime := this.GetString("startime")
1223
+	fmt.Println("开始时间", startime)
1224
+	startimeStr, _ := utils.ParseTimeStringToTime("2006-01-02", startime)
1225
+	startimeStrUnix := startimeStr.Unix()
1226
+	fmt.Println("时间搓", startimeStrUnix)
1227
+	endtime := this.GetString("endtime")
1228
+	fmt.Println("结束时间", endtime)
1229
+	endtimeStr := endtime + " 23:59:59"
1230
+	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
1231
+	endtimeStrsUnix := endtimeStrs.Unix()
1232
+	fmt.Println("结束时间搓", endtimeStrsUnix)
1233
+	limit, _ := this.GetInt64("limit")
1234
+	page, _ := this.GetInt64("page")
1235
+	cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1236
+	_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
1237
+	if err != nil {
1238
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1239
+		return
1240
+	}
1241
+
1242
+	this.ServeSuccessJSON(map[string]interface{}{
1243
+		"cartogramlist": cartogramlist,
1244
+		"total":         total,
1245
+	})
1246
+}
1247
+
1248
+func (this *CommonApiController) GetPatientContor() {
1249
+
1250
+	adminUser := this.GetAdminUserInfo()
1251
+	orgid := adminUser.CurrentOrgId
1252
+	fmt.Println(orgid)
1253
+	lapstor, _ := this.GetInt64("lapstor")
1254
+	fmt.Println("lapstor", lapstor)
1255
+	keyword := this.GetString("keyword")
1256
+	fmt.Println("keyword", keyword)
1257
+	startime := this.GetString("startime")
1258
+	fmt.Println("开始时间", startime)
1259
+	startimeStr, _ := utils.ParseTimeStringToTime("2006-01-02", startime)
1260
+	startimeStrUnix := startimeStr.Unix()
1261
+	fmt.Println("时间搓", startimeStrUnix)
1262
+	endtime := this.GetString("endtime")
1263
+	fmt.Println("结束时间", endtime)
1264
+	endtimeStr := endtime + " 23:59:59"
1265
+	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
1266
+	endtimeStrsUnix := endtimeStrs.Unix()
1267
+	fmt.Println("结束时间搓", endtimeStrsUnix)
1268
+	patients, err := service.GetPatientNames(orgid, keyword)
1269
+	patientcontorDetail, err := service.GetLastPatientsControlTwo(orgid, patients.ID, startimeStrUnix, endtimeStrsUnix)
1270
+	if err != nil {
1271
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1272
+		return
1273
+	}
1274
+
1275
+	this.ServeSuccessJSON(map[string]interface{}{
1276
+		"patientcontorDetail": patientcontorDetail,
1277
+		"name":                patients.Name,
1278
+	})
1279
+}
1280
+
1281
+func (this *CommonApiController) GetQualityControl() {
1282
+
1283
+	adminUser := this.GetAdminUserInfo()
1284
+	orgid := adminUser.CurrentOrgId
1285
+	fmt.Println(orgid)
1286
+	patientid, _ := this.GetInt64("patientid")
1287
+	startime, _ := this.GetInt64("startime")
1288
+	fmt.Println("startime", startime)
1289
+	endtime, _ := this.GetInt64("endtime")
1290
+	fmt.Println("endtime", endtime)
1291
+	itemid, _ := this.GetInt64("itemid")
1292
+	fmt.Println("itemid", itemid)
1293
+	list, err := service.GetQualityControlById(orgid, patientid, startime, endtime, itemid)
1294
+	if err != nil {
1295
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1296
+		return
1297
+	}
1298
+
1299
+	this.ServeSuccessJSON(map[string]interface{}{
1300
+
1301
+		"list": list,
1302
+	})
1303
+}

+ 3 - 0
controllers/new_mobile_api_controllers/common_api_router.go 查看文件

46
 	beego.Router("/com/api/getprojectlist", &CommonApiController{}, "Get:GetProjectList")
46
 	beego.Router("/com/api/getprojectlist", &CommonApiController{}, "Get:GetProjectList")
47
 	beego.Router("/com/api/getmonthprojectlist", &CommonApiController{}, "Get:GetMonthProjectList")
47
 	beego.Router("/com/api/getmonthprojectlist", &CommonApiController{}, "Get:GetMonthProjectList")
48
 	beego.Router("/com/api/getpatientscontrol", &CommonApiController{}, "Get:GetPatientscontrol")
48
 	beego.Router("/com/api/getpatientscontrol", &CommonApiController{}, "Get:GetPatientscontrol")
49
+	beego.Router("/com/api/getcartogramlist", &CommonApiController{}, "Get:GetCartogramList")
50
+	beego.Router("/com/api/getpatientcontor", &CommonApiController{}, "Get:GetPatientContor")
51
+	beego.Router("/com/api/getqualitycontrol", &CommonApiController{}, "Get:GetQualityControl")
49
 }
52
 }

+ 128 - 4
controllers/new_mobile_api_controllers/new_common_api_controller.go 查看文件

50
 	fmt.Println("endtime", endtime)
50
 	fmt.Println("endtime", endtime)
51
 	adminUser := this.GetMobileAdminUserInfo()
51
 	adminUser := this.GetMobileAdminUserInfo()
52
 	orgid := adminUser.Org.Id
52
 	orgid := adminUser.Org.Id
53
-	_, total, err := service.GetTotalRollOutPatients(orgid)
53
+	//统计转出的病人
54
+	patient, err := service.GetTotalRollOutPatients(orgid, startime, endtime)
55
+	patienttwo, err := service.GetTotalRollOutPatientsTwo(orgid, startime, endtime)
54
 	count := service.GetPatientTotalCount(orgid)
56
 	count := service.GetPatientTotalCount(orgid)
55
 	if err != nil {
57
 	if err != nil {
56
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
58
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
57
 		return
59
 		return
58
 	}
60
 	}
59
 	this.ServeSuccessJSON(map[string]interface{}{
61
 	this.ServeSuccessJSON(map[string]interface{}{
60
-		"total": total,
61
-		"count": count,
62
+		"patient":    patient,
63
+		"count":      count,
64
+		"patienttwo": patienttwo,
62
 	})
65
 	})
63
 }
66
 }
64
 
67
 
91
 	//统计透析总人数
94
 	//统计透析总人数
92
 	total := service.GetPatientTotalCount(orgid)
95
 	total := service.GetPatientTotalCount(orgid)
93
 	//统计透析人数传染病所占比例
96
 	//统计透析人数传染病所占比例
94
-	count, err := service.GetPatientInfectiousCount(orgid)
97
+	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
95
 	//统计其他
98
 	//统计其他
96
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
99
 	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
97
 	if err != nil {
100
 	if err != nil {
739
 		"checkDetail": checkDetail,
742
 		"checkDetail": checkDetail,
740
 	})
743
 	})
741
 }
744
 }
745
+
746
+func (this *NewCommonApiController) GetMobilePatientControl() {
747
+	adminInfo := this.GetMobileAdminUserInfo()
748
+	orgid := adminInfo.Org.Id
749
+	lapstor, _ := this.GetInt64("lapstor")
750
+	fmt.Println("lapstor", lapstor)
751
+	startime := this.GetString("startime")
752
+	fmt.Println("开始时间", startime)
753
+	startimeStr, _ := utils.ParseTimeStringToTime("2006-01-02", startime)
754
+	startimeStrUnix := startimeStr.Unix()
755
+	fmt.Println("时间搓", startimeStrUnix)
756
+	endtime := this.GetString("endtime")
757
+	fmt.Println("结束时间", endtime)
758
+	endtimeStr := endtime + " 23:59:59"
759
+	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
760
+	endtimeStrsUnix := endtimeStrs.Unix()
761
+	fmt.Println("结束时间搓", endtimeStrsUnix)
762
+	page, _ := this.GetInt64("page")
763
+	fmt.Println("page", page)
764
+	limit, _ := this.GetInt64("limit")
765
+	fmt.Println("limit", limit)
766
+	patients, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
767
+
768
+	control, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
769
+	//获取最后一次数据
770
+
771
+	if err != nil {
772
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
773
+		return
774
+	}
775
+
776
+	this.ServeSuccessJSON(map[string]interface{}{
777
+		"patients": patients,
778
+		"total":    total,
779
+		"control":  control,
780
+	})
781
+}
782
+
783
+func (this *NewCommonApiController) GetMobileCartogramlist() {
784
+	adminInfo := this.GetMobileAdminUserInfo()
785
+	orgid := adminInfo.Org.Id
786
+	lapstor, _ := this.GetInt64("lapstor")
787
+	fmt.Println("lapstor", lapstor)
788
+	startime := this.GetString("startime")
789
+	fmt.Println("开始时间", startime)
790
+	startimeStr, _ := utils.ParseTimeStringToTime("2006-01-02", startime)
791
+	startimeStrUnix := startimeStr.Unix()
792
+	fmt.Println("时间搓", startimeStrUnix)
793
+	endtime := this.GetString("endtime")
794
+	fmt.Println("结束时间", endtime)
795
+	endtimeStr := endtime + " 23:59:59"
796
+	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
797
+	endtimeStrsUnix := endtimeStrs.Unix()
798
+	fmt.Println("结束时间搓", endtimeStrsUnix)
799
+	limit, _ := this.GetInt64("limit")
800
+	page, _ := this.GetInt64("page")
801
+	cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
802
+	_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
803
+	if err != nil {
804
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
805
+		return
806
+	}
807
+
808
+	this.ServeSuccessJSON(map[string]interface{}{
809
+		"cartogramlist": cartogramlist,
810
+		"total":         total,
811
+	})
812
+}
813
+
814
+func (this *NewCommonApiController) GetMobileQualityControl() {
815
+	adminInfo := this.GetMobileAdminUserInfo()
816
+	orgid := adminInfo.Org.Id
817
+	fmt.Println("orgd", orgid)
818
+	patientid, _ := this.GetInt64("patientid")
819
+	fmt.Println("patientid", patientid)
820
+	startime, _ := this.GetInt64("startime")
821
+	fmt.Println("startime", startime)
822
+	endtime, _ := this.GetInt64("endtime")
823
+	fmt.Println("endtime", endtime)
824
+	itemid, _ := this.GetInt64("itemid")
825
+	fmt.Println("itemid", itemid)
826
+	list, err := service.GetQualityControlById(orgid, patientid, startime, endtime, itemid)
827
+	if err != nil {
828
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
829
+		return
830
+	}
831
+
832
+	this.ServeSuccessJSON(map[string]interface{}{
833
+
834
+		"list": list,
835
+	})
836
+}
837
+
838
+func (this *NewCommonApiController) GetSeachPatientsControl() {
839
+	adminUser := this.GetMobileAdminUserInfo()
840
+	orgid := adminUser.Org.Id
841
+	fmt.Println("orgid", orgid)
842
+	id, _ := this.GetInt64("id")
843
+	fmt.Println("id", id)
844
+	startime := this.GetString("startime")
845
+	fmt.Println("开始时间", startime)
846
+	startimeStr, _ := utils.ParseTimeStringToTime("2006-01-02", startime)
847
+	startimeStrUnix := startimeStr.Unix()
848
+	fmt.Println("时间搓", startimeStrUnix)
849
+	endtime := this.GetString("endtime")
850
+	fmt.Println("结束时间", endtime)
851
+	endtimeStr := endtime + " 23:59:59"
852
+	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
853
+	endtimeStrsUnix := endtimeStrs.Unix()
854
+	fmt.Println("结束时间搓", endtimeStrsUnix)
855
+	control, err := service.GetLastPatientsControlTwo(orgid, id, startimeStrUnix, endtimeStrsUnix)
856
+	if err != nil {
857
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
858
+		return
859
+	}
860
+
861
+	this.ServeSuccessJSON(map[string]interface{}{
862
+
863
+		"control": control,
864
+	})
865
+}

+ 4 - 0
controllers/new_mobile_api_controllers/new_common_api_router.go 查看文件

25
 	beego.Router("/m/api/getallmobilemajorinspection", &NewCommonApiController{}, "Get:GetAllMobileMajorInspection")
25
 	beego.Router("/m/api/getallmobilemajorinspection", &NewCommonApiController{}, "Get:GetAllMobileMajorInspection")
26
 	beego.Router("/m/api/getmobilepatientlist", &NewCommonApiController{}, "Get:GetMobilePatient")
26
 	beego.Router("/m/api/getmobilepatientlist", &NewCommonApiController{}, "Get:GetMobilePatient")
27
 	beego.Router("/m/api/getmobilepatientdetailcheck", &NewCommonApiController{}, "Get:GetMobilePatientDetailCheck")
27
 	beego.Router("/m/api/getmobilepatientdetailcheck", &NewCommonApiController{}, "Get:GetMobilePatientDetailCheck")
28
+	beego.Router("/m/api/getmobilepatientcontrol", &NewCommonApiController{}, "Get:GetMobilePatientControl")
29
+	beego.Router("m/api/getmobilecartogramlist", &NewCommonApiController{}, "Get:GetMobileCartogramlist")
30
+	beego.Router("/m/api/getmobilequalitycontrol", &NewCommonApiController{}, "Get:GetMobileQualityControl")
31
+	beego.Router("/m/api/toseachpatientscontrol", &NewCommonApiController{}, "Get:GetSeachPatientsControl")
28
 }
32
 }

+ 15 - 2
controllers/patient_api_controller.go 查看文件

467
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
467
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
468
 		return
468
 		return
469
 	}
469
 	}
470
-	fmt.Println("病人--------------------------------------------------------------", patient.Name, patient.Age)
470
+	//更新转归状态
471
+
472
+	fmt.Println("病人id--------------------------------------------------------------", patient.ID)
473
+	lapseto := models.PatientLapseto{
474
+		LapsetoType: patient.Lapseto,
475
+		LapsetoTime: time.Now().Unix(),
476
+		UpdatedTime: time.Now().Unix(),
477
+	}
478
+	err = service.UpdatePatientLapseto(patient.ID, lapseto)
479
+	fmt.Println("更新转归失败", err)
480
+	if err != nil {
481
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
482
+		return
483
+	}
471
 	patientsNew := models.XtPatientsNew{
484
 	patientsNew := models.XtPatientsNew{
472
 		UserOrgId:                 patient.UserOrgId,
485
 		UserOrgId:                 patient.UserOrgId,
473
 		UserId:                    patient.UserId,
486
 		UserId:                    patient.UserId,
619
 
632
 
620
 func (c *PatientApiController) EditLapseto() {
633
 func (c *PatientApiController) EditLapseto() {
621
 	id, _ := c.GetInt64("id", 0)
634
 	id, _ := c.GetInt64("id", 0)
635
+	fmt.Println("id===========", id)
622
 	if id <= 0 {
636
 	if id <= 0 {
623
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
637
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
624
 		return
638
 		return
691
 	//		return
705
 	//		return
692
 	//	}
706
 	//	}
693
 	//}
707
 	//}
694
-
695
 	err = service.EditPatientLapseto(&patient, &lapseto)
708
 	err = service.EditPatientLapseto(&patient, &lapseto)
696
 	if err != nil {
709
 	if err != nil {
697
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
710
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)

+ 2 - 0
models/common_models.go 查看文件

404
 	Name         string `gorm:"column:name" json:"name" form:"name"`
404
 	Name         string `gorm:"column:name" json:"name" form:"name"`
405
 	RangMax      string `gorm:"column:range_max" json:"range_max" form:"range_max"`
405
 	RangMax      string `gorm:"column:range_max" json:"range_max" form:"range_max"`
406
 	RangMin      string `gorm:"column:range_min" json:"range_min" form:"range_min"`
406
 	RangMin      string `gorm:"column:range_min" json:"range_min" form:"range_min"`
407
+	Unit         string `gorm:"column:unit" json:"unit" form:"unit"`
407
 	DialysisNo   string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
408
 	DialysisNo   string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
408
 	RangeValue   string `gorm:"column:range_value" json:"range_value" form:"range_value"`
409
 	RangeValue   string `gorm:"column:range_value" json:"range_value" form:"range_value"`
410
+	Sort         int64  `gorm:"column:sort" json:"sort" form:"sort"`
409
 }
411
 }
410
 
412
 
411
 func (PatientInspectionCount) TableName() string {
413
 func (PatientInspectionCount) TableName() string {

+ 231 - 89
service/common_service.go 查看文件

13
 	return inspection, err
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
 	return inspection, err
19
 	return inspection, err
20
 }
20
 }
21
 
21
 
160
 	return err
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
 func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
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
 	return counts, err
174
 	return counts, err
175
+
171
 }
176
 }
172
 
177
 
173
 func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
178
 func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
179
 	return counts, total, err
184
 	return counts, total, err
180
 }
185
 }
181
 
186
 
182
-func GetTotalRollOutPatients(orgid int64) (patients []*models.XtPatients, total int64, err error) {
187
+func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
183
 
188
 
184
-	err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and lapseto = 2", orgid).Count(&total).Find(&patients).Error
185
-	return patients, total, err
189
+	db := XTReadDB().Table("x.patients as x")
190
+	err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
191
+	return patients, err
192
+}
193
+
194
+func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
195
+
196
+	db := XTReadDB().Table("x.patients as x")
197
+	err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
198
+	return patients, err
186
 }
199
 }
187
 
200
 
188
 func GetPatientTotalCount(orgID int64) (total int64) {
201
 func GetPatientTotalCount(orgID int64) (total int64) {
217
 //	return counts, err
230
 //	return counts, err
218
 //}
231
 //}
219
 
232
 
220
-func GetPatientInfectiousCount(orgid int64) (counts []*models.PatientContagionsCountStruct, err error) {
233
+func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
221
 
234
 
222
-	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
223
 	return counts, err
236
 	return counts, err
224
 }
237
 }
225
 
238
 
234
 	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
247
 	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
235
 	 SELECT
248
 	 SELECT
236
 	 CASE
249
 	 CASE
237
-	  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'
238
-	  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'
239
-	  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'
240
-	  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'
241
-	  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'
242
-	  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'
243
 	 END
255
 	 END
244
 	 AS nnd FROM xt_patients as s  where s.user_org_id=? and s.status=1
256
 	 AS nnd FROM xt_patients as s  where s.user_org_id=? and s.status=1
245
 	 )a GROUP BY nnd`, orgid).Scan(&counts)
257
 	 )a GROUP BY nnd`, orgid).Scan(&counts)
312
 	err = readDb.Raw(countSQL, countParams...).Scan(&counts).Error
324
 	err = readDb.Raw(countSQL, countParams...).Scan(&counts).Error
313
 	return
325
 	return
314
 
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
+
315
 }
340
 }
316
 
341
 
317
 func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {
342
 func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {
767
 	if endtime > 0 {
792
 	if endtime > 0 {
768
 		db = db.Where("x.inspect_date <=?", endtime)
793
 		db = db.Where("x.inspect_date <=?", endtime)
769
 	}
794
 	}
795
+	if lapseto == 0 {
796
+		db = db.Where("s.lapseto = 1 or s.lapseto = 2")
797
+	}
770
 	if lapseto > 0 {
798
 	if lapseto > 0 {
771
-		d = d.Where("s.lapseto = ?", lapseto)
799
+		db = db.Where("s.lapseto = ?", lapseto)
772
 	}
800
 	}
773
 	err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as  s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
801
 	err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as  s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
774
 	return inspection, err
802
 	return inspection, err
1301
 }
1329
 }
1302
 
1330
 
1303
 func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
1331
 func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
1304
-
1332
+	fmt.Println("lapseto=======", lapseto)
1305
 	if lapseto == 0 {
1333
 	if lapseto == 0 {
1306
 		d := XTReadDB().Table("xt_patients as s")
1334
 		d := XTReadDB().Table("xt_patients as s")
1307
 		fmt.Println("d", d)
1335
 		fmt.Println("d", d)
1445
 		}
1473
 		}
1446
 		countSQL += ")a GROUP BY nnd"
1474
 		countSQL += ")a GROUP BY nnd"
1447
 		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1475
 		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1476
+	}
1448
 
1477
 
1449
-		if lapseto == 2 {
1450
-
1451
-			d := XTReadDB().Table("xt_patients as s")
1452
-			fmt.Println("d", d)
1453
-			db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1454
-			table := XTReadDB().Table("xt_inspection_reference as r")
1455
-			fmt.Println(table)
1456
-			countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1457
-				"SELECT " +
1458
-				"CASE " +
1459
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '一月'" +
1460
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '二月'" +
1461
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '三月'" +
1462
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '四月'" +
1463
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '五月'" +
1464
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '六月'" +
1465
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '七月'" +
1466
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '八月'" +
1467
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '九月'" +
1468
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十月'" +
1469
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十一月'" +
1470
-				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十二月'" +
1471
-				" ELSE '其他'" +
1472
-				"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1473
-			countParams := make([]interface{}, 0)
1478
+	if lapseto == 2 {
1479
+		d := XTReadDB().Table("xt_patients as s")
1480
+		fmt.Println("d", d)
1481
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1482
+		table := XTReadDB().Table("xt_inspection_reference as r")
1483
+		fmt.Println(table)
1484
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1485
+			"SELECT " +
1486
+			"CASE " +
1487
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '一月'" +
1488
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '二月'" +
1489
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '三月'" +
1490
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '四月'" +
1491
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '五月'" +
1492
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '六月'" +
1493
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '七月'" +
1494
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '八月'" +
1495
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '九月'" +
1496
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十月'" +
1497
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十一月'" +
1498
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十二月'" +
1499
+			" ELSE '其他'" +
1500
+			"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1501
+		countParams := make([]interface{}, 0)
1502
+		countParams = append(countParams, januaryStartStrUnix)
1503
+		countParams = append(countParams, januaryEndStrUnix)
1504
+		countParams = append(countParams, febStartStrStrUnix)
1505
+		countParams = append(countParams, febEndStrUnix)
1506
+		countParams = append(countParams, marchStartStrUnix)
1507
+		countParams = append(countParams, marchEndStrUnix)
1508
+		countParams = append(countParams, aprStartStrUnix)
1509
+		countParams = append(countParams, aprEndStrsUnix)
1510
+		countParams = append(countParams, mayStartStrUnix)
1511
+		countParams = append(countParams, mayEndStrsUnix)
1512
+		countParams = append(countParams, junStartStrUnix)
1513
+		countParams = append(countParams, junEndStrsUnix)
1514
+		countParams = append(countParams, julStartStrUnix)
1515
+		countParams = append(countParams, julEndStrsUnix)
1516
+		countParams = append(countParams, augStartStrUnix)
1517
+		countParams = append(countParams, augEndStrsUnix)
1518
+		countParams = append(countParams, sepStartStrUnix)
1519
+		countParams = append(countParams, sepEndStrsUnix)
1520
+		countParams = append(countParams, octStartStrUnix)
1521
+		countParams = append(countParams, octEndStrsUnix)
1522
+		countParams = append(countParams, novStartStrUnix)
1523
+		countParams = append(countParams, novEndStrsUnix)
1524
+		countParams = append(countParams, decStartStrUnix)
1525
+		countParams = append(countParams, decEndStrsUnix)
1526
+		if orgid > 0 {
1527
+			db = db.Where("x.org_id=?", orgid)
1528
+			countSQL += " AND x.org_id=?"
1529
+			countParams = append(countParams, orgid)
1530
+		}
1531
+		if modetype > 0 {
1532
+			db = db.Where("x.item_id = ?", modetype)
1533
+			countSQL += " AND x.item_id=?"
1534
+			countParams = append(countParams, modetype)
1535
+		}
1536
+		if januaryStartStrUnix > 0 {
1537
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1538
+			countSQL += " AND x.inspect_date >=?"
1474
 			countParams = append(countParams, januaryStartStrUnix)
1539
 			countParams = append(countParams, januaryStartStrUnix)
1475
-			countParams = append(countParams, januaryEndStrUnix)
1476
-			countParams = append(countParams, febStartStrStrUnix)
1477
-			countParams = append(countParams, febEndStrUnix)
1478
-			countParams = append(countParams, marchStartStrUnix)
1479
-			countParams = append(countParams, marchEndStrUnix)
1480
-			countParams = append(countParams, aprStartStrUnix)
1481
-			countParams = append(countParams, aprEndStrsUnix)
1482
-			countParams = append(countParams, mayStartStrUnix)
1483
-			countParams = append(countParams, mayEndStrsUnix)
1484
-			countParams = append(countParams, junStartStrUnix)
1485
-			countParams = append(countParams, junEndStrsUnix)
1486
-			countParams = append(countParams, julStartStrUnix)
1487
-			countParams = append(countParams, julEndStrsUnix)
1488
-			countParams = append(countParams, augStartStrUnix)
1489
-			countParams = append(countParams, augEndStrsUnix)
1490
-			countParams = append(countParams, sepStartStrUnix)
1491
-			countParams = append(countParams, sepEndStrsUnix)
1492
-			countParams = append(countParams, octStartStrUnix)
1493
-			countParams = append(countParams, octEndStrsUnix)
1494
-			countParams = append(countParams, novStartStrUnix)
1495
-			countParams = append(countParams, novEndStrsUnix)
1496
-			countParams = append(countParams, decStartStrUnix)
1540
+		}
1541
+		if decEndStrsUnix > 0 {
1542
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1543
+			countSQL += " AND x.inspect_date <=?"
1497
 			countParams = append(countParams, decEndStrsUnix)
1544
 			countParams = append(countParams, decEndStrsUnix)
1498
-			if orgid > 0 {
1499
-				db = db.Where("x.org_id=?", orgid)
1500
-				countSQL += " AND x.org_id=?"
1501
-				countParams = append(countParams, orgid)
1502
-			}
1503
-			if modetype > 0 {
1504
-				db = db.Where("x.item_id = ?", modetype)
1505
-				countSQL += " AND x.item_id=?"
1506
-				countParams = append(countParams, modetype)
1507
-			}
1508
-			if januaryStartStrUnix > 0 {
1509
-				db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1510
-				countSQL += " AND x.inspect_date >=?"
1511
-				countParams = append(countParams, januaryStartStrUnix)
1512
-			}
1513
-			if decEndStrsUnix > 0 {
1514
-				db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1515
-				countSQL += " AND x.inspect_date <=?"
1516
-				countParams = append(countParams, decEndStrsUnix)
1517
-			}
1518
-			countSQL += ")a GROUP BY nnd"
1519
-			err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1520
 		}
1545
 		}
1546
+		countSQL += ")a GROUP BY nnd"
1547
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1521
 	}
1548
 	}
1522
 	return
1549
 	return
1523
 }
1550
 }
1536
 	if lapstor == 0 {
1563
 	if lapstor == 0 {
1537
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
1564
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
1538
 	}
1565
 	}
1566
+	if lapstor == 1 {
1567
+		db = db.Where("s.lapseto = 1")
1568
+	}
1569
+	if lapstor == 2 {
1570
+		db = db.Where("s.lapseto = 2")
1571
+	}
1539
 	if startime > 0 {
1572
 	if startime > 0 {
1540
 		db = db.Where("x.inspect_date >=?", startime)
1573
 		db = db.Where("x.inspect_date >=?", startime)
1541
 	}
1574
 	}
1555
 	fmt.Println(table)
1588
 	fmt.Println(table)
1556
 	d := readDb.Table(" xt_inspection_reference as r")
1589
 	d := readDb.Table(" xt_inspection_reference as r")
1557
 	fmt.Println(d)
1590
 	fmt.Println(d)
1591
+	d2 := readDb.Table("xt_quality_control_standard as d")
1592
+	fmt.Println("d2", d2)
1593
+	if orgid > 0 {
1594
+		db = db.Where("x.org_id = ?", orgid)
1595
+	}
1596
+	if lapstor == 0 {
1597
+		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
1598
+	}
1599
+
1600
+	if lapstor == 1 {
1601
+		table = table.Where("s.lapseto = 1")
1602
+	}
1603
+	if lapstor == 2 {
1604
+		table = table.Where("s.lapseto = 2")
1605
+	}
1606
+	if startime > 0 {
1607
+		db = db.Where("x.inspect_date >=?", startime)
1608
+	}
1609
+	if endtime > 0 {
1610
+		db = db.Where("x.inspect_date <=?", endtime)
1611
+	}
1612
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
1613
+
1614
+	return inspection, err
1615
+}
1616
+
1617
+func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
1618
+
1619
+	db := readDb.Table("xt_inspection as x").Where("x.status =1")
1620
+	table := readDb.Table("xt_patients as s")
1621
+	fmt.Println(table)
1622
+	d := readDb.Table(" xt_inspection_reference as r")
1623
+	fmt.Println(d)
1624
+	d2 := readDb.Table("xt_quality_control_standard as d")
1625
+	fmt.Println("d2", d2)
1626
+
1627
+	if len(keywords) > 0 {
1628
+		db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
1629
+	}
1558
 
1630
 
1559
 	if orgid > 0 {
1631
 	if orgid > 0 {
1560
 		db = db.Where("x.org_id = ?", orgid)
1632
 		db = db.Where("x.org_id = ?", orgid)
1562
 	if lapstor == 0 {
1634
 	if lapstor == 0 {
1563
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
1635
 		table = table.Where("s.lapseto = 1 or s.lapseto = 2")
1564
 	}
1636
 	}
1637
+
1638
+	if lapstor == 1 {
1639
+		table = table.Where("s.lapseto = 1")
1640
+	}
1641
+	if lapstor == 2 {
1642
+		table = table.Where("s.lapseto = 2")
1643
+	}
1644
+	if startime > 0 {
1645
+		db = db.Where("x.inspect_date >=?", startime)
1646
+	}
1647
+	if endtime > 0 {
1648
+		db = db.Where("x.inspect_date <=?", endtime)
1649
+	}
1650
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
1651
+
1652
+	return inspection, err
1653
+}
1654
+
1655
+func GetPatientNames(orgid int64, patientname string) (models.XtPatients, error) {
1656
+	patients := models.XtPatients{}
1657
+	err := readDb.Where("user_org_id = ? and (name=? or dialysis_no=?) and status = 1", orgid, patientname, patientname).Find(&patients).Error
1658
+	return patients, err
1659
+}
1660
+
1661
+func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
1662
+
1663
+	db := readDb.Table("xt_inspection as x").Where("x.status =1")
1664
+	table := readDb.Table("xt_patients as s")
1665
+	fmt.Println(table)
1666
+	d := readDb.Table(" xt_inspection_reference as r")
1667
+	fmt.Println(d)
1668
+	d2 := readDb.Table("xt_quality_control_standard as d")
1669
+	fmt.Println("d2", d2)
1670
+
1671
+	if orgid > 0 {
1672
+		db = db.Where("x.org_id = ?", orgid)
1673
+	}
1674
+	if patientid > 0 {
1675
+		db = db.Where("x.patient_id = ?", patientid)
1676
+	}
1677
+
1678
+	if startime > 0 {
1679
+		db = db.Where("x.inspect_date >=?", startime)
1680
+	}
1681
+	if endtime > 0 {
1682
+		db = db.Where("x.inspect_date <=?", endtime)
1683
+	}
1684
+	if itemid > 0 {
1685
+		db = db.Where("x.item_id = ?", itemid)
1686
+	}
1687
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
1688
+
1689
+	return inspection, err
1690
+}
1691
+
1692
+func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
1693
+
1694
+	db := readDb.Table("xt_inspection as x").Where("x.status =1")
1695
+	table := readDb.Table("xt_patients as s")
1696
+	fmt.Println(table)
1697
+	d := readDb.Table(" xt_inspection_reference as r")
1698
+	fmt.Println(d)
1699
+	d2 := readDb.Table("xt_quality_control_standard as d")
1700
+	fmt.Println("d2", d2)
1701
+	if orgid > 0 {
1702
+		db = db.Where("x.org_id = ?", orgid)
1703
+	}
1704
+	if patientid > 0 {
1705
+		db = db.Where("x.patient_id = ?", patientid)
1706
+	}
1565
 	if startime > 0 {
1707
 	if startime > 0 {
1566
 		db = db.Where("x.inspect_date >=?", startime)
1708
 		db = db.Where("x.inspect_date >=?", startime)
1567
 	}
1709
 	}
1568
 	if endtime > 0 {
1710
 	if endtime > 0 {
1569
 		db = db.Where("x.inspect_date <=?", endtime)
1711
 		db = db.Where("x.inspect_date <=?", endtime)
1570
 	}
1712
 	}
1571
-	err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
1713
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
1572
 
1714
 
1573
 	return inspection, err
1715
 	return inspection, err
1574
 }
1716
 }

+ 7 - 1
service/patient_service.go 查看文件

277
 
277
 
278
 func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
278
 func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
279
 	utx := writeDb.Begin()
279
 	utx := writeDb.Begin()
280
-	err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"Lapseto": patient.Lapseto}).Error
280
+	//err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"Lapseto": patient.Lapseto}).Error
281
+	err = utx.Model(&models.PatientLapseto{}).Where("id=?", patient.ID).Update(map[string]interface{}{"lapseto_type": patient.Lapseto, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
281
 	if err != nil {
282
 	if err != nil {
282
 		utx.Rollback()
283
 		utx.Rollback()
283
 		return
284
 		return
380
 	return
381
 	return
381
 }
382
 }
382
 
383
 
384
+func UpdatePatientLapseto(patientid int64, lapseto models.PatientLapseto) error {
385
+	err := XTWriteDB().Model(&lapseto).Where("patient_id = ?", patientid).Updates(map[string]interface{}{"lapseto_type": lapseto.LapsetoType, "lapseto_time": time.Now().Unix(), "updated_time": time.Now().Unix()}).Error
386
+	return err
387
+}
388
+
383
 func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
389
 func UpdatepatientTwo(patientsNew *models.XtPatientsNew, id int64) error {
384
 
390
 
385
 	err := XTWriteDB().Model(&patientsNew).Where("blood_id = ?", id).Update(map[string]interface{}{"user_org_id": patientsNew.UserOrgId, "user_id": patientsNew.UserId, "avatar": patientsNew.Avatar, "patient_type": patientsNew.Avatar, "dialysis_no": patientsNew.DialysisNo, "admission_number": patientsNew.AdmissionNumber, "source": patientsNew.Source, "lapseto": patientsNew.Lapseto, "partition_id": patientsNew.PartitionId, "bed_id": patientsNew.BedId, "name": patientsNew.Name, "alias": patientsNew.Alias, "gender": patientsNew.Gender, "marital_status": patientsNew.MaritalStatus, "id_card_no": patientsNew.IdCardNo, "birthday": patientsNew.Birthday, "reimbursement_way_id": patientsNew.ReimbursementWayId, "health_care_type": patientsNew.HealthCareType, "health_care_no": patientsNew.HealthCareType, "health_care_due_date": patientsNew.HealthCareType, "height": patientsNew.Height, "blood_type": patientsNew.BloodType, "rh": patientsNew.Rh, "health_care_due_alert_date": patientsNew.HealthCareDueAlertDate, "education_level": patientsNew.EducationLevel, "profession": patientsNew.Profession, "phone": patientsNew.Phone, "home_telephone": patientsNew.HomeTelephone, "relative_phone": patientsNew.RelativePhone, "relative_relations": patientsNew.RelativeRelations, "home_address": patientsNew.HomeAddress, "work_unit": patientsNew.WorkUnit, "unit_address": patientsNew.UnitAddress, "children": patientsNew.Children, "receiving_date": patientsNew.ReceivingDate, "is_hospital_first_dialysis": patientsNew.IsHospitalFirstDialysis, "first_dialysis_date": patientsNew.FirstDialysisDate, "first_dialysis_hospital": patientsNew.FirstDialysisHospital, "predialysis_condition": patientsNew.PredialysisCondition, "pre_hospital_dialysis_frequency": patientsNew.PreHospitalDialysisFrequency, "pre_hospital_dialysis_times": patientsNew.PreHospitalDialysisFrequency, "hospital_first_dialysis_date": patientsNew.HospitalFirstDialysisDate, "induction_period": patientsNew.InductionPeriod, "initial_dialysis": patientsNew.InitialDialysis, "total_dialysis": patientsNew.TotalDialysis, "attending_doctor_id": patientsNew.AttendingDoctorId, "head_nurse_id": patientsNew.HeadNurseId, "evaluate": patientsNew.Evaluate, "diagnose": patientsNew.Diagnose, "remark": patientsNew.Remark, "registrars_id": patientsNew.RegistrarsId, "registrars": patientsNew.Registrars, "qr_code": patientsNew.QrCode, "binding_state": patientsNew.BindingState, "patient_complains": patientsNew.PatientComplains, "present_history": patientsNew.PresentHistory, "past_history": patientsNew.PastHistory, "temperature": patientsNew.Temperature,
391
 	err := XTWriteDB().Model(&patientsNew).Where("blood_id = ?", id).Update(map[string]interface{}{"user_org_id": patientsNew.UserOrgId, "user_id": patientsNew.UserId, "avatar": patientsNew.Avatar, "patient_type": patientsNew.Avatar, "dialysis_no": patientsNew.DialysisNo, "admission_number": patientsNew.AdmissionNumber, "source": patientsNew.Source, "lapseto": patientsNew.Lapseto, "partition_id": patientsNew.PartitionId, "bed_id": patientsNew.BedId, "name": patientsNew.Name, "alias": patientsNew.Alias, "gender": patientsNew.Gender, "marital_status": patientsNew.MaritalStatus, "id_card_no": patientsNew.IdCardNo, "birthday": patientsNew.Birthday, "reimbursement_way_id": patientsNew.ReimbursementWayId, "health_care_type": patientsNew.HealthCareType, "health_care_no": patientsNew.HealthCareType, "health_care_due_date": patientsNew.HealthCareType, "height": patientsNew.Height, "blood_type": patientsNew.BloodType, "rh": patientsNew.Rh, "health_care_due_alert_date": patientsNew.HealthCareDueAlertDate, "education_level": patientsNew.EducationLevel, "profession": patientsNew.Profession, "phone": patientsNew.Phone, "home_telephone": patientsNew.HomeTelephone, "relative_phone": patientsNew.RelativePhone, "relative_relations": patientsNew.RelativeRelations, "home_address": patientsNew.HomeAddress, "work_unit": patientsNew.WorkUnit, "unit_address": patientsNew.UnitAddress, "children": patientsNew.Children, "receiving_date": patientsNew.ReceivingDate, "is_hospital_first_dialysis": patientsNew.IsHospitalFirstDialysis, "first_dialysis_date": patientsNew.FirstDialysisDate, "first_dialysis_hospital": patientsNew.FirstDialysisHospital, "predialysis_condition": patientsNew.PredialysisCondition, "pre_hospital_dialysis_frequency": patientsNew.PreHospitalDialysisFrequency, "pre_hospital_dialysis_times": patientsNew.PreHospitalDialysisFrequency, "hospital_first_dialysis_date": patientsNew.HospitalFirstDialysisDate, "induction_period": patientsNew.InductionPeriod, "initial_dialysis": patientsNew.InitialDialysis, "total_dialysis": patientsNew.TotalDialysis, "attending_doctor_id": patientsNew.AttendingDoctorId, "head_nurse_id": patientsNew.HeadNurseId, "evaluate": patientsNew.Evaluate, "diagnose": patientsNew.Diagnose, "remark": patientsNew.Remark, "registrars_id": patientsNew.RegistrarsId, "registrars": patientsNew.Registrars, "qr_code": patientsNew.QrCode, "binding_state": patientsNew.BindingState, "patient_complains": patientsNew.PatientComplains, "present_history": patientsNew.PresentHistory, "past_history": patientsNew.PastHistory, "temperature": patientsNew.Temperature,