his_summary_service.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetHisSummaryDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (patients []*models.ChargePatient, err error) {
  8. err = XTReadDB().Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1 AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 and orders.patient_id = ?", start_time, end_time, org_id, patient_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
  9. return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id,psn_cash_pay,acct_pay,fund_pay_sumamt,is_medicine_insurance,medfee_sumamt,maf_pay,hifes_pay,hifp_pay,hifmi_pay").
  10. Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  11. return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type,fulamt_ownpay_amt,overlmt_amt,preselfpay_amt,pric_uplmt_amt").Where("status = 1").
  12. Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  13. return db.Preload("Drug", "status = 1").Where("status = 1 ")
  14. }).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
  15. return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type,unit,remark").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
  16. return db.Select("id,project_name,unit,medical_coverage,cost_classify").Where("status = 1 ")
  17. }).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
  18. return db.Select("id,good_name,good_unit,specification_name,packing_unit,medical_insurance_level").Where("status = 1 ")
  19. }).Where("status = 1 ")
  20. })
  21. }).Where("status = 1 AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
  22. }).Where("p.status = 1 AND p.user_org_id = ? and p.id = ?", org_id, patient_id).Group("id").Find(&patients).Error
  23. return
  24. }
  25. func GetModeTemplateName(mode_id int64, user_org_id int64) (template []*models.HisPrescriptionModeTemplate, err error) {
  26. err = XTReadDB().Where("mode = ? and user_org_id = ? and patient_id = ? and status = 1", mode_id, user_org_id, 0).Find(&template).Error
  27. return template, err
  28. }
  29. func GetModeTemplateNameDetail(mode_id int64, user_org_id int64) (models.HisPrescriptionModeTemplate, error) {
  30. template := models.HisPrescriptionModeTemplate{}
  31. err := XTReadDB().Where("mode = ? and user_org_id = ? and status = 1 and patient_id= 0", mode_id, user_org_id).Find(&template).Error
  32. return template, err
  33. }
  34. func GetModeTemplateInfo(id int64, user_org_id int64) (models.HisPrescriptionInfoTemplate, error) {
  35. template := models.HisPrescriptionInfoTemplate{}
  36. err := XTReadDB().Where("p_template_id = ? and user_org_id = ? and status = 1", id, user_org_id).Find(&template).Error
  37. return template, err
  38. }
  39. func GetPrescriptionAdviceTemplateDetail(template_id int64, orgid int64) (template []*models.HisPrescriptionAdviceTemplate, err error) {
  40. err = XTReadDB().Where("prescription_id in(?) and user_org_id = ? and status = 1", template_id, orgid).Find(&template).Error
  41. return template, err
  42. }
  43. func GetPrescriptionProjectTemplateDetail(template_id int64, orgid int64) (template []*models.HisPrescriptionProjectTemplate, err error) {
  44. err = XTReadDB().Where("prescription_id in(?) and user_org_id = ? and status = 1", template_id, orgid).Find(&template).Error
  45. return template, err
  46. }
  47. func GetHisPrescriptionModeTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoModeTemplate, err error) {
  48. err = readDb.Model(&models.HisPrescriptionInfoModeTemplate{}).
  49. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  50. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  51. }).
  52. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  53. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  54. }).
  55. Where("status = 1 AND p_template_id = ? ", template_id).
  56. Find(&prescription).Error
  57. return
  58. }
  59. func GetHisModePrescriptionTemplateByID(template_id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
  60. err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("id = ? AND status = 1 ", template_id).First(&prescription).Error
  61. return
  62. }
  63. func CreateHisModePrescriptionTemplate(template *models.HisPrescriptionModeTemplate) (err error) {
  64. err = writeDb.Create(&template).Error
  65. return
  66. }
  67. func SaveHisModePrescriptionTemplate(template *models.HisPrescriptionModeTemplate) (err error) {
  68. err = writeDb.Save(&template).Error
  69. return
  70. }
  71. func CreateHisModePrescriptionInfoTemplate(s *models.HisPrescriptionInfoModeTemplate) (err error) {
  72. err = writeDb.Save(&s).Error
  73. return
  74. }
  75. func CreateHisModePrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceModeTemplate) (err error) {
  76. err = writeDb.Save(&s).Error
  77. return
  78. }
  79. func GetHisModePrescriptionTemplateByModeId(mode_id int64, patient_id int64, user_org_id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
  80. err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ?", mode_id, patient_id, user_org_id).First(&prescription).Error
  81. return
  82. }
  83. func GetHisModePrescriptionTemplateByModeIdTwo(mode_id int64, patient_id int64, user_org_id int64, id int64) (prescription models.HisPrescriptionModeTemplate, err error) {
  84. err = readDb.Model(&models.HisPrescriptionModeTemplate{}).Where("mode = ? AND status = 1 AND patient_id = ? and user_org_id = ? and id <> ?", mode_id, patient_id, user_org_id, id).First(&prescription).Error
  85. return
  86. }
  87. func CreateHisModePrescriptionProjectTemplate(project *models.HisPrescriptionProjectModeTemplate) (err error) {
  88. err = writeDb.Save(&project).Error
  89. return
  90. }
  91. func DelelteHisModePrescriptionTemplate(id int64, user_org_id int64) (err error) {
  92. err = writeDb.Model(&models.HisPrescriptionModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0}).Error
  93. err = writeDb.Model(&models.HisPrescriptionInfoModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  94. return
  95. }
  96. func DelelteHisModePrescriptionProjectTemplate(id int64, user_org_id int64) (err error) {
  97. err = writeDb.Model(&models.HisPrescriptionProjectModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  98. return
  99. }
  100. func DelelteHisModePrescriptionAdviceTemplate(id int64, user_org_id int64) (err error) {
  101. err = writeDb.Model(&models.HisPrescriptionAdviceModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  102. return
  103. }
  104. func DelelteHisPrescriptionInfoModeTemplate(id int64, user_org_id int64) (err error) {
  105. err = writeDb.Model(&models.HisPrescriptionInfoModeTemplate{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  106. err = writeDb.Model(&models.HisPrescriptionAdviceModeTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  107. err = writeDb.Model(&models.HisPrescriptionProjectModeTemplate{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  108. return
  109. }
  110. func GetAdviceGatherDetaiList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (orderInfo []*models.VmHisOrderInfo, err error) {
  111. db := XTReadDB().Model(&orderInfo).Where("status = 1")
  112. if org_id > 0 {
  113. db = db.Where("user_org_id = ? and advice_id > 0", org_id)
  114. }
  115. if start_time > 0 {
  116. db = db.Where("ctime >=?", start_time)
  117. }
  118. if end_time > 0 {
  119. db = db.Where("ctime <=?", end_time)
  120. }
  121. err = db.Preload("VmHisDoctorAdviceInfo", "patient_id = ? and advice_date>=? and advice_date<=?", patient_id, start_time, end_time).Group("advice_id").Scan(&orderInfo).Error
  122. return orderInfo, err
  123. }
  124. func GetProjectGatherDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (orderInfo []*models.VmHisOrderInfo, err error) {
  125. db := XTReadDB().Model(&orderInfo).Where("status = 1")
  126. if org_id > 0 {
  127. db = db.Where("user_org_id = ? and project_id > 0", org_id)
  128. }
  129. if start_time > 0 {
  130. db = db.Where("ctime >=?", start_time)
  131. }
  132. if end_time > 0 {
  133. db = db.Where("ctime <=?", end_time)
  134. }
  135. err = db.Group("project_id").Preload("HisPrescriptionProject", "patient_id = ? and record_date>=? and record_date<=?", patient_id, start_time, end_time).Find(&orderInfo).Error
  136. return orderInfo, err
  137. }
  138. func GetGatherHisOrder(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (order []*models.GatherHisOrder, err error) {
  139. db := XTReadDB().Model(&order).Where("status = 1")
  140. if org_id > 0 {
  141. db = db.Where("user_org_id = ?", org_id)
  142. }
  143. if start_time > 0 {
  144. db = db.Where("settle_accounts_date >=?", start_time)
  145. }
  146. if end_time > 0 {
  147. db = db.Where("settle_accounts_date<=?", end_time)
  148. }
  149. if patient_id > 0 {
  150. db = db.Where("patient_id = ?", patient_id)
  151. }
  152. if len(keyword) > 0 {
  153. }
  154. err = db.Find(&order).Error
  155. return order, err
  156. }
  157. func GetGatherHisOrderTwo(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (models.GatherHisOrder, error) {
  158. hisOrder := models.GatherHisOrder{}
  159. db := XTReadDB().Model(&hisOrder).Where("status = 1")
  160. if org_id > 0 {
  161. db = db.Where("user_org_id = ?", org_id)
  162. }
  163. if start_time > 0 {
  164. db = db.Where("settle_accounts_date >=?", start_time)
  165. }
  166. if end_time > 0 {
  167. db = db.Where("settle_accounts_date<=?", end_time)
  168. }
  169. if patient_id > 0 {
  170. db = db.Where("patient_id = ?", patient_id)
  171. }
  172. if len(keyword) > 0 {
  173. }
  174. err = db.Last(&hisOrder).Error
  175. return hisOrder, err
  176. }
  177. func GetHisSummaryPatientInfo(org_id int64, patient_id int64, start_time int64, end_time int64) (info models.HisPatient, err error) {
  178. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_time, end_time, patient_id).Last(&info).Error
  179. return
  180. }
  181. func GetHisSummaryPatientInfoSix(org_id int64, patient_id int64, start_time int64, end_time int64) (info models.HisHospitalCheckRecord, err error) {
  182. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_time, end_time, patient_id).Last(&info).Error
  183. return
  184. }
  185. func GetDetailPatients(keywords string, org_id int64) (patients []*models.ChargePatientTwo, err error) {
  186. if len(keywords) == 0 {
  187. err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  188. }
  189. if len(keywords) > 0 {
  190. keyword := "%" + keywords + "%"
  191. err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1 and name like ?", org_id, keyword).Find(&patients).Error
  192. }
  193. return
  194. }
  195. func GetHisDepatment(user_org_id int64) (hisdepartment []*models.XtHisDepartment, err error) {
  196. err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&hisdepartment).Error
  197. return hisdepartment, err
  198. }
  199. func GetHisPatientInfoFive(org_id int64, patient_id int64, startime int64, endtime int64) (info models.HisPatient, err error) {
  200. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 and patient_id = ? AND record_date >= ? and record_date <=?", org_id, patient_id, startime, endtime).Last(&info).Error
  201. return
  202. }
  203. func GetHisPrescriptionTenty(org_id int64, patient_id int64, start_time int64, end_time int64, keyword string, item_type int64) (prescription []*models.HisPrescription, err error) {
  204. db := readDb.Model(&models.HisPrescription{}).Where("status = 1")
  205. if org_id > 0 {
  206. db = db.Where("user_org_id = ?", org_id)
  207. }
  208. if start_time > 0 {
  209. db = db.Where("record_date >=?", start_time)
  210. }
  211. if end_time > 0 {
  212. db = db.Where("record_date <=?", end_time)
  213. }
  214. if patient_id > 0 {
  215. db = db.Where("patient_id = ?", patient_id)
  216. }
  217. if len(keyword) > 0 {
  218. err = db.Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  219. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  220. }).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  221. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  222. }).Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).Find(&prescription).Error
  223. } else {
  224. err = db.Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  225. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  226. }).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  227. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  228. }).
  229. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).Find(&prescription).Error
  230. }
  231. return
  232. }
  233. func GetHisLastOrder(org_id int64, patient_id int64, start_time int64, end_time int64) (models.HisOrder, error) {
  234. order := models.HisOrder{}
  235. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and ctime>=? and ctime<=? and status = 1", org_id, patient_id, start_time, end_time).Last(&order).Error
  236. return order, err
  237. }
  238. func GetHisSchedule(patient_id int64, org_id int64, start_time int64, end_time int64) (schedule []*models.XtSchedule, err error) {
  239. err = XTReadDB().Where("patient_id = ? and user_org_id = ? and schedule_date >=? and schedule_date<=? and status = 1", patient_id, org_id, start_time, end_time).Find(&schedule).Error
  240. return schedule, err
  241. }
  242. func GetHisChargeOrder(org_id int64, patient_id int64, start_time int64, end_time int64, keyword string, item_type int64) (order []*models.HisChargeOrder, err error) {
  243. db := XTReadDB().Model(&order).Where("status = 1")
  244. if org_id > 0 {
  245. db = db.Where("user_org_id = ?", org_id)
  246. }
  247. if patient_id > 0 {
  248. db = db.Where("patient_id = ?", patient_id)
  249. }
  250. if start_time > 0 {
  251. db = db.Where("settle_accounts_date>=?", start_time)
  252. }
  253. if end_time > 0 {
  254. db = db.Where("settle_accounts_date<=?", end_time)
  255. }
  256. err = db.Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
  257. return db.Where("status = 1").Preload("HisChargePrescriptionProject", "status=1").Preload("HisChargeDoctorAdviceInfo", "status=1")
  258. }).Error
  259. return order, err
  260. }
  261. func GetAllHisOrderList(org_id int64, patient_id int64, start_time int64, end_time int64) (order []*models.VmHisOrder, err error) {
  262. db := XTReadDB().Model(&order).Where("status = 1")
  263. if org_id > 0 {
  264. db = db.Where("user_org_id = ?", org_id)
  265. }
  266. if patient_id > 0 {
  267. db = db.Where("patient_id = ?", patient_id)
  268. }
  269. if start_time > 0 {
  270. db = db.Where("settle_accounts_date >=?", start_time)
  271. }
  272. if end_time > 0 {
  273. db = db.Where("settle_accounts_date<=?", end_time)
  274. }
  275. err = db.Find(&order).Error
  276. return order, err
  277. }
  278. func GetHisOrderListByMedChrgitemType(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
  279. db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
  280. if patient_id > 0 {
  281. db = db.Where("patient_id = ?", patient_id)
  282. }
  283. if startime > 0 {
  284. db = db.Where("settle_accounts_date >= ?", startime)
  285. }
  286. if endtime > 0 {
  287. db = db.Where("settle_accounts_date<=?", endtime)
  288. }
  289. if orgid > 0 {
  290. db = db.Where("user_org_id = ?", orgid)
  291. }
  292. err = db.Group("med_chrgitm_type").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
  293. return info, err
  294. }
  295. func GetOrderInfoList(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
  296. db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
  297. if patient_id > 0 {
  298. db = db.Where("patient_id = ?", patient_id)
  299. }
  300. if startime > 0 {
  301. db = db.Where("upload_date >= ?", startime)
  302. }
  303. if endtime > 0 {
  304. db = db.Where("upload_date<=?", endtime)
  305. }
  306. if orgid > 0 {
  307. db = db.Where("user_org_id = ?", orgid)
  308. }
  309. err = db.Preload("HisOrderTenty", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  310. return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1")
  311. }).Preload("HisDoctorAdvice", "status = 1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
  312. return info, err
  313. }
  314. func GetHisOrderListTwenty(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderTenty, err error) {
  315. db := XTReadDB().Model(&models.HisOrderTenty{}).Where("status = 1")
  316. if patient_id > 0 {
  317. db = db.Where("patient_id = ?", patient_id)
  318. }
  319. if startime > 0 {
  320. db = db.Where("settle_accounts_date>=?", startime)
  321. }
  322. if endtime > 0 {
  323. db = db.Where("settle_accounts_date<=?", endtime)
  324. }
  325. if orgid > 0 {
  326. db = db.Where("user_org_id = ?", orgid)
  327. }
  328. err = db.Preload("HisOrderInfoTwenty", "status=1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status=1").Order("settle_accounts_date asc").Find(&info).Error
  329. return info, err
  330. }
  331. func GetHisAdviceOrderList() {
  332. }