his_service.go 183KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019
  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:HisPatientId,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 VMHisPrescriptionInfo 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. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  44. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  45. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  48. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  49. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  50. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  51. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  52. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  53. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  54. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  55. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  56. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  57. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  58. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  59. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  60. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  61. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  62. }
  63. func (VMHisPrescriptionInfo) TableName() string {
  64. return "his_prescription_info"
  65. }
  66. type VMHisOrder struct {
  67. ID int64 `gorm:"column:id" json:"id" form:"id"`
  68. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  69. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  70. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  71. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  72. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  73. Status int64 `gorm:"column:status" json:"status" form:"status"`
  74. Number string `gorm:"column:number" json:"number" form:"number"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  76. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  77. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  78. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  79. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  80. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  81. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  82. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  83. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  84. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  85. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  86. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  87. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  88. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  89. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  90. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  91. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  92. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  93. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  94. }
  95. func (VMHisOrder) TableName() string {
  96. return "his_order"
  97. }
  98. type Patients struct {
  99. ID int64 `gorm:"column:id" json:"id" form:"id"`
  100. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  101. Name string `gorm:"column:name" json:"name" form:"name"`
  102. Status int64 `gorm:"column:status" json:"status" form:"status"`
  103. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  104. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  105. Phone int64 `gorm:"column:phone" json:"phone" form:"phone"`
  106. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  107. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  108. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  109. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  110. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  111. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  112. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  113. }
  114. func (Patients) TableName() string {
  115. return "xt_patients"
  116. }
  117. type HisPrescription struct {
  118. ID int64 `gorm:"column:id" json:"id" form:"id"`
  119. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  120. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  121. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  122. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  123. Status int64 `gorm:"column:status" json:"status" form:"status"`
  124. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  125. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  126. }
  127. func (HisPrescription) TableName() string {
  128. return "his_prescription"
  129. }
  130. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  131. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  132. if sch_type != 0 {
  133. 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)
  134. } else {
  135. 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)
  136. }
  137. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  138. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  139. 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
  140. return
  141. }
  142. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  143. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  144. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  145. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  146. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  147. return
  148. }
  149. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  150. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  151. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  152. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  153. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  154. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  155. return
  156. }
  157. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  158. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  159. 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)
  160. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  161. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  162. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  163. return
  164. }
  165. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  166. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  167. 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)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  169. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  170. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  171. return
  172. }
  173. type PatientTwo struct {
  174. ID int64 `gorm:"column:id" json:"id" form:"id"`
  175. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  176. Name string `gorm:"column:name" json:"name" form:"name"`
  177. Status int64 `gorm:"column:status" json:"status" form:"status"`
  178. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  179. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  180. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  181. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  182. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  183. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  184. }
  185. func (PatientTwo) TableName() string {
  186. return "xt_patients"
  187. }
  188. type HisPatientTwo struct {
  189. ID int64 `gorm:"column:id" json:"id" form:"id"`
  190. Name string `gorm:"column:name" json:"name" form:"name"`
  191. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  192. Total float64 `gorm:"column:total" json:"total" form:"total"`
  193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  194. Status int64 `gorm:"column:status" json:"status" form:"status"`
  195. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  196. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  197. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  198. Number string `gorm:"column:number" json:"number" form:"number"`
  199. }
  200. func (HisPatientTwo) TableName() string {
  201. return "his_patient"
  202. }
  203. type HisPrescriptionTwo struct {
  204. ID int64 `gorm:"column:id" json:"id" form:"id"`
  205. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  206. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  207. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  208. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  209. Status int64 `gorm:"column:status" json:"status" form:"status"`
  210. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  211. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  212. Number string `gorm:"column:number" json:"number" form:"number"`
  213. Type int64 `gorm:"column:type" json:"type" form:"type"`
  214. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  215. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  216. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  217. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  218. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  219. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  220. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  221. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  222. }
  223. func (HisPrescriptionTwo) TableName() string {
  224. return "his_prescription"
  225. }
  226. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  227. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  228. 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)
  229. if sch_type > 0 {
  230. 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 schedule_type = ?", record_date, org_id, sch_type)
  231. }
  232. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  233. 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)
  234. })
  235. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  236. return
  237. }
  238. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  239. 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)
  240. if sch_type != 0 {
  241. 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)
  242. } else {
  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 = ? ", record_date, org_id)
  244. }
  245. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  246. 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
  247. return
  248. }
  249. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  250. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  251. return
  252. }
  253. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  254. 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
  255. return
  256. }
  257. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  258. 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
  259. return
  260. }
  261. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  262. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  263. return
  264. }
  265. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  266. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  267. return
  268. }
  269. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  270. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND id = ?", org_id, record_date, patient_id, his_patient_id).First(&info).Error
  271. return
  272. }
  273. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  274. 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
  275. return
  276. }
  277. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  278. 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
  279. return
  280. }
  281. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  282. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  283. return
  284. }
  285. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  286. 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
  287. return
  288. }
  289. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  290. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  291. return
  292. }
  293. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  294. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  295. return
  296. }
  297. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  298. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  299. err = db.Find(&caseHistorys).Error
  300. return
  301. }
  302. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  303. likekey := "%" + keyword + "%"
  304. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  305. if startime > 0 {
  306. db = db.Where("record_date>=?", startime)
  307. }
  308. if endtime > 0 {
  309. db = db.Where("record_date<=?", endtime)
  310. }
  311. if len(keyword) > 0 {
  312. db = db.Where("template_name like ? ", likekey)
  313. }
  314. err = db.Find(&caseHistorys).Error
  315. return
  316. }
  317. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  318. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  319. return caseHistory, err
  320. }
  321. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  322. err = writeDb.Create(&template).Error
  323. return
  324. }
  325. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  326. history := models.HisPatientCaseHistory{}
  327. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1 and user_org_id = ? and record_date = ?", patient_id, user_org_id, record_date).Find(&history).Error
  328. if err != nil {
  329. if err == gorm.ErrRecordNotFound {
  330. return nil, err
  331. } else {
  332. return nil, err
  333. }
  334. }
  335. return &history, nil
  336. }
  337. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  338. history := models.HisPatientCaseHistory{}
  339. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  340. return history, err
  341. }
  342. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  343. err := writeDb.Create(&caseHistory).Error
  344. return err
  345. }
  346. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  347. err := XTWriteDB().Model(&his).Where("patient_id = ? and record_date = ? and user_org_id = ? and status =1", patient_id, record_date, user_org_id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "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, "sbp": his.Sbp, "dbp": his.Dbp, "primary_disease": his.PrimaryDisease, "confirm_failure_date": his.ConfirmFailureDate, "drug_allergy_history": his.DrugAllergyHistory, "physical_examination": his.PhysicalExamination, "special_inspection": his.SpecialInspection, "lab_apparatus": his.LabApparatus}).Error
  348. return err
  349. }
  350. func SaveHisPrescription(tx *gorm.DB, prescription *models.HisPrescription) (err error) {
  351. err = tx.Model(&models.HisPrescription{}).Save(prescription).Error
  352. if err != nil {
  353. tx.Rollback()
  354. return
  355. }
  356. tx.Commit()
  357. return
  358. }
  359. func SaveHisPrescriptionTwo(prescription *models.HisPrescription) (err error) {
  360. err = writeDb.Model(&models.HisPrescription{}).Save(prescription).Error
  361. return
  362. }
  363. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  364. 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
  365. 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
  366. 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
  367. return
  368. }
  369. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  370. 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
  371. return
  372. }
  373. func DelelteProject(id int64, user_org_id int64) (err error) {
  374. 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
  375. return
  376. }
  377. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  378. err = readDb.Model(&models.HisPrescription{}).
  379. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  380. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  381. }).
  382. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  383. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  384. }).
  385. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  386. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  387. }).
  388. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  389. Find(&prescription).Error
  390. return
  391. }
  392. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  393. err = readDb.Model(&models.HisPrescription{}).
  394. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  395. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  396. }).
  397. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  398. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  399. }).
  400. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  401. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  402. }).
  403. 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).
  404. Find(&prescription).Error
  405. return
  406. }
  407. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  408. err = readDb.Model(&models.HisPrescription{}).
  409. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  410. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  411. }).
  412. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  413. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  414. }).
  415. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  416. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  417. }).
  418. 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).
  419. Find(&prescription).Error
  420. return
  421. }
  422. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  423. err = readDb.Model(&models.HisPrescription{}).
  424. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  425. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  426. }).
  427. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  428. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  429. }).
  430. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  431. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  432. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  433. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  434. }).
  435. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?) AND (his_patient_id = ? OR his_patient_id = 0)", org_id, record_date, patient_id, p_type, his_patient_id).
  436. Find(&prescription).Error
  437. return
  438. }
  439. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  440. err = readDb.Model(&models.HisPrescription{}).
  441. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  442. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  443. }).
  444. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  445. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  446. }).
  447. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  448. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  449. }).
  450. 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).
  451. Find(&prescription).Error
  452. return
  453. }
  454. func GetSettleHisPrescriptionTX(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  455. err = tx.Model(&models.HisPrescription{}).
  456. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  457. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  458. }).
  459. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  460. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  461. }).
  462. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  463. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  464. }).
  465. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  466. Find(&prescription).Error
  467. return
  468. }
  469. func GetSettleHisPrescriptionTXOne(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  470. err = tx.Model(&models.HisPrescription{}).
  471. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  472. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  473. }).
  474. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  475. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  476. }).
  477. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  478. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  479. }).
  480. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  481. Find(&prescription).Error
  482. return
  483. }
  484. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  485. err = readDb.Model(&models.HisPrescription{}).
  486. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  487. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  488. }).
  489. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  490. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  491. }).
  492. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  493. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  494. }).
  495. 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).
  496. Find(&prescription).Error
  497. return
  498. }
  499. func GetMonthHisPrescriptionTX(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  500. err = tx.Model(&models.HisPrescription{}).
  501. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  502. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  503. }).
  504. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  505. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  506. }).
  507. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  508. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  509. }).
  510. 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).
  511. Find(&prescription).Error
  512. return
  513. }
  514. func GetMonthHisPrescriptionTXOne(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  515. err = tx.Model(&models.HisPrescription{}).
  516. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  517. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  518. }).
  519. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  520. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  521. }).
  522. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  523. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  524. }).
  525. 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).
  526. Find(&prescription).Error
  527. return
  528. }
  529. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  530. err = readDb.Model(&models.HisPrescription{}).
  531. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  532. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  533. }).
  534. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  535. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  536. }).
  537. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  538. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  539. }).
  540. 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).
  541. Find(&prescription).Error
  542. return
  543. }
  544. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  545. err = readDb.Model(&models.HisPrescription{}).
  546. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  547. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  548. }).
  549. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  550. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  551. }).
  552. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  553. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  554. }).
  555. 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).
  556. Find(&prescription).Error
  557. return
  558. }
  559. // 未收费
  560. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  561. err = readDb.Model(&models.HisPrescription{}).
  562. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  563. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  564. }).
  565. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  566. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  567. }).
  568. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  569. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  570. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  571. return db.Where("status = 1 AND user_org_id = ?", org_id)
  572. }).
  573. 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 order_status <> 4 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  574. Find(&prescription).Error
  575. return
  576. }
  577. // 已收费
  578. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  579. err = readDb.Model(&models.HisPrescription{}).
  580. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  581. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  582. }).
  583. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  584. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  585. }).
  586. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  587. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  588. }).
  589. 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).
  590. Find(&prescription).Error
  591. return
  592. }
  593. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  594. err = readDb.Model(&models.HisPrescription{}).
  595. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  596. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  597. }).
  598. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  599. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  600. }).
  601. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  602. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  603. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  604. return db.Where("status = 1 AND user_org_id = ?", org_id)
  605. }).
  606. 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 order_status <> 4", org_id, start_date, end_date, patient_id).
  607. Find(&prescription).Error
  608. return
  609. }
  610. type OtherDrugWarehouseInfo struct {
  611. ID int64 `gorm:"column:id" json:"id" form:"id"`
  612. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  613. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  614. Status int64 `gorm:"column:status" json:"status" form:"status"`
  615. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  616. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  617. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  618. Price float64 `gorm:"column:price" json:"price" form:"price"`
  619. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  620. }
  621. func (OtherDrugWarehouseInfo) TableName() string {
  622. return "xt_drug_warehouse_info"
  623. }
  624. type VMDrugSalesReturnInfo struct {
  625. ID int64 `gorm:"column:id" json:"id" form:"id"`
  626. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  627. Count int64 `gorm:"column:count" json:"count" form:"count"`
  628. Status int64 `gorm:"column:status" json:"status" form:"status"`
  629. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  630. }
  631. func (VMDrugSalesReturnInfo) TableName() string {
  632. return "xt_drug_sales_return_info"
  633. }
  634. type VMDrugWarehouseOutInfo struct {
  635. ID int64 `gorm:"column:id" json:"id" form:"id"`
  636. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  637. Count int64 `gorm:"column:count" json:"count" form:"count"`
  638. Status int64 `gorm:"column:status" json:"status" form:"status"`
  639. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  640. }
  641. func (VMDrugWarehouseOutInfo) TableName() string {
  642. return "xt_drug_warehouse_out_info"
  643. }
  644. type VMDrugCancelStockInfo struct {
  645. ID int64 `gorm:"column:id" json:"id" form:"id"`
  646. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  647. Count int64 `gorm:"column:count" json:"count" form:"count"`
  648. Status int64 `gorm:"column:status" json:"status" form:"status"`
  649. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  650. }
  651. func (VMDrugCancelStockInfo) TableName() string {
  652. return "xt_drug_cancel_stock_info"
  653. }
  654. type BaseDrugLib struct {
  655. ID int64 `gorm:"column:id" json:"id" form:"id"`
  656. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  657. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  658. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  659. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  660. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  661. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  662. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  663. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  664. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  665. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  666. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  667. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  668. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  669. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  670. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  671. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  672. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  673. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  674. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  675. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  676. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  677. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  678. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  679. Number string `gorm:"column:number" json:"number" form:"number"`
  680. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  681. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  682. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  683. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  684. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  685. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  686. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  687. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  688. Code string `gorm:"column:code" json:"code" form:"code"`
  689. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  690. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  691. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  692. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  693. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  694. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  695. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  696. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  697. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  698. Label int64 `gorm:"column:label" json:"label" form:"label"`
  699. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  700. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  701. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  702. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  703. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  704. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  705. Status int64 `gorm:"column:status" json:"status" form:"status"`
  706. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  707. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  708. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  709. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  710. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  711. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  712. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  713. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  714. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  715. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  716. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  717. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  718. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  719. //Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  720. //Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  721. //PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  722. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  723. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  724. Total float64 `gorm:"column:total" json:"total" form:"total"`
  725. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  726. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  727. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  728. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  729. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  730. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  731. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  732. IsProject int64 `gorm:"column:is_project" json:"is_project" form:"is_project"`
  733. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  734. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  735. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  736. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  737. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  738. }
  739. func (BaseDrugLib) TableName() string {
  740. return "xt_base_drug"
  741. }
  742. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  743. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  744. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  745. }).Find(&list).Error
  746. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  747. return
  748. }
  749. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  750. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  751. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  752. }).Find(&list).Error
  753. return
  754. }
  755. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  756. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  757. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  758. }).Find(&list).Error
  759. return
  760. }
  761. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  762. 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")
  763. err = db.Find(&drugs).Error
  764. return
  765. }
  766. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  767. if len(keyword) != 0 {
  768. key := "%" + keyword + "%"
  769. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  770. } else {
  771. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  772. }
  773. return
  774. }
  775. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  776. err = writeDb.Create(&charge).Error
  777. return
  778. }
  779. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  780. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  781. 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")
  782. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  783. return
  784. }
  785. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  786. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  787. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  788. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  789. return
  790. }
  791. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) {
  792. err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error
  793. if err != nil {
  794. tx.Rollback()
  795. return
  796. }
  797. return
  798. }
  799. func CreateHisDoctorAdviceTwo(s *models.HisDoctorAdviceInfo) (err error) {
  800. tx := writeDb.Begin()
  801. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  802. tx.Rollback()
  803. return
  804. }
  805. tx.Commit()
  806. return
  807. }
  808. func CreateHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  809. err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error
  810. if err != nil {
  811. tx.Rollback()
  812. return
  813. }
  814. return
  815. }
  816. func GetLastHisProject(patient_id int64, user_org_id int64, record_date int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
  817. prescriptionProject := models.HisPrescriptionProject{}
  818. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and status=1", patient_id, user_org_id, record_date).Find(&prescriptionProject).Error
  819. if err != gorm.ErrRecordNotFound {
  820. if err != nil {
  821. tx.Rollback()
  822. return prescriptionProject, err
  823. }
  824. }
  825. return prescriptionProject, err
  826. }
  827. func CreateHisProjectThree(project *models.HisPrescriptionProject) (err error) {
  828. tx := writeDb.Begin()
  829. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  830. tx.Rollback()
  831. return
  832. }
  833. return
  834. }
  835. func SaveHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  836. //err = tx.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
  837. if err = tx.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; err != nil {
  838. tx.Rollback()
  839. return
  840. }
  841. return
  842. }
  843. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  844. err := writeDb.Create(&patient).Error
  845. return err
  846. }
  847. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  848. 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
  849. return
  850. }
  851. func CreateOrder(order *models.HisOrder) (err error) {
  852. err = writeDb.Create(&order).Error
  853. return
  854. }
  855. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  856. err = tx.Create(&order).Error
  857. return
  858. }
  859. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  860. err = writeDb.Create(&order).Error
  861. return
  862. }
  863. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  864. err = tx.Create(&order).Error
  865. return
  866. }
  867. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  868. 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
  869. return
  870. }
  871. func FindPatientPrescriptionInfoTen(org_id int64, patient_id int64, start_time int64, end_time int64, p_type int64) (info []models.HisPrescriptionInfo, err error) {
  872. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_time, end_time, patient_id, p_type).Find(&info).Error
  873. return
  874. }
  875. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  876. 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
  877. return
  878. }
  879. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  880. 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).Last(&info).Error
  881. return
  882. }
  883. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  884. 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
  885. return
  886. }
  887. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  888. 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
  889. return
  890. }
  891. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  892. tx := writeDb.Begin()
  893. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  894. tx.Rollback()
  895. return
  896. }
  897. tx.Commit()
  898. return
  899. }
  900. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, doctor_id int64, keywords string, p_type int64, sort_type int64, start_time string, end_time string, charge_type int64, sch_type int64, zone_type int64, med_type int64) (order []*models.HisOrder, err error, total int64) {
  901. offset := (page - 1) * limit
  902. db := readDb.Model(&models.HisOrder{})
  903. if doctor_id > 0 {
  904. 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)
  905. }
  906. if len(keywords) > 0 {
  907. keywords = "%" + keywords + "%"
  908. 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)
  909. }
  910. if sch_type > 0 && zone_type > 0 {
  911. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp, zone_type)
  912. }
  913. if sch_type > 0 && zone_type == 0 {
  914. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp)
  915. }
  916. if sch_type == 0 && zone_type > 0 {
  917. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", start_time_timestamp, end_time_timestamp, zone_type)
  918. }
  919. if med_type > 0 {
  920. db = db.Where("his_order.med_type = ?", med_type)
  921. }
  922. //if zone_type > 0 {
  923. // db = db.Joins("join xt_schedule sch_two on sch_two.schedule_date = his_order.settle_accounts_date AND sch_two.patient_id = his_order.patient_id AND sch_two.partition_id = ?", zone_type)
  924. //}
  925. if sort_type == 1 {
  926. if start_time_timestamp != 0 {
  927. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  928. }
  929. if end_time_timestamp != 0 {
  930. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  931. }
  932. } else {
  933. if len(start_time) != 0 {
  934. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  935. }
  936. if len(end_time) != 0 {
  937. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  938. }
  939. }
  940. if p_type > 0 {
  941. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ? AND his_order.order_status = 2", user_org_id, p_type)
  942. } else {
  943. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  944. }
  945. if charge_type > 0 {
  946. if charge_type == 2 {
  947. db = db.Where("his_order.is_medicine_insurance = 0")
  948. } else {
  949. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  950. }
  951. }
  952. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  953. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  954. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  955. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  956. db = db.Preload("HisFundSettleListResult", "status = 1")
  957. db = db.Count(&total)
  958. db = db.Limit(limit).Offset(offset)
  959. if user_org_id == 10215 {
  960. if sort_type == 1 {
  961. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  962. }
  963. if sort_type == 2 {
  964. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  965. }
  966. } else {
  967. if sort_type == 1 {
  968. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  969. }
  970. if sort_type == 2 {
  971. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  972. }
  973. }
  974. return
  975. }
  976. func GetNewHisOrderListTwo(user_org_id int64, start_time_timestamp int64, end_time_timestamp int64) (order []*models.HisOrderELE, err error) {
  977. db := readDb.Model(&models.HisOrderELE{})
  978. if start_time_timestamp != 0 {
  979. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  980. }
  981. if end_time_timestamp != 0 {
  982. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  983. }
  984. db = db.Where("user_org_id = ? and order_status = 2 and status = 1", user_org_id)
  985. err = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).Find(&order).Error
  986. return
  987. }
  988. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  989. 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
  990. return
  991. }
  992. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  993. err = tx.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
  994. return
  995. }
  996. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  997. 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
  998. return
  999. }
  1000. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  1001. 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
  1002. return
  1003. }
  1004. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  1005. 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
  1006. return
  1007. }
  1008. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  1009. err = tx.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
  1010. return
  1011. }
  1012. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  1013. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1014. return
  1015. }
  1016. type HisOrder 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. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1020. Number string `gorm:"column:number" json:"number" form:"number"`
  1021. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1022. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1023. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1024. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  1025. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  1026. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  1027. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  1028. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  1029. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  1030. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1031. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1032. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  1033. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1034. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  1035. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  1036. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1037. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  1038. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1039. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1040. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1041. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  1042. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  1043. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  1044. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1045. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1046. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1047. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  1048. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1049. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1050. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1051. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1052. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  1053. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1054. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  1055. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1056. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1057. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1058. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1059. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1060. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1061. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1062. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1063. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1064. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1065. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1066. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1067. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1068. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1069. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1070. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1071. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1072. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1073. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1074. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1075. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1076. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1077. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1078. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1079. }
  1080. func (HisOrder) TableName() string {
  1081. return "his_order"
  1082. }
  1083. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1084. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1085. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1086. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1087. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1088. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1089. Order("ctime desc").
  1090. Find(&order).Error
  1091. return
  1092. }
  1093. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1094. err = readDb.Model(&models.HisPrescription{}).
  1095. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1096. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1097. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1098. }).
  1099. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1100. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1101. Find(&prescription).Error
  1102. return
  1103. }
  1104. type HisPrescriptionInfo struct {
  1105. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1106. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1107. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1108. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1109. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1110. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1111. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1112. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1113. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1114. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1115. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1116. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1117. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1118. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1119. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1120. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1121. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1122. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1123. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1124. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1125. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1126. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1127. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1128. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1129. }
  1130. func (HisPrescriptionInfo) TableName() string {
  1131. return "his_prescription_info"
  1132. }
  1133. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1134. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1135. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1136. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1137. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1138. Order("ctime desc").Find(&prescriptionOrder).Error
  1139. return
  1140. }
  1141. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1142. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1143. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1144. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1145. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1146. return
  1147. }
  1148. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1149. err = readDb.Model(&models.HisPrescription{}).
  1150. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1151. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1152. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1153. }).
  1154. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1155. Find(&prescription).Error
  1156. return
  1157. }
  1158. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1159. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1160. return
  1161. }
  1162. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1163. 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(), "status": 0}).Error
  1164. 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
  1165. 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
  1166. return
  1167. }
  1168. func UpdataOrderStatusten(id int64, number string, user_org_id int64) (err error) {
  1169. 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(), "status": 0}).Error
  1170. //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
  1171. return
  1172. }
  1173. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1174. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 1}).Error
  1175. 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": 4, "mtime": time.Now().Unix()}).Error
  1176. 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": 4, "mtime": time.Now().Unix()}).Error
  1177. return
  1178. }
  1179. func UpdataOrderStatusTen(id int64, number string, user_org_id int64) (err error) {
  1180. 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
  1181. 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
  1182. return
  1183. }
  1184. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1185. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1186. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ? AND order_number = ?", user_org_id, number).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1187. return
  1188. }
  1189. func SaveHisPatient(his models.HisPatient) (err error) {
  1190. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", his.RecordDate, his.UserOrgId, his.ID).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1191. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1192. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1193. return
  1194. }
  1195. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1196. 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()})
  1197. }
  1198. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1199. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1200. return
  1201. }
  1202. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1203. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1204. First(&order).Error
  1205. return
  1206. }
  1207. func UpDateOrder(order models.HisOrder) (err error) {
  1208. err = writeDb.Save(&order).Error
  1209. return
  1210. }
  1211. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1212. err = writeDb.Save(&order).Error
  1213. return
  1214. }
  1215. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1216. 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
  1217. 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
  1218. return
  1219. }
  1220. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1221. err = tx.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
  1222. err = tx.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
  1223. return
  1224. }
  1225. func CreateErrMsgLog(log *models.HisOrderError) {
  1226. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1227. }
  1228. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1229. 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
  1230. return
  1231. }
  1232. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1233. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1234. return
  1235. }
  1236. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1237. db := readDb.Model(&models.OutpatientServiceSick{})
  1238. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1239. err = db.Order("ctime desc").Find(&list).Error
  1240. return
  1241. }
  1242. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1243. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1244. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1245. err = db.Order("ctime desc").Find(&list).Error
  1246. return
  1247. }
  1248. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1249. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1250. return list, err
  1251. }
  1252. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1253. db := readDb.Model(&models.XtHisAddtionConfig{})
  1254. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1255. err = db.Order("ctime desc").Find(&list).Error
  1256. return
  1257. }
  1258. type XtHisOrder struct {
  1259. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1260. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1261. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1262. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1263. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1264. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1265. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1266. Number string `gorm:"column:number" json:"number" form:"number"`
  1267. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1268. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1269. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1270. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1271. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1272. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1273. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1274. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1275. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1276. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1277. }
  1278. func (XtHisOrder) TableName() string {
  1279. return "his_order"
  1280. }
  1281. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1282. err = readDb.Model(&models.HisPrescription{}).
  1283. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1284. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1285. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1286. }).
  1287. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1288. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1289. Find(&prescription).Error
  1290. return
  1291. }
  1292. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1293. 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
  1294. return
  1295. }
  1296. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1297. 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
  1298. return
  1299. }
  1300. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1301. offset := (page - 1) * limit
  1302. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type <> 1 ", org_id, record_date)
  1303. if len(keywords) > 0 {
  1304. keywords = "%" + keywords + "%"
  1305. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1306. }
  1307. if sch_type > 0 {
  1308. db = db.Joins("JOIN xt_schedule On xt_schedule.status = 1 AND his_prescription_info.patient_id = xt_schedule.patient_id AND xt_schedule.schedule_date = ? AND xt_schedule.schedule_type = ?", record_date, sch_type)
  1309. }
  1310. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1311. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1312. db = db.Count(&total)
  1313. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1314. return
  1315. }
  1316. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1317. offset := (page - 1) * limit
  1318. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1319. if len(keywords) > 0 {
  1320. keywords = "%" + keywords + "%"
  1321. 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)
  1322. 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)
  1323. }
  1324. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1325. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1326. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1327. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1328. db = db.Count(&total)
  1329. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1330. return
  1331. }
  1332. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1333. patient := models.VMHisPatient{}
  1334. 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
  1335. return patient, err
  1336. }
  1337. type VMOtherHisPrescriptionInfo struct {
  1338. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1339. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1340. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1341. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1342. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1343. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1344. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1345. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1346. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1347. }
  1348. func (VMOtherHisPrescriptionInfo) TableName() string {
  1349. return "his_prescription_info"
  1350. }
  1351. type VMHisPrescription struct {
  1352. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1353. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1354. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1355. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1356. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1357. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1358. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1359. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1360. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1361. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1362. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1363. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1364. }
  1365. func (VMHisPrescription) TableName() string {
  1366. return "his_prescription"
  1367. }
  1368. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1369. if change_type == 1 { //根据日期取出上一方数据
  1370. var Id AdviceDate
  1371. 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
  1372. 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).
  1373. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1374. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1375. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1376. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1377. }).
  1378. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1379. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1380. })
  1381. }).Find(&advice).Error
  1382. } else if change_type == 2 {
  1383. var Id AdviceDate
  1384. 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
  1385. 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).
  1386. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1387. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1388. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1389. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1390. }).
  1391. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1392. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1393. })
  1394. }).Find(&advice).Error
  1395. }
  1396. return
  1397. }
  1398. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1399. 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).
  1400. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1401. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1402. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1403. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1404. }).
  1405. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1406. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1407. })
  1408. }).Order("record_date desc").Find(&advice).Error
  1409. return
  1410. }
  1411. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1412. 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).
  1413. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1414. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1415. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1416. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1417. }).
  1418. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1420. })
  1421. }).Find(&advice).Error
  1422. return
  1423. }
  1424. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1425. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1426. return
  1427. }
  1428. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1429. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1430. return
  1431. }
  1432. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1433. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1434. return
  1435. }
  1436. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1437. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1438. return
  1439. }
  1440. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1441. 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
  1442. return
  1443. }
  1444. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1445. 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
  1446. return
  1447. }
  1448. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1449. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1450. return
  1451. }
  1452. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1453. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1454. return
  1455. }
  1456. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1457. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1458. return
  1459. }
  1460. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1461. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1462. return
  1463. }
  1464. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1465. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1466. return
  1467. }
  1468. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1469. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1470. return
  1471. }
  1472. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1473. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1474. return
  1475. }
  1476. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1477. 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
  1478. return
  1479. }
  1480. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1481. var patient Patients
  1482. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1483. return patient, err
  1484. }
  1485. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1486. var patient models.PatientTwos
  1487. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1488. return patient, err
  1489. }
  1490. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1491. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1492. return
  1493. }
  1494. type VMHisProjectTeam struct {
  1495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1496. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1497. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1498. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1499. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1500. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1501. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1502. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1503. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1504. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1505. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1506. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1507. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1508. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1509. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1510. }
  1511. func (VMHisProjectTeam) TableName() string {
  1512. return "xt_his_project_team"
  1513. }
  1514. type VMHisProject struct {
  1515. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1516. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1517. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1518. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1519. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1520. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1521. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1522. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1523. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1524. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1525. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1526. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1527. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1528. }
  1529. func (VMHisProject) TableName() string {
  1530. return "xt_his_project"
  1531. }
  1532. type VMItemProjectList struct {
  1533. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1534. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1535. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1536. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1537. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1538. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1539. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1540. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1541. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1542. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1543. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1544. }
  1545. func (VMItemProjectList) TableName() string {
  1546. return "xt_his_project_list"
  1547. }
  1548. type VMHisPrescriptionTwo struct {
  1549. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1550. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1551. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1552. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1553. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1554. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1555. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1556. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1557. }
  1558. func (VMHisPrescriptionTwo) TableName() string {
  1559. return "his_prescription"
  1560. }
  1561. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1562. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1563. for _, item := range project {
  1564. var project_item []*VMItemProjectList
  1565. ids := strings.Split(item.ItemId, ",")
  1566. 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)
  1567. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1568. }
  1569. return
  1570. }
  1571. type HisDoctorAdviceInfo struct {
  1572. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1573. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1574. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1575. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1576. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1577. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1578. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1579. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1580. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1581. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1582. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1583. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1584. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1585. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1586. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1587. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1588. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1589. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1590. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1591. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1592. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1593. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1594. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1595. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1596. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1597. }
  1598. func (HisDoctorAdviceInfo) TableName() string {
  1599. return "his_doctor_advice_info"
  1600. }
  1601. type HisPrescriptionProject struct {
  1602. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1603. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1604. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1605. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1606. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1607. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1608. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1609. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1610. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1611. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1612. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1613. Count string `gorm:"column:count" json:"count" form:"count"`
  1614. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1615. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1616. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1617. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1618. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1619. Day string `gorm:"column:day" json:"day" form:"day"`
  1620. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1621. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1622. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1623. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1624. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1625. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1626. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1627. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1628. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1629. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1630. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1631. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1632. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1633. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1634. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1635. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1636. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1637. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1638. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1639. }
  1640. func (HisPrescriptionProject) TableName() string {
  1641. return "his_prescription_project"
  1642. }
  1643. type HisOrderInfo struct {
  1644. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1645. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1646. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1647. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1648. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1649. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1650. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1651. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1652. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1653. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1654. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1655. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1656. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1657. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1658. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1659. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1660. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1661. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1662. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1663. }
  1664. func (HisOrderInfo) TableName() string {
  1665. return "his_order_info"
  1666. }
  1667. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1668. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1669. 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)
  1670. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1671. 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)
  1672. }).Find(&order).Error
  1673. return
  1674. }
  1675. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1676. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1677. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1678. // })
  1679. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1680. // return
  1681. //}
  1682. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1683. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1684. return db.Preload("Drug", "status = 1").Where("status = 1")
  1685. })
  1686. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1687. return
  1688. }
  1689. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1690. db := readDb.Model(&models.HisOrderInfoTwo{})
  1691. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1692. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1693. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1694. })
  1695. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0 ", order_number).Find(&order).Error
  1696. return
  1697. }
  1698. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1699. db := readDb.Model(&models.HisOrderInfoTwo{})
  1700. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1701. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1702. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1703. })
  1704. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0", order_number).Find(&order).Error
  1705. return
  1706. }
  1707. type MedicalInsuranceCostCompare struct {
  1708. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1709. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1710. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1711. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1712. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1713. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1714. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1715. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1716. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1717. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1718. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1719. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1720. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1721. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1722. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1723. }
  1724. func (MedicalInsuranceCostCompare) TableName() string {
  1725. return "medical_insurance_cost_compare"
  1726. }
  1727. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1728. offset := (page - 1) * limit
  1729. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1730. if len(keywords) == 0 {
  1731. db = db.Where("status=1")
  1732. if len(insutype) != 0 {
  1733. db = db.Where("insutype = ?", insutype)
  1734. }
  1735. if start_time != 0 {
  1736. db = db.Where("ctime >= ? ", start_time)
  1737. }
  1738. if end_time != 0 {
  1739. db = db.Where("ctime <= ? ", end_time)
  1740. }
  1741. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1742. } else {
  1743. keywords = "%" + keywords + "%"
  1744. 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)
  1745. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1746. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1747. }
  1748. return
  1749. }
  1750. type TempPatients struct {
  1751. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1752. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1753. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1754. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1755. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1756. Name string `gorm:"column:name" json:"name" form:"name"`
  1757. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1758. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1759. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1760. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1761. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1762. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1763. }
  1764. func (TempPatients) TableName() string {
  1765. return "xt_patients"
  1766. }
  1767. type GdybPsnNcdsRecord struct {
  1768. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1769. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1770. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1771. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1772. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1773. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1774. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1775. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1776. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1777. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1778. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1779. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1780. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1781. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1782. }
  1783. func (GdybPsnNcdsRecord) TableName() string {
  1784. return "gdyb_psn_ncds_record"
  1785. }
  1786. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1787. offset := (page - 1) * limit
  1788. db := readDb.Model(&TempPatients{})
  1789. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1790. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1791. })
  1792. fmt.Println(is_cancel)
  1793. if len(keywords) == 0 {
  1794. if is_cancel == 1 {
  1795. 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)
  1796. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1797. } else if is_cancel == 0 {
  1798. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1799. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1800. } else if is_cancel == 2 {
  1801. 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)")
  1802. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1803. }
  1804. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1805. } else {
  1806. keywords = "%" + keywords + "%"
  1807. 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)
  1808. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1809. }
  1810. return
  1811. }
  1812. type CustomAccountFormData struct {
  1813. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1814. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1815. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1816. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1817. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1818. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1819. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1820. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1821. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1822. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1823. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1824. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1825. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1826. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1827. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1828. DialysisCount int64 `gorm:"-"`
  1829. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1830. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1831. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1832. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1833. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1834. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1835. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1836. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1837. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1838. }
  1839. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1840. if clr_type == "9903" {
  1841. 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,o.hifp_pay as hifp_pay, o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time 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 o.insutype = ? AND o.clr_type = ? Group by o.id", org_id, start_time, end_time, insutype, clr_type).Scan(&cus).Error
  1842. } else {
  1843. 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,o.hifp_pay as hifp_pay,o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time 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 o.insutype = ? AND o.clr_type <> 9903 Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1844. }
  1845. for _, item := range cus {
  1846. var total int64
  1847. if item.SettleStartTime == 0 && item.SettleEndTime == 0 {
  1848. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleAccountsDate, item.SettleAccountsDate).Count(&total)
  1849. } else {
  1850. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleEndTime, item.SettleStartTime).Count(&total)
  1851. }
  1852. fmt.Println(total)
  1853. item.DialysisCount = total
  1854. fmt.Println(item.DialysisCount)
  1855. }
  1856. return
  1857. }
  1858. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1859. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1860. return
  1861. }
  1862. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1863. err = readDb.Model(&models.HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1864. Last(&order).Error
  1865. return
  1866. }
  1867. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1868. 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).
  1869. Order("ctime desc").
  1870. Find(&order).Error
  1871. return
  1872. }
  1873. type NewCustomPatients struct {
  1874. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1875. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1876. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1877. Number string `gorm:"column:number" json:"number" form:"number"`
  1878. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1879. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1880. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1881. }
  1882. func (NewCustomPatients) TableName() string {
  1883. return "his_patients"
  1884. }
  1885. type NewSZCustomPatients struct {
  1886. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1887. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1888. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1889. Number string `gorm:"column:number" json:"number" form:"number"`
  1890. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1891. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1892. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1893. }
  1894. func (NewSZCustomPatients) TableName() string {
  1895. return "his_patients"
  1896. }
  1897. //
  1898. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1899. // var tempPatients []*NewSZCustomPatients
  1900. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1901. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1902. // return tempPatients, err
  1903. //}
  1904. type NewTempPatients struct {
  1905. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1906. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1907. Name string `gorm:"column:name" json:"name" form:"name"`
  1908. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1909. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1910. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1911. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  1912. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1913. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1914. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1915. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1916. }
  1917. func (NewTempPatients) TableName() string {
  1918. return "xt_patients"
  1919. }
  1920. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1921. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1922. db := readDb.Model(&NewTempPatients{})
  1923. if sch_type > 0 {
  1924. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  1925. }
  1926. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1927. db = db.Preload("Schedule", "status = 1")
  1928. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1929. 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)
  1930. })
  1931. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  1932. 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).Group("xt_patients.id").Error
  1933. for _, item := range patients {
  1934. for _, sumItem := range item.HisPatient {
  1935. if len(sumItem.VMHisOrders) > 0 {
  1936. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1937. }
  1938. }
  1939. }
  1940. return
  1941. }
  1942. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1943. db := readDb.Model(&NewTempPatients{})
  1944. fmt.Println("sch_type")
  1945. fmt.Println(sch_type)
  1946. if sch_type > 0 {
  1947. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  1948. }
  1949. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1950. db = db.Preload("Schedule", "status = 1")
  1951. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1952. 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)
  1953. })
  1954. 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)
  1955. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  1956. for _, item := range patients {
  1957. for _, sumItem := range item.HisPatient {
  1958. if len(sumItem.VMHisOrders) > 0 {
  1959. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1960. }
  1961. }
  1962. }
  1963. return
  1964. }
  1965. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1966. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1967. return
  1968. }
  1969. func GetPrescriptionByIdTwo(id int64) (prescription models.HisPrescription, err error) {
  1970. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND status = 1", id).First(&prescription).Error
  1971. return
  1972. }
  1973. type CustomInComeStatistics struct {
  1974. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1975. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1976. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1977. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1978. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1979. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1980. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1981. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1982. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1983. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1984. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1985. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1986. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1987. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1988. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1989. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1990. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1991. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1992. }
  1993. func (CustomInComeStatistics) TableName() string {
  1994. return "his_order"
  1995. }
  1996. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1997. offset := (page - 1) * limit
  1998. if len(keywords) != 0 {
  1999. 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
  2000. } else {
  2001. if start_time != 0 && end_time != 0 {
  2002. 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
  2003. } else {
  2004. 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
  2005. }
  2006. }
  2007. return
  2008. }
  2009. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  2010. offset := (page - 1) * limit
  2011. if len(keywords) != 0 {
  2012. 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
  2013. } else {
  2014. if start_time != 0 && end_time != 0 {
  2015. 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
  2016. } else {
  2017. 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
  2018. }
  2019. }
  2020. return
  2021. }
  2022. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  2023. // 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
  2024. // return
  2025. //}
  2026. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  2027. err = writeDb.Create(&template).Error
  2028. return
  2029. }
  2030. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  2031. err = writeDb.Save(&s).Error
  2032. return
  2033. }
  2034. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  2035. err = writeDb.Save(&s).Error
  2036. return
  2037. }
  2038. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  2039. err = writeDb.Save(&project).Error
  2040. return
  2041. }
  2042. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  2043. 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
  2044. return
  2045. }
  2046. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  2047. 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
  2048. return
  2049. }
  2050. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  2051. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  2052. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2053. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2054. }).
  2055. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2056. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2057. }).
  2058. Where("status = 1 AND p_template_id = ? ", template_id).
  2059. Find(&prescription).Error
  2060. return
  2061. }
  2062. // 组
  2063. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  2064. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  2065. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2066. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2067. }).
  2068. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2069. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2070. }).
  2071. Where("status = 1 AND p_template_id = ? ", template_id).
  2072. Find(&prescription).Error
  2073. return
  2074. }
  2075. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  2076. 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
  2077. return
  2078. }
  2079. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  2080. err = writeDb.Save(&consumables).Error
  2081. return
  2082. }
  2083. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  2084. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  2085. return
  2086. }
  2087. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2088. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id = 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2089. return
  2090. }
  2091. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2092. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1 AND user_org_id = ?", user_org_id).Preload("HisProject", "status = 1 AND user_org_id = ?", user_org_id).Preload("GoodInfo", "status = 1 AND org_id = ?", user_org_id).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id > 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2093. return
  2094. }
  2095. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2096. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2097. return
  2098. }
  2099. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2100. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2101. return
  2102. }
  2103. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2104. err = writeDb.Save(&good_info).Error
  2105. return
  2106. }
  2107. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2108. err = readDb.Model(&models.HisPrescription{}).
  2109. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2110. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2111. }).
  2112. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2113. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2114. }).
  2115. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2116. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2117. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2118. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2119. }).
  2120. 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).
  2121. Find(&prescription).Error
  2122. return
  2123. }
  2124. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2125. err = readDb.Model(&models.HisPrescription{}).
  2126. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2127. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2128. }).
  2129. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2130. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2131. }).
  2132. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2133. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2134. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2135. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2136. }).
  2137. 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).
  2138. Find(&prescription).Error
  2139. return
  2140. }
  2141. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2142. err = readDb.Model(&models.HisPrescription{}).
  2143. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2144. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2145. }).
  2146. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2147. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2148. }).
  2149. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2150. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2151. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2152. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2153. }).
  2154. 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).
  2155. Find(&prescription).Error
  2156. return
  2157. }
  2158. // 已收费
  2159. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2160. err = readDb.Model(&models.HisPrescription{}).
  2161. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2162. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2163. }).
  2164. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2165. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2166. }).
  2167. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2168. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2169. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2170. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2171. }).
  2172. 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).
  2173. Find(&prescription).Error
  2174. return
  2175. }
  2176. func UpdataHisPateint(his *models.HisPatient) {
  2177. writeDb.Save(&his)
  2178. }
  2179. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2180. tx.Save(&his)
  2181. }
  2182. func SaveHisOrder(his *models.HisOrder) (err error) {
  2183. err = writeDb.Save(&his).Error
  2184. return
  2185. }
  2186. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2187. writeDb.Save(&his)
  2188. }
  2189. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2190. err = readDb.Model(&models.HisPrescription{}).
  2191. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2192. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2193. }).
  2194. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2195. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2196. }).
  2197. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2198. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2199. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2200. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2201. }).
  2202. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2203. Find(&prescription).Error
  2204. return
  2205. }
  2206. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2207. err = tx.Model(&models.HisPrescription{}).
  2208. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2209. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2210. }).
  2211. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2212. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2213. }).
  2214. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2215. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2216. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2217. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2218. }).
  2219. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2220. Find(&prescription).Error
  2221. return
  2222. }
  2223. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2224. err = tx.Model(&models.HisPrescription{}).
  2225. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2226. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2227. }).
  2228. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2229. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2230. }).
  2231. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2232. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2233. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2234. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2235. }).
  2236. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2237. Find(&prescription).Error
  2238. return
  2239. }
  2240. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2241. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2242. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2243. 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 = ? AND order_status <> 2", org_id, record_date)
  2244. })
  2245. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2246. 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
  2247. for _, item := range patients {
  2248. for _, sumItem := range item.HisPatient {
  2249. if len(sumItem.VMHisOrders) > 0 {
  2250. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2251. }
  2252. }
  2253. }
  2254. return
  2255. }
  2256. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2257. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  2258. return
  2259. }
  2260. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2261. err = readDb.Model(&models.NewHisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Preload("HisPatient", "status = 1").Find(&order).Error
  2262. var numbers []string
  2263. for _, item := range order {
  2264. numbers = append(numbers, item.Number)
  2265. }
  2266. return
  2267. }
  2268. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2269. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2270. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2271. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2272. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2273. }).Find(&order).Error
  2274. return
  2275. }
  2276. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2277. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
  2278. return
  2279. }
  2280. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2281. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
  2282. return
  2283. }
  2284. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2285. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND item_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, team_id, patient_id, record_time).First(&label).Error
  2286. return
  2287. }
  2288. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2289. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND p_project_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, p_project_id, patient_id, record_time).First(&label).Error
  2290. return
  2291. }
  2292. func DeletePrintInfo(id int64) {
  2293. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2294. }
  2295. func CreateHisLabelRecord(label *models.HisLabelPrintInfo, tx *gorm.DB) (err error) {
  2296. if err = tx.Save(&label).Error; err != nil {
  2297. tx.Rollback()
  2298. return
  2299. }
  2300. return
  2301. }
  2302. func CreateHisLabelRecordTwo(label *models.HisLabelPrintInfo) (err error) {
  2303. err = writeDb.Save(&label).Error
  2304. return
  2305. }
  2306. func DeletePsnNCDSRecordById(id int64) (err error) {
  2307. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2308. return
  2309. }
  2310. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2311. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2312. return db.Where("status = 1 AND project_id > 0").Preload("NewCustomHisPrescriptionProject", "(status = 1 and project_id = 1027 AND type = 2) OR (status = 1 AND project_id = 2036 AND type = 3)")
  2313. }).Where("user_org_id = 10138 AND settle_accounts_date >= 1638288000 AND settle_accounts_date <= 1640880000 AND order_status = 2 AND status = 1 AND (medfee_sumamt = 50 OR medfee_sumamt = 40)").Find(&order)
  2314. return
  2315. }
  2316. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2317. info := models.HisDoctorAdviceInfo{}
  2318. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2319. return info, err
  2320. }
  2321. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2322. tx := writeDb.Begin()
  2323. if err = tx.Model(&models.HisPrescription{}).Where("id in (?) AND status = 1 AND user_org_id=? AND med_type = ? AND record_date >= ? AND record_date <= ?", ids, user_org_id, old_med_type, start_time, end_time).Updates(map[string]interface{}{"med_type": med_type}).Error; err != nil {
  2324. tx.Rollback()
  2325. return
  2326. }
  2327. tx.Commit()
  2328. return
  2329. }
  2330. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2331. err = readDb.Model(&OtherDrugWarehouseInfo{}).Where("(drug_id = ? AND org_id = ? AND status = 1 and stock_max_number > 0) or (drug_id = ? AND org_id = ? AND status = 1 AND stock_min_number >0)", drug_id, org_id, drug_id, org_id).First(&info).Error
  2332. return
  2333. }
  2334. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2335. err = readDb.Model(&models.GoodSotckInfo{}).Where("stock_count > 0 and status = 1 and good_id = ? and org_id = ?", good_id, org_id).First(&info).Error
  2336. return
  2337. }
  2338. type MonthChargePatients struct {
  2339. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2340. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2341. Name string `gorm:"column:name" json:"name" form:"name"`
  2342. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2343. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2344. Number string `gorm:"column:number" json:"number" form:"number"`
  2345. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2346. }
  2347. func (MonthChargePatients) TableName() string {
  2348. return "his_patient"
  2349. }
  2350. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2351. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2352. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, start_time, end_time)
  2353. return
  2354. }
  2355. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2356. 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": 5, "mtime": time.Now().Unix()}).Error
  2357. 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": 5, "mtime": time.Now().Unix()}).Error
  2358. return
  2359. }
  2360. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2361. err = tx.Save(&order).Error
  2362. return
  2363. }
  2364. type HisOrderInfoTen struct {
  2365. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2366. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2367. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2368. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2369. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2370. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2371. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2372. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2373. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2374. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2375. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2376. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2377. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2378. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2379. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2380. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2381. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2382. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2383. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2384. }
  2385. func (HisOrderInfoTen) TableName() string {
  2386. return "his_order_info"
  2387. }
  2388. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2389. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2390. return db.Where("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)
  2391. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2392. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2393. }).Find(&order).Error
  2394. return
  2395. }
  2396. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2397. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2398. return db.Where("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)
  2399. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2400. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2401. }).Find(&order).Error
  2402. return
  2403. }
  2404. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2405. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2406. return
  2407. }
  2408. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2409. project := models.HisPrescriptionProject{}
  2410. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2411. return project, err
  2412. }
  2413. type HisOrderInfoTwo struct {
  2414. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2415. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2416. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2417. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2418. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2419. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2420. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2421. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2422. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2423. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2424. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2425. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2426. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2427. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2428. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2429. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2430. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2431. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2432. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2433. }
  2434. func (HisOrderInfoTwo) TableName() string {
  2435. return "his_order_info"
  2436. }
  2437. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2438. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2439. return db.Where("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)
  2440. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2441. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2442. }).Find(&order).Error
  2443. return
  2444. }
  2445. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2446. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2447. return db.Where("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)
  2448. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2449. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2450. }).Find(&order).Error
  2451. return
  2452. }
  2453. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2454. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2455. return
  2456. }
  2457. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2458. drug := models.XtDrugStockCount{}
  2459. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
  2460. return drug, err
  2461. }
  2462. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2463. stockCount := models.XtGoodStockCount{}
  2464. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2465. return stockCount, err
  2466. }
  2467. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2468. order := models.HisOrder{}
  2469. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2470. return order, err
  2471. }
  2472. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2473. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2474. return patient, err
  2475. }
  2476. func UpdatePatienPlan(id int64, trement_plan string) error {
  2477. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2478. return err
  2479. }
  2480. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2481. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2482. return order, err
  2483. }
  2484. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2485. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2486. return err
  2487. }
  2488. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2489. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2490. return
  2491. }
  2492. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2493. info := models.HisDoctorAdviceInfo{}
  2494. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2495. return info, err
  2496. }
  2497. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2498. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2499. return
  2500. }
  2501. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2502. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2503. return
  2504. }
  2505. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2506. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2507. return
  2508. }
  2509. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2510. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2511. return
  2512. }
  2513. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2514. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2515. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2516. 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)
  2517. })
  2518. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1 AND order_status <> 2 AND order_status <> 3 and record_date >= ? and record_date <= ?", org_id, start_date, end_date)
  2519. 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
  2520. for _, item := range patients {
  2521. for _, sumItem := range item.HisPatient {
  2522. if len(sumItem.VMHisOrders) > 0 {
  2523. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2524. }
  2525. }
  2526. }
  2527. return
  2528. }
  2529. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2530. err = readDb.Model(&models.HisOrder{}).Preload("Patients", "status = 1").Where("settle_accounts_date = ? and user_org_id = ? AND status = 1 and order_status = 2", record_date, org_id).Find(&order).Error
  2531. return
  2532. }
  2533. func GetGoodByIdIsStop(good_id int64, org_id int64) (models.GoodInfoSeven, error) {
  2534. goodInfoSeven := models.GoodInfoSeven{}
  2535. err = XTReadDB().Where("org_id = ? and status = 1 and find_in_set('停用',good_status) = 0 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2536. return goodInfoSeven, err
  2537. }
  2538. func GetHisPrescriptionByBatchNumber(org_id int64, number string) (prescription []*models.HisPrescription, err error) {
  2539. err = readDb.Model(&models.HisPrescription{}).
  2540. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2541. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2542. }).
  2543. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2544. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2545. }).
  2546. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2547. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  2548. }).
  2549. Where("user_org_id = ? AND status = 1 AND batch_number = ?", org_id, number).
  2550. Find(&prescription).Error
  2551. return
  2552. }
  2553. func GetLastHisOrderThree(org_id int64) (err error, o models.HisOrder) {
  2554. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and status = 1 and order_status = 2", org_id).First(&o).Error
  2555. return
  2556. }
  2557. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  2558. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  2559. return
  2560. }
  2561. //func GetZuoBiaoNewAllUnChargeHisPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  2562. // db := readDb.Model(&NewTempPatients{})
  2563. //
  2564. // db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2565. // db = db.Preload("Schedule", "status = 1")
  2566. // db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2567. // 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)
  2568. // })
  2569. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2570. // 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
  2571. //
  2572. // for _, item := range patients {
  2573. // for _, sumItem := range item.HisPatient {
  2574. // if len(sumItem.VMHisOrders) > 0 {
  2575. // sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2576. // }
  2577. // }
  2578. //
  2579. // }
  2580. //
  2581. // return
  2582. //}
  2583. //func GetHisPrescriptionByHisPatientID(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  2584. // err = readDb.Model(&models.HisPrescriptionTen{}).
  2585. // Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 2 and his_patient_id = 0", org_id, record_date, patient_id).
  2586. // Find(&prescription).Error
  2587. // return
  2588. //}
  2589. func GetHisPrescriptionByHisPatientID(record_date int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  2590. 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, record_date, record_date, 2).
  2591. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  2592. return db.Where("status = 1 AND user_org_id = ?", org_id).
  2593. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2594. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2595. }).
  2596. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2597. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  2598. }).Where("status = 1 and order_status = 1")
  2599. }).Order("record_date desc").Find(&advice).Error
  2600. return
  2601. }
  2602. func GetBatchHisDoctorAdviceByIDs(ids []int64) (list []*models.HisDoctorAdviceInfo, err error) {
  2603. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2604. return
  2605. }
  2606. func GetBatchHisProjectByIDs(ids []int64) (list []*models.HisPrescriptionProject, err error) {
  2607. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2608. return
  2609. }