his_service.go 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. type HisPatient struct {
  8. ID int64 `gorm:"column:id" json:"id" form:"id"`
  9. Name string `gorm:"column:name" json:"name" form:"name"`
  10. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  11. Total float64 `gorm:"column:total" json:"total" form:"total"`
  12. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  15. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  16. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  17. Number string `gorm:"column:number" json:"number" form:"number"`
  18. }
  19. func (HisPatient) TableName() string {
  20. return "his_patient"
  21. }
  22. type Schedule struct {
  23. ID int64 `gorm:"column:id" json:"id" form:"id"`
  24. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  25. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  26. Status int64 `gorm:"column:status" json:"status" form:"status"`
  27. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  28. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  29. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  30. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  31. }
  32. func (Schedule) TableName() string {
  33. return "xt_schedule"
  34. }
  35. type Patients struct {
  36. ID int64 `gorm:"column:id" json:"id" form:"id"`
  37. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  38. Name string `gorm:"column:name" json:"name" form:"name"`
  39. Status int64 `gorm:"column:status" json:"status" form:"status"`
  40. }
  41. func (Patients) TableName() string {
  42. return "xt_patients"
  43. }
  44. type HisPrescription struct {
  45. ID int64 `gorm:"column:id" json:"id" form:"id"`
  46. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  47. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  48. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  49. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  50. Status int64 `gorm:"column:status" json:"status" form:"status"`
  51. }
  52. func (HisPrescription) TableName() string {
  53. return "his_prescription"
  54. }
  55. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  56. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  57. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  58. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  59. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  60. return
  61. }
  62. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  63. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  64. return
  65. }
  66. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info HisPatient, err error) {
  67. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  68. return
  69. }
  70. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  71. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  72. return
  73. }
  74. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  75. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  76. return
  77. }
  78. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  79. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  80. err = db.Find(&caseHistorys).Error
  81. return
  82. }
  83. func GetHisPatientCaseHistoryTemplate(org_id int64) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  84. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  85. err = db.Find(&caseHistorys).Error
  86. return
  87. }
  88. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  89. err = writeDb.Create(&template).Error
  90. return
  91. }
  92. func SaveHisPatientCaseHistory(caseHistory models.HisPatientCaseHistory) (err error) {
  93. err = writeDb.Create(&caseHistory).Error
  94. return
  95. }
  96. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  97. err = writeDb.Save(&prescription).Error
  98. return
  99. }
  100. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  101. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  102. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  103. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  104. return
  105. }
  106. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  107. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  108. return
  109. }
  110. func DelelteProject(id int64, user_org_id int64) (err error) {
  111. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  112. return
  113. }
  114. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  115. err = readDb.Model(&models.HisPrescription{}).
  116. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  117. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  118. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  119. }).
  120. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  121. Find(&prescription).Error
  122. return
  123. }
  124. func GetAllDrugLibList(org_id int64) (list []*models.BaseDrugLib, err error) {
  125. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  126. return
  127. }
  128. func GetAllProjectList(org_id int64) (list []*models.HisProject, err error) {
  129. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
  130. return
  131. }
  132. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  133. err = writeDb.Create(&charge).Error
  134. return
  135. }
  136. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  137. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  138. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  139. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  140. return
  141. }
  142. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  143. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  144. return
  145. }
  146. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  147. err = writeDb.Save(s).Error
  148. return
  149. }
  150. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  151. err = writeDb.Save(project).Error
  152. return
  153. }
  154. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  155. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  156. return
  157. }
  158. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  159. err := writeDb.Create(&patient).Error
  160. return err
  161. }
  162. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  163. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  164. return
  165. }
  166. func CreateOrder(order *models.HisOrder) (err error) {
  167. err = writeDb.Create(&order).Error
  168. return
  169. }
  170. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  171. err = writeDb.Create(&order).Error
  172. return
  173. }
  174. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  175. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  176. return
  177. }
  178. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  179. err = writeDb.Save(&info).Error
  180. return
  181. }