his_hospital_service.go 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type HospitalPatient struct {
  7. ID int64 `gorm:"column:id" json:"id" form:"id"`
  8. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  9. Name string `gorm:"column:name" json:"name" form:"name"`
  10. Status int64 `gorm:"column:status" json:"status" form:"status"`
  11. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  12. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  13. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  14. HisHospitalCheckRecord models.HisHospitalCheckRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  15. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  16. //HisHospitalOrder models.HisHospitalOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  17. }
  18. func (HospitalPatient) TableName() string {
  19. return "xt_patients"
  20. }
  21. func GetHisHospitalPatientList(org_id int64, record_date int64) (patients []*HospitalPatient, err error) {
  22. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  23. db = db.Joins("join his_hospital_check_record as record ON record.patient_id = xt_patients.id AND record.status = 1 AND record.user_org_id = ? AND record.in_hospital_status = 1 AND record.out_hospital_status = 0", org_id)
  24. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  25. return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id)
  26. })
  27. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type = 1", org_id, record_date).Group("id").Find(&patients).Error
  28. return
  29. }
  30. func GetNewAllChargeHisHospitalPatientList(org_id int64, record_date int64) (patients []*HospitalPatient, err error) {
  31. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  32. db = db.Joins("join his_hospital_check_record as hp ON hp.patient_id = xt_patients.id AND hp.status = 1 AND hp.user_org_id = ? ", org_id)
  33. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  34. return db.Where("status = 1 AND user_org_id = ? AND in_hospital_status = 1", org_id).Preload("HisHospitalOrder", "user_org_id = ? AND status = 1", org_id)
  35. })
  36. //db = db.Preload("HisHospitalOrder", "user_org_id = ? AND status = 1 ", org_id)
  37. err = db.Group("id").Find(&patients).Error
  38. return
  39. }
  40. func GetNewHisHospitalPatientInfo(his_patient_id int64) (info models.HisHospitalCheckRecord, err error) {
  41. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  42. return
  43. }
  44. func GetUnChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  45. err = readDb.Model(&models.HisPrescription{}).
  46. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  47. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  48. }).
  49. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  50. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  51. }).
  52. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  53. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  54. }).
  55. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id).
  56. Find(&prescription).Error
  57. return
  58. }
  59. func GetChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  60. err = readDb.Model(&models.HisPrescription{}).
  61. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  62. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  63. }).
  64. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  65. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  66. }).
  67. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  68. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  69. }).
  70. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 ", org_id, record_date, patient_id).
  71. Find(&prescription).Error
  72. return
  73. }
  74. //
  75. type VMHospitalPatient struct {
  76. ID int64 `gorm:"column:id" json:"id" form:"id"`
  77. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  78. Name string `gorm:"column:name" json:"name" form:"name"`
  79. Status int64 `gorm:"column:status" json:"status" form:"status"`
  80. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  81. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  82. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  83. HisHospitalCheckRecord models.HisHospitalCheckRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  84. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  85. }
  86. func (VMHospitalPatient) TableName() string {
  87. return "xt_patients"
  88. }
  89. //
  90. //
  91. //func GetHisHospitalPatientPrescriptionList(org_id int64, record_date int64,page int64, limit int64) (patients []*HospitalPatient, err error) {
  92. // offset := (page - 1) * limit
  93. // db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  94. // db = db.Joins("join his_hospital_check_record as record ON record.patient_id = xt_patients.id AND record.status = 1 AND record.user_org_id = ?", org_id)
  95. // db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  96. // return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id)
  97. // })
  98. // err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type = 1", org_id, record_date).Group("id").Find(&patients).Error
  99. // return
  100. //}
  101. //
  102. //func GetHisHospitalPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  103. // offset := (page - 1) * limit
  104. // db := readDb.Model(&VMHospitalPatient{}).Where("user_org_id = ? AND status = 1", org_id)
  105. // if len(keywords) > 0 {
  106. // wkkk keywords = "%" + keywords + "%"
  107. // db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  108. // db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ? AND info.p_type == 1", org_id, record_date, keywords)
  109. // }
  110. // db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  111. // db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  112. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type == 1", org_id).
  113. // Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type == 1", org_id)
  114. // db = db.Count(&total)
  115. // err = db.Limit(limit).Offset(offset).Find(&patients).Error
  116. // return
  117. //}
  118. type VMHisHospitalPrescriptionInfo struct {
  119. ID int64 `gorm:"column:id" json:"id" form:"id"`
  120. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  121. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  122. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  123. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  124. Status int64 `gorm:"column:status" json:"status" form:"status"`
  125. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  126. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  127. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  128. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  129. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  130. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  131. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  132. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  133. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  134. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  135. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  136. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  137. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  138. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  139. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  140. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  141. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"prescription"`
  142. }
  143. func (VMHisHospitalPrescriptionInfo) TableName() string {
  144. return "his_prescription_info"
  145. }
  146. func GetHisHospitalPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  147. offset := (page - 1) * limit
  148. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND p_type = 1 ", org_id, record_date)
  149. if len(keywords) > 0 {
  150. keywords = "%" + keywords + "%"
  151. db = db.Joins("JOIN xt_patients as p On his_prescription_info.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  152. }
  153. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  154. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type = 1", org_id)
  155. db = db.Count(&total)
  156. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  157. return
  158. }