Browse Source

体积小

XMLWAN 3 years ago
parent
commit
df1df3c236

+ 32 - 32
controllers/xcx_mobile_api_controller.go/xcx_api_controller.go View File

@@ -361,20 +361,20 @@ func (this *XcxApiController) GetScheduleInfo() {
361 361
 func (this *XcxApiController) GetMobileSchedule() {
362 362
 
363 363
 	patientID, _ := this.GetInt64("patient_id")
364
-	recordDateStr := this.GetString("date")
365
-	if patientID <= 0 {
366
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
367
-		return
368
-	}
369
-	if len(recordDateStr) == 0 {
370
-		recordDateStr = time.Now().Format("2006-01-02")
371
-	}
372
-	date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
373
-	if parseDateErr != nil {
374
-		this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
375
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
376
-		return
377
-	}
364
+	//recordDateStr := this.GetString("date")
365
+	//if patientID <= 0 {
366
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
367
+	//	return
368
+	//}
369
+	//if len(recordDateStr) == 0 {
370
+	//	recordDateStr = time.Now().Format("2006-01-02")
371
+	//}
372
+	//date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
373
+	//if parseDateErr != nil {
374
+	//	this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
375
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
376
+	//	return
377
+	//}
378 378
 
379 379
 	adminInfo := this.GetMobileAdminUserInfo()
380 380
 	patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
@@ -387,7 +387,7 @@ func (this *XcxApiController) GetMobileSchedule() {
387 387
 		return
388 388
 	}
389 389
 
390
-	schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
390
+	schedual, getSchedualErr := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID)
391 391
 
392 392
 	if getSchedualErr != nil {
393 393
 		this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
@@ -395,49 +395,49 @@ func (this *XcxApiController) GetMobileSchedule() {
395 395
 		return
396 396
 	}
397 397
 
398
-	receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
398
+	receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecordOne(adminInfo.Org.Id, patientID)
399 399
 	if getRTARErr != nil {
400 400
 		this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
401 401
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
402 402
 		return
403 403
 	}
404 404
 
405
-	predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
405
+	predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminInfo.Org.Id, patientID)
406 406
 	if getPEErr != nil {
407 407
 		this.ErrorLog("获取透前评估失败:%v", getPEErr)
408 408
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
409 409
 		return
410 410
 	}
411 411
 
412
-	lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
412
+	lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluationOne(adminInfo.Org.Id, patientID)
413 413
 	if getLPEErr != nil {
414 414
 		this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
415 415
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
416 416
 		return
417 417
 	}
418 418
 
419
-	doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
419
+	doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroupsOne(adminInfo.Org.Id, patientID)
420 420
 	if getDoctorAdvicesErr != nil {
421 421
 		this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
422 422
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
423 423
 		return
424 424
 	}
425 425
 
426
-	dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
426
+	dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecordOne(adminInfo.Org.Id, patientID)
427 427
 	if getDialysisOrderErr != nil {
428 428
 		this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
429 429
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
430 430
 		return
431 431
 	}
432 432
 
433
-	doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
433
+	doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheckOne(adminInfo.Org.Id, patientID)
434 434
 	if getDoubleCheckErr != nil {
435 435
 		this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
436 436
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
437 437
 		return
438 438
 	}
439 439
 
440
-	monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
440
+	monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordsOne(adminInfo.Org.Id, patientID)
441 441
 	if getMonitorRecordsErr != nil {
442 442
 		this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
443 443
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -445,35 +445,35 @@ func (this *XcxApiController) GetMobileSchedule() {
445 445
 	}
446 446
 	var lastMonitorRecord *models.MonitoringRecord
447 447
 
448
-	lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
448
+	lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecordOne(adminInfo.Org.Id, patientID)
449 449
 	if getLastErr != nil {
450 450
 		this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
451 451
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
452 452
 		return
453 453
 	}
454 454
 
455
-	assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
455
+	assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminInfo.Org.Id, patientID)
456 456
 	if getAADErr != nil {
457 457
 		this.ErrorLog("获取透后评估失败:%v", getAADErr)
458 458
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
459 459
 		return
460 460
 	}
461 461
 
462
-	lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
462
+	lastAssessmentAfterDislysis, getLAADErr := service.MobileGetAssessmentAfterDislysisOne(adminInfo.Org.Id, patientID)
463 463
 	if getLAADErr != nil {
464 464
 		this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
465 465
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
466 466
 		return
467 467
 	}
468 468
 
469
-	treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
469
+	treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummaryOne(adminInfo.Org.Id, patientID)
470 470
 	if getTreatmentSummaryErr != nil {
471 471
 		this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
472 472
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
473 473
 		return
474 474
 	}
475 475
 
476
-	dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
476
+	dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
477 477
 
478 478
 	dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
479 479
 
@@ -486,19 +486,19 @@ func (this *XcxApiController) GetMobileSchedule() {
486 486
 
487 487
 	_, is_project_open_config := service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
488 488
 
489
-	projects, _ := service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
489
+	projects, _ := service.GetHisPrescriptionProjectsOne(adminInfo.Org.Id, patientID)
490 490
 
491 491
 	stockType, _ := service.GetStockType(adminInfo.Org.Id)
492 492
 
493
-	prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
493
+	prepare, _ := service.GetDialyStockOutOne(adminInfo.Org.Id, patientID)
494 494
 
495 495
 	//获取最后一次血管通路
496
-	lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
496
+	lastAssessment, _ := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
497 497
 
498
-	prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
498
+	prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdFive(adminInfo.Org.Id, patientID)
499 499
 	var his_advices []*models.HisDoctorAdviceInfo
500 500
 	if is_open_config.IsOpen == 1 {
501
-		his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
501
+		his_advices, _ = service.GetAllHisDoctorAdviceOne(adminInfo.Org.Id, patientID)
502 502
 	}
503 503
 
504 504
 	if getLPEErr != nil {

+ 208 - 2
service/xcx_mobile_api_service.go View File

@@ -266,12 +266,12 @@ func GetDoctorAdviceConfig(orgid int64) (models.XcxDoctorAdviceConfig, error) {
266 266
 
267 267
 func GetDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxDoctorAdvice, err error) {
268 268
 
269
-	err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Find(&advice).Error
269
+	err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Order("advice_date desc").Find(&advice).Error
270 270
 	return advice, err
271 271
 }
272 272
 
273 273
 func GetHisDoctorAdviceGroup(patient_id int64, startime int64, endtime int64) (advice []*models.XcxHisDoctorAdviceInfo, err error) {
274
-	err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Find(&advice).Error
274
+	err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Group("advice_date").Order("advice_date desc").Find(&advice).Error
275 275
 	return advice, err
276 276
 }
277 277
 
@@ -286,3 +286,209 @@ func GetHisDoctorAdvice(patient_id int64, startime int64, endtime int64) (advice
286 286
 	err = XTReadDB().Where("patient_id = ? and advice_date >=? and advice_date<=? and status = 1", patient_id, startime, endtime).Find(&advice).Error
287 287
 	return advice, err
288 288
 }
289
+
290
+// 用户排班信息
291
+func MobileGetSchedualDetailOne(orgID int64, patientID int64) (*MDialysisScheduleVM, error) {
292
+	var vm MDialysisScheduleVM
293
+	err := readDb.
294
+		Table("xt_schedule").
295
+		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
296
+		Where("status = 1 AND user_org_id = ? AND patient_id = ?", orgID, patientID).
297
+		First(&vm).Error
298
+	if err != nil {
299
+		if err == gorm.ErrRecordNotFound {
300
+			return nil, nil
301
+		} else {
302
+			return nil, err
303
+		}
304
+	}
305
+	return &vm, err
306
+}
307
+
308
+// 接诊评估
309
+func MobileGetReceiverTreatmentAccessRecordOne(orgID int64, patientID int64) (*models.ReceiveTreatmentAsses, error) {
310
+	var record models.ReceiveTreatmentAsses
311
+	err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
312
+	if err != nil {
313
+		if err == gorm.ErrRecordNotFound {
314
+			return nil, nil
315
+		} else {
316
+			return nil, err
317
+		}
318
+	}
319
+	return &record, nil
320
+}
321
+
322
+// 透前评估
323
+func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64) (*models.PredialysisEvaluation, error) {
324
+	var record models.PredialysisEvaluation
325
+	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
326
+	if err != nil {
327
+		if err == gorm.ErrRecordNotFound {
328
+			return nil, nil
329
+		} else {
330
+			return nil, err
331
+		}
332
+	}
333
+	return &record, nil
334
+}
335
+
336
+// 获取 maxDate 之前一次的透前评估记录
337
+func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64) (*models.PredialysisEvaluation, error) {
338
+	var record models.PredialysisEvaluation
339
+	err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("assessment_date desc").Last(&record).Error
340
+	if err != nil {
341
+		if err == gorm.ErrRecordNotFound {
342
+			return nil, nil
343
+		} else {
344
+			return nil, err
345
+		}
346
+	}
347
+	return &record, nil
348
+}
349
+
350
+func MobileGetDoctorAdvicesByGroupsOne(orgID int64, patientID int64) ([]*models.DoctorAdvice, error) {
351
+	var records []*models.DoctorAdvice
352
+	err := readDb.
353
+		Model(&models.DoctorAdvice{}).
354
+		Where("patient_id = ? and user_org_id = ? and status = 1  and (advice_type = 2 || advice_type = 3)", patientID, orgID).
355
+		Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
356
+		Order("start_time asc, groupno desc, advice_order desc, id asc").
357
+		Scan(&records).Error
358
+
359
+	if err != nil {
360
+		return nil, err
361
+	}
362
+	return records, nil
363
+}
364
+
365
+// 透析记录
366
+func MobileGetSchedualDialysisRecordOne(orgID int64, patientID int64) (*models.DialysisOrder, error) {
367
+	var record models.DialysisOrder
368
+	err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND  status = 1", orgID).Where("user_org_id = ? AND patient_id = ?", orgID, patientID).Last(&record).Error
369
+	if err != nil {
370
+		if err == gorm.ErrRecordNotFound {
371
+			return nil, nil
372
+		} else {
373
+			return nil, err
374
+		}
375
+	}
376
+	return &record, nil
377
+}
378
+
379
+// 双人核对
380
+func MobileGetDoubleCheckOne(orgID int64, patientID int64) (*models.DoubleCheck, error) {
381
+	var record models.DoubleCheck
382
+	err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
383
+	if err != nil {
384
+		if err == gorm.ErrRecordNotFound {
385
+			return nil, nil
386
+		} else {
387
+			return nil, err
388
+		}
389
+	}
390
+	return &record, nil
391
+}
392
+
393
+// 透析监测记录
394
+func MobileGetMonitorRecordsOne(orgID int64, patientID int64) ([]*models.MonitoringRecord, error) {
395
+	var records []*models.MonitoringRecord
396
+	err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("operate_time asc").Last(&records).Error
397
+	if err != nil {
398
+		return nil, err
399
+	}
400
+	return records, nil
401
+}
402
+
403
+func MobileGetLastMonitorRecordOne(orgID int64, patientID int64) (*models.MonitoringRecord, error) {
404
+	var record models.MonitoringRecord
405
+	err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Order("operate_time desc").Last(&record).Error
406
+	if err != nil {
407
+		if err == gorm.ErrRecordNotFound {
408
+			return nil, nil
409
+		} else {
410
+			return nil, err
411
+		}
412
+	}
413
+	return &record, nil
414
+}
415
+
416
+// 透后评估
417
+func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64) (*models.AssessmentAfterDislysis, error) {
418
+	var record models.AssessmentAfterDislysis
419
+	err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
420
+	if err != nil {
421
+		if err == gorm.ErrRecordNotFound {
422
+			return nil, nil
423
+		} else {
424
+			return nil, err
425
+		}
426
+	}
427
+	return &record, nil
428
+}
429
+
430
+// 治疗小结
431
+func MobileGetTreatmentSummaryOne(orgID int64, patientID int64) (*models.TreatmentSummary, error) {
432
+	var record models.TreatmentSummary
433
+	err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
434
+	if err != nil {
435
+		if err == gorm.ErrRecordNotFound {
436
+			return nil, nil
437
+		} else {
438
+			return nil, err
439
+		}
440
+	}
441
+	return &record, nil
442
+}
443
+
444
+// 透析处方
445
+func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
446
+	var record models.DialysisPrescription
447
+	err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
448
+	if err != nil {
449
+		if err == gorm.ErrRecordNotFound {
450
+			return nil, nil
451
+		} else {
452
+			return nil, err
453
+		}
454
+	}
455
+	return &record, nil
456
+}
457
+
458
+func GetHisPrescriptionProjectsOne(user_org_id int64, patient_id int64) (projects []*models.HisPrescriptionProject, err error) {
459
+	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ?  AND  status = 1", user_org_id, patient_id).Find(&projects).Error
460
+	return
461
+}
462
+
463
+func GetDialyStockOutOne(orgid int64, patientId int64) (prepare []*models.XtDialysisBeforePrepare, err error) {
464
+
465
+	db := XTReadDB().Table("dialysis_before_prepare as x").Where("x.status = 1")
466
+	if orgid > 0 {
467
+		db = db.Where("x.user_org_id = ?", orgid)
468
+	}
469
+
470
+	if patientId > 0 {
471
+		db = db.Where("x.patient_id = ?", patientId)
472
+	}
473
+	err = db.Select("x.id,x.user_org_id,x.patient_id,x.record_date,x.good_id,x.good_type_id,x.count,x.commdity_code,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id and t.org_id = ? and t.status = 1", orgid).Scan(&prepare).Error
474
+	return prepare, err
475
+}
476
+
477
+func MobileGetDialysisPrescribeByModeIdFive(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
478
+	var record models.DialysisPrescription
479
+	err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
480
+	if err != nil {
481
+		if err == gorm.ErrRecordNotFound {
482
+			return nil, nil
483
+		} else {
484
+			return nil, err
485
+		}
486
+	}
487
+	return &record, nil
488
+}
489
+
490
+func GetAllHisDoctorAdviceOne(orgid int64, patientid int64) (his []*models.HisDoctorAdviceInfo, err error) {
491
+	err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1", patientid, orgid).Last(&his).Error
492
+	return
493
+
494
+}