his_service.go 205KB

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