his_hospital_service.go 40KB

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