his_print_service.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func GetBatchDrugHisPrescription(ids []string, record_time int64, user_org_id int64) (patients []*models.PrintPatient, err error) {
  7. readDb.Model(&models.PrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
  8. Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
  9. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type = 1 AND p_type = 2", user_org_id, record_time).
  10. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  11. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("Drug", "status=1")
  12. })
  13. }).
  14. Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
  15. Where("id in (?) AND user_org_id = ?", ids, user_org_id).Find(&patients)
  16. return
  17. }
  18. type HisPrintPrescriptionProject struct {
  19. ID int64 `gorm:"column:id" json:"id" form:"id"`
  20. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  21. Price float64 `gorm:"column:price" json:"price" form:"price"`
  22. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  23. Status int64 `gorm:"column:status" json:"status" form:"status"`
  24. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  25. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  26. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  27. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  28. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  29. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  30. Count string `gorm:"column:count" json:"count" form:"count"`
  31. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  32. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  33. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  34. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  35. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  36. Day string `gorm:"column:day" json:"day" form:"day"`
  37. HisProject HisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  38. GoodInfo GoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  39. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  40. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  41. Type int64 `gorm:"column:type" json:"type" form:"type"`
  42. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  43. ExecutionTime int64 `gborm:"column:execution_time" json:"execution_time" form:"execution_time"`
  44. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  45. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  46. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  47. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  48. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  49. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  50. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  51. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  52. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  53. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  54. IsCheckTeam int64 `gorm:"-" json:"is_check_team" form:"is_check_team"`
  55. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  56. }
  57. type HisProject struct {
  58. ID int64 `gorm:"column:id" json:"id" form:"id"`
  59. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  60. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  61. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  62. Price float64 `gorm:"column:price" json:"price" form:"price"`
  63. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  64. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  65. ExecutiveSection int64 `gorm:"column:executive_section" json:"executive_section" form:"executive_section"`
  66. MedicalCoverage int64 `gorm:"column:medical_coverage" json:"medical_coverage" form:"medical_coverage"`
  67. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  68. DiseaseDirectory int64 `gorm:"column:disease_directory" json:"disease_directory" form:"disease_directory"`
  69. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  70. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  71. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  72. MedicalStatus int64 `gorm:"column:medical_status" json:"medical_status" form:"medical_status"`
  73. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  74. Sign int64 `gorm:"column:sign" json:"sign" form:"sign"`
  75. DefaultNumber string `gorm:"column:default_number" json:"default_number" form:"default_number"`
  76. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  77. IsCharge int64 `gorm:"column:is_charge" json:"is_charge" form:"is_charge"`
  78. IsEstimate int64 `gorm:"column:is_estimate" json:"is_estimate" form:"is_estimate"`
  79. IsWorkload int64 `gorm:"column:is_workload" json:"is_workload" form:"is_workload"`
  80. Sort string `gorm:"column:sort" json:"sort" form:"sort"`
  81. DoctorAdvice int64 `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
  82. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  83. Status int64 `gorm:"column:status" json:"status" form:"status"`
  84. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  85. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  86. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  87. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  88. Total string `gorm:"column:total" json:"total" form:"total"`
  89. Category int64 `gorm:"column:category" json:"category" form:"category"`
  90. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  91. SpecailProject int64 `gorm:"column:specail_project" json:"specail_project" form:"specail_project"`
  92. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  93. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  94. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  95. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  96. }
  97. func (HisProject) TableName() string {
  98. return "xt_his_project"
  99. }
  100. func (HisPrintPrescriptionProject) TableName() string {
  101. return "his_prescription_project"
  102. }
  103. func GetBatchProjectHisPrescription(ids []string, record_time int64, user_org_id int64) (patients []*models.PrintPatient, err error) {
  104. readDb.Model(&models.PrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
  105. Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
  106. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
  107. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  108. return db.Joins("").Joins("Join xt_his_project p On p.id = his_prescription_project.project_id ").Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
  109. })
  110. }).
  111. Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
  112. Where("id in (?) AND user_org_id = ? ", ids, user_org_id).Find(&patients)
  113. return
  114. }
  115. func GetBatchInspectionProjectHisPrescription(ids []string, record_time int64, user_org_id int64) (patients []*models.PrintPatient, err error) {
  116. readDb.Model(&models.PrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
  117. Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
  118. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
  119. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  120. return db.Joins("Join xt_his_project p On p.id = his_prescription_project.project_id AND p.cost_classify = 3").Where("his_prescription_project.status = 1 AND his_prescription_project.type = 2").Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1")
  121. })
  122. }).
  123. Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
  124. Where("id in (?) AND user_org_id = ? ", ids, user_org_id).Find(&patients)
  125. return
  126. }
  127. func GetBatchInspectionProjectHisPrescriptionTwo(ids []string, record_time int64, user_org_id int64) (patients []*models.CheckPrintPatient, err error) {
  128. readDb.Model(&models.CheckPrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
  129. Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
  130. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
  131. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  132. return db.Joins("Join xt_his_project p On p.id = his_prescription_project.project_id AND p.cost_classify = 3").Where("his_prescription_project.status = 1 ").Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1")
  133. })
  134. }).
  135. Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
  136. Where("id in (?) AND user_org_id = ? ", ids, user_org_id).Find(&patients)
  137. return
  138. }
  139. func GetUnChargeHisPrescriptionTen(org_id int64, patient_id int64, record_date int64, p_type 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. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  150. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  151. }).
  152. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?)", org_id, record_date, patient_id, p_type).
  153. Find(&prescription).Error
  154. return
  155. }
  156. func CreateLabelPrint(label *models.HisLabelPrintStatusInfo) (err error) {
  157. err = writeDb.Save(&label).Error
  158. return
  159. }
  160. func GetLabelPrint(ids string, org_id int64, record_date string, patient_id int64) (label models.HisLabelPrintStatusInfo, err error) {
  161. err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Where("ids = ? and user_org_id = ? and record_date = ? and patient_id = ?", ids, org_id, record_date, patient_id).First(&label).Error
  162. return
  163. }
  164. func GetLabelPrintByID(id int64) (label models.HisLabelPrintStatusInfo, err error) {
  165. err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("id = ?", id).First(&label).Error
  166. return
  167. }