|
@@ -249,6 +249,37 @@ func GetPatientDiseasesTwo(id int64) []int64 {
|
249
|
249
|
return ids
|
250
|
250
|
}
|
251
|
251
|
|
|
252
|
+func GetSlowPatientDiseases(id int64) (infeciousdisease []*models.CdmPatientsInfectiousDiseases, err error) {
|
|
253
|
+ //var dis []models.CdmPatientsInfectiousDiseases
|
|
254
|
+ //diseases := models.CdmPatientsChronicDiseases{}
|
|
255
|
+ //ids := make([]int64, 0)
|
|
256
|
+ //err := PatientReadDB().Model(&diseases).Where("patient_id = ? and status =1", id).Find(&ids).Error
|
|
257
|
+ //if err != nil || len(dis) == 0 {
|
|
258
|
+ // return ids
|
|
259
|
+ //}
|
|
260
|
+ //for _, item := range dis {
|
|
261
|
+ // ids = append(ids, item.DiseaseId)
|
|
262
|
+ //}
|
|
263
|
+ //return ids
|
|
264
|
+ err = PatientReadDB().Model(&infeciousdisease).Where("patient_id = ? and status =1", id).Find(&infeciousdisease).Error
|
|
265
|
+ return infeciousdisease, err
|
|
266
|
+}
|
|
267
|
+
|
|
268
|
+func GetCronicDiseases(id int64) (chronic []*models.CdmPatientsChronicDiseases, err error) {
|
|
269
|
+ //var dis []models.CdmPatientsChronicDiseases
|
|
270
|
+ //ids := make([]int64, 0)
|
|
271
|
+ //err := PatientReadDB().Model(&models.CdmPatientsChronicDiseases{}).Where("patient_id = ? and status =1", id).Find(&ids).Error
|
|
272
|
+ //if err != nil || len(dis) == 0 {
|
|
273
|
+ // return ids
|
|
274
|
+ //}
|
|
275
|
+ //for _, item := range dis {
|
|
276
|
+ // ids = append(ids, item.DiseaseId)
|
|
277
|
+ //}
|
|
278
|
+ //return ids
|
|
279
|
+ err = PatientReadDB().Model(&chronic).Where("patient_id = ? and status =1", id).Find(&chronic).Error
|
|
280
|
+ return chronic, err
|
|
281
|
+}
|
|
282
|
+
|
252
|
283
|
func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
|
253
|
284
|
|
254
|
285
|
user, _ := GetSgjUserByMobild(patient.Phone)
|
|
@@ -424,28 +455,32 @@ func GetLastNewSlowPatient(phone string, orgid int64) (*models.XtPatientsNew, er
|
424
|
455
|
return &patientnew, nil
|
425
|
456
|
}
|
426
|
457
|
|
427
|
|
-func GetNewDoctorAdvice(patientid int64, doctype int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
|
428
|
|
- db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1")
|
429
|
|
- if orgId > 0 {
|
430
|
|
- db = db.Where("x.user_org_id = ?", orgId)
|
|
458
|
+func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
|
|
459
|
+ db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
|
|
460
|
+ table := UserReadDB().Table("sgj_user_admin_role as r")
|
|
461
|
+ fmt.Print("table", table)
|
|
462
|
+ if orgID > 0 {
|
|
463
|
+ db = db.Where("x.user_org_id=?", orgID)
|
431
|
464
|
}
|
432
|
|
-
|
433
|
|
- if patientid > 0 {
|
434
|
|
- db = db.Where("x.patient_id = ?", patientid)
|
|
465
|
+ if patientID > 0 {
|
|
466
|
+ db = db.Where("x.patient_id = ?", patientID)
|
435
|
467
|
}
|
436
|
|
- if startime != 0 {
|
437
|
|
- db = db.Where("x.record_date>= ?", startime)
|
|
468
|
+ if advice_type > 0 {
|
|
469
|
+ db = db.Where("x.advice_type = ?", advice_type)
|
|
470
|
+ } else if advice_type == 0 {
|
|
471
|
+ db = db.Where("x.advice_type in (?)", []int{1, 3})
|
438
|
472
|
}
|
439
|
|
- if endtime != 0 {
|
440
|
|
- db = db.Where("x.record_date<=?", endtime)
|
|
473
|
+ if start != 0 {
|
|
474
|
+ db = db.Where("x.start_time>=?", start)
|
441
|
475
|
}
|
442
|
|
-
|
443
|
|
- if doctype > 0 {
|
444
|
|
- db = db.Where("x.advice_type = ?", doctype)
|
|
476
|
+ if end != 0 {
|
|
477
|
+ db = db.Where("start_time<=?", end)
|
445
|
478
|
}
|
446
|
479
|
offset := (page - 1) * limit
|
447
|
|
- err = db.Count(&total).Order("x.record_date desc").Offset(offset).Limit(limit).Group("x.id").Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&doctoradvice).Error
|
|
480
|
+ err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Offset(offset).Limit(limit).Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
|
|
481
|
+ fmt.Print("err", err)
|
448
|
482
|
return
|
|
483
|
+
|
449
|
484
|
}
|
450
|
485
|
|
451
|
486
|
func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
|
|
@@ -603,3 +638,178 @@ func GetEducation(patientid int64, startime int64, endtime int64, limit int64, p
|
603
|
638
|
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
|
604
|
639
|
return
|
605
|
640
|
}
|
|
641
|
+
|
|
642
|
+func GetSchedulingDetail(id int64) (models.XtScheduless, error) {
|
|
643
|
+ schedules := models.XtScheduless{}
|
|
644
|
+ db := XTReadDB().Table("xt_schedule as x")
|
|
645
|
+ err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,n.number,z.name").Joins("left join xt_device_number as n on n.id = x.bed_id").Joins("left join xt_device_zone as z on z.id = x.partition_id").Where("x.id =?", id).Scan(&schedules).Error
|
|
646
|
+ return schedules, err
|
|
647
|
+}
|
|
648
|
+
|
|
649
|
+func GetSchedulingTwo(id int64) (models.XtScheduless, error) {
|
|
650
|
+ schedules := models.XtScheduless{}
|
|
651
|
+ db := XTReadDB().Table("xt_schedule as x")
|
|
652
|
+ err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,z.name").Joins("left join xt_patients as z on z.id = x.patient_id").Where("x.id =?", id).Scan(&schedules).Error
|
|
653
|
+ return schedules, err
|
|
654
|
+}
|
|
655
|
+
|
|
656
|
+func DeleteScheduling(id int64) error {
|
|
657
|
+ err := XTWriteDB().Model(models.XtSchedules{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
658
|
+ return err
|
|
659
|
+}
|
|
660
|
+
|
|
661
|
+func GetEducationDetailOne(id int64) (models.XtTreatmentSummarys, error) {
|
|
662
|
+ summarys := models.XtTreatmentSummarys{}
|
|
663
|
+ db := XTReadDB().Table("xt_treatment_summary as x")
|
|
664
|
+ err := db.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.creater,x.modifier,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id = ?", id).Scan(&summarys).Error
|
|
665
|
+ return summarys, err
|
|
666
|
+}
|
|
667
|
+
|
|
668
|
+func DeleteEducation(id int64) error {
|
|
669
|
+ err := XTWriteDB().Model(models.XtTreatmentSummary{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
670
|
+ return err
|
|
671
|
+}
|
|
672
|
+
|
|
673
|
+func GetRescueRecordDetail(id int64) (models.XtPatientRescueRecords, error) {
|
|
674
|
+ records := models.XtPatientRescueRecords{}
|
|
675
|
+ db := XTReadDB().Table("xt_patient_rescue_record as x")
|
|
676
|
+ err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,r.user_name,s.name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id=?", id).Scan(&records).Error
|
|
677
|
+ return records, err
|
|
678
|
+}
|
|
679
|
+
|
|
680
|
+func DeleteRescueRecord(id int64) error {
|
|
681
|
+ err := XTWriteDB().Model(models.XtPatientRescueRecord{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
682
|
+ return err
|
|
683
|
+}
|
|
684
|
+
|
|
685
|
+func ToSearchePatient(keyword string, orgId int64) (paitents []*models.XtPatientsNew, err error) {
|
|
686
|
+ likeKey := "%" + keyword + "%"
|
|
687
|
+ err = XTReadDB().Where("name like ? or dialysis_no like ? and user_org_id = ?", likeKey, likeKey, orgId).Find(&paitents).Error
|
|
688
|
+ return paitents, err
|
|
689
|
+}
|
|
690
|
+
|
|
691
|
+func SearchallPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
|
|
692
|
+ likeKey := "%" + keyword + "%"
|
|
693
|
+ err = XTReadDB().Where("name like ? or dialysis_no = ? and user_org_id = ?", likeKey, keyword, orgid).Find(&patients).Error
|
|
694
|
+ return patients, err
|
|
695
|
+}
|
|
696
|
+
|
|
697
|
+func GetSearchallBlood(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
|
|
698
|
+ likeKey := "%" + keyword + "%"
|
|
699
|
+ err = XTReadDB().Where("name like ? or dialysis_no = ? and user_org_id = ? and blood_patients = 1", likeKey, keyword, orgid).Find(&patients).Error
|
|
700
|
+ return patients, err
|
|
701
|
+}
|
|
702
|
+
|
|
703
|
+func GetSlowSearchePatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
|
|
704
|
+ likeKey := "%" + keyword + "%"
|
|
705
|
+ err = XTReadDB().Where("name like ? or dialysis_no = ? and user_org_id = ? and slow_patients = 1", likeKey, keyword, orgid).Find(&patients).Error
|
|
706
|
+ return patients, err
|
|
707
|
+}
|
|
708
|
+
|
|
709
|
+func GetMemberSearchPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
|
|
710
|
+ likeKey := "%" + keyword + "%"
|
|
711
|
+ err = XTReadDB().Where("name like ? or dialysis_no = ? and user_org_id = ? and member_patients = 1", likeKey, keyword, orgid).Find(&patients).Error
|
|
712
|
+ return patients, err
|
|
713
|
+}
|
|
714
|
+
|
|
715
|
+func GetLongDialysisDetail(id int64) (models.XtDialysisSolution, error) {
|
|
716
|
+ solution := models.XtDialysisSolution{}
|
|
717
|
+ err := XTReadDB().Model(&solution).Where("id=? and status =1", id).Find(&solution).Error
|
|
718
|
+ return solution, err
|
|
719
|
+}
|
|
720
|
+
|
|
721
|
+func GetPatientName(id int64) (models.Patients, error) {
|
|
722
|
+ patientsNew := models.Patients{}
|
|
723
|
+ err := XTReadDB().Model(&patientsNew).Where("id=? and status = 1", id).Find(&patientsNew).Error
|
|
724
|
+ return patientsNew, err
|
|
725
|
+}
|
|
726
|
+
|
|
727
|
+func DeleteLongDialysis(id int64) error {
|
|
728
|
+ err := XTWriteDB().Model(models.XtDialysisSolution{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
729
|
+ return err
|
|
730
|
+}
|
|
731
|
+
|
|
732
|
+func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, page int64, orgID int64, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
|
|
733
|
+ offset := (page - 1) * limit
|
|
734
|
+ var total int64
|
|
735
|
+ var err error
|
|
736
|
+ var orders []*models.PatientDialysisRecord
|
|
737
|
+
|
|
738
|
+ db := readDb.Table("xt_dialysis_order as do").
|
|
739
|
+ Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
740
|
+ Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
741
|
+ Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
|
|
742
|
+ return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
|
|
743
|
+ return readUserDb.Where("status = 1")
|
|
744
|
+ })
|
|
745
|
+ }).
|
|
746
|
+ Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
747
|
+ Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
748
|
+ Preload("Device", "org_id=? and status=1", orgID).
|
|
749
|
+ Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
|
|
750
|
+ return readUserDb.Where("org_id=? and status = 1", orgID)
|
|
751
|
+ }).
|
|
752
|
+ Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
|
|
753
|
+ Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
|
|
754
|
+ Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
|
|
755
|
+
|
|
756
|
+ if start != 0 {
|
|
757
|
+ db = db.Where("do.dialysis_date>=?", start)
|
|
758
|
+ }
|
|
759
|
+ if end != 0 {
|
|
760
|
+ db = db.Where("do.dialysis_date<=?", end)
|
|
761
|
+ }
|
|
762
|
+ if mode_id > 0 {
|
|
763
|
+ db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.record_id=do.id")
|
|
764
|
+ db = db.Where("dp.mode_id=?", mode_id)
|
|
765
|
+ }
|
|
766
|
+
|
|
767
|
+ err = db.Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select("do.bed_id, do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time,do.start_nurse,do.finish_nurse ,s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
|
|
768
|
+
|
|
769
|
+ if len(orders) > 0 {
|
|
770
|
+ ids := make([]int64, 0)
|
|
771
|
+ for _, order := range orders {
|
|
772
|
+ dialyzer := order.DialysisPrescription.Dialyzer
|
|
773
|
+ ids = append(ids, dialyzer)
|
|
774
|
+ }
|
|
775
|
+ if len(ids) > 0 {
|
|
776
|
+ var dialyzers []*models.DeviceNumber
|
|
777
|
+ err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
|
|
778
|
+ if err != nil {
|
|
779
|
+ return nil, 0, err
|
|
780
|
+ }
|
|
781
|
+
|
|
782
|
+ dialyzerMap := make(map[int64]models.DeviceNumber, 0)
|
|
783
|
+ for _, item := range dialyzers {
|
|
784
|
+ dialyzerMap[item.ID] = *item
|
|
785
|
+ }
|
|
786
|
+ for orderIndex, order := range orders {
|
|
787
|
+ if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
|
|
788
|
+ orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
|
|
789
|
+ }
|
|
790
|
+ }
|
|
791
|
+ }
|
|
792
|
+ }
|
|
793
|
+
|
|
794
|
+ return orders, total, err
|
|
795
|
+}
|
|
796
|
+
|
|
797
|
+func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.App_Role, err error) {
|
|
798
|
+
|
|
799
|
+ err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = ? ", orgid, appid, 1).Find(&appRole).Error
|
|
800
|
+ return appRole, err
|
|
801
|
+}
|
|
802
|
+
|
|
803
|
+func GetDoctorAdviceDetail(id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
|
|
804
|
+
|
|
805
|
+ db := XTReadDB().Table("xt_doctor_advice as x")
|
|
806
|
+ err = db.Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.created_time,x.updated_time,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.execution_state,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.groupno = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
|
|
807
|
+
|
|
808
|
+ return advices, err
|
|
809
|
+}
|
|
810
|
+
|
|
811
|
+func DeleteManagement(groupid int64, orgid int64) error {
|
|
812
|
+
|
|
813
|
+ err := XTWriteDB().Model(models.DoctorAdvice{}).Where("groupno=? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
|
|
814
|
+ return err
|
|
815
|
+}
|