his_service.go 211KB

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