his_service.go 205KB

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