|
@@ -720,3 +720,76 @@ func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (m
|
720
|
720
|
err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
|
721
|
721
|
return patient, err
|
722
|
722
|
}
|
|
723
|
+
|
|
724
|
+type VMOtherHisPrescriptionInfo struct {
|
|
725
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
726
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
|
|
727
|
+ RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
|
|
728
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
|
|
729
|
+ Status int64 `gorm:"column:status" json:"status" form:"status"`
|
|
730
|
+ CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
|
|
731
|
+ VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
|
|
732
|
+}
|
|
733
|
+
|
|
734
|
+func (VMOtherHisPrescriptionInfo) TableName() string {
|
|
735
|
+ return "his_prescription_info"
|
|
736
|
+}
|
|
737
|
+
|
|
738
|
+type VMHisPrescription struct {
|
|
739
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
740
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
|
|
741
|
+ RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
|
|
742
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
|
|
743
|
+ Status int64 `gorm:"column:status" json:"status" form:"status"`
|
|
744
|
+ OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
|
|
745
|
+ BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
|
|
746
|
+ PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
|
|
747
|
+ Type int64 `gorm:"column:type" json:"type" form:"type"`
|
|
748
|
+ HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
|
|
749
|
+ HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
|
|
750
|
+}
|
|
751
|
+
|
|
752
|
+func (VMHisPrescription) TableName() string {
|
|
753
|
+ return "his_prescription"
|
|
754
|
+}
|
|
755
|
+
|
|
756
|
+func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
|
|
757
|
+ if change_type == 1 { //根据日期取出上一方数据
|
|
758
|
+ var Id AdviceDate
|
|
759
|
+ err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ?", patient_id, org_id, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
|
|
760
|
+ err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patient_id, org_id, Id.RecordDate).
|
|
761
|
+ Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
|
|
762
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).
|
|
763
|
+ Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
|
|
764
|
+ Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
|
|
765
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
|
|
766
|
+ })
|
|
767
|
+ }).Find(&advice).Error
|
|
768
|
+
|
|
769
|
+ } else if change_type == 2 {
|
|
770
|
+ var Id AdviceDate
|
|
771
|
+ err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ?", patient_id, org_id, record_time).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
|
|
772
|
+ err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patient_id, org_id, Id.RecordDate).
|
|
773
|
+ Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
|
|
774
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).
|
|
775
|
+ Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
|
|
776
|
+ Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
|
|
777
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
|
|
778
|
+ })
|
|
779
|
+ }).Find(&advice).Error
|
|
780
|
+ }
|
|
781
|
+ return
|
|
782
|
+}
|
|
783
|
+
|
|
784
|
+func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
|
|
785
|
+ err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
|
|
786
|
+ Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
|
|
787
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).
|
|
788
|
+ Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
|
|
789
|
+ Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
|
|
790
|
+ return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
|
|
791
|
+ })
|
|
792
|
+ }).Find(&advice).Error
|
|
793
|
+
|
|
794
|
+ return
|
|
795
|
+}
|