his_hospital_service.go 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. type HospitalPatient struct {
  8. ID int64 `gorm:"column:id" json:"id" form:"id"`
  9. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  10. Name string `gorm:"column:name" json:"name" form:"name"`
  11. Status int64 `gorm:"column:status" json:"status" form:"status"`
  12. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  13. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  14. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  15. HisHospitalCheckRecord models.HisHospitalCheckRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  16. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  17. HisHospitalOrder models.HisHospitalOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  18. }
  19. func (HospitalPatient) TableName() string {
  20. return "xt_patients"
  21. }
  22. type HospitalPatientTWo 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. Name string `gorm:"column:name" json:"name" form:"name"`
  26. Status int64 `gorm:"column:status" json:"status" form:"status"`
  27. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  28. }
  29. func (HospitalPatientTWo) TableName() string {
  30. return "xt_patients"
  31. }
  32. type HisHospitalOrder struct {
  33. ID int64 `gorm:"column:id" json:"id" form:"id"`
  34. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  35. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  36. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  37. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  38. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  39. Status int64 `gorm:"column:status" json:"status" form:"status"`
  40. Number string `gorm:"column:number" json:"number" form:"number"`
  41. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  42. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  43. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  44. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  45. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  46. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  47. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  48. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  49. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  50. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  51. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  52. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  53. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  54. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  55. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  56. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  57. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  58. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  59. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  60. Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
  61. HisHospitalCheckRecord models.HisHospitalCheckRecord `gorm:"ForeignKey:Number;AssociationForeignKey:MdtrtId" json:"his_patient"`
  62. }
  63. func (HisHospitalOrder) TableName() string {
  64. return "his_order"
  65. }
  66. func GetAllHisHospitalPatientList(org_id int64, record_date int64, sch_type int64) (patients []*HospitalPatient, err error) {
  67. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  68. 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", org_id)
  69. //db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? AND sch.schedule_type = ? ", org_id, record_date, sch_type)
  70. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  71. return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id).Order("id desc")
  72. })
  73. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type = 1", org_id, record_date).Group("id").Find(&patients).Error
  74. return
  75. }
  76. func GetHisHospitalPatientList(org_id int64, record_date int64, sch_type int64) (patients []*HospitalPatient, err error) {
  77. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  78. 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.record_date = ? ", org_id, record_date)
  79. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? AND sch.schedule_type = ? ", org_id, record_date, sch_type)
  80. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  81. return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id).Order("id desc")
  82. })
  83. 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
  84. return
  85. }
  86. func GetHisHospitalSchPatientList(org_id int64, record_date int64, sch_type int64) (patients []*HospitalPatient, err error) {
  87. if sch_type > 0 {
  88. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  89. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? AND sch.schedule_type = ? ", org_id, record_date, sch_type)
  90. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  91. return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id).Order("id desc")
  92. })
  93. 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
  94. return
  95. } else {
  96. db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  97. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? ", org_id, record_date)
  98. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  99. return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id).Order("id desc")
  100. })
  101. 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
  102. return
  103. }
  104. }
  105. func GetNewAllUnChargeHisHospitalPatientList(org_id int64, record_date int64) (patients []*models.HisHospitalCheckRecord, err error) {
  106. db := readDb.Model(&models.HisHospitalCheckRecord{}).Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1", org_id)
  107. db = db.Preload("HisHospitalOrder", "user_org_id = ? AND status = 1", org_id)
  108. err = db.Group("number").Find(&patients).Error
  109. return
  110. }
  111. func GetNewAllChargeHisHospitalPatientList(org_id int64, record_date int64) (orders []*HisHospitalOrder, err error) {
  112. db := readDb.Model(&HisHospitalOrder{}).Where("his_order.user_org_id = ? AND his_order.status = 1 AND his_order.settle_accounts_date = ? AND his_order.p_type = 1 AND his_order.order_status = 2", org_id, record_date)
  113. db = db.Preload("Patient", "status = 1")
  114. db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  115. return db.Where("status = 1 AND user_org_id = ? AND in_hospital_status = 1", org_id)
  116. })
  117. err = db.Find(&orders).Error
  118. return
  119. }
  120. func GetNewHisHospitalPatientInfo(his_patient_id int64) (info models.HisHospitalCheckRecord, err error) {
  121. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  122. return
  123. }
  124. func GetUnChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  125. err = readDb.Model(&models.HisPrescription{}).
  126. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  127. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  128. }).
  129. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  130. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  131. }).
  132. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  133. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  134. }).
  135. 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).
  136. Find(&prescription).Error
  137. return
  138. }
  139. func GetChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  140. err = readDb.Model(&models.HisPrescription{}).
  141. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  142. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  143. }).
  144. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  145. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  146. }).
  147. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  148. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  149. }).
  150. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 ", org_id, record_date, patient_id).
  151. Find(&prescription).Error
  152. return
  153. }
  154. //
  155. type VMHospitalPatient struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. Name string `gorm:"column:name" json:"name" form:"name"`
  159. Status int64 `gorm:"column:status" json:"status" form:"status"`
  160. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  161. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  162. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  163. HisHospitalCheckRecord models.HisHospitalCheckRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  164. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  165. }
  166. func (VMHospitalPatient) TableName() string {
  167. return "xt_patients"
  168. }
  169. //
  170. //
  171. //func GetHisHospitalPatientPrescriptionList(org_id int64, record_date int64,page int64, limit int64) (patients []*HospitalPatient, err error) {
  172. // offset := (page - 1) * limit
  173. // db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  174. // 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)
  175. // db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
  176. // return db.Where("user_org_id = ? AND status = 1 AND in_hospital_status = 1 AND out_hospital_status = 0", org_id)
  177. // })
  178. // 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
  179. // return
  180. //}
  181. //
  182. //func GetHisHospitalPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  183. // offset := (page - 1) * limit
  184. // db := readDb.Model(&VMHospitalPatient{}).Where("user_org_id = ? AND status = 1", org_id)
  185. // if len(keywords) > 0 {
  186. // wkkk keywords = "%" + keywords + "%"
  187. // 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)
  188. // 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)
  189. // }
  190. // db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  191. // db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  192. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type == 1", org_id).
  193. // Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type == 1", org_id)
  194. // db = db.Count(&total)
  195. // err = db.Limit(limit).Offset(offset).Find(&patients).Error
  196. // return
  197. //}
  198. type VMHisHospitalPrescriptionInfo struct {
  199. ID int64 `gorm:"column:id" json:"id" form:"id"`
  200. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  201. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  202. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  203. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  204. Status int64 `gorm:"column:status" json:"status" form:"status"`
  205. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  206. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  207. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  208. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  209. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  210. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  211. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  212. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  213. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  214. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  215. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  216. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  217. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  218. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  219. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  220. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  221. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"prescription"`
  222. }
  223. func (VMHisHospitalPrescriptionInfo) TableName() string {
  224. return "his_prescription_info"
  225. }
  226. func GetHisHospitalPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  227. offset := (page - 1) * limit
  228. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type = 1 ", org_id, record_date)
  229. if len(keywords) > 0 {
  230. keywords = "%" + keywords + "%"
  231. 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)
  232. }
  233. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  234. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type = 1", org_id)
  235. db = db.Count(&total)
  236. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  237. return
  238. }
  239. func CreateHospitalRecord(record *models.HisHospitalCheckRecord) (err error) {
  240. err = writeDb.Save(&record).Error
  241. return
  242. }
  243. func GetInHospitalRecord(id int64) (record models.HisHospitalCheckRecord, err error) {
  244. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1", id).First(&record).Error
  245. return
  246. }
  247. func GetInHospitalRecordTX(id int64, tx *gorm.DB) (record models.HisHospitalCheckRecord, err error) {
  248. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1", id).First(&record).Error
  249. return
  250. }
  251. func GetInHospitalRecordByNumber(number string) (record models.HisHospitalCheckRecord, err error) {
  252. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("number = ? AND status = 1", number).First(&record).Error
  253. return
  254. }
  255. func GetLastHospitalRecord(id int64, user_org_id int64) (record models.HisHospitalCheckRecord, err error) {
  256. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1 AND user_org_id = ?", id, user_org_id).Last(&record).Error
  257. return
  258. }
  259. func GetLastHospitalRecordTwo(patient_id int64, user_org_id int64) (record models.HisHospitalCheckRecord, err error) {
  260. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ? AND in_hospital_status = 1 AND out_hospital_status = 0", patient_id, user_org_id).Last(&record).Error
  261. return
  262. }
  263. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  264. dealer := []*models.HisXtDiagnoseConfig{}
  265. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  266. return dealer, err
  267. }
  268. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  269. outPatient := &models.OutpatientServiceSick{}
  270. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  271. return outPatient, err
  272. }
  273. func GetHospitalMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  274. err = readDb.Model(&models.HisPrescription{}).
  275. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  276. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  277. }).
  278. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  279. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  280. }).
  281. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  282. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  283. }).
  284. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
  285. Find(&prescription).Error
  286. return
  287. }
  288. func GetSettleHisHospitalPrescription(org_id int64, patient_id int64, batch_number string) (prescription []*models.HisHospitalPrescription, err error) {
  289. err = readDb.Model(&models.HisHospitalPrescription{}).
  290. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  291. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  292. }).
  293. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  294. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  295. }).
  296. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  297. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  298. }).
  299. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 4 AND batch_number = ? ", org_id, patient_id, batch_number).
  300. Find(&prescription).Error
  301. return
  302. }
  303. func GetHisHospitalUnUploadPrescriptionDetailPatientList(org_id int64, record_date int64, sch_type int64) (patients []*models.HisHospitalCheckRecord, err error) {
  304. db := readDb.Model(&models.HisHospitalCheckRecord{})
  305. db = db.Joins("inner join his_prescription pre On pre.patient_id = his_hospital_check_record.patient_id and pre.record_date = ? AND pre.p_type = 1 AND pre.user_org_id = ? AND pre.status = 1 AND pre.order_status <> 4 AND pre.order_status <> 2", record_date, org_id)
  306. //db = db.Joins("inner join his_prescription pre On pre.patient_id = his_hospital_check_record.patient_id and pre.record_date = ? AND pre.p_type = 1 AND pre.user_org_id = ? AND pre.status = 1 AND pre.order_status <> 4 AND pre.order_status <> 2", record_date, org_id)
  307. db = db.Joins("join xt_schedule as sch ON sch.patient_id = his_hospital_check_record.patient_id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ?", org_id, record_date)
  308. if sch_type > 0 {
  309. db = db.Joins("join xt_schedule as schs ON schs.patient_id = his_hospital_check_record.patient_id AND schs.status = 1 AND schs.user_org_id = ? AND schs.schedule_date = ? AND schs.schedule_type = ? ", org_id, record_date, sch_type)
  310. }
  311. db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1 AND his_hospital_check_record.out_hospital_status = 0", org_id)
  312. err = db.Group("number").Find(&patients).Error
  313. return
  314. }
  315. func GetHisHospitalUploadPrescriptionDetailPatientList(org_id int64, record_date int64, sch_type int64) (patients []*models.HisHospitalCheckRecord, err error) {
  316. db := readDb.Model(&models.HisHospitalCheckRecord{})
  317. db = db.Joins("inner join his_prescription pre On pre.patient_id = his_hospital_check_record.patient_id and pre.record_date = ? AND pre.p_type = 1 AND pre.user_org_id = ? AND pre.order_status = 4 AND pre.status = 1 ", record_date, org_id)
  318. if sch_type > 0 {
  319. db = db.Joins("join xt_schedule as sch ON sch.patient_id = his_hospital_check_record.patient_id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? AND sch.schedule_type = ? ", org_id, record_date, sch_type)
  320. }
  321. db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1 AND his_hospital_check_record.out_hospital_status = 0", org_id)
  322. err = db.Group("number").Find(&patients).Error
  323. return
  324. }
  325. func GetUnUploadHisHospitalPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  326. err = readDb.Model(&models.HisPrescription{}).
  327. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  328. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  329. }).
  330. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  331. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  332. }).
  333. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  334. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  335. }).
  336. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status<> 4 AND p_type = 1", org_id, record_date, patient_id).
  337. Find(&prescription).Error
  338. return
  339. }
  340. func GetUploadHisHospitalPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  341. err = readDb.Model(&models.HisPrescription{}).
  342. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  343. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  344. }).
  345. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  346. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  347. }).
  348. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  349. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  350. }).
  351. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 0 AND order_status <> 1 AND p_type = 1", org_id, record_date, patient_id).
  352. Find(&prescription).Error
  353. return
  354. }
  355. func GetMonthUnUploadHisHospitalPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  356. err = readDb.Model(&models.HisPrescription{}).
  357. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  358. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  359. }).
  360. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  361. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  362. }).
  363. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  364. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  365. }).
  366. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? AND order_status <> 2 AND order_status <> 3 AND order_status<> 4 AND p_type = 1", org_id, patient_id, end_time, start_time).
  367. Find(&prescription).Error
  368. return
  369. }
  370. func GetMonthUploadHisHospitalPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  371. err = readDb.Model(&models.HisPrescription{}).
  372. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  373. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  374. }).
  375. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  376. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  377. }).
  378. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  379. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  380. }).
  381. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? AND order_status <> 0 AND order_status <> 1 AND p_type = 1", org_id, patient_id, end_time, start_time).
  382. Find(&prescription).Error
  383. return
  384. }
  385. func GetAllMonthHisHospitalPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  386. err = readDb.Model(&models.HisPrescription{}).
  387. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  388. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  389. }).
  390. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  391. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  392. }).
  393. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  394. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  395. }).
  396. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND record_date >= ? AND p_type = 1", org_id, patient_id, end_time, start_time).
  397. Find(&prescription).Error
  398. return
  399. }
  400. func GetSettleHisHospitalPrescriptionTwo(org_id int64, patient_id int64, number string) (prescription []*models.HisHospitalPrescription, err error) {
  401. err = readDb.Model(&models.HisHospitalPrescription{}).
  402. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  403. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  404. }).
  405. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  406. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  407. }).
  408. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  409. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  410. }).
  411. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? ", org_id, patient_id, number).
  412. Find(&prescription).Error
  413. return
  414. }
  415. func GetZHHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  416. err = readDb.Model(&models.HisPrescription{}).
  417. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  418. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  419. }).
  420. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  421. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  422. }).
  423. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  424. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
  425. }).
  426. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND p_type = 1", org_id, record_date, patient_id).
  427. Find(&prescription).Error
  428. return
  429. }
  430. func GetZHMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
  431. err = readDb.Model(&models.HisPrescription{}).
  432. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  433. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  434. }).
  435. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  436. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  437. }).
  438. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  439. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
  440. }).
  441. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
  442. Find(&prescription).Error
  443. return
  444. }
  445. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  446. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  447. return
  448. }
  449. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  450. db := readDb.Model(&models.HisOrderInfo{})
  451. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  452. return
  453. }
  454. func GetNewChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisHospitalPrescription, err error) {
  455. err = readDb.Model(&models.HisHospitalPrescription{}).
  456. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  457. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  458. }).
  459. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  460. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  461. }).
  462. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  463. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  464. }).
  465. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 ", org_id, record_date, patient_id).
  466. Find(&prescription).Error
  467. return
  468. }
  469. func GetNewUnChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisHospitalPrescription, err error) {
  470. err = readDb.Model(&models.HisHospitalPrescription{}).
  471. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  472. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  473. }).
  474. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  475. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  476. }).
  477. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  478. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  479. }).
  480. 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).
  481. Find(&prescription).Error
  482. return
  483. }
  484. func GetZHHisUploadOrderInfo(org_id int64, patient_id int64, record_date int64, record_end_date int64, number string) (infos []*models.HisOrderInfo, err error) {
  485. err = readDb.Model(&models.HisOrderInfo{}).
  486. Where("user_org_id = ? AND status = 1 AND upload_date <= ? AND upload_date >= ? AND patient_id = ? AND order_number = ? ", org_id, record_end_date, record_date, patient_id, number).
  487. Find(&infos).Error
  488. return
  489. }
  490. func UpDateOrderInfoStatus(patient_id int64, record_date int64, org_id int64, record_two_date int64) (err error) {
  491. err = writeDb.Model(&models.HisOrderInfo{}).Where("user_org_id = ? AND status = 1 AND upload_date <= ? AND upload_date >= ? AND patient_id = ?", org_id, record_two_date, record_date, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  492. return
  493. }
  494. func UpDatePrescriptionOrderStatusTwo(patient_id int64, record_date int64, org_id int64) (err error) {
  495. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 1", org_id, record_date, patient_id).Updates(map[string]interface{}{"order_status": 1}).Error
  496. return
  497. }
  498. func UpdataHospitalOrderStatusTwo(number string, user_org_id int64) (err error) {
  499. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  500. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  501. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  502. return
  503. }
  504. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  505. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  506. return
  507. }
  508. func GetHisPrescriptionProjectByIDTwo(id int64) (projects models.HisPrescriptionProject, err error) {
  509. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  510. return
  511. }