Browse Source

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

csx 5 years ago
parent
commit
a3683e31d9

+ 111 - 101
controllers/manage_api_controller.go View File

@@ -191,12 +191,19 @@ func (this *MachineApiController) SaveManageInfo() {
191 191
 		ids = append(ids, id)
192 192
 	}
193 193
 
194
+	//查询机位号是否绑定设备
195
+	thisAddmacher, err := service.GetEquitmentByBedID(bed_number, orgid)
196
+	if thisAddmacher.ID > 0 {
197
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
198
+		return
199
+	}
200
+
194 201
 	addmacher := &models.DeviceAddmacher{
195
-		SerialNumber:        serial_numbe,
196
-		DeviceType:          device_type,
197
-		BedNumber:           number.Number,
198
-		BedId:               bed_number,
199
-		ZoneId:              number.ZoneID,
202
+		SerialNumber: serial_numbe,
203
+		DeviceType:   device_type,
204
+		BedNumber:    number.Number,
205
+		BedId:        bed_number,
206
+		//ZoneId:              number.ZoneID,
200 207
 		DeviceName:          device_name,
201 208
 		ManufactureFactory:  manufacture_factory,
202 209
 		ServiceManufacturer: service_manufacturer,
@@ -1146,38 +1153,38 @@ func (this *MachineApiController) SaveInformation() {
1146 1153
 	fmt.Print("information", information)
1147 1154
 	if errinfor == gorm.ErrRecordNotFound {
1148 1155
 		infor := models.DeviceInformation{
1149
-			Date:                startdate,
1150
-			Class:               classtype,
1151
-			Zone:                zone,
1152
-			BedNumber:           bednumber,
1153
-			PatientId:           patient_time,
1154
-			Contagion:           contagion,
1155
-			DialysisMode:        dialysis_mode,
1156
-			StartTime:           startDate.Unix(),
1157
-			EndTime:             endDate.Unix(),
1158
-			DialysisHour:        dialysis_time,
1159
-			Hyperfiltratio:      hyperfiletration,
1160
-			WeightLoss:          weight_loss,
1161
-			WarningValue:        warining_value,
1162
-			UserTotal:           user_total,
1163
-			Move:                run,
1164
-			FailureStage:        failure_stage,
1165
-			FaultDescription:    falult_desciription,
1166
-			CodeInformation:     code_information,
1167
-			DisinfectantType:    disinfectant_type,
1168
-			DisinfectType:       disinfect_type,
1169
-			Disinfection:        disinfection,
1170
-			MachineRun:          machine_run,
1171
-			FluidPath:           fluid_path,
1172
-			Disinfectant:        disinfectant,
1173
-			DisinfectionStatus:  disinfection_status,
1174
-			DisinfectionResidue: disinfection_residue,
1175
-			LongTime:            longtime,
1176
-			DisinfecStartime:    start_Date.Unix(),
1177
-			DisinfecEndtime:     end_Date.Unix(),
1178
-			DialysisChecked:     dialysis_checked,
1179
-			DialysisName:        dialysis_name,
1180
-			Norms:               norms,
1156
+			Date:                  startdate,
1157
+			Class:                 classtype,
1158
+			Zone:                  zone,
1159
+			BedNumber:             bednumber,
1160
+			PatientId:             patient_time,
1161
+			Contagion:             contagion,
1162
+			DialysisMode:          dialysis_mode,
1163
+			StartTime:             startDate.Unix(),
1164
+			EndTime:               endDate.Unix(),
1165
+			DialysisHour:          dialysis_time,
1166
+			Hyperfiltratio:        hyperfiletration,
1167
+			WeightLoss:            weight_loss,
1168
+			WarningValue:          warining_value,
1169
+			UserTotal:             user_total,
1170
+			Move:                  run,
1171
+			FailureStage:          failure_stage,
1172
+			FaultDescription:      falult_desciription,
1173
+			CodeInformation:       code_information,
1174
+			DisinfectantType:      disinfectant_type,
1175
+			DisinfectType:         disinfect_type,
1176
+			Disinfection:          disinfection,
1177
+			MachineRun:            machine_run,
1178
+			FluidPath:             fluid_path,
1179
+			Disinfectant:          disinfectant,
1180
+			DisinfectionStatus:    disinfection_status,
1181
+			DisinfectionResidue:   disinfection_residue,
1182
+			LongTime:              longtime,
1183
+			DisinfecStartime:      start_Date.Unix(),
1184
+			DisinfecEndtime:       end_Date.Unix(),
1185
+			DialysisChecked:       dialysis_checked,
1186
+			DialysisName:          dialysis_name,
1187
+			Norms:                 norms,
1181 1188
 			DialysisConcentration: dialysis_concentration,
1182 1189
 			GermChecked:           germ_checked,
1183 1190
 			GermName:              germ_name,
@@ -1198,38 +1205,38 @@ func (this *MachineApiController) SaveInformation() {
1198 1205
 		})
1199 1206
 	} else if errinfor == nil {
1200 1207
 		infor := models.DeviceInformation{
1201
-			Date:                startdate,
1202
-			Class:               classtype,
1203
-			Zone:                zone,
1204
-			BedNumber:           bednumber,
1205
-			PatientId:           patient_time,
1206
-			Contagion:           contagion,
1207
-			DialysisMode:        dialysis_mode,
1208
-			StartTime:           startDate.Unix(),
1209
-			EndTime:             endDate.Unix(),
1210
-			DialysisHour:        dialysis_time,
1211
-			Hyperfiltratio:      hyperfiletration,
1212
-			WeightLoss:          weight_loss,
1213
-			WarningValue:        warining_value,
1214
-			UserTotal:           user_total,
1215
-			Move:                run,
1216
-			FailureStage:        failure_stage,
1217
-			FaultDescription:    falult_desciription,
1218
-			CodeInformation:     code_information,
1219
-			DisinfectantType:    disinfectant_type,
1220
-			DisinfectType:       disinfect_type,
1221
-			Disinfection:        disinfection,
1222
-			MachineRun:          machine_run,
1223
-			FluidPath:           fluid_path,
1224
-			Disinfectant:        disinfectant,
1225
-			DisinfectionStatus:  disinfection_status,
1226
-			DisinfectionResidue: disinfection_residue,
1227
-			LongTime:            longtime,
1228
-			DisinfecStartime:    start_Date.Unix(),
1229
-			DisinfecEndtime:     end_Date.Unix(),
1230
-			DialysisChecked:     dialysis_checked,
1231
-			DialysisName:        dialysis_name,
1232
-			Norms:               norms,
1208
+			Date:                  startdate,
1209
+			Class:                 classtype,
1210
+			Zone:                  zone,
1211
+			BedNumber:             bednumber,
1212
+			PatientId:             patient_time,
1213
+			Contagion:             contagion,
1214
+			DialysisMode:          dialysis_mode,
1215
+			StartTime:             startDate.Unix(),
1216
+			EndTime:               endDate.Unix(),
1217
+			DialysisHour:          dialysis_time,
1218
+			Hyperfiltratio:        hyperfiletration,
1219
+			WeightLoss:            weight_loss,
1220
+			WarningValue:          warining_value,
1221
+			UserTotal:             user_total,
1222
+			Move:                  run,
1223
+			FailureStage:          failure_stage,
1224
+			FaultDescription:      falult_desciription,
1225
+			CodeInformation:       code_information,
1226
+			DisinfectantType:      disinfectant_type,
1227
+			DisinfectType:         disinfect_type,
1228
+			Disinfection:          disinfection,
1229
+			MachineRun:            machine_run,
1230
+			FluidPath:             fluid_path,
1231
+			Disinfectant:          disinfectant,
1232
+			DisinfectionStatus:    disinfection_status,
1233
+			DisinfectionResidue:   disinfection_residue,
1234
+			LongTime:              longtime,
1235
+			DisinfecStartime:      start_Date.Unix(),
1236
+			DisinfecEndtime:       end_Date.Unix(),
1237
+			DialysisChecked:       dialysis_checked,
1238
+			DialysisName:          dialysis_name,
1239
+			Norms:                 norms,
1233 1240
 			DialysisConcentration: dialysis_concentration,
1234 1241
 			GermChecked:           germ_checked,
1235 1242
 			GermName:              germ_name,
@@ -2367,37 +2374,37 @@ func (this *MachineApiController) UpdateForm() {
2367 2374
 	fmt.Println("签名", sign_name)
2368 2375
 
2369 2376
 	information := models.DeviceInformation{
2370
-		Date:                startdate,
2371
-		Class:               classtype,
2372
-		Zone:                zone,
2373
-		BedNumber:           bednumber,
2374
-		Contagion:           contagion,
2375
-		DialysisMode:        dialysis_mode,
2376
-		StartTime:           startDate.Unix(),
2377
-		EndTime:             endDate.Unix(),
2378
-		DialysisHour:        dialysis_time,
2379
-		Hyperfiltratio:      hyperfiletration,
2380
-		WeightLoss:          weight_loss,
2381
-		WarningValue:        warining_value,
2382
-		UserTotal:           user_total,
2383
-		Move:                run,
2384
-		FailureStage:        failure_stage,
2385
-		FaultDescription:    falult_desciription,
2386
-		CodeInformation:     code_information,
2387
-		DisinfectantType:    disinfectant_type,
2388
-		DisinfectType:       disinfect_type,
2389
-		Disinfection:        disinfection,
2390
-		MachineRun:          machine_run,
2391
-		FluidPath:           fluid_path,
2392
-		Disinfectant:        disinfectant,
2393
-		DisinfectionStatus:  disinfection_status,
2394
-		DisinfectionResidue: disinfection_residue,
2395
-		LongTime:            longtime,
2396
-		DisinfecStartime:    distartime,
2397
-		DisinfecEndtime:     diendtime,
2398
-		DialysisChecked:     dialysis_checked,
2399
-		DialysisName:        dialysis_name,
2400
-		Norms:               norms,
2377
+		Date:                  startdate,
2378
+		Class:                 classtype,
2379
+		Zone:                  zone,
2380
+		BedNumber:             bednumber,
2381
+		Contagion:             contagion,
2382
+		DialysisMode:          dialysis_mode,
2383
+		StartTime:             startDate.Unix(),
2384
+		EndTime:               endDate.Unix(),
2385
+		DialysisHour:          dialysis_time,
2386
+		Hyperfiltratio:        hyperfiletration,
2387
+		WeightLoss:            weight_loss,
2388
+		WarningValue:          warining_value,
2389
+		UserTotal:             user_total,
2390
+		Move:                  run,
2391
+		FailureStage:          failure_stage,
2392
+		FaultDescription:      falult_desciription,
2393
+		CodeInformation:       code_information,
2394
+		DisinfectantType:      disinfectant_type,
2395
+		DisinfectType:         disinfect_type,
2396
+		Disinfection:          disinfection,
2397
+		MachineRun:            machine_run,
2398
+		FluidPath:             fluid_path,
2399
+		Disinfectant:          disinfectant,
2400
+		DisinfectionStatus:    disinfection_status,
2401
+		DisinfectionResidue:   disinfection_residue,
2402
+		LongTime:              longtime,
2403
+		DisinfecStartime:      distartime,
2404
+		DisinfecEndtime:       diendtime,
2405
+		DialysisChecked:       dialysis_checked,
2406
+		DialysisName:          dialysis_name,
2407
+		Norms:                 norms,
2401 2408
 		DialysisConcentration: dialysis_concentration,
2402 2409
 		GermChecked:           germ_checked,
2403 2410
 		GermName:              germ_name,
@@ -2521,10 +2528,13 @@ func (this *MachineApiController) GetUserForm() {
2521 2528
 }
2522 2529
 
2523 2530
 func (this *MachineApiController) GetBedForm() {
2531
+	adminUser := this.GetAdminUserInfo()
2532
+	orgId := adminUser.CurrentOrgId
2524 2533
 	id, _ := this.GetInt64("id")
2525 2534
 	fmt.Println("id", id)
2526 2535
 	addmacher, err := service.GetZoneForm(id)
2527
-	number, err := service.GetBedForm(addmacher.ZoneId)
2536
+	bed, err := service.GetZoneId(addmacher.BedId, orgId)
2537
+	number, err := service.GetBedForm(bed.ZoneID)
2528 2538
 	if err != nil {
2529 2539
 		this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询:("+err.Error()+")")
2530 2540
 		return

+ 48 - 7
controllers/new_mobile_api_controllers/mobile_regist_controller.go View File

@@ -515,14 +515,55 @@ func InitPatientAndSchedule(org *models.Org) {
515 515
 
516 516
 	//创建两个血透的虚拟病人到新表
517 517
 	fmt.Print("patients", patients)
518
-	for _, it := range ids {
518
+	for _, it := range patients {
519 519
 		patientsNew := models.XtPatientsNew{
520
-			UserOrgId:     org.Id,
521
-			CreatedTime:   time.Now().Unix(),
522
-			UpdatedTime:   time.Now().Unix(),
523
-			Status:        1,
524
-			BloodId:       it,
525
-			BloodPatients: 1,
520
+			UserOrgId:                    org.Id,
521
+			CreatedTime:                  time.Now().Unix(),
522
+			UpdatedTime:                  time.Now().Unix(),
523
+			Status:                       1,
524
+			BloodId:                      it.ID,
525
+			BloodPatients:                1,
526
+			Name:                         it.Name,
527
+			Avatar:                       it.Avatar,
528
+			PatientType:                  it.PatientType,
529
+			DialysisNo:                   it.DialysisNo,
530
+			Source:                       it.Source,
531
+			Lapseto:                      it.Lapseto,
532
+			Gender:                       it.Gender,
533
+			Nation:                       it.Nation,
534
+			NativePlace:                  it.NativePlace,
535
+			MaritalStatus:                it.MaritalStatus,
536
+			IdCardNo:                     it.IdCardNo,
537
+			Birthday:                     it.Birthday,
538
+			ReimbursementWayId:           it.ReimbursementWayId,
539
+			HealthCareNo:                 it.HealthCareNo,
540
+			Phone:                        it.Phone,
541
+			HomeAddress:                  it.HomeAddress,
542
+			WorkUnit:                     it.WorkUnit,
543
+			UnitAddress:                  it.UnitAddress,
544
+			Children:                     it.Children,
545
+			IsHospitalFirstDialysis:      it.IsHospitalFirstDialysis,
546
+			FirstDialysisDate:            it.FirstDialysisDate,
547
+			FirstDialysisHospital:        it.FirstDialysisHospital,
548
+			PreHospitalDialysisFrequency: it.PreHospitalDialysisFrequency,
549
+			PreHospitalDialysisTimes:     it.PreHospitalDialysisTimes,
550
+			HospitalFirstDialysisDate:    it.HospitalFirstDialysisDate,
551
+			TotalDialysis:                it.TotalDialysis,
552
+			Diagnose:                     it.Diagnose,
553
+			Remark:                       it.Remark,
554
+			RegistrarsId:                 it.RegistrarsId,
555
+			BindingState:                 it.BindingState,
556
+			PatientComplains:             it.PatientComplains,
557
+			PresentHistory:               it.PresentHistory,
558
+			PastHistory:                  it.PastHistory,
559
+			Temperature:                  it.Temperature,
560
+			Pulse:                        it.Pulse,
561
+			Respiratory:                  it.Respiratory,
562
+			Age:                          it.Age,
563
+			IsOpenRemind:                 it.IsOpenRemind,
564
+			TellPhone:                    it.TellPhone,
565
+			FirstTreatmentDate:           it.FirstTreatmentDate,
566
+			ContactName:                  it.ContactName,
526 567
 		}
527 568
 		service.CreateVMOrgNewPatient(&patientsNew)
528 569
 	}

+ 224 - 77
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go View File

@@ -243,72 +243,91 @@ func (this *NewDialysisApiController) SavePatient() {
243 243
 
244 244
 	//如果是血透病人
245 245
 	if bloodPatient == 1 {
246
-		_, errcode := service.GetPatientData(phone, orgid)
247
-		if errcode == gorm.ErrRecordNotFound {
248
-			patients := models.Patients{
249
-				Name:              name,
250
-				Gender:            sex,
251
-				Birthday:          birth,
252
-				Age:               ages,
253
-				Phone:             phone,
254
-				Lapseto:           lapseto,
255
-				AdmissionNumber:   adminssionNumber,
256
-				FirstDialysisDate: fisttime,
257
-				Diagnose:          diagonse,
258
-				Source:            patientsoure,
259
-				DialysisNo:        dialysis,
260
-				UserOrgId:         orgid,
261
-				Status:            1,
262
-				CreatedTime:       time.Now().Unix(),
263
-				Avatar:            avatar,
264
-				IdCardNo:          idCard,
265
-				IsInfectious:      is_infectious,
266
-			}
267
-			err := service.CreateOldPatient(&patients)
268
-			fmt.Print("报错", err)
269
-			patient, err := service.GetLastOldPatient(orgid)
270
-			fmt.Print("病人ID", patient.ID)
271
-			err = service.AddContagions(patient.ID, patient.CreatedTime, patient.UpdatedTime, ids)
272
-			fmt.Println("添加传染病失败", err)
273
-
274
-			patientsNew := models.XtPatientsNew{
275
-				Name:              name,
276
-				Gender:            sex,
277
-				Birthday:          birth,
278
-				Age:               ages,
279
-				Phone:             phone,
280
-				Lapseto:           lapseto,
281
-				AdmissionNumber:   adminssionNumber,
282
-				FirstDialysisDate: fisttime,
283
-				Diagnose:          diagonse,
284
-				Source:            patientsoure,
285
-				DialysisNo:        dialysis,
286
-				UserOrgId:         orgid,
287
-				Status:            1,
288
-				CreatedTime:       time.Now().Unix(),
289
-				Avatar:            avatar,
290
-				MemberPatients:    memberpatient,
291
-				BloodPatients:     bloodPatient,
292
-				SlowPatients:      slowpatient,
293
-				BloodId:           patient.ID,
294
-				IsInfectious:      is_infectious,
295
-				IdCardNo:          idCard,
296
-			}
297
-			err = service.CreateNewPatient(&patientsNew)
298
-			fmt.Print("报错", err)
299
-			if err != nil {
300
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
301
-				return
302
-			}
303
-			this.ServeSuccessJSON(map[string]interface{}{
304
-				"patient": patientsNew,
305
-			})
306
-		} else if errcode == nil {
307
-			fmt.Print("病人已存在")
246
+		//查询身份证号码是否存在
247
+		thisPatientOne, _ := service.FindPatientByIdCardNoOne(orgid, idCard)
248
+		if thisPatientOne.ID > 0 {
249
+			returnData := make(map[string]interface{}, 0)
250
+			returnData["msg"] = "身份证号码已存在"
251
+			this.ServeSuccessJSON(returnData)
308 252
 			return
309
-		} else {
253
+		}
254
+
255
+		//查询手机号码是否存在
256
+		thisPatient, err := service.FindPatientByMobileOne(phone, orgid)
257
+		if thisPatient.ID > 0 {
258
+			returnData := make(map[string]interface{}, 0)
259
+			returnData["msg"] = "手机号码已存在"
260
+			this.ServeSuccessJSON(returnData)
261
+			return
262
+		}
310 263
 
264
+		//查询透析号是否存在
265
+		thisPatientTwo, _ := service.FindPatientByDialysisNoOne(orgid, dialysis)
266
+		if thisPatientTwo.ID > 0 {
267
+			returnData := make(map[string]interface{}, 0)
268
+			returnData["msg"] = "透析号已存在"
269
+			this.ServeSuccessJSON(returnData)
270
+			return
311 271
 		}
272
+
273
+		patients := models.Patients{
274
+			Name:              name,
275
+			Gender:            sex,
276
+			Birthday:          birth,
277
+			Age:               ages,
278
+			Phone:             phone,
279
+			Lapseto:           lapseto,
280
+			AdmissionNumber:   adminssionNumber,
281
+			FirstDialysisDate: fisttime,
282
+			Diagnose:          diagonse,
283
+			Source:            patientsoure,
284
+			DialysisNo:        dialysis,
285
+			UserOrgId:         orgid,
286
+			Status:            1,
287
+			CreatedTime:       time.Now().Unix(),
288
+			Avatar:            avatar,
289
+			IdCardNo:          idCard,
290
+			IsInfectious:      is_infectious,
291
+		}
292
+		err = service.CreateOldPatient(&patients)
293
+		fmt.Print("报错", err)
294
+		patient, err := service.GetLastOldPatient(orgid)
295
+		fmt.Print("病人ID", patient.ID)
296
+		err = service.AddContagions(patient.ID, patient.CreatedTime, patient.UpdatedTime, ids)
297
+		fmt.Println("添加传染病失败", err)
298
+
299
+		patientsNew := models.XtPatientsNew{
300
+			Name:              name,
301
+			Gender:            sex,
302
+			Birthday:          birth,
303
+			Age:               ages,
304
+			Phone:             phone,
305
+			Lapseto:           lapseto,
306
+			AdmissionNumber:   adminssionNumber,
307
+			FirstDialysisDate: fisttime,
308
+			Diagnose:          diagonse,
309
+			Source:            patientsoure,
310
+			DialysisNo:        dialysis,
311
+			UserOrgId:         orgid,
312
+			Status:            1,
313
+			CreatedTime:       time.Now().Unix(),
314
+			Avatar:            avatar,
315
+			MemberPatients:    memberpatient,
316
+			BloodPatients:     bloodPatient,
317
+			SlowPatients:      slowpatient,
318
+			BloodId:           patient.ID,
319
+			IsInfectious:      is_infectious,
320
+			IdCardNo:          idCard,
321
+		}
322
+		err = service.CreateNewPatient(&patientsNew)
323
+		fmt.Print("报错", err)
324
+		if err != nil {
325
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
326
+			return
327
+		}
328
+		this.ServeSuccessJSON(map[string]interface{}{
329
+			"patient": patientsNew,
330
+		})
312 331
 	}
313 332
 
314 333
 	fmt.Print("slowpatient", slowpatient)
@@ -511,7 +530,7 @@ func (this *NewDialysisApiController) SavePatient() {
511 530
 					MemberTreatement:  treatmentmethod,
512 531
 				}
513 532
 				err = service.CreateNewPatient(&patientsNew)
514
-				fmt.Print("报错-----------------------", err)
533
+				fmt.Print("报错", err)
515 534
 				if err != nil {
516 535
 					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
517 536
 					return
@@ -578,7 +597,7 @@ func (this *NewDialysisApiController) GetDoctorAdvices() {
578 597
 	fmt.Print("开始时间", startime)
579 598
 	end := this.GetString("endtime")
580 599
 	fmt.Print("end", end)
581
-	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
600
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
582 601
 	endtime := endTimes.Unix()
583 602
 	fmt.Print("结束时间", endtime)
584 603
 	limit, _ := this.GetInt64("limit")
@@ -607,7 +626,8 @@ func (this *NewDialysisApiController) GetDryWeight() {
607 626
 	startime := startTimes.Unix()
608 627
 	fmt.Print("startime", startime)
609 628
 	end := this.GetString("endtime")
610
-	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
629
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
630
+
611 631
 	endtime := endTimes.Unix()
612 632
 	fmt.Print("endtime", endtime)
613 633
 	limit, _ := this.GetInt64("limit")
@@ -652,7 +672,7 @@ func (this *NewDialysisApiController) GetCourseManagement() {
652 672
 	startime := startTimes.Unix()
653 673
 	fmt.Print("startime", startime)
654 674
 	end := this.GetString("endtime")
655
-	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
675
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
656 676
 	endtime := endTimes.Unix()
657 677
 	fmt.Print("endtime", endtime)
658 678
 	limit, _ := this.GetInt64("limit")
@@ -814,7 +834,7 @@ func (this *NewDialysisApiController) GetRescuerecord() {
814 834
 	startime := startTimes.Unix()
815 835
 	fmt.Print("startime", startime)
816 836
 	end := this.GetString("endtime")
817
-	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
837
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
818 838
 	endtime := endTimes.Unix()
819 839
 	fmt.Print("endtime", endtime)
820 840
 	limit, _ := this.GetInt64("limit")
@@ -1241,6 +1261,34 @@ func (this *NewDialysisApiController) UpdatedPatient() {
1241 1261
 	if bloodPatient == 1 {
1242 1262
 		//根据新表ID获取老表病人ID
1243 1263
 		patient, _ := service.GetNewPatient(id)
1264
+
1265
+		//判断身份证号是否相同
1266
+		thisPatient, _ := service.FindPatientByIdCardNoOne(orgid, idCard)
1267
+		if thisPatient.ID > 0 && thisPatient.ID != patient.BloodId {
1268
+			returnData := make(map[string]interface{}, 0)
1269
+			returnData["msg"] = "身份证号码已存在"
1270
+			this.ServeSuccessJSON(returnData)
1271
+			return
1272
+		}
1273
+
1274
+		//查询手机号码是否存在
1275
+		thisPatientOne, err := service.FindPatientByMobileOne(phone, orgid)
1276
+		if thisPatientOne.ID > 0 && thisPatientOne.ID != patient.BloodId {
1277
+			returnData := make(map[string]interface{}, 0)
1278
+			returnData["msg"] = "手机号码已存在"
1279
+			this.ServeSuccessJSON(returnData)
1280
+			return
1281
+		}
1282
+
1283
+		//查询号透析号是否相同
1284
+		thisPatientother, _ := service.FindPatientByDialysisNoOne(orgid, dialysis)
1285
+		if thisPatientother.ID > 0 && thisPatientother.ID != patient.BloodId {
1286
+			returnData := make(map[string]interface{}, 0)
1287
+			returnData["msg"] = "透析号码已存在"
1288
+			this.ServeSuccessJSON(returnData)
1289
+			return
1290
+		}
1291
+
1244 1292
 		patients := models.Patients{
1245 1293
 			Name:              name,
1246 1294
 			Gender:            sex,
@@ -1260,7 +1308,7 @@ func (this *NewDialysisApiController) UpdatedPatient() {
1260 1308
 			IdCardNo:          idCard,
1261 1309
 			IsInfectious:      is_infectious,
1262 1310
 		}
1263
-		err := service.UpdatedPatient(patients, patient.BloodId)
1311
+		err = service.UpdatedPatient(patients, patient.BloodId)
1264 1312
 		patientsNew := models.XtPatientsNew{
1265 1313
 			ID:                id,
1266 1314
 			Name:              name,
@@ -1289,6 +1337,12 @@ func (this *NewDialysisApiController) UpdatedPatient() {
1289 1337
 		this.ServeSuccessJSON(map[string]interface{}{
1290 1338
 			"patients": patientsNew,
1291 1339
 		})
1340
+		//更改传染病
1341
+		updateContagions, err := service.UpdateContagions(patient.BloodId)
1342
+		fmt.Print("更新传染病失败", err)
1343
+		fmt.Print("up", updateContagions)
1344
+		err = service.AddContagions(patient.BloodId, patient.CreatedTime, patient.UpdatedTime, ids)
1345
+		fmt.Println("添加传染病失败", err)
1292 1346
 	}
1293 1347
 	if slowpatient == 1 {
1294 1348
 		patient, _ := service.GetNewPatient(id)
@@ -1412,14 +1466,32 @@ func (this *NewDialysisApiController) GetAllDoctor() {
1412 1466
 
1413 1467
 func (this *NewDialysisApiController) GetAllInspection() {
1414 1468
 
1415
-	inspection, err := service.GetAllInspection(0)
1416
-	if err != nil {
1417
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1418
-		return
1469
+	//查询该机构是否存在检验检测项目
1470
+	orgid := this.GetMobileAdminUserInfo().Org.Id
1471
+	fmt.Print("orgid", orgid)
1472
+	_, errcode := service.GetInspectionByOrgId(orgid)
1473
+	if errcode == gorm.ErrRecordNotFound {
1474
+		inspection, err := service.GetAllInspection(0)
1475
+		if err != nil {
1476
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1477
+			return
1478
+		}
1479
+		this.ServeSuccessJSON(map[string]interface{}{
1480
+			"inspection": inspection,
1481
+		})
1482
+	} else if errcode == nil {
1483
+		inspection, err := service.GetAllInspection(orgid)
1484
+		if err != nil {
1485
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1486
+			return
1487
+		}
1488
+		this.ServeSuccessJSON(map[string]interface{}{
1489
+			"inspection": inspection,
1490
+		})
1491
+	} else {
1492
+
1419 1493
 	}
1420
-	this.ServeSuccessJSON(map[string]interface{}{
1421
-		"inspection": inspection,
1422
-	})
1494
+
1423 1495
 }
1424 1496
 
1425 1497
 func (this *NewDialysisApiController) GetInspection() {
@@ -1444,6 +1516,12 @@ func (this *NewDialysisApiController) GetInspection() {
1444 1516
 	orgid := adminInfo.Org.Id
1445 1517
 	fmt.Print("patient", patient)
1446 1518
 	fmt.Print("orgid", orgid)
1519
+
1520
+	//查询该机构是否存在
1521
+	//inspection, _ := service.GetInspectionById(patient.BloodId, startime, endtime, orgid)
1522
+	//if len(inspection) == 0 {
1523
+	//
1524
+	//}
1447 1525
 	inspection, total, err := service.GetInspection(patient.BloodId, startime, endtime, limit, page, orgid)
1448 1526
 	if err != nil {
1449 1527
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -1459,7 +1537,7 @@ func (this *NewDialysisApiController) GetMyInformation() {
1459 1537
 	adminUserInfo := this.GetMobileAdminUserInfo()
1460 1538
 
1461 1539
 	roleInfo := adminUserInfo.AppRole
1462
-
1540
+	fmt.Print("aa")
1463 1541
 	es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
1464 1542
 
1465 1543
 	this.ServeSuccessJSON(map[string]interface{}{
@@ -1468,3 +1546,72 @@ func (this *NewDialysisApiController) GetMyInformation() {
1468 1546
 	})
1469 1547
 	return
1470 1548
 }
1549
+
1550
+func (this *NewDialysisApiController) GetPatientName() {
1551
+	id, _ := this.GetInt64("id")
1552
+	patients, _ := service.GetPatientDetailTwo(id)
1553
+	fmt.Print("paitents", patients.ID)
1554
+	patientName, err := service.GetPatientName(patients.BloodId)
1555
+	fmt.Print("err", err)
1556
+	if err != nil {
1557
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1558
+		return
1559
+	}
1560
+	this.ServeSuccessJSON(map[string]interface{}{
1561
+		"patientName": patientName,
1562
+	})
1563
+}
1564
+
1565
+func (this *NewDialysisApiController) GetInspectionDetail() {
1566
+
1567
+	patientid, _ := this.GetInt64("patientid")
1568
+	fmt.Print("patientid", patientid)
1569
+	patients, _ := service.GetPatientDetailTwo(patientid)
1570
+	date, _ := this.GetInt64("date")
1571
+	fmt.Print("date", date)
1572
+	projectid, _ := this.GetInt64("projectid")
1573
+	adminUser := this.GetMobileAdminUserInfo()
1574
+	orgid := adminUser.Org.Id
1575
+	InspectionDetail, err := service.GetInspectionDetail(patients.BloodId, date, orgid, projectid)
1576
+	if err != nil {
1577
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1578
+		return
1579
+	}
1580
+	this.ServeSuccessJSON(map[string]interface{}{
1581
+		"InspectionDetail": InspectionDetail,
1582
+	})
1583
+}
1584
+
1585
+func (this *NewDialysisApiController) SaveFeed() {
1586
+
1587
+	question, _ := this.GetInt64("question")
1588
+	fmt.Print("question", question)
1589
+	title := this.GetString("title")
1590
+	fmt.Print("title", title)
1591
+	content := this.GetString("content")
1592
+	fmt.Print("content", content)
1593
+	phone := this.GetString("phone")
1594
+	fmt.Print("phone", phone)
1595
+	times, _ := this.GetInt64("time")
1596
+	fmt.Print("time", times)
1597
+	adminUser := this.GetMobileAdminUserInfo()
1598
+	orgid := adminUser.Org.Id
1599
+	feedback := models.XtPatientFeedback{
1600
+		ProblemType: question,
1601
+		Title:       title,
1602
+		Content:     content,
1603
+		Phone:       phone,
1604
+		TimeQuantum: times,
1605
+		UserOrgId:   orgid,
1606
+		Ctime:       time.Now().Unix(),
1607
+		Status:      1,
1608
+	}
1609
+	err := service.CreateFeedBack(&feedback)
1610
+	if err != nil {
1611
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1612
+		return
1613
+	}
1614
+	this.ServeSuccessJSON(map[string]interface{}{
1615
+		"feedback": feedback,
1616
+	})
1617
+}

+ 3 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go View File

@@ -95,4 +95,7 @@ func NewMobileAPIControllersRegisterRouters() {
95 95
 	beego.Router("/m/api/patient/getallinspection", &NewDialysisApiController{}, "Get:GetAllInspection")
96 96
 	beego.Router("/m/api/patient/getinspection", &NewDialysisApiController{}, "Get:GetInspection")
97 97
 	beego.Router("/m/api/patient/getmyinformation", &NewDialysisApiController{}, "Get:GetMyInformation")
98
+	beego.Router("/m/api/patient/getpatientname", &NewDialysisApiController{}, "Get:GetPatientName")
99
+	beego.Router("/m/api/patient/getinspectiondetail", &NewDialysisApiController{}, "Get:GetInspectionDetail")
100
+	beego.Router("/m/api/patient/savefeed", &NewDialysisApiController{}, "Get:SaveFeed")
98 101
 }

+ 97 - 0
controllers/patient_api_controller.go View File

@@ -239,6 +239,103 @@ func (c *PatientApiController) CreatePatient() {
239 239
 		return
240 240
 	}
241 241
 
242
+	//获取老表的最后一条数据
243
+	patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
244
+	patientsNew := models.XtPatientsNew{
245
+		UserOrgId:                    adminUserInfo.CurrentOrgId,
246
+		UserId:                       0,
247
+		Avatar:                       patients.Avatar,
248
+		PatientType:                  patients.PatientType,
249
+		DialysisNo:                   patients.DialysisNo,
250
+		AdmissionNumber:              patients.AdmissionNumber,
251
+		Source:                       patients.Source,
252
+		Lapseto:                      patients.Lapseto,
253
+		PartitionId:                  patients.PartitionId,
254
+		BedId:                        patients.BedId,
255
+		Name:                         patients.Name,
256
+		Alias:                        patients.Alias,
257
+		Gender:                       patients.Gender,
258
+		MaritalStatus:                patients.MaritalStatus,
259
+		IdCardNo:                     patients.IdCardNo,
260
+		Birthday:                     patients.Birthday,
261
+		ReimbursementWayId:           patients.ReimbursementWayId,
262
+		HealthCareType:               patients.HealthCareType,
263
+		HealthCareNo:                 patients.HealthCareNo,
264
+		HealthCareDueDate:            patients.HealthCareDueDate,
265
+		Height:                       patients.Height,
266
+		BloodType:                    patients.BloodType,
267
+		Rh:                           patients.Rh,
268
+		HealthCareDueAlertDate:       patients.HealthCareDueAlertDate,
269
+		EducationLevel:               patients.EducationLevel,
270
+		Profession:                   patients.Profession,
271
+		Phone:                        patients.Phone,
272
+		HomeTelephone:                patients.HomeTelephone,
273
+		RelativePhone:                patients.RelativePhone,
274
+		RelativeRelations:            patients.RelativeRelations,
275
+		HomeAddress:                  patients.HomeAddress,
276
+		WorkUnit:                     patients.WorkUnit,
277
+		UnitAddress:                  patients.UnitAddress,
278
+		Children:                     patients.Children,
279
+		ReceivingDate:                patients.ReceivingDate,
280
+		IsHospitalFirstDialysis:      patients.IsHospitalFirstDialysis,
281
+		FirstDialysisDate:            patients.FirstDialysisDate,
282
+		FirstDialysisHospital:        patients.FirstDialysisHospital,
283
+		PredialysisCondition:         patients.PredialysisCondition,
284
+		PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
285
+		PreHospitalDialysisTimes:     patients.PreHospitalDialysisTimes,
286
+		HospitalFirstDialysisDate:    patients.HospitalFirstDialysisDate,
287
+		InductionPeriod:              patients.InductionPeriod,
288
+		InitialDialysis:              patients.InitialDialysis,
289
+		TotalDialysis:                patients.TotalDialysis,
290
+		AttendingDoctorId:            patients.AttendingDoctorId,
291
+		HeadNurseId:                  patients.HeadNurseId,
292
+		Evaluate:                     patients.Evaluate,
293
+		Diagnose:                     patients.Diagnose,
294
+		Remark:                       patients.Remark,
295
+		RegistrarsId:                 patients.RegistrarsId,
296
+		Registrars:                   patients.Registrars,
297
+		QrCode:                       patients.QrCode,
298
+		BindingState:                 patients.BindingState,
299
+		PatientComplains:             patients.PatientComplains,
300
+		PresentHistory:               patients.PresentHistory,
301
+		PastHistory:                  patients.PresentHistory,
302
+		Temperature:                  patients.Temperature,
303
+		Pulse:                        patients.Pulse,
304
+		Respiratory:                  patients.Respiratory,
305
+		Sbp:                          patients.SBP,
306
+		Dbp:                          patients.DBP,
307
+		Status:                       patients.Status,
308
+		CreatedTime:                  patients.CreatedTime,
309
+		UpdatedTime:                  patients.UpdatedTime,
310
+		Nation:                       patients.Nation,
311
+		NativePlace:                  patients.NativePlace,
312
+		Age:                          patients.Age,
313
+		InfectiousNextRecordTime:     patients.InfectiousNextRecordTime,
314
+		IsInfectious:                 patients.IsInfectious,
315
+		RemindCycle:                  patients.RemindCycle,
316
+		ResponseResult:               patients.ResponseResult,
317
+		IsOpenRemind:                 patients.IsOpenRemind,
318
+		FirstTreatmentDate:           patients.FirstTreatmentDate,
319
+		DialysisAge:                  patients.DialysisAge,
320
+		ExpenseKind:                  patients.ExpenseKind,
321
+		TellPhone:                    patients.TellPhone,
322
+		ContactName:                  patients.ContactName,
323
+		BloodPatients:                1,
324
+		SlowPatients:                 0,
325
+		MemberPatients:               0,
326
+		EcommerPatients:              "",
327
+		BloodId:                      patients.ID,
328
+		SlowId:                       0,
329
+		MemberId:                     0,
330
+		MemberFistdate:               0,
331
+		MemberPatienttype:            0,
332
+		MemberTreatement:             0,
333
+		EquitmentId:                  "",
334
+	}
335
+
336
+	err = service.CreatePatientsNew(&patientsNew)
337
+	fmt.Print("创建失败", err)
338
+
242 339
 	if len(record_date) > 0 {
243 340
 		var recordTime int64
244 341
 		timeLayout := "2006-01-02"

+ 1 - 0
models/device_models.go View File

@@ -183,6 +183,7 @@ type DeviceAddmachers struct {
183 183
 	EquitmentName       string `gorm:"column:equitment_name" json:"equitment_name" form:"equitment_name"`
184 184
 	BedId               int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
185 185
 	DeviceMode          string `gorm:"column:device_mode" json:"device_mode" form:"device_mode"`
186
+	Number              string `gorm:"column:number" json:"number" form:"number"`
186 187
 }
187 188
 
188 189
 type DeviceAddmacher struct {

+ 42 - 0
models/inspection_models.go View File

@@ -20,6 +20,28 @@ func (Inspection) TableName() string {
20 20
 	return "xt_inspection"
21 21
 }
22 22
 
23
+type Inspections struct {
24
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
25
+	PatientId    int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
26
+	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
27
+	ProjectId    int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
28
+	ItemId       int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
29
+	ItemName     string `gorm:"column:item_name" json:"item_name" form:"item_name"`
30
+	ProjectName  string `gorm:"column:project_name" json:"project_name" form:"project_name"`
31
+	InspectType  int64  `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
32
+	InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
33
+	InspectDate  int64  `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
34
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
35
+	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
36
+	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
37
+	RangeType    int64  `gorm:"column:range_type" json:"range_type" form:"range_type"`
38
+	RangeMin     string `gorm:"column:range_min" json:"range_min" form:"range_min"`
39
+	RangeMax     string `gorm:"column:range_max" json:"range_max" form:"range_max"`
40
+	RangeValue   string `gorm:"column:range_value" json:"range_value" form:"range_value"`
41
+	RangeOptions string `gorm:"column:range_options" json:"range_options" form:"range_options"`
42
+	Unit         string `gorm:"column:unit" json:"unit" form:"unit"`
43
+}
44
+
23 45
 type InspectionReference struct {
24 46
 	ID               int64  `gorm:"column:id" json:"id" form:"id"`
25 47
 	OrgId            int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
@@ -77,3 +99,23 @@ type InepectionForm struct {
77 99
 type InspectionDate struct {
78 100
 	InspectDate int64
79 101
 }
102
+
103
+type XtPatientFeedback struct {
104
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
105
+	ProblemType int64  `gorm:"column:problem_type" json:"problem_type" form:"problem_type"`
106
+	Title       string `gorm:"column:title" json:"title" form:"title"`
107
+	Content     string `gorm:"column:content" json:"content" form:"content"`
108
+	Image       string `gorm:"column:image" json:"image" form:"image"`
109
+	Phone       string `gorm:"column:phone" json:"phone" form:"phone"`
110
+	TimeQuantum int64  `gorm:"column:time_quantum" json:"time_quantum" form:"time_quantum"`
111
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
112
+	Mtime       int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
113
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
114
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
115
+	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
116
+	AppId       int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
117
+}
118
+
119
+func (XtPatientFeedback) TableName() string {
120
+	return "xt_patient_feedback"
121
+}

+ 87 - 0
models/patient_models.go View File

@@ -710,3 +710,90 @@ func (XtInspection) TableName() string {
710 710
 
711 711
 	return "xt_inspection"
712 712
 }
713
+
714
+type XtPatients struct {
715
+	ID                           int64   `gorm:"column:id" json:"id" form:"id"`
716
+	UserOrgId                    int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
717
+	UserId                       int64   `gorm:"column:user_id" json:"user_id" form:"user_id"`
718
+	Avatar                       string  `gorm:"column:avatar" json:"avatar" form:"avatar"`
719
+	PatientType                  int64   `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
720
+	DialysisNo                   string  `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
721
+	AdmissionNumber              string  `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
722
+	Source                       int64   `gorm:"column:source" json:"source" form:"source"`
723
+	Lapseto                      int64   `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
724
+	PartitionId                  int64   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
725
+	BedId                        int64   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
726
+	Name                         string  `gorm:"column:name" json:"name" form:"name"`
727
+	Alias                        string  `gorm:"column:alias" json:"alias" form:"alias"`
728
+	Gender                       int64   `gorm:"column:gender" json:"gender" form:"gender"`
729
+	MaritalStatus                int64   `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
730
+	IdCardNo                     string  `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
731
+	Birthday                     int64   `gorm:"column:birthday" json:"birthday" form:"birthday"`
732
+	ReimbursementWayId           int64   `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
733
+	HealthCareType               int64   `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
734
+	HealthCareNo                 string  `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
735
+	HealthCareDueDate            int64   `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
736
+	Height                       int64   `gorm:"column:height" json:"height" form:"height"`
737
+	BloodType                    int64   `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
738
+	Rh                           int64   `gorm:"column:rh" json:"rh" form:"rh"`
739
+	HealthCareDueAlertDate       int64   `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
740
+	EducationLevel               int64   `gorm:"column:education_level" json:"education_level" form:"education_level"`
741
+	Profession                   int64   `gorm:"column:profession" json:"profession" form:"profession"`
742
+	Phone                        string  `gorm:"column:phone" json:"phone" form:"phone"`
743
+	HomeTelephone                string  `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
744
+	RelativePhone                string  `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
745
+	RelativeRelations            string  `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
746
+	HomeAddress                  string  `gorm:"column:home_address" json:"home_address" form:"home_address"`
747
+	WorkUnit                     string  `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
748
+	UnitAddress                  string  `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
749
+	Children                     int64   `gorm:"column:children" json:"children" form:"children"`
750
+	ReceivingDate                int64   `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
751
+	IsHospitalFirstDialysis      int64   `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
752
+	FirstDialysisDate            int64   `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
753
+	FirstDialysisHospital        string  `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
754
+	PredialysisCondition         string  `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
755
+	PreHospitalDialysisFrequency string  `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
756
+	PreHospitalDialysisTimes     int64   `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
757
+	HospitalFirstDialysisDate    int64   `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
758
+	InductionPeriod              int64   `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
759
+	InitialDialysis              int64   `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
760
+	TotalDialysis                int64   `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
761
+	AttendingDoctorId            int64   `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
762
+	HeadNurseId                  int64   `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
763
+	Evaluate                     string  `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
764
+	Diagnose                     string  `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
765
+	Remark                       string  `gorm:"column:remark" json:"remark" form:"remark"`
766
+	RegistrarsId                 int64   `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
767
+	Registrars                   string  `gorm:"column:registrars" json:"registrars" form:"registrars"`
768
+	QrCode                       string  `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
769
+	BindingState                 int64   `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
770
+	PatientComplains             string  `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
771
+	PresentHistory               string  `gorm:"column:present_history" json:"present_history" form:"present_history"`
772
+	PastHistory                  string  `gorm:"column:past_history" json:"past_history" form:"past_history"`
773
+	Temperature                  float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
774
+	Pulse                        int64   `gorm:"column:pulse" json:"pulse" form:"pulse"`
775
+	Respiratory                  int64   `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
776
+	Sbp                          int64   `gorm:"column:sbp" json:"sbp" form:"sbp"`
777
+	Dbp                          int64   `gorm:"column:dbp" json:"dbp" form:"dbp"`
778
+	Status                       int64   `gorm:"column:status" json:"status" form:"status"`
779
+	CreatedTime                  int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
780
+	UpdatedTime                  int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
781
+	Nation                       string  `gorm:"column:nation" json:"nation" form:"nation"`
782
+	NativePlace                  string  `gorm:"column:native_place" json:"native_place" form:"native_place"`
783
+	Age                          int64   `gorm:"column:age" json:"age" form:"age"`
784
+	InfectiousNextRecordTime     int64   `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
785
+	IsInfectious                 int64   `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
786
+	RemindCycle                  int64   `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
787
+	ResponseResult               string  `gorm:"column:response_result" json:"response_result" form:"response_result"`
788
+	IsOpenRemind                 int64   `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
789
+	FirstTreatmentDate           int64   `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
790
+	DialysisAge                  int64   `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
791
+	ExpenseKind                  int64   `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
792
+	TellPhone                    string  `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
793
+	ContactName                  string  `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
794
+}
795
+
796
+func (XtPatients) TableName() string {
797
+
798
+	return "xt_patients"
799
+}

+ 8 - 4
service/device_service.go View File

@@ -565,8 +565,10 @@ func GetAllMachineInfo(page int64, limit int64, keyword string, zoneid int64, eq
565 565
 	db := readUserDb.Table("xt_device_addmacher as a").Where("a.status = 1")
566 566
 	table := XTReadDB().Table("xt_device_zone as x")
567 567
 	d := readUserDb.Table("xt_device_mode as m")
568
+	d2 := XTReadDB().Table("xt_device_number as n")
568 569
 	fmt.Print("d", d)
569 570
 	fmt.Println("table", table)
571
+	fmt.Print("d2", d2)
570 572
 	if orgid > 0 {
571 573
 		db = db.Where("a.user_org_id = ?", orgid)
572 574
 	}
@@ -587,8 +589,8 @@ func GetAllMachineInfo(page int64, limit int64, keyword string, zoneid int64, eq
587 589
 
588 590
 	offset := (page - 1) * limit
589 591
 
590
-	err = db.Order("a.ctime asc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.bed_id,x.name,m.device_mode").Count(&total).
591
-		Joins("Left JOIN sgj_xt.xt_device_zone as x On x.id = a.zone_id").Joins("Left JOIN xt_device_mode as m on m.id = a.unit_type ").Offset(offset).Limit(limit).Scan(&addmahcer).Error
592
+	err = db.Order("a.ctime asc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.bed_id,x.name,m.device_mode,n.number").Count(&total).
593
+		Joins("Left JOIN xt_device_mode as m on m.id = a.unit_type ").Joins("left join sgj_xt.xt_device_number as n on n.id = a.bed_id").Joins("Left JOIN sgj_xt.xt_device_zone as x On x.id = n.zone_id").Offset(offset).Limit(limit).Scan(&addmahcer).Error
592 594
 
593 595
 	if err != nil {
594 596
 
@@ -605,6 +607,8 @@ func GetAllMachine(zoneid int64, classid int64, deviceid int64, timenow int64, o
605 607
 	fmt.Println("tab", tab)
606 608
 	d := readUserDb.Table("xt_device_mode as m")
607 609
 	fmt.Print("d", d)
610
+	table := XTReadDB().Table("xt_device_number as n")
611
+	fmt.Print("table", table)
608 612
 	if orgid > 0 {
609 613
 		db = db.Where("a.user_org_id = ?", orgid)
610 614
 	}
@@ -616,10 +620,10 @@ func GetAllMachine(zoneid int64, classid int64, deviceid int64, timenow int64, o
616 620
 		db = db.Where("a.device_type = ?", deviceid)
617 621
 	}
618 622
 	if classid > 0 {
619
-		error := db.Joins("LEFT JOIN sgj_xt.xt_schedule as x On x.bed_id = a.bed_id").Joins("LEFT JOIN xt_device_mode as d on d.id = a.unit_type").Where("x.user_org_id = ? AND x.schedule_date = ? AND x.schedule_type = ? AND x.status = ?", orgid, timenow, classid, 1).Order("a.ctime desc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,d.device_mode").Find(&addmahcer).Error
623
+		error := db.Joins("LEFT JOIN sgj_xt.xt_schedule as x On x.bed_id = a.bed_id").Joins("LEFT JOIN xt_device_mode as d on d.id = a.unit_type").Joins("lefj join sgj_xt.xt_device_number as n on n.id = a.bed_id").Where("x.user_org_id = ? AND x.schedule_date = ? AND x.schedule_type = ? AND x.status = ?", orgid, timenow, classid, 1).Order("a.ctime desc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,d.device_mode,n.number").Find(&addmahcer).Error
620 624
 		fmt.Println("err", error)
621 625
 	} else {
622
-		err = db.Order("a.ctime asc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.bed_id,d.device_mode").Joins("LEFT JOIN xt_device_mode as d on d.id = a.unit_type").Find(&addmahcer).Error
626
+		err = db.Order("a.ctime asc").Select("a.id,a.serial_number,a.device_type,a.bed_number,a.device_name,a.manufacture_factory,a.service_manufacturer,a.unit_type,a.use_section,a.section_number,a.buy_date,a.install_date,a.start_date,a.maintenace_engineer,a.telephone,a.guarantee_date,a.machine_status,a.user_total,a.disinfection_mode,a.remarks,a.rubbish_date,a.rubbish_reason,a.user_year,a.work_time,a.revers_mode,a.user_org_id,a.status,a.ctime,a.mtime,a.bed_id,d.device_mode,n.number").Joins("LEFT JOIN xt_device_mode as d on d.id = a.unit_type").Joins("left join sgj_xt.xt_device_number as n on n.id = a.bed_id").Find(&addmahcer).Error
623 627
 		fmt.Println("错误是什么", err)
624 628
 		if err != nil {
625 629
 

+ 7 - 1
service/manage_service.go View File

@@ -29,6 +29,12 @@ func CreateEquimentName(equimentname models.DeviceEquimentname) error {
29 29
 	return err
30 30
 }
31 31
 
32
+func GetEquitmentByBedID(bedid int64, orgid int64) (models.DeviceAddmacher, error) {
33
+	addmacher := models.DeviceAddmacher{}
34
+	err := UserReadDB().Model(&addmacher).Where("bed_id = ? and user_org_id = ? and status = 1", bedid, orgid).First(&addmacher).Error
35
+	return addmacher, err
36
+}
37
+
32 38
 func CreateMacher(machers *models.DeviceAddmacher) error {
33 39
 
34 40
 	//err := writeDb.Create(&machers).Error
@@ -811,7 +817,7 @@ func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*model
811 817
 	if orgId > 0 {
812 818
 		db = db.Where("x.user_org_id = ?", orgId)
813 819
 	}
814
-	err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Order("x.ctime desc").Offset(offset).Limit(limit).Scan(&infor).Error
820
+	err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Scan(&infor).Error
815 821
 	if err != nil {
816 822
 
817 823
 		return

+ 13 - 1
service/patient_service.go View File

@@ -256,6 +256,18 @@ func CreatePatient(patient *models.Patients, contagions []int64, diseases []int6
256 256
 	return
257 257
 }
258 258
 
259
+func GetLastPatientData(orgid int64) (models.Patients, error) {
260
+	patients := models.Patients{}
261
+	err := XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1", orgid).Last(&patients).Error
262
+	return patients, err
263
+}
264
+
265
+func CreatePatientsNew(patientsNew *models.XtPatientsNew) error {
266
+
267
+	err := XTWriteDB().Model(&patientsNew).Create(&patientsNew).Error
268
+	return err
269
+}
270
+
259 271
 func EditPatientLapseto(patient *models.Patients, lapseto *models.PatientLapseto) (err error) {
260 272
 	utx := writeDb.Begin()
261 273
 	err = utx.Model(&models.Patients{}).Where("id=?", patient.ID).Update(map[string]interface{}{"Lapseto": patient.Lapseto}).Error
@@ -304,7 +316,7 @@ func UpdatePatient(patient *models.Patients, contagions []int64, diseases []int6
304 316
 		return
305 317
 	}
306 318
 	err = utx.Model(&models.InfectiousDiseases{}).Where("patient_id=?", patient.ID).Update(map[string]interface{}{"Status": 2, "UpdatedTime": patient.UpdatedTime}).Error
307
-	fmt.Println("错误是什么。。。。。。。。。。。。。。。。。。。。。。。。。。。", err)
319
+	fmt.Println("err", err)
308 320
 	if err != nil {
309 321
 		utx.Rollback()
310 322
 		return

+ 90 - 7
service/patientmanage_service.go View File

@@ -400,6 +400,21 @@ func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []i
400 400
 	return
401 401
 }
402 402
 
403
+func FindPatientByIdCardNoOne(orgID int64, idCardNo string) (patient models.Patients, err error) {
404
+	err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
405
+	return
406
+}
407
+
408
+func FindPatientByDialysisNoOne(orgID int64, dialysisNo string) (patient models.Patients, err error) {
409
+	err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=?", orgID, dialysisNo).First(&patient).Error
410
+	return
411
+}
412
+
413
+func FindPatientByMobileOne(mobile string, orgID int64) (patient models.Patients, err error) {
414
+	err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
415
+	return
416
+}
417
+
403 418
 func GetPatientData(phone string, orgid int64) (*models.XtPatientsNew, error) {
404 419
 	var patientnew models.XtPatientsNew
405 420
 	var err error
@@ -470,10 +485,10 @@ func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int
470 485
 	} else if advice_type == 0 {
471 486
 		db = db.Where("x.advice_type in (?)", []int{1, 3})
472 487
 	}
473
-	if start != 0 {
488
+	if start > 0 {
474 489
 		db = db.Where("x.start_time>=?", start)
475 490
 	}
476
-	if end != 0 {
491
+	if end > 0 {
477 492
 		db = db.Where("start_time<=?", end)
478 493
 	}
479 494
 	offset := (page - 1) * limit
@@ -634,7 +649,7 @@ func GetEducation(patientid int64, startime int64, endtime int64, limit int64, p
634 649
 		db = db.Where("x.assessment_date <= ?", endtime)
635 650
 	}
636 651
 	offset := (page - 1) * limit
637
-	err = db.Count(&total).Order("x.assessment_date").Offset(offset).Limit(limit).Group("x.id").
652
+	err = db.Count(&total).Order("x.assessment_date desc").Offset(offset).Limit(limit).Group("x.id").
638 653
 		Select("x.id,x.user_org_id,x.patient_id,x.assessment_date,x.dialysis_order_id,x.mission,x.dialysis_summary,x.change,x.sj_nurse,x.zl_nurse,x.hd_nurse,x.xj_nurse,x.zl_doctor,x.channel_image,x.puncture,x.puncture_needle,x.puncture_direction,x.status,x.created_time,x.updated_time,x.creater,x.modifier").Scan(&treatment).Error
639 654
 	return
640 655
 }
@@ -783,10 +798,10 @@ func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, pag
783 798
 		Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
784 799
 		Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
785 800
 
786
-	if start != 0 {
801
+	if start > 0 {
787 802
 		db = db.Where("do.dialysis_date>=?", start)
788 803
 	}
789
-	if end != 0 {
804
+	if end > 0 {
790 805
 		db = db.Where("do.dialysis_date<=?", end)
791 806
 	}
792 807
 	if mode_id > 0 {
@@ -864,6 +879,12 @@ func UpdateXtPatientNew(patients models.XtPatientsNew, id int64) error {
864 879
 	return err
865 880
 }
866 881
 
882
+func UpdateContagions(patientid int64) (models.XtPatientsInfectiousDiseases, error) {
883
+	diseases := models.XtPatientsInfectiousDiseases{}
884
+	err := XTWriteDB().Model(&diseases).Where("patient_id = ?", patientid).Update(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
885
+	return diseases, err
886
+}
887
+
867 888
 func UpdateCustomer(cdmpatient models.CdmPatients, id int64) error {
868 889
 
869 890
 	err := PatientWriteDB().Model(&cdmpatient).Where("id=?", id).Update(map[string]interface{}{"name": cdmpatient.Name, "phone": cdmpatient.Phone, "gender": cdmpatient.Gender, "birthday": cdmpatient.Birthday, "diagnose": cdmpatient.Diagnose, "source": cdmpatient.Source, "avatar": cdmpatient.Avatar, "id_card_no": cdmpatient.IdCardNo, "updated_time": cdmpatient.UpdatedTime}).Error
@@ -876,6 +897,39 @@ func UpdatedCustomer(customer models.SgjUserCustomer, id int64) error {
876 897
 	return err
877 898
 }
878 899
 
900
+func GetInspectionByOrgId(orgid int64) (*models.XtInspectionReference, error) {
901
+	diseases := models.XtInspectionReference{}
902
+	err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
903
+	if err == gorm.ErrRecordNotFound {
904
+		return nil, err
905
+	}
906
+	if err != nil {
907
+		return nil, err
908
+	}
909
+	return &diseases, nil
910
+
911
+}
912
+
913
+//func GetInspectionById(patientid int64,startime int64,endtime int64,orgId int64)(inspection []*models.XtInspectionReference,err error)  {
914
+//
915
+//  db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
916
+//  if patientid > 0 {
917
+//    db = db.Where("x.patient_id = ?", patientid)
918
+//  }
919
+//  if startime > 0 {
920
+//    db = db.Where("x.inspect_date >= ?", startime)
921
+//  }
922
+//  if endtime > 0 {
923
+//    db = db.Where("x.inspect_date<=?", endtime)
924
+//  }
925
+//  if orgId > 0 {
926
+//    db = db.Where("x.org_id = ?", orgId)
927
+//  }
928
+//  err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.created_time").Find(inspection).Error
929
+//
930
+//  return inspection,err
931
+//}
932
+
879 933
 func GetAllInspection(orgid int64) (inspection []*models.XtInspectionReference, err error) {
880 934
 
881 935
 	err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&inspection).Error
@@ -883,7 +937,7 @@ func GetAllInspection(orgid int64) (inspection []*models.XtInspectionReference,
883 937
 }
884 938
 
885 939
 func GetInspection(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (inspection []*models.Inspection, total int64, err error) {
886
-	fmt.Print(limit, page)
940
+
887 941
 	db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
888 942
 	if patientid > 0 {
889 943
 		db = db.Where("x.patient_id = ?", patientid)
@@ -897,7 +951,36 @@ func GetInspection(patientid int64, startime int64, endtime int64, limit int64,
897 951
 	if orgid > 0 {
898 952
 		db = db.Where("x.org_id = ?", orgid)
899 953
 	}
900
-	err = db.Count(&total).Order("x.inspect_date").Group("x.id").
954
+	err = db.Count(&total).Order("x.inspect_date desc").Group("x.id").
901 955
 		Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.created_time").Find(&inspection).Error
902 956
 	return inspection, total, err
903 957
 }
958
+
959
+func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int64) (inspection []*models.Inspections, err error) {
960
+
961
+	db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
962
+	table := XTReadDB().Table("xt_inspection_reference as r")
963
+	fmt.Print("table", table)
964
+	if patientid > 0 {
965
+		db = db.Where("x.patient_id = ?", patientid)
966
+	}
967
+
968
+	if date > 0 {
969
+		db = db.Where("x.inspect_date = ?", date)
970
+	}
971
+	if orgid > 0 {
972
+
973
+		db = db.Where("x.org_id = ?", orgid)
974
+	}
975
+	if projectid > 0 {
976
+		db = db.Where("x.project_id = ?", projectid)
977
+	}
978
+	err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on r.id = x.item_id ").Scan(&inspection).Error
979
+	return inspection, err
980
+}
981
+
982
+func CreateFeedBack(feedback *models.XtPatientFeedback) error {
983
+
984
+	err := XTWriteDB().Model(&feedback).Create(&feedback).Error
985
+	return err
986
+}