瀏覽代碼

医保对接

csx 3 年之前
父節點
當前提交
f87643ff3e
共有 1 個文件被更改,包括 124 次插入14 次删除
  1. 124 14
      service/mobile_dialysis_service.go

+ 124 - 14
service/mobile_dialysis_service.go 查看文件

@@ -902,6 +902,7 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
902 902
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
903 903
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
904 904
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
905
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
905 906
 				Where("status = 1 AND user_org_id = ?", orgID)
906 907
 			if scheduleDate != 0 {
907 908
 				db = db.Where("schedule_date = ?", scheduleDate)
@@ -919,6 +920,7 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
919 920
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
920 921
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
921 922
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
923
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
922 924
 				Where("status = 1 AND user_org_id = ?", orgID)
923 925
 			if scheduleDate != 0 {
924 926
 				db = db.Where("schedule_date = ?", scheduleDate)
@@ -938,6 +940,7 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
938 940
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
939 941
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
940 942
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
943
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
941 944
 				Where("status = 1 AND user_org_id = ?", orgID)
942 945
 			if scheduleDate != 0 {
943 946
 				db = db.Where("schedule_date = ?", scheduleDate)
@@ -956,6 +959,7 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
956 959
 				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
957 960
 				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
958 961
 				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
962
+				Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
959 963
 				Where("status = 1 AND user_org_id = ?", orgID)
960 964
 			if scheduleDate != 0 {
961 965
 				db = db.Where("schedule_date = ?", scheduleDate)
@@ -968,6 +972,48 @@ func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, pat
968 972
 	return vms, err
969 973
 }
970 974
 
975
+func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
976
+	var vms []*HisMScheduleProjectVM
977
+	if patientType == 0 {
978
+		db := readDb.
979
+			Table("xt_schedule").
980
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
981
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
982
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
983
+			}).
984
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
985
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
986
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
987
+			Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
988
+			Where("status = 1 AND user_org_id = ?", orgID)
989
+		if scheduleDate != 0 {
990
+			db = db.Where("schedule_date = ?", scheduleDate)
991
+		}
992
+		err = db.Find(&vms).Error
993
+	}
994
+
995
+	if patientType > 0 {
996
+		db := readDb.
997
+			Table("xt_schedule").
998
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
999
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1000
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1001
+			}).
1002
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1003
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1004
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1005
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
1006
+			Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1007
+			Where("status = 1 AND user_org_id = ?", orgID)
1008
+		if scheduleDate != 0 {
1009
+			db = db.Where("schedule_date = ?", scheduleDate)
1010
+		}
1011
+		err = db.Find(&vms).Error
1012
+	}
1013
+
1014
+	return vms, err
1015
+}
1016
+
971 1017
 func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
972 1018
 	now := time.Now()
973 1019
 	tx := writeDb.Begin()
@@ -1775,26 +1821,48 @@ func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, record
1775 1821
 }
1776 1822
 
1777 1823
 type HisMScheduleDoctorAdviceVM struct {
1778
-	ID                  int64                            `gorm:"column:id" json:"id"`
1779
-	UserOrgId           int64                            `gorm:"column:user_org_id" json:"user_org_id"`
1780
-	PartitionId         int64                            `gorm:"column:partition_id" json:"partition_id"`
1781
-	BedId               int64                            `gorm:"column:bed_id" json:"bed_id"`
1782
-	PatientId           int64                            `gorm:"column:patient_id" json:"patient_id"`
1783
-	ScheduleDate        int64                            `gorm:"column:schedule_date" json:"schedule_date"`
1784
-	ScheduleType        int64                            `gorm:"column:schedule_type" json:"schedule_type"`
1785
-	ModeId              int64                            `gorm:"column:mode_id" json:"mode_id"`
1786
-	Status              int64                            `gorm:"column:status" json:"status"`
1787
-	DialysisOrder       *MDialysisOrderVM                `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
1788
-	SchedualPatient     *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1789
-	DeviceNumber        *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
1790
-	Prescription        *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
1791
-	HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
1824
+	ID                     int64                            `gorm:"column:id" json:"id"`
1825
+	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id"`
1826
+	PartitionId            int64                            `gorm:"column:partition_id" json:"partition_id"`
1827
+	BedId                  int64                            `gorm:"column:bed_id" json:"bed_id"`
1828
+	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id"`
1829
+	ScheduleDate           int64                            `gorm:"column:schedule_date" json:"schedule_date"`
1830
+	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
1831
+	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
1832
+	Status                 int64                            `gorm:"column:status" json:"status"`
1833
+	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
1834
+	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1835
+	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
1836
+	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
1837
+	HisDoctorAdviceInfo    []*models.HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
1838
+	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
1792 1839
 }
1793 1840
 
1794 1841
 func (HisMScheduleDoctorAdviceVM) TableName() string {
1795 1842
 	return "xt_schedule"
1796 1843
 }
1797 1844
 
1845
+type HisMScheduleProjectVM struct {
1846
+	ID                     int64                            `gorm:"column:id" json:"id"`
1847
+	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id"`
1848
+	PartitionId            int64                            `gorm:"column:partition_id" json:"partition_id"`
1849
+	BedId                  int64                            `gorm:"column:bed_id" json:"bed_id"`
1850
+	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id"`
1851
+	ScheduleDate           int64                            `gorm:"column:schedule_date" json:"schedule_date"`
1852
+	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
1853
+	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
1854
+	Status                 int64                            `gorm:"column:status" json:"status"`
1855
+	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId" json:"dialysis_order"`
1856
+	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1857
+	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
1858
+	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
1859
+	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
1860
+}
1861
+
1862
+func (HisMScheduleProjectVM) TableName() string {
1863
+	return "xt_schedule"
1864
+}
1865
+
1798 1866
 func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
1799 1867
 	config := models.XtHisConfig{}
1800 1868
 	err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
@@ -2121,3 +2189,45 @@ func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64
2121 2189
 
2122 2190
 	return
2123 2191
 }
2192
+
2193
+func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
2194
+	var vms []*HisMScheduleProjectVM
2195
+	if patientType == 0 {
2196
+		db := readDb.
2197
+			Table("xt_schedule").
2198
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2199
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2200
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2201
+			}).
2202
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2203
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2204
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2205
+			Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2206
+			Where("status = 1 AND user_org_id = ?", orgID)
2207
+		if scheduleDate != 0 {
2208
+			db = db.Where("schedule_date = ?", scheduleDate)
2209
+		}
2210
+		err = db.Find(&vms).Error
2211
+	}
2212
+
2213
+	if patientType > 0 {
2214
+		db := readDb.
2215
+			Table("xt_schedule").
2216
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2217
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
2218
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
2219
+			}).
2220
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2221
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
2222
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2223
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
2224
+			Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
2225
+			Where("status = 1 AND user_org_id = ?", orgID)
2226
+		if scheduleDate != 0 {
2227
+			db = db.Where("schedule_date = ?", scheduleDate)
2228
+		}
2229
+		err = db.Find(&vms).Error
2230
+	}
2231
+
2232
+	return vms, err
2233
+}