his_service.go 201KB

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