|
@@ -707,3 +707,91 @@ func GetMemberSearchPatient(keyword string, orgid int64) (patients []*models.XtP
|
707
|
707
|
err = XTReadDB().Where("name like ? or dialysis_no = ? and user_org_id = ? and member_patients = 1", likeKey, keyword, orgid).Find(&patients).Error
|
708
|
708
|
return patients, err
|
709
|
709
|
}
|
|
710
|
+
|
|
711
|
+func GetLongDialysisDetail(id int64) (models.XtDialysisSolution, error) {
|
|
712
|
+ solution := models.XtDialysisSolution{}
|
|
713
|
+ err := XTReadDB().Model(&solution).Where("id=? and status =1", id).Find(&solution).Error
|
|
714
|
+ return solution, err
|
|
715
|
+}
|
|
716
|
+
|
|
717
|
+func GetPatientName(id int64) (models.Patients, error) {
|
|
718
|
+ patientsNew := models.Patients{}
|
|
719
|
+ err := XTReadDB().Model(&patientsNew).Where("id=? and status = 1", id).Find(&patientsNew).Error
|
|
720
|
+ return patientsNew, err
|
|
721
|
+}
|
|
722
|
+
|
|
723
|
+func DeleteLongDialysis(id int64) error {
|
|
724
|
+ err := XTWriteDB().Model(models.XtDialysisSolution{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
|
|
725
|
+ return err
|
|
726
|
+}
|
|
727
|
+
|
|
728
|
+func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, page int64, orgID int64, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
|
|
729
|
+ offset := (page - 1) * limit
|
|
730
|
+ var total int64
|
|
731
|
+ var err error
|
|
732
|
+ var orders []*models.PatientDialysisRecord
|
|
733
|
+
|
|
734
|
+ db := readDb.Table("xt_dialysis_order as do").
|
|
735
|
+ Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
736
|
+ Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
737
|
+ Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
|
|
738
|
+ return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
|
|
739
|
+ return readUserDb.Where("status = 1")
|
|
740
|
+ })
|
|
741
|
+ }).
|
|
742
|
+ Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
743
|
+ Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
|
|
744
|
+ Preload("Device", "org_id=? and status=1", orgID).
|
|
745
|
+ Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
|
|
746
|
+ return readUserDb.Where("org_id=? and status = 1", orgID)
|
|
747
|
+ }).
|
|
748
|
+ 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).
|
|
749
|
+ Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
|
|
750
|
+ Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
|
|
751
|
+
|
|
752
|
+ if start != 0 {
|
|
753
|
+ db = db.Where("do.dialysis_date>=?", start)
|
|
754
|
+ }
|
|
755
|
+ if end != 0 {
|
|
756
|
+ db = db.Where("do.dialysis_date<=?", end)
|
|
757
|
+ }
|
|
758
|
+ if mode_id > 0 {
|
|
759
|
+ db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.record_id=do.id")
|
|
760
|
+ db = db.Where("dp.mode_id=?", mode_id)
|
|
761
|
+ }
|
|
762
|
+
|
|
763
|
+ 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
|
|
764
|
+
|
|
765
|
+ if len(orders) > 0 {
|
|
766
|
+ ids := make([]int64, 0)
|
|
767
|
+ for _, order := range orders {
|
|
768
|
+ dialyzer := order.DialysisPrescription.Dialyzer
|
|
769
|
+ ids = append(ids, dialyzer)
|
|
770
|
+ }
|
|
771
|
+ if len(ids) > 0 {
|
|
772
|
+ var dialyzers []*models.DeviceNumber
|
|
773
|
+ err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
|
|
774
|
+ if err != nil {
|
|
775
|
+ return nil, 0, err
|
|
776
|
+ }
|
|
777
|
+
|
|
778
|
+ dialyzerMap := make(map[int64]models.DeviceNumber, 0)
|
|
779
|
+ for _, item := range dialyzers {
|
|
780
|
+ dialyzerMap[item.ID] = *item
|
|
781
|
+ }
|
|
782
|
+ for orderIndex, order := range orders {
|
|
783
|
+ if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
|
|
784
|
+ orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
|
|
785
|
+ }
|
|
786
|
+ }
|
|
787
|
+ }
|
|
788
|
+ }
|
|
789
|
+
|
|
790
|
+ return orders, total, err
|
|
791
|
+}
|
|
792
|
+
|
|
793
|
+func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.App_Role, err error) {
|
|
794
|
+
|
|
795
|
+ err = UserReadDB().Where("org_id = ? AND app_id = ? AND status = ? ", orgid, appid, 1).Find(&appRole).Error
|
|
796
|
+ return appRole, err
|
|
797
|
+}
|