his_service.go 123KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  8. )
  9. type VMSchedule struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  12. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  15. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  16. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  18. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  19. }
  20. func (VMSchedule) TableName() string {
  21. return "xt_schedule"
  22. }
  23. type HisPatient struct {
  24. ID int64 `gorm:"column:id" json:"id" form:"id"`
  25. Name string `gorm:"column:name" json:"name" form:"name"`
  26. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  27. Total float64 `gorm:"column:total" json:"total" form:"total"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  31. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  32. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  33. Number string `gorm:"column:number" json:"number" form:"number"`
  34. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  35. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  36. }
  37. func (HisPatient) TableName() string {
  38. return "his_patient"
  39. }
  40. type Schedule struct {
  41. ID int64 `gorm:"column:id" json:"id" form:"id"`
  42. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  43. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  44. Status int64 `gorm:"column:status" json:"status" form:"status"`
  45. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  46. }
  47. func (Schedule) TableName() string {
  48. return "xt_schedule"
  49. }
  50. type VMHisPrescriptionInfo struct {
  51. ID int64 `gorm:"column:id" json:"id" form:"id"`
  52. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  53. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  54. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  55. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  56. Status int64 `gorm:"column:status" json:"status" form:"status"`
  57. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  58. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  59. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  60. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  61. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  62. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  63. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  64. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  65. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  66. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  67. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  68. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  69. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  70. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  71. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  72. }
  73. func (VMHisPrescriptionInfo) TableName() string {
  74. return "his_prescription_info"
  75. }
  76. type VMHisOrder struct {
  77. ID int64 `gorm:"column:id" json:"id" form:"id"`
  78. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  79. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  80. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  81. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  82. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  83. Status int64 `gorm:"column:status" json:"status" form:"status"`
  84. Number string `gorm:"column:number" json:"number" form:"number"`
  85. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  86. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  87. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  88. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  89. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  90. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  91. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  92. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  93. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  94. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  95. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  96. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  97. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  98. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  99. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  100. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  101. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  102. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  103. }
  104. func (VMHisOrder) TableName() string {
  105. return "his_order"
  106. }
  107. type Patients struct {
  108. ID int64 `gorm:"column:id" json:"id" form:"id"`
  109. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  110. Name string `gorm:"column:name" json:"name" form:"name"`
  111. Status int64 `gorm:"column:status" json:"status" form:"status"`
  112. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  113. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  114. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  115. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  116. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  117. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  118. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  119. }
  120. func (Patients) TableName() string {
  121. return "xt_patients"
  122. }
  123. type HisPrescription struct {
  124. ID int64 `gorm:"column:id" json:"id" form:"id"`
  125. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  126. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  127. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  128. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  129. Status int64 `gorm:"column:status" json:"status" form:"status"`
  130. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  131. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  132. }
  133. func (HisPrescription) TableName() string {
  134. return "his_prescription"
  135. }
  136. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  137. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  138. if sch_type != 0 {
  139. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  140. } else {
  141. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  142. }
  143. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  144. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  145. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  146. return
  147. }
  148. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  149. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  150. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  151. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  152. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  153. return
  154. }
  155. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  156. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  157. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  158. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  159. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  160. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  161. return
  162. }
  163. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  164. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  165. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  166. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  167. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  168. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  169. return
  170. }
  171. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  172. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  173. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  174. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  175. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  176. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  177. return
  178. }
  179. type PatientTwo struct {
  180. ID int64 `gorm:"column:id" json:"id" form:"id"`
  181. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  182. Name string `gorm:"column:name" json:"name" form:"name"`
  183. Status int64 `gorm:"column:status" json:"status" form:"status"`
  184. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  185. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  186. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  187. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  188. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  189. }
  190. func (PatientTwo) TableName() string {
  191. return "xt_patients"
  192. }
  193. type HisPatientTwo struct {
  194. ID int64 `gorm:"column:id" json:"id" form:"id"`
  195. Name string `gorm:"column:name" json:"name" form:"name"`
  196. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  197. Total float64 `gorm:"column:total" json:"total" form:"total"`
  198. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  199. Status int64 `gorm:"column:status" json:"status" form:"status"`
  200. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  201. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  202. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  203. Number string `gorm:"column:number" json:"number" form:"number"`
  204. }
  205. func (HisPatientTwo) TableName() string {
  206. return "his_patient"
  207. }
  208. type HisPrescriptionTwo struct {
  209. ID int64 `gorm:"column:id" json:"id" form:"id"`
  210. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  211. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  212. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  213. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  214. Status int64 `gorm:"column:status" json:"status" form:"status"`
  215. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  216. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  217. Number string `gorm:"column:number" json:"number" form:"number"`
  218. Type int64 `gorm:"column:type" json:"type" form:"type"`
  219. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  220. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  221. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  222. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  223. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  224. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  225. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  226. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  227. }
  228. func (HisPrescriptionTwo) TableName() string {
  229. return "his_prescription"
  230. }
  231. func GetNewHisPatientList(org_id int64, record_date int64) (patients []*PatientTwo, err error) {
  232. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  233. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  234. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  235. return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  236. })
  237. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  238. return
  239. }
  240. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  241. db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  242. if sch_type != 0 {
  243. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  244. } else {
  245. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  246. }
  247. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  248. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  249. return
  250. }
  251. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  252. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  253. return
  254. }
  255. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  256. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  257. return
  258. }
  259. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  260. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  261. return
  262. }
  263. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  264. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  265. return
  266. }
  267. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  268. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  269. return
  270. }
  271. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  272. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Count(&total).Error
  273. return
  274. }
  275. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  276. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  277. return
  278. }
  279. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  280. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  281. return
  282. }
  283. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  284. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  285. err = db.Find(&caseHistorys).Error
  286. return
  287. }
  288. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  289. likekey := "%" + keyword + "%"
  290. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  291. if startime > 0 {
  292. db = db.Where("record_date>=?", startime)
  293. }
  294. if endtime > 0 {
  295. db = db.Where("record_date<=?", endtime)
  296. }
  297. if len(keyword) > 0 {
  298. db = db.Where("template_name like ? ", likekey)
  299. }
  300. err = db.Find(&caseHistorys).Error
  301. return
  302. }
  303. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  304. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  305. return caseHistory, err
  306. }
  307. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  308. err = writeDb.Create(&template).Error
  309. return
  310. }
  311. func GetHisPatientCaseHistoryById(id int64) (*models.HisPatientCaseHistory, error) {
  312. history := models.HisPatientCaseHistory{}
  313. err := XTReadDB().Model(&history).Where("id = ? and status = 1", id).Find(&history).Error
  314. if err != nil {
  315. if err == gorm.ErrRecordNotFound {
  316. return nil, err
  317. } else {
  318. return nil, err
  319. }
  320. }
  321. return &history, nil
  322. }
  323. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  324. err := writeDb.Create(&caseHistory).Error
  325. return err
  326. }
  327. func UpdatePatientCaseHistory(id int64, his *models.HisPatientCaseHistory) error {
  328. err := XTWriteDB().Model(&his).Where("id = ? and status =1", id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.BloodSugar, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat}).Error
  329. return err
  330. }
  331. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  332. tx := writeDb.Begin()
  333. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  334. tx.Rollback()
  335. return
  336. }
  337. tx.Commit()
  338. return
  339. }
  340. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  341. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  342. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  343. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  344. return
  345. }
  346. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  347. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  348. return
  349. }
  350. func DelelteProject(id int64, user_org_id int64) (err error) {
  351. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  352. return
  353. }
  354. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  355. err = readDb.Model(&models.HisPrescription{}).
  356. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  357. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  358. }).
  359. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  360. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  361. }).
  362. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  363. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  364. }).
  365. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  366. Find(&prescription).Error
  367. return
  368. }
  369. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  370. err = readDb.Model(&models.HisPrescription{}).
  371. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  372. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  373. }).
  374. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  375. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  376. }).
  377. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  378. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  379. }).
  380. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, his_patient_id, p_type).
  381. Find(&prescription).Error
  382. return
  383. }
  384. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  385. err = readDb.Model(&models.HisPrescription{}).
  386. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  387. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  388. }).
  389. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  390. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  391. }).
  392. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  393. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  394. }).
  395. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ? AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  396. Find(&prescription).Error
  397. return
  398. }
  399. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  400. err = readDb.Model(&models.HisPrescription{}).
  401. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  402. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  403. }).
  404. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  405. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  406. }).
  407. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  408. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  409. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  410. return db.Where("status = 1 AND user_org_id = ?", org_id)
  411. }).
  412. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  413. Find(&prescription).Error
  414. return
  415. }
  416. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  417. err = readDb.Model(&models.HisPrescription{}).
  418. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  420. }).
  421. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  422. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  423. }).
  424. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  425. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  426. }).
  427. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  428. Find(&prescription).Error
  429. return
  430. }
  431. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  432. err = readDb.Model(&models.HisPrescription{}).
  433. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  434. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  435. }).
  436. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  437. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  438. }).
  439. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  440. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  441. }).
  442. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  443. Find(&prescription).Error
  444. return
  445. }
  446. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  447. err = readDb.Model(&models.HisPrescription{}).
  448. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  449. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  450. }).
  451. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  452. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  453. }).
  454. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  455. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  456. }).
  457. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  458. Find(&prescription).Error
  459. return
  460. }
  461. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  462. err = readDb.Model(&models.HisPrescription{}).
  463. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  464. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  465. }).
  466. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  467. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  468. }).
  469. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  470. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  471. }).
  472. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? ", org_id, start_date, end_date, patient_id, p_type).
  473. Find(&prescription).Error
  474. return
  475. }
  476. //未收费
  477. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  478. err = readDb.Model(&models.HisPrescription{}).
  479. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  480. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  481. }).
  482. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  483. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  484. }).
  485. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  486. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  487. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  488. return db.Where("status = 1 AND user_org_id = ?", org_id)
  489. }).
  490. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  491. Find(&prescription).Error
  492. return
  493. }
  494. //已收费
  495. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  496. err = readDb.Model(&models.HisPrescription{}).
  497. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  498. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  499. }).
  500. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  501. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  502. }).
  503. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  504. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  505. }).
  506. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  507. Find(&prescription).Error
  508. return
  509. }
  510. type OtherDrugWarehouseInfo struct {
  511. ID int64 `gorm:"column:id" json:"id" form:"id"`
  512. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  513. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  514. Status int64 `gorm:"column:status" json:"status" form:"status"`
  515. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  516. }
  517. func (OtherDrugWarehouseInfo) TableName() string {
  518. return "xt_drug_warehouse_info"
  519. }
  520. type VMDrugSalesReturnInfo struct {
  521. ID int64 `gorm:"column:id" json:"id" form:"id"`
  522. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  523. Count int64 `gorm:"column:count" json:"count" form:"count"`
  524. Status int64 `gorm:"column:status" json:"status" form:"status"`
  525. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  526. }
  527. func (VMDrugSalesReturnInfo) TableName() string {
  528. return "xt_drug_sales_return_info"
  529. }
  530. type VMDrugWarehouseOutInfo struct {
  531. ID int64 `gorm:"column:id" json:"id" form:"id"`
  532. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  533. Count int64 `gorm:"column:count" json:"count" form:"count"`
  534. Status int64 `gorm:"column:status" json:"status" form:"status"`
  535. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  536. }
  537. func (VMDrugWarehouseOutInfo) TableName() string {
  538. return "xt_drug_warehouse_out_info"
  539. }
  540. type VMDrugCancelStockInfo struct {
  541. ID int64 `gorm:"column:id" json:"id" form:"id"`
  542. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  543. Count int64 `gorm:"column:count" json:"count" form:"count"`
  544. Status int64 `gorm:"column:status" json:"status" form:"status"`
  545. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  546. }
  547. func (VMDrugCancelStockInfo) TableName() string {
  548. return "xt_drug_cancel_stock_info"
  549. }
  550. type BaseDrugLib struct {
  551. ID int64 `gorm:"column:id" json:"id" form:"id"`
  552. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  553. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  554. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  555. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  556. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  557. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  558. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  559. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  560. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  561. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  562. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  563. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  564. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  565. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  566. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  567. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  568. Dose float64 `gorm:"column:dose" json:"dose" form:"dose"`
  569. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  570. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  571. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  572. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  573. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  574. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  575. Number string `gorm:"column:number" json:"number" form:"number"`
  576. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  577. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  578. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  579. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  580. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  581. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  582. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  583. Code string `gorm:"column:code" json:"code" form:"code"`
  584. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  585. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  586. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  587. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  588. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  589. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  590. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  591. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  592. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  593. Label int64 `gorm:"column:label" json:"label" form:"label"`
  594. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  595. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  596. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  597. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  598. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  599. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  600. Status int64 `gorm:"column:status" json:"status" form:"status"`
  601. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  602. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  603. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  604. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  605. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  606. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  607. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  608. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  609. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  610. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  611. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  612. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  613. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  614. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  615. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  616. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  617. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  618. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  619. Total float64 `gorm:"column:total" json:"total" form:"total"`
  620. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  621. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  622. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  623. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  624. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  625. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  626. }
  627. func (BaseDrugLib) TableName() string {
  628. return "xt_base_drug"
  629. }
  630. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  631. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  632. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  633. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  634. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  635. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  636. return
  637. }
  638. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  639. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  640. err = db.Find(&drugs).Error
  641. return
  642. }
  643. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  644. if len(keyword) != 0 {
  645. key := "%" + keyword + "%"
  646. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ?", org_id, key).Find(&list).Error
  647. } else {
  648. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
  649. }
  650. return
  651. }
  652. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  653. err = writeDb.Create(&charge).Error
  654. return
  655. }
  656. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  657. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  658. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  659. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  660. return
  661. }
  662. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  663. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  664. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  665. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  666. return
  667. }
  668. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  669. tx := writeDb.Begin()
  670. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  671. tx.Rollback()
  672. return
  673. }
  674. tx.Commit()
  675. return
  676. }
  677. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  678. tx := writeDb.Begin()
  679. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  680. tx.Rollback()
  681. return
  682. }
  683. tx.Commit()
  684. return
  685. }
  686. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  687. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  688. return
  689. }
  690. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  691. err := writeDb.Create(&patient).Error
  692. return err
  693. }
  694. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  695. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  696. return
  697. }
  698. func CreateOrder(order *models.HisOrder) (err error) {
  699. err = writeDb.Create(&order).Error
  700. return
  701. }
  702. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  703. err = writeDb.Create(&order).Error
  704. return
  705. }
  706. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  707. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  708. return
  709. }
  710. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  711. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  712. return
  713. }
  714. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  715. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  716. return
  717. }
  718. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  719. tx := writeDb.Begin()
  720. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  721. tx.Rollback()
  722. return
  723. }
  724. tx.Commit()
  725. return
  726. }
  727. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string, p_type int64) (order []*models.HisOrder, err error, total int64) {
  728. offset := (page - 1) * limit
  729. db := readDb.Model(&models.HisOrder{})
  730. if doctor_id > 0 {
  731. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  732. }
  733. if len(keywords) > 0 {
  734. keywords = "%" + keywords + "%"
  735. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  736. }
  737. if start_time != 0 {
  738. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  739. }
  740. if end_time != 0 {
  741. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  742. }
  743. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ?", user_org_id, p_type)
  744. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  745. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  746. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  747. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  748. db = db.Preload("HisFundSettleListResult", "status = 1")
  749. db = db.Count(&total)
  750. err = db.Limit(limit).Offset(offset).Order("settle_accounts_date desc,ctime").Find(&order).Error
  751. return
  752. }
  753. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  754. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  755. return
  756. }
  757. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  758. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  759. return
  760. }
  761. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  762. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  763. return
  764. }
  765. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  766. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  767. return
  768. }
  769. type HisOrder struct {
  770. ID int64 `gorm:"column:id" json:"id" form:"id"`
  771. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  772. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  773. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  774. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  775. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  776. Status int64 `gorm:"column:status" json:"status" form:"status"`
  777. Number string `gorm:"column:number" json:"number" form:"number"`
  778. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  779. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  780. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  781. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  782. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  783. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  784. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  785. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  786. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  787. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  788. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  789. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  790. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  791. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  792. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  793. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  794. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  795. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  796. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  797. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  798. }
  799. func (HisOrder) TableName() string {
  800. return "his_order"
  801. }
  802. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  803. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  804. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  805. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  806. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  807. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  808. Order("ctime desc").
  809. Find(&order).Error
  810. return
  811. }
  812. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  813. err = readDb.Model(&models.HisPrescription{}).
  814. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  815. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  816. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  817. }).
  818. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  819. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  820. Find(&prescription).Error
  821. return
  822. }
  823. type HisPrescriptionInfo struct {
  824. ID int64 `gorm:"column:id" json:"id" form:"id"`
  825. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  826. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  827. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  828. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  829. Status int64 `gorm:"column:status" json:"status" form:"status"`
  830. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  831. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  832. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  833. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  834. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  835. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  836. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  837. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  838. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  839. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  840. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  841. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  842. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  843. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  844. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  845. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  846. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  847. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  848. }
  849. func (HisPrescriptionInfo) TableName() string {
  850. return "his_prescription_info"
  851. }
  852. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  853. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  854. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  855. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  856. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  857. Order("ctime desc").Find(&prescriptionOrder).Error
  858. return
  859. }
  860. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  861. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  862. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  863. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  864. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  865. return
  866. }
  867. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  868. err = readDb.Model(&models.HisPrescription{}).
  869. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  870. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  871. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  872. }).
  873. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  874. Find(&prescription).Error
  875. return
  876. }
  877. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  878. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  879. return
  880. }
  881. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  882. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
  883. 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
  884. 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
  885. return
  886. }
  887. func SaveHisPatient(his models.HisPatient) (err error) {
  888. err = writeDb.Save(&his).Error
  889. return
  890. }
  891. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  892. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  893. }
  894. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  895. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  896. return
  897. }
  898. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  899. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  900. First(&order).Error
  901. return
  902. }
  903. func UpDateOrder(order models.HisOrder) (err error) {
  904. err = writeDb.Save(&order).Error
  905. return
  906. }
  907. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  908. 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": 2, "mtime": time.Now().Unix()}).Error
  909. 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": 3, "mtime": time.Now().Unix()}).Error
  910. return
  911. }
  912. func CreateErrMsgLog(log *models.HisOrderError) {
  913. writeDb.Model(&models.HisOrderError{}).Create(&log)
  914. }
  915. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  916. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  917. return
  918. }
  919. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  920. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  921. return
  922. }
  923. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  924. db := readDb.Model(&models.OutpatientServiceSick{})
  925. db = db.Where("user_org_id = ? AND status = 1", orgId)
  926. err = db.Order("ctime desc").Find(&list).Error
  927. return
  928. }
  929. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  930. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  931. db = db.Where("user_org_id = ? AND status = 1", orgId)
  932. err = db.Order("ctime desc").Find(&list).Error
  933. return
  934. }
  935. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  936. db := readDb.Model(&models.XtHisAddtionConfig{})
  937. db = db.Where("user_org_id = ? AND status = 1", orgId)
  938. err = db.Order("ctime desc").Find(&list).Error
  939. return
  940. }
  941. type XtHisOrder struct {
  942. ID int64 `gorm:"column:id" json:"id" form:"id"`
  943. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  944. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  945. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  946. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  947. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  948. Status int64 `gorm:"column:status" json:"status" form:"status"`
  949. Number string `gorm:"column:number" json:"number" form:"number"`
  950. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  951. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  952. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  953. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  954. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  955. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  956. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  957. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  958. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  959. }
  960. func (XtHisOrder) TableName() string {
  961. return "his_order"
  962. }
  963. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  964. err = readDb.Model(&models.HisPrescription{}).
  965. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  966. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  967. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  968. }).
  969. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  970. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  971. Find(&prescription).Error
  972. return
  973. }
  974. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  975. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  976. return
  977. }
  978. func DelelteAddition(id int64, user_org_id int64) (err error) {
  979. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  980. return
  981. }
  982. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  983. offset := (page - 1) * limit
  984. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 ", org_id, record_date)
  985. if len(keywords) > 0 {
  986. keywords = "%" + keywords + "%"
  987. 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)
  988. }
  989. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  990. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  991. db = db.Count(&total)
  992. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  993. return
  994. }
  995. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  996. offset := (page - 1) * limit
  997. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  998. if len(keywords) > 0 {
  999. keywords = "%" + keywords + "%"
  1000. 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)
  1001. 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)
  1002. }
  1003. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1004. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1005. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1006. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1007. db = db.Count(&total)
  1008. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1009. return
  1010. }
  1011. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1012. patient := models.VMHisPatient{}
  1013. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  1014. return patient, err
  1015. }
  1016. type VMOtherHisPrescriptionInfo struct {
  1017. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1018. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1019. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1020. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1021. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1022. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1023. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1024. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1025. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1026. }
  1027. func (VMOtherHisPrescriptionInfo) TableName() string {
  1028. return "his_prescription_info"
  1029. }
  1030. type VMHisPrescription struct {
  1031. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1032. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1033. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1034. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1035. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1036. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1037. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1038. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1039. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1040. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1041. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1042. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1043. }
  1044. func (VMHisPrescription) TableName() string {
  1045. return "his_prescription"
  1046. }
  1047. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1048. if change_type == 1 { //根据日期取出上一方数据
  1049. var Id AdviceDate
  1050. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1051. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1052. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1053. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1054. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1055. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1056. }).
  1057. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1058. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1059. })
  1060. }).Find(&advice).Error
  1061. } else if change_type == 2 {
  1062. var Id AdviceDate
  1063. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  1064. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1065. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1066. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1067. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1068. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1069. }).
  1070. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1071. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1072. })
  1073. }).Find(&advice).Error
  1074. }
  1075. return
  1076. }
  1077. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1078. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, start_time, end_time, p_type).
  1079. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1080. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1081. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1082. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1083. }).
  1084. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1085. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1086. })
  1087. }).Find(&advice).Error
  1088. return
  1089. }
  1090. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1091. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  1092. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1093. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1094. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1095. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1096. }).
  1097. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1098. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1099. })
  1100. }).Find(&advice).Error
  1101. return
  1102. }
  1103. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1104. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1105. return
  1106. }
  1107. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1108. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1109. return
  1110. }
  1111. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1112. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? AND insutype = ? AND clr_type = ? ", org_id, end_time, start_time, insutype, clr_type).Find(&orders).Error
  1113. return
  1114. }
  1115. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1116. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? ", org_id, end_time, start_time).Find(&orders).Error
  1117. return
  1118. }
  1119. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1120. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1121. return
  1122. }
  1123. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1124. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1125. return
  1126. }
  1127. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1128. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1129. return
  1130. }
  1131. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1132. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1133. return
  1134. }
  1135. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1136. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1137. return
  1138. }
  1139. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1140. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1141. return
  1142. }
  1143. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1144. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1145. return
  1146. }
  1147. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1148. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  1149. return
  1150. }
  1151. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1152. var patient Patients
  1153. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1154. return patient, err
  1155. }
  1156. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1157. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1158. return
  1159. }
  1160. type VMHisProjectTeam struct {
  1161. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1162. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1163. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1164. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1165. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1166. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1167. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1168. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1169. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1170. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1171. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1172. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1173. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1174. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1175. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1176. }
  1177. func (VMHisProjectTeam) TableName() string {
  1178. return "xt_his_project_team"
  1179. }
  1180. type VMHisProject struct {
  1181. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1182. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1183. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1184. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1185. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1186. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1187. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1188. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1189. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1190. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1191. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1192. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1193. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1194. }
  1195. func (VMHisProject) TableName() string {
  1196. return "xt_his_project"
  1197. }
  1198. type VMItemProjectList struct {
  1199. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1200. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1201. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1202. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1203. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1204. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1205. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1206. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1207. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1208. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1209. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1210. }
  1211. func (VMItemProjectList) TableName() string {
  1212. return "xt_his_project_list"
  1213. }
  1214. type VMHisPrescriptionTwo struct {
  1215. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1216. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1217. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1218. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1219. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1220. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1221. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1222. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1223. }
  1224. func (VMHisPrescriptionTwo) TableName() string {
  1225. return "his_prescription"
  1226. }
  1227. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1228. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1229. for _, item := range project {
  1230. var project_item []*VMItemProjectList
  1231. ids := strings.Split(item.ItemId, ",")
  1232. XTReadDB().Model(&VMItemProjectList{}).Where("status = 1 AND id IN (?)", ids).Preload("VMHisProject", "status = 1 AND user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 AND org_id = ?", orgid).Find(&project_item)
  1233. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1234. }
  1235. return
  1236. }
  1237. type HisDoctorAdviceInfo struct {
  1238. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1239. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1240. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1241. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1242. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1243. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1244. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1245. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1246. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1247. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1248. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1249. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1250. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1251. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1252. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1253. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1254. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1255. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1256. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1257. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1258. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1259. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1260. }
  1261. func (HisDoctorAdviceInfo) TableName() string {
  1262. return "his_doctor_advice_info"
  1263. }
  1264. type HisPrescriptionProject struct {
  1265. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1266. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1267. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1268. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1269. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1270. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1271. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1272. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1273. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1274. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1275. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1276. Count int64 `gorm:"column:count" json:"count" form:"count"`
  1277. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1278. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1279. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1280. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1281. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1282. Day string `gorm:"column:day" json:"day" form:"day"`
  1283. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1284. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1285. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1286. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1287. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1288. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1289. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1290. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1291. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1292. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1293. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1294. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1295. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1296. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1297. }
  1298. func (HisPrescriptionProject) TableName() string {
  1299. return "his_prescription_project"
  1300. }
  1301. type HisOrderInfo struct {
  1302. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1303. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1304. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1305. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1306. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1307. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1308. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1309. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1310. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1311. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1312. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1313. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1314. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1315. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1316. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1317. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1318. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1319. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1320. }
  1321. func (HisOrderInfo) TableName() string {
  1322. return "his_order_info"
  1323. }
  1324. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1325. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1326. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1327. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1328. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  1329. }).Find(&order).Error
  1330. return
  1331. }
  1332. type MedicalInsuranceCostCompare struct {
  1333. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1334. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1335. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1336. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1337. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1338. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1339. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1340. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1341. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1342. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1343. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1344. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1345. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1346. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1347. }
  1348. func (MedicalInsuranceCostCompare) TableName() string {
  1349. return "medical_insurance_cost_compare"
  1350. }
  1351. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1352. offset := (page - 1) * limit
  1353. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1354. if len(keywords) == 0 {
  1355. db = db.Where("status=1")
  1356. if len(insutype) != 0 {
  1357. db = db.Where("insutype = ?", insutype)
  1358. }
  1359. if start_time != 0 {
  1360. db = db.Where("ctime >= ? ", start_time)
  1361. }
  1362. if end_time != 0 {
  1363. db = db.Where("ctime <= ? ", end_time)
  1364. }
  1365. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1366. } else {
  1367. keywords = "%" + keywords + "%"
  1368. db = db.Joins("join sgj_users.sgj_user_admin_role role on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
  1369. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1370. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1371. }
  1372. return
  1373. }
  1374. type TempPatients struct {
  1375. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1376. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1377. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1378. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1379. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1380. Name string `gorm:"column:name" json:"name" form:"name"`
  1381. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1382. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1383. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1384. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1385. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1386. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1387. }
  1388. func (TempPatients) TableName() string {
  1389. return "xt_patients"
  1390. }
  1391. type GdybPsnNcdsRecord struct {
  1392. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1393. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1394. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1395. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1396. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1397. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1398. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1399. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1400. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1401. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1402. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1403. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1404. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1405. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1406. }
  1407. func (GdybPsnNcdsRecord) TableName() string {
  1408. return "gdyb_psn_ncds_record"
  1409. }
  1410. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1411. offset := (page - 1) * limit
  1412. db := readDb.Model(&TempPatients{})
  1413. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1414. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1415. })
  1416. fmt.Println(is_cancel)
  1417. if len(keywords) == 0 {
  1418. if is_cancel == 1 {
  1419. db = db.Joins("JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND gdyb_psn_ncds_record.is_cancel = ?", is_cancel)
  1420. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1421. } else if is_cancel == 0 {
  1422. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1423. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1424. } else if is_cancel == 2 {
  1425. db = db.Joins("LEFT JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND (gdyb_psn_ncds_record.is_cancel <> 1 OR gdyb_psn_ncds_record.is_cancel is null)")
  1426. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1427. }
  1428. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1429. } else {
  1430. keywords = "%" + keywords + "%"
  1431. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1 AND xt_patients.name LIKE ?", orgID, keywords)
  1432. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1433. }
  1434. return
  1435. }
  1436. type CustomAccountFormData struct {
  1437. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1438. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1439. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1440. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1441. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1442. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1443. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1444. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1445. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1446. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1447. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1448. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1449. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1450. DiagnosisId int64 `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1451. DialysisCount int64 `gorm:"-"`
  1452. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1453. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1454. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1455. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1456. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1457. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1458. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1459. }
  1460. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
  1461. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1462. for _, item := range cus {
  1463. var total int64
  1464. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
  1465. fmt.Println(total)
  1466. item.DialysisCount = total
  1467. fmt.Println(item.DialysisCount)
  1468. }
  1469. return
  1470. }
  1471. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1472. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1473. return
  1474. }
  1475. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order HisOrder, err error) {
  1476. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1477. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1478. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1479. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1480. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1481. Order("ctime desc").
  1482. Last(&order).Error
  1483. return
  1484. }
  1485. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1486. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1487. Order("ctime desc").
  1488. Find(&order).Error
  1489. return
  1490. }
  1491. type NewCustomPatients struct {
  1492. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1493. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1494. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1495. Number string `gorm:"column:number" json:"number" form:"number"`
  1496. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1497. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1498. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1499. }
  1500. func (NewCustomPatients) TableName() string {
  1501. return "his_patients"
  1502. }
  1503. type NewSZCustomPatients struct {
  1504. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1505. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1506. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1507. Number string `gorm:"column:number" json:"number" form:"number"`
  1508. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1509. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1510. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1511. }
  1512. func (NewSZCustomPatients) TableName() string {
  1513. return "his_patients"
  1514. }
  1515. //
  1516. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1517. // var tempPatients []*NewSZCustomPatients
  1518. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1519. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1520. // return tempPatients, err
  1521. //}
  1522. type NewTempPatients struct {
  1523. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1524. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1525. Name string `gorm:"column:name" json:"name" form:"name"`
  1526. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1527. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1528. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1529. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1530. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1531. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1532. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1533. }
  1534. func (NewTempPatients) TableName() string {
  1535. return "xt_patients"
  1536. }
  1537. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1538. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1539. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1540. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1541. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1542. })
  1543. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2", org_id, record_date)
  1544. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  1545. for _, item := range patients {
  1546. for _, sumItem := range item.HisPatient {
  1547. if len(sumItem.VMHisOrders) > 0 {
  1548. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1549. }
  1550. }
  1551. }
  1552. return
  1553. }
  1554. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1555. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1556. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1557. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1558. })
  1559. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  1560. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  1561. for _, item := range patients {
  1562. for _, sumItem := range item.HisPatient {
  1563. if len(sumItem.VMHisOrders) > 0 {
  1564. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1565. }
  1566. }
  1567. }
  1568. return
  1569. }
  1570. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1571. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1572. return
  1573. }
  1574. type CustomInComeStatistics struct {
  1575. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1576. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1577. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1578. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1579. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1580. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1581. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1582. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1583. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1584. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1585. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1586. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1587. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1588. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1589. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1590. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1591. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1592. }
  1593. func (CustomInComeStatistics) TableName() string {
  1594. return "his_order"
  1595. }
  1596. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1597. offset := (page - 1) * limit
  1598. if len(keywords) != 0 {
  1599. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1600. } else {
  1601. if start_time != 0 && end_time != 0 {
  1602. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1603. } else {
  1604. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1605. }
  1606. }
  1607. return
  1608. }
  1609. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1610. offset := (page - 1) * limit
  1611. if len(keywords) != 0 {
  1612. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1613. } else {
  1614. if start_time != 0 && end_time != 0 {
  1615. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ? ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1616. } else {
  1617. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1618. }
  1619. }
  1620. return
  1621. }
  1622. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1623. // err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  1624. // return
  1625. //}
  1626. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1627. err = writeDb.Create(&template).Error
  1628. return
  1629. }
  1630. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1631. err = writeDb.Save(&s).Error
  1632. return
  1633. }
  1634. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1635. err = writeDb.Save(&s).Error
  1636. return
  1637. }
  1638. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1639. err = writeDb.Save(&project).Error
  1640. return
  1641. }
  1642. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1643. err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ? AND status = 1", org_id, patient_id, sch_date).First(&sch).Error
  1644. return
  1645. }
  1646. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1647. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1 AND mode = ? AND patient_id = ?", org_id, mode_id, patient_id).Last(&prescription).Error
  1648. return
  1649. }
  1650. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1651. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1652. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1653. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1654. }).
  1655. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1656. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1657. }).
  1658. Where("status = 1 AND p_template_id = ? ", template_id).
  1659. Find(&prescription).Error
  1660. return
  1661. }
  1662. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  1663. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
  1664. return
  1665. }
  1666. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  1667. err = writeDb.Save(&consumables).Error
  1668. return
  1669. }
  1670. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  1671. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  1672. return
  1673. }
  1674. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  1675. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, patient_id, record_time).Find(&projects).Error
  1676. return
  1677. }
  1678. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  1679. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  1680. return
  1681. }
  1682. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  1683. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  1684. return
  1685. }
  1686. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  1687. err = writeDb.Save(&good_info).Error
  1688. return
  1689. }
  1690. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1691. err = readDb.Model(&models.HisPrescription{}).
  1692. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1693. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1694. }).
  1695. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1696. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1697. }).
  1698. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1699. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1700. }).
  1701. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
  1702. Find(&prescription).Error
  1703. return
  1704. }
  1705. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1706. err = readDb.Model(&models.HisPrescription{}).
  1707. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1708. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1709. }).
  1710. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1711. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1712. }).
  1713. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1714. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1715. }).
  1716. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
  1717. Find(&prescription).Error
  1718. return
  1719. }
  1720. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1721. err = readDb.Model(&models.HisPrescription{}).
  1722. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1723. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1724. }).
  1725. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1726. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1727. }).
  1728. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1729. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1730. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1731. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1732. }).
  1733. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
  1734. Find(&prescription).Error
  1735. return
  1736. }
  1737. //已收费
  1738. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1739. err = readDb.Model(&models.HisPrescription{}).
  1740. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1741. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1742. }).
  1743. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1744. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1745. }).
  1746. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1747. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1748. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1749. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1750. }).
  1751. Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
  1752. Find(&prescription).Error
  1753. return
  1754. }
  1755. func UpdataHisPateint(his *models.HisPatient) {
  1756. writeDb.Save(&his)
  1757. }
  1758. func SaveHisOrder(his *models.HisOrder) (err error) {
  1759. err = writeDb.Save(&his).Error
  1760. return
  1761. }