his_api_controller.go 513KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. //if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. // advices := items["advices"].([]interface{})
  1648. //
  1649. // if len(advices) > 0 {
  1650. // for _, advice := range advices {
  1651. //
  1652. // var adviceId int64
  1653. // if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1654. // adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1655. // }
  1656. // if adviceId > 0 {
  1657. // his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1658. //
  1659. // if err == nil {
  1660. // if his_advice_info.IsMedicine == 1 {
  1661. //
  1662. // isMidicine = true
  1663. // }
  1664. // }
  1665. // }
  1666. // }
  1667. // }
  1668. //}
  1669. }
  1670. }
  1671. }
  1672. if isMidicine == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1674. return
  1675. }
  1676. if isCharge == true {
  1677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1678. return
  1679. }
  1680. // 开始主事务
  1681. db := service.XTWriteDB()
  1682. tx := db.Begin()
  1683. // 在函数结束时处理事务回滚
  1684. defer func() {
  1685. if r := recover(); r != nil {
  1686. tx.Rollback()
  1687. }
  1688. }()
  1689. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1690. //药品发药出库
  1691. if pharmacyConfig.IsOpen == 1 {
  1692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1694. if len(prescriptions) > 0 {
  1695. for _, item := range prescriptions {
  1696. items := item.(map[string]interface{})
  1697. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1698. advices := items["advices"].([]interface{})
  1699. if len(advices) > 0 {
  1700. for _, advice := range advices {
  1701. var drug_id int64
  1702. var prescribing_number float64
  1703. var prescribingNumberUnit string
  1704. var adviceId int64
  1705. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1706. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1709. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1710. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1711. }
  1712. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1713. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1714. }
  1715. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1716. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1717. }
  1718. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1719. if drug.ID == 0 {
  1720. tx.Rollback()
  1721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1722. return
  1723. }
  1724. //查询药品的所有库存
  1725. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1726. var total_count int64
  1727. for _, it := range list {
  1728. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1729. }
  1730. totals := strconv.FormatInt(total_count, 10)
  1731. //查询该药品是否存在开药记录
  1732. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1733. //新增处方盘点库存是否充足
  1734. if advicelist.ID == 0 {
  1735. all_count, _ := strconv.ParseFloat(totals, 64)
  1736. if prescribingNumberUnit == drug.MinUnit {
  1737. if drug.IsUse != 1 {
  1738. if drug.IsProject == 0 || drug.IsProject == 2 {
  1739. if all_count == 0 {
  1740. tx.Rollback()
  1741. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1742. return
  1743. }
  1744. if prescribing_number > all_count {
  1745. tx.Rollback()
  1746. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1747. return
  1748. }
  1749. }
  1750. }
  1751. }
  1752. if prescribingNumberUnit == drug.MaxUnit {
  1753. num := prescribing_number * float64(drug.MinNumber)
  1754. if drug.IsUse != 1 {
  1755. if drug.IsProject == 0 || drug.IsProject == 2 {
  1756. if all_count == 0 {
  1757. tx.Rollback()
  1758. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1759. return
  1760. }
  1761. if num > all_count {
  1762. tx.Rollback()
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1771. //不使用保存处方出库
  1772. if drugOutConfig.IsOpen != 1 {
  1773. //修改处方
  1774. for _, advice := range advices {
  1775. var drug_id int64
  1776. var prescribing_number float64
  1777. var prescribingNumberUnit string
  1778. var prescribingNumber string
  1779. var adviceId int64
  1780. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1781. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1782. }
  1783. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1784. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1785. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1786. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1787. }
  1788. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1789. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1790. }
  1791. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1792. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1793. }
  1794. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1795. if drug.ID == 0 {
  1796. tx.Rollback()
  1797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1798. return
  1799. }
  1800. //查询药品的所有库存
  1801. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1802. var total_count int64
  1803. for _, it := range list {
  1804. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1805. }
  1806. totals := strconv.FormatInt(total_count, 10)
  1807. //查询该药品是否存在开药记录
  1808. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1809. //新增处方
  1810. if advicelist.ID == 0 {
  1811. all_count, _ := strconv.ParseFloat(totals, 64)
  1812. if prescribingNumberUnit == drug.MinUnit {
  1813. if drug.IsUse != 1 {
  1814. if drug.IsProject == 0 || drug.IsProject == 2 {
  1815. if all_count == 0 {
  1816. tx.Rollback()
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1818. return
  1819. }
  1820. if prescribing_number > all_count {
  1821. tx.Rollback()
  1822. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1823. return
  1824. }
  1825. }
  1826. }
  1827. } else {
  1828. if prescribingNumberUnit == drug.MaxUnit {
  1829. num := prescribing_number * float64(drug.MinNumber)
  1830. if drug.IsUse != 1 {
  1831. if drug.IsProject == 0 || drug.IsProject == 2 {
  1832. if all_count == 0 {
  1833. tx.Rollback()
  1834. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1835. return
  1836. }
  1837. if num > all_count {
  1838. tx.Rollback()
  1839. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1840. return
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. //修改处方
  1848. if advicelist.ID > 0 {
  1849. var device_number int64
  1850. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1851. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1853. device_number = prescribingNumberInt * drug.MinNumber
  1854. }
  1855. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1856. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1857. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1858. device_number = prescribingNumberInt
  1859. }
  1860. var number_count int64
  1861. if prescribingNumberUnit == drug.MaxUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt * drug.MinNumber
  1864. }
  1865. if prescribingNumberUnit == drug.MinUnit {
  1866. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1867. number_count = prescribingNumberInt
  1868. }
  1869. //如果修改的数量大于之前修改的数量
  1870. if (number_count - device_number) > 0 {
  1871. //如果修改的差数量 大于库存数量
  1872. if drug.IsUse != 1 {
  1873. if (number_count - device_number) > total_count {
  1874. tx.Rollback()
  1875. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1876. return
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. //已发药和已收费限制逻辑
  1891. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1892. //校验库存总量
  1893. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1894. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1895. if len(prescriptions) > 0 {
  1896. for _, item := range prescriptions {
  1897. items := item.(map[string]interface{})
  1898. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1899. advices := items["advices"].([]interface{})
  1900. if len(advices) > 0 {
  1901. for _, advice := range advices {
  1902. var drug_id int64
  1903. var prescribing_number float64
  1904. var prescribingNumberUnit string
  1905. var adviceId int64
  1906. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1907. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1910. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1911. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1912. }
  1913. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1914. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1915. }
  1916. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1917. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1918. }
  1919. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1920. if drug.ID == 0 {
  1921. tx.Rollback()
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1923. return
  1924. }
  1925. //查询药品的所有库存
  1926. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1927. var total_count int64
  1928. for _, it := range list {
  1929. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1930. }
  1931. totals := strconv.FormatInt(total_count, 10)
  1932. //查询该药品是否存在开药记录
  1933. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1934. //查询最新批次库存
  1935. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1936. var batch_number_count int64
  1937. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1938. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1939. //新增处方
  1940. if advicelist.ID == 0 {
  1941. all_count, _ := strconv.ParseFloat(totals, 64)
  1942. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1943. if prescribingNumberUnit == drug.MinUnit {
  1944. if drug.IsUse != 1 {
  1945. if drug.IsProject == 0 || drug.IsProject == 2 {
  1946. if all_count == 0 {
  1947. tx.Rollback()
  1948. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1949. return
  1950. }
  1951. if prescribing_number > all_count {
  1952. tx.Rollback()
  1953. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1954. return
  1955. }
  1956. }
  1957. if adminInfo.CurrentOrgId == 10215 {
  1958. if prescribing_number > batch_number_all_count {
  1959. tx.Rollback()
  1960. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1961. return
  1962. }
  1963. }
  1964. }
  1965. }
  1966. if prescribingNumberUnit == drug.MaxUnit {
  1967. num := prescribing_number * float64(drug.MinNumber)
  1968. if drug.IsUse != 1 {
  1969. if drug.IsProject == 0 || drug.IsProject == 2 {
  1970. if all_count == 0 {
  1971. tx.Rollback()
  1972. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1973. return
  1974. }
  1975. if num > all_count {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1978. return
  1979. }
  1980. }
  1981. if adminInfo.CurrentOrgId == 10215 {
  1982. if num > batch_number_all_count {
  1983. tx.Rollback()
  1984. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1985. return
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1992. if drugOutConfig.IsOpen != 1 {
  1993. //修改处方
  1994. for _, advice := range advices {
  1995. var drug_id int64
  1996. var prescribing_number float64
  1997. var prescribingNumberUnit string
  1998. var prescribingNumber string
  1999. var adviceId int64
  2000. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2001. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2002. }
  2003. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2004. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2005. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2006. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2007. }
  2008. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2009. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2010. }
  2011. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2012. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2013. }
  2014. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2015. if drug.ID == 0 {
  2016. tx.Rollback()
  2017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2018. return
  2019. }
  2020. //查询药品的所有库存
  2021. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2022. var total_count int64
  2023. for _, it := range list {
  2024. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2025. }
  2026. totals := strconv.FormatInt(total_count, 10)
  2027. //查询该药品是否存在开药记录
  2028. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2029. //新增处方
  2030. if advicelist.ID == 0 {
  2031. //查询最新批次库存
  2032. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2033. var batch_number_count int64
  2034. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2035. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2036. all_count, _ := strconv.ParseFloat(totals, 64)
  2037. if prescribingNumberUnit == drug.MinUnit {
  2038. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2039. if drug.IsUse != 1 {
  2040. if drug.IsProject == 0 || drug.IsProject == 2 {
  2041. if all_count == 0 {
  2042. tx.Rollback()
  2043. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2044. return
  2045. }
  2046. if prescribing_number > all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2049. return
  2050. }
  2051. }
  2052. if adminInfo.CurrentOrgId == 10215 {
  2053. if prescribing_number > batch_number_all_count {
  2054. tx.Rollback()
  2055. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2056. return
  2057. }
  2058. }
  2059. }
  2060. } else {
  2061. if prescribingNumberUnit == drug.MaxUnit {
  2062. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2063. num := prescribing_number * float64(drug.MinNumber)
  2064. if drug.IsUse != 1 {
  2065. if drug.IsProject == 0 || drug.IsProject == 2 {
  2066. if all_count == 0 {
  2067. tx.Rollback()
  2068. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2069. return
  2070. }
  2071. if num > all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2074. return
  2075. }
  2076. }
  2077. if adminInfo.CurrentOrgId == 10215 {
  2078. if prescribing_number > batch_number_all_count {
  2079. tx.Rollback()
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. //修改处方
  2089. if advicelist.ID > 0 {
  2090. //查询最新批次库存
  2091. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2092. var batch_number_count int64
  2093. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2094. var device_number int64
  2095. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2096. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2097. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2098. device_number = prescribingNumberInt * drug.MinNumber
  2099. }
  2100. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2101. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2103. device_number = prescribingNumberInt
  2104. }
  2105. var number_count int64
  2106. if prescribingNumberUnit == drug.MaxUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt * drug.MinNumber
  2109. }
  2110. if prescribingNumberUnit == drug.MinUnit {
  2111. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2112. number_count = prescribingNumberInt
  2113. }
  2114. //如果修改的数量大于之前修改的数量
  2115. if (number_count - device_number) > 0 {
  2116. //如果修改的差数量 大于库存数量
  2117. if drug.IsUse != 1 {
  2118. if drug.IsProject == 0 || drug.IsProject == 2 {
  2119. if total_count == 0 {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > total_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2127. return
  2128. }
  2129. if (number_count - device_number) > batch_number_count {
  2130. tx.Rollback()
  2131. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2132. return
  2133. }
  2134. }
  2135. if adminInfo.CurrentOrgId == 10215 {
  2136. // 查询该药品最后一次出库记录
  2137. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2138. var out_count int64
  2139. var in_count int64
  2140. var stock_max_number int64
  2141. var stock_min_number int64
  2142. for _, it := range outInfo {
  2143. if it.CountUnit == drug.MaxUnit {
  2144. it.Count = it.Count * drug.MinNumber
  2145. }
  2146. out_count += it.Count
  2147. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2148. stock_max_number = warehouseInfoList.StockMaxNumber
  2149. stock_min_number = warehouseInfoList.StockMinNumber
  2150. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2151. }
  2152. if out_count > 0 {
  2153. if (number_count - device_number) > in_count {
  2154. tx.Rollback()
  2155. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2156. return
  2157. }
  2158. }
  2159. // 未出库
  2160. if out_count == 0 {
  2161. var sum_in_count int64
  2162. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2163. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2164. fmt.Println("sum_in_count", sum_in_count)
  2165. //如果修改的数量大于有库存的第一个批次
  2166. if number_count > sum_in_count {
  2167. tx.Rollback()
  2168. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2169. return
  2170. }
  2171. }
  2172. }
  2173. }
  2174. }
  2175. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2176. if pharmacyConfig.IsOpen != 1 {
  2177. if device_number != number_count {
  2178. // 查询该药品最后一次出库记录
  2179. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2180. //回退库存
  2181. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2183. }
  2184. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. var stock_max_number int64
  2186. var stock_min_number int64
  2187. if number_count >= drug.MinNumber {
  2188. stock_max_number = device_number / drug.MinNumber
  2189. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2190. stock_min_number = device_number % drug.MinNumber
  2191. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2192. } else {
  2193. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. }
  2196. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2197. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2198. }
  2199. //删除记录
  2200. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2201. //查询默认仓库剩余多少库存
  2202. var sum_count int64
  2203. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2204. for _, its := range stockInfo {
  2205. if its.MaxUnit == drug.MaxUnit {
  2206. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2207. }
  2208. sum_count += its.StockMaxNumber + its.StockMinNumber
  2209. }
  2210. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2211. }
  2212. }
  2213. }
  2214. }
  2215. }
  2216. //保存处方开药
  2217. if drugOutConfig.IsOpen == 1 {
  2218. //修改处方
  2219. for _, advice := range advices {
  2220. var drug_id int64
  2221. var prescribing_number float64
  2222. var prescribingNumberUnit string
  2223. var prescribingNumber string
  2224. var adviceId int64
  2225. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2226. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2227. }
  2228. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2229. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2230. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2231. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2232. }
  2233. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2234. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2235. }
  2236. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2237. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2238. }
  2239. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2240. if drug.ID == 0 {
  2241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2242. return
  2243. }
  2244. //查询药品的所有库存
  2245. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2246. var total_count int64
  2247. for _, it := range list {
  2248. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2249. }
  2250. totals := strconv.FormatInt(total_count, 10)
  2251. //查询该药品是否存在开药记录
  2252. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2253. //新增处方
  2254. if advicelist.ID == 0 {
  2255. //查询最新批次库存
  2256. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2257. var batch_number_count int64
  2258. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2259. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2260. all_count, _ := strconv.ParseFloat(totals, 64)
  2261. if prescribingNumberUnit == drug.MinUnit {
  2262. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2263. if drug.IsUse != 1 {
  2264. if drug.IsProject == 0 || drug.IsProject == 2 {
  2265. if all_count == 0 {
  2266. tx.Rollback()
  2267. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2268. return
  2269. }
  2270. if prescribing_number > all_count {
  2271. tx.Rollback()
  2272. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2273. return
  2274. }
  2275. }
  2276. if adminInfo.CurrentOrgId == 10215 {
  2277. if prescribing_number > batch_number_all_count {
  2278. tx.Rollback()
  2279. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2280. return
  2281. }
  2282. }
  2283. }
  2284. } else {
  2285. if prescribingNumberUnit == drug.MaxUnit {
  2286. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2287. num := prescribing_number * float64(drug.MinNumber)
  2288. if drug.IsUse != 1 {
  2289. if drug.IsProject == 0 || drug.IsProject == 2 {
  2290. if all_count == 0 {
  2291. tx.Rollback()
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if num > all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if prescribing_number > batch_number_all_count {
  2303. tx.Rollback()
  2304. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2305. return
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. //修改处方
  2313. if advicelist.ID > 0 {
  2314. //查询最新批次库存
  2315. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2316. var batch_number_count int64
  2317. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2318. var device_number int64
  2319. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2320. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2321. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2322. device_number = prescribingNumberInt * drug.MinNumber
  2323. }
  2324. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2325. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2326. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2327. device_number = prescribingNumberInt
  2328. }
  2329. var number_count int64
  2330. if prescribingNumberUnit == drug.MaxUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt * drug.MinNumber
  2333. }
  2334. if prescribingNumberUnit == drug.MinUnit {
  2335. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2336. number_count = prescribingNumberInt
  2337. }
  2338. fmt.Println("number_count--------------", number_count)
  2339. fmt.Println("device_number--------------", device_number)
  2340. fmt.Println("batch_number_count", batch_number_count)
  2341. //如果修改的数量大于之前修改的数量
  2342. if (number_count - device_number) > 0 {
  2343. //如果修改的差数量 大于库存数量
  2344. if drug.IsUse != 1 {
  2345. if drug.IsProject == 0 || drug.IsProject == 2 {
  2346. if total_count == 0 {
  2347. tx.Rollback()
  2348. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2349. return
  2350. }
  2351. if (number_count - device_number) > total_count {
  2352. tx.Rollback()
  2353. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2354. return
  2355. }
  2356. }
  2357. if adminInfo.CurrentOrgId == 10215 {
  2358. if (number_count - device_number) > batch_number_count {
  2359. tx.Rollback()
  2360. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2361. return
  2362. }
  2363. }
  2364. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2365. //查询历史出库数据总批次
  2366. // 查询该药品最后一次出库记录
  2367. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2368. var out_count int64
  2369. var in_count int64
  2370. var stock_max_number int64
  2371. var stock_min_number int64
  2372. for _, it := range outInfo {
  2373. if it.CountUnit == drug.MaxUnit {
  2374. it.Count = it.Count * drug.MinNumber
  2375. }
  2376. out_count += it.Count
  2377. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2378. stock_max_number = warehouseInfoList.StockMaxNumber
  2379. stock_min_number = warehouseInfoList.StockMinNumber
  2380. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2381. }
  2382. if out_count > 0 {
  2383. if (number_count - device_number) > in_count {
  2384. tx.Rollback()
  2385. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2386. return
  2387. }
  2388. }
  2389. // 未出库
  2390. if out_count == 0 {
  2391. var sum_in_count int64
  2392. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2393. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2394. if sum_in_count == 0 {
  2395. tx.Rollback()
  2396. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2397. return
  2398. }
  2399. //如果修改的数量大于有库存的第一个批次
  2400. if number_count > sum_in_count {
  2401. tx.Rollback()
  2402. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2403. return
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }
  2416. }
  2417. }
  2418. }
  2419. //校验耗材库存
  2420. if goodOutConfig.IsOpen == 1 {
  2421. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2422. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2423. if len(prescriptions) > 0 {
  2424. for _, item := range prescriptions {
  2425. items := item.(map[string]interface{})
  2426. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2427. projects := items["project"].([]interface{})
  2428. if len(projects) > 0 {
  2429. for _, project := range projects {
  2430. var project_id int64
  2431. var project_type int64
  2432. var totals float64
  2433. var project_name string
  2434. var parsetotal int64
  2435. var id int64
  2436. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2437. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2438. }
  2439. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2440. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2441. }
  2442. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2443. total, _ := project.(map[string]interface{})["total"].(string)
  2444. totals, _ = strconv.ParseFloat(total, 64)
  2445. }
  2446. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2447. project_name = project.(map[string]interface{})["project_name"].(string)
  2448. }
  2449. if project_type == 3 {
  2450. //查找该耗材的出库记录
  2451. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2452. if len(goodWarehouseInfo) == 0 {
  2453. //查询耗材库存
  2454. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2455. var stock_count int64
  2456. for _, it := range list {
  2457. stock_count += it.StockCount
  2458. }
  2459. stock_counts := strconv.FormatInt(stock_count, 10)
  2460. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2461. if stock_total_count == 0 {
  2462. tx.Rollback()
  2463. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2464. return
  2465. }
  2466. if totals > stock_total_count {
  2467. tx.Rollback()
  2468. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2469. return
  2470. }
  2471. }
  2472. if len(goodWarehouseInfo) > 0 {
  2473. //查询该患者耗材的历史数据
  2474. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2475. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2476. //数量发生改变
  2477. if parsetotal != count {
  2478. //如果现在的数量大于历史数量,就要看库存是否足够
  2479. if parsetotal > count {
  2480. //查询耗材所有库存
  2481. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2482. var stock_count int64
  2483. for _, it := range list {
  2484. stock_count += it.StockCount
  2485. }
  2486. //库存不足
  2487. if stock_count == 0 {
  2488. tx.Rollback()
  2489. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2490. return
  2491. }
  2492. if (parsetotal - count) > stock_count {
  2493. tx.Rollback()
  2494. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2495. return
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. }
  2507. }
  2508. //不使用耗材保存处方出库
  2509. if goodOutConfig.IsOpen != 1 {
  2510. if stockConfig.IsOpen == 1 {
  2511. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2512. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2513. if len(prescriptions) > 0 {
  2514. for _, item := range prescriptions {
  2515. items := item.(map[string]interface{})
  2516. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2517. projects := items["project"].([]interface{})
  2518. if len(projects) > 0 {
  2519. for _, project := range projects {
  2520. var project_id int64
  2521. var project_type int64
  2522. var totals float64
  2523. var project_name string
  2524. var parsetotal int64
  2525. var id int64
  2526. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2527. id = int64(project.(map[string]interface{})["id"].(float64))
  2528. }
  2529. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2530. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2531. }
  2532. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2533. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2534. }
  2535. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2536. total, _ := project.(map[string]interface{})["total"].(string)
  2537. totals, _ = strconv.ParseFloat(total, 64)
  2538. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2539. }
  2540. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2541. project_name = project.(map[string]interface{})["project_name"].(string)
  2542. }
  2543. if project_type == 3 {
  2544. //查找该耗材的出库记录
  2545. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2546. //没有出库记录
  2547. if len(goodWarehouseInfo) == 0 {
  2548. //查询耗材库存
  2549. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2550. var stock_count int64
  2551. for _, it := range list {
  2552. stock_count += it.StockCount
  2553. }
  2554. stock_counts := strconv.FormatInt(stock_count, 10)
  2555. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2556. if stock_total_count == 0 {
  2557. tx.Rollback()
  2558. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2559. return
  2560. }
  2561. if totals > stock_total_count {
  2562. tx.Rollback()
  2563. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2564. return
  2565. }
  2566. //查找今日该患者已经出库的所有耗材
  2567. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2568. for _, item := range goodList {
  2569. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2570. var flush_count int64
  2571. for _, it := range goodListSix {
  2572. flush_count += it.StockCount
  2573. }
  2574. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2575. creater := adminInfo.AdminUser.Id
  2576. if errs != nil {
  2577. goodErrcode := models.XtGoodErrcode{
  2578. UserOrgId: item.OrgId,
  2579. Errcode: "手动出库更新剩余出库失败",
  2580. GoodId: item.GoodId,
  2581. Status: 1,
  2582. Ctime: time.Now().Unix(),
  2583. Mtime: 0,
  2584. Count: 0,
  2585. StockCount: 0,
  2586. Creater: creater,
  2587. BatchNumberId: 0,
  2588. WarehouseOutId: 0,
  2589. }
  2590. service.CreateGoodErrcode(goodErrcode)
  2591. }
  2592. }
  2593. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2594. }
  2595. //有出库记录
  2596. if len(goodWarehouseInfo) > 0 {
  2597. //查询该患者耗材的历史数据
  2598. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2599. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2600. //数量发生改变
  2601. if parsetotal != count {
  2602. //查找今日该患者已经出库的所有耗材
  2603. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2604. for _, item := range goodList {
  2605. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2606. var flush_count int64
  2607. for _, it := range goodListSix {
  2608. flush_count += it.StockCount
  2609. }
  2610. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2611. //减少出库数量
  2612. creater := adminInfo.AdminUser.Id
  2613. if errs != nil {
  2614. goodErrcode := models.XtGoodErrcode{
  2615. UserOrgId: item.OrgId,
  2616. Errcode: "手动出库更新剩余出库失败",
  2617. GoodId: item.GoodId,
  2618. Status: 1,
  2619. Ctime: time.Now().Unix(),
  2620. Mtime: 0,
  2621. Count: 0,
  2622. StockCount: 0,
  2623. Creater: creater,
  2624. BatchNumberId: 0,
  2625. WarehouseOutId: 0,
  2626. }
  2627. service.CreateGoodErrcode(goodErrcode)
  2628. }
  2629. //查询默认仓库
  2630. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2631. var total_count int64
  2632. for _, it := range stockList {
  2633. total_count += it.StockCount
  2634. }
  2635. //基础库插入数据
  2636. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2637. }
  2638. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. }
  2647. }
  2648. }
  2649. }
  2650. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2651. var hpInfo models.HisPrescriptionInfo
  2652. if info.ID == 0 {
  2653. var randNum int
  2654. randNum = rand.Intn(10000) + 1000
  2655. timestamp := time.Now().Unix()
  2656. tempTime := time.Unix(timestamp, 0)
  2657. timeFormat := tempTime.Format("20060102150405")
  2658. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2659. hpInfo = models.HisPrescriptionInfo{
  2660. HisPatientId: his_patient_id,
  2661. UserOrgId: adminInfo.CurrentOrgId,
  2662. RecordDate: theTime.Unix(),
  2663. PatientId: patient_id,
  2664. Status: 1,
  2665. Ctime: time.Now().Unix(),
  2666. Mtime: time.Now().Unix(),
  2667. Creator: adminInfo.AdminUser.Id,
  2668. Modifier: adminInfo.AdminUser.Id,
  2669. Diagnosis: diagnose,
  2670. SickHistory: sick_history,
  2671. Departments: department,
  2672. RegisterType: reg_type,
  2673. PrescriptionNumber: p_number,
  2674. PrescriptionStatus: 1,
  2675. Doctor: role.UserName,
  2676. DoctorId: doctor_id,
  2677. SickType: sick_type,
  2678. PType: p_type,
  2679. PatientDiagnosis: patient_diagnose,
  2680. }
  2681. service.SavePatientPrescriptionInfo(hpInfo)
  2682. //创建步骤表
  2683. finish := models.XtDialysisFinish{
  2684. IsFinish: 1,
  2685. UserOrgId: adminInfo.CurrentOrgId,
  2686. Status: 1,
  2687. Ctime: time.Now().Unix(),
  2688. Mtime: 0,
  2689. Module: 4,
  2690. RecordDate: theTime.Unix(),
  2691. Sourse: 1,
  2692. PatientId: patient_id,
  2693. }
  2694. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2695. if dialysisFinish.ID == 0 {
  2696. service.CreateDialysisFinish(finish)
  2697. }
  2698. redis := service.RedisClient()
  2699. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2700. redis.Set(key, "", time.Second)
  2701. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2702. redis.Set(keyOne, "", time.Second)
  2703. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2704. redis.Set(keySeven, "", time.Second)
  2705. defer redis.Close()
  2706. } else {
  2707. hpInfo = models.HisPrescriptionInfo{
  2708. ID: info.ID,
  2709. UserOrgId: adminInfo.CurrentOrgId,
  2710. RecordDate: info.RecordDate,
  2711. PatientId: info.PatientId,
  2712. Status: 1,
  2713. Ctime: info.Ctime,
  2714. Mtime: time.Now().Unix(),
  2715. Creator: info.Creator,
  2716. Modifier: adminInfo.AdminUser.Id,
  2717. Diagnosis: diagnose,
  2718. SickHistory: sick_history,
  2719. Departments: department,
  2720. RegisterType: reg_type,
  2721. PrescriptionNumber: info.PrescriptionNumber,
  2722. Doctor: role.UserName,
  2723. PrescriptionStatus: info.PrescriptionStatus,
  2724. DoctorId: doctor_id,
  2725. SickType: sick_type,
  2726. PType: info.PType,
  2727. HisPatientId: info.HisPatientId,
  2728. PatientDiagnosis: patient_diagnose,
  2729. }
  2730. service.SavePatientPrescriptionInfo(hpInfo)
  2731. //创建步骤表
  2732. finish := models.XtDialysisFinish{
  2733. IsFinish: 1,
  2734. UserOrgId: adminInfo.CurrentOrgId,
  2735. Status: 1,
  2736. Ctime: time.Now().Unix(),
  2737. Mtime: 0,
  2738. Module: 4,
  2739. RecordDate: info.RecordDate,
  2740. Sourse: 1,
  2741. PatientId: info.PatientId,
  2742. }
  2743. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2744. if dialysisFinish.ID == 0 {
  2745. service.CreateDialysisFinish(finish)
  2746. }
  2747. redis := service.RedisClient()
  2748. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(key, "", time.Second)
  2750. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyOne, "", time.Second)
  2752. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keySeven, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. //定义切片
  2757. var adviceList []models.HisDoctorAdviceInfo
  2758. var projectList []models.HisPrescriptionProject
  2759. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 {
  2760. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2761. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2762. var tempPrescription *models.HisPrescription
  2763. if len(prescriptions) > 0 {
  2764. for _, item := range prescriptions {
  2765. // 开始外部循环的事务
  2766. tx := db.Begin()
  2767. // 在函数结束时处理事务回滚
  2768. defer func() {
  2769. if r := recover(); r != nil {
  2770. tx.Rollback()
  2771. }
  2772. }()
  2773. items := item.(map[string]interface{})
  2774. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2775. utils.ErrorLog("id")
  2776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2777. return
  2778. }
  2779. id := int64(items["id"].(float64))
  2780. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2781. tempPrescription = &new_prescription
  2782. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2783. utils.ErrorLog("type")
  2784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2785. return
  2786. }
  2787. types := int64(items["type"].(float64))
  2788. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2789. utils.ErrorLog("med_type")
  2790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2791. return
  2792. }
  2793. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2794. if med_type == "0" {
  2795. med_type = "14"
  2796. }
  2797. //if order_status == 0 {
  2798. // order_status = 1
  2799. //}
  2800. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2801. utils.ErrorLog("pre_time")
  2802. }
  2803. preTime, _ := items["pre_time"].(string)
  2804. fmt.Println("preTime", preTime)
  2805. timeLayout := "2006-01-02"
  2806. loc, _ := time.LoadLocation("Local")
  2807. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2808. result := strings.Split(preTime, " ")
  2809. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2810. if err != nil {
  2811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2812. return
  2813. }
  2814. pTime := theTime2.Unix()
  2815. ctime := time.Now().Unix()
  2816. if tempPrescription.ID == 0 {
  2817. prescription := &models.HisPrescription{
  2818. ID: 0,
  2819. PatientId: patient_id,
  2820. UserOrgId: adminInfo.CurrentOrgId,
  2821. RecordDate: recordDateTime,
  2822. Ctime: ctime,
  2823. Mtime: ctime,
  2824. Type: types,
  2825. Modifier: adminInfo.AdminUser.Id,
  2826. Creator: adminInfo.AdminUser.Id,
  2827. Status: 1,
  2828. Doctor: role.UserName,
  2829. HisPatientId: his_patient_id,
  2830. OrderStatus: 1,
  2831. BatchNumber: "",
  2832. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2833. PreTime: pTime,
  2834. PType: p_type,
  2835. MedType: med_type,
  2836. }
  2837. tempPrescription = prescription
  2838. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2839. redis := service.RedisClient()
  2840. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2841. redis.Set(key, "", time.Second)
  2842. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2843. redis.Set(keyOne, "", time.Second)
  2844. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2845. redis.Set(keySeven, "", time.Second)
  2846. defer redis.Close()
  2847. } else {
  2848. tempPrescription.ID = id
  2849. tempPrescription.Type = types
  2850. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2851. tempPrescription.Mtime = time.Now().Unix()
  2852. tempPrescription.Doctor = role.UserName
  2853. //tempPrescription.OrderStatus = order_status
  2854. tempPrescription.PreTime = pTime
  2855. tempPrescription.MedType = med_type
  2856. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2857. redis := service.RedisClient()
  2858. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2859. redis.Set(key, "", time.Second)
  2860. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2861. redis.Set(keyOne, "", time.Second)
  2862. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2863. redis.Set(keySeven, "", time.Second)
  2864. defer redis.Close()
  2865. }
  2866. //service.SaveHisPrescription(prescription)
  2867. //更改患者挂号状态
  2868. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2869. fmt.Println("更改失败", err2)
  2870. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2871. advices := items["advices"].([]interface{})
  2872. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2873. groupNo := int64(0)
  2874. if len(advices) > 0 {
  2875. for _, advice := range advices {
  2876. tx := db.Begin()
  2877. // 在函数结束时处理事务回滚
  2878. defer func() {
  2879. if r := recover(); r != nil {
  2880. tx.Rollback()
  2881. }
  2882. }()
  2883. var s models.HisDoctorAdviceInfo
  2884. s.PrescriptionId = tempPrescription.ID
  2885. s.AdviceType = 2
  2886. s.AdviceDoctor = doctor_id
  2887. s.StopState = 2
  2888. s.ExecutionState = 2
  2889. s.AdviceDate = theTime3.Unix()
  2890. s.Status = 1
  2891. s.UserOrgId = adminInfo.CurrentOrgId
  2892. s.RecordDate = theTime3.Unix()
  2893. s.StartTime = tempPrescription.PreTime
  2894. s.Groupno = groupNo
  2895. s.PatientId = patient_id
  2896. s.HisPatientId = his_patient_id
  2897. s.StartTime = pTime
  2898. s.IsSettle = 2
  2899. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2900. if errcode > 0 {
  2901. c.ServeFailJSONWithSGJErrorCode(errcode)
  2902. return
  2903. }
  2904. s.StartTime = pTime
  2905. var total_count int64 //处方总库存
  2906. //查询改药品信息
  2907. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2908. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2909. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2910. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2911. total_count += prescribingNumberSeven * medical.MinNumber
  2912. }
  2913. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2914. total_count += prescribingNumberSeven
  2915. }
  2916. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2917. total_count += prescribingNumberSeven
  2918. }
  2919. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2920. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2921. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2922. if s.Price != lastWarehouse.RetailPrice {
  2923. s.Price = lastWarehouse.RetailPrice
  2924. }
  2925. if s.Price == 0 {
  2926. if lastWarehouse.ID == 0 {
  2927. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2928. s.Price = lastWarehouseTwo.RetailPrice
  2929. }
  2930. }
  2931. }
  2932. //查询保存处方出库开关是否打开
  2933. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2934. if s.PatientId != 30038 {
  2935. if drugOutConfig.IsOpen == 1 {
  2936. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2937. // 查询该药品最后一次出库记录
  2938. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2939. var is_user_total int64
  2940. var no_user_total int64
  2941. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2942. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2943. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2944. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2945. }
  2946. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2947. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2948. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2949. no_user_total += prescribingNumberSevenTy
  2950. }
  2951. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2952. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2953. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2954. no_user_total += prescribingNumberSevenTy
  2955. }
  2956. if len(druginfo) > 0 {
  2957. for _, it := range druginfo {
  2958. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2959. it.Count = it.Count * drug.MinNumber
  2960. is_user_total += it.Count
  2961. }
  2962. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. is_user_total += it.Count
  2964. }
  2965. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2966. is_user_total += it.Count
  2967. }
  2968. }
  2969. }
  2970. if is_user_total != no_user_total {
  2971. //出库
  2972. if drug.IsUse == 2 {
  2973. creater := adminInfo.AdminUser.Id
  2974. newadviceInfo := &models.HisDoctorAdviceInfo{
  2975. ID: s.ID,
  2976. UserOrgId: s.UserOrgId,
  2977. PatientId: s.PatientId,
  2978. HisPatientId: s.HisPatientId,
  2979. AdviceType: s.AdviceType,
  2980. AdviceDate: s.AdviceDate,
  2981. StartTime: s.StartTime,
  2982. AdviceName: s.AdviceName,
  2983. AdviceDesc: s.AdviceDesc,
  2984. ReminderDate: s.ReminderDate,
  2985. SingleDose: s.SingleDose,
  2986. SingleDoseUnit: s.SingleDoseUnit,
  2987. PrescribingNumber: s.PrescribingNumber,
  2988. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2989. DeliveryWay: s.DeliveryWay,
  2990. ExecutionFrequency: s.ExecutionFrequency,
  2991. AdviceDoctor: s.AdviceDoctor,
  2992. Status: s.Status,
  2993. CreatedTime: s.CreatedTime,
  2994. UpdatedTime: s.UpdatedTime,
  2995. AdviceAffirm: s.AdviceAffirm,
  2996. Remark: s.Remark,
  2997. StopTime: s.StopTime,
  2998. StopReason: s.StopReason,
  2999. StopDoctor: s.StopDoctor,
  3000. StopState: s.StopState,
  3001. ParentId: s.ParentId,
  3002. ExecutionTime: s.ExecutionTime,
  3003. ExecutionStaff: s.ExecutionStaff,
  3004. ExecutionState: s.ExecutionState,
  3005. Checker: s.Checker,
  3006. RecordDate: s.RecordDate,
  3007. DialysisOrderId: s.DialysisOrderId,
  3008. CheckTime: s.CheckTime,
  3009. CheckState: s.CheckState,
  3010. DrugSpec: s.DrugSpec,
  3011. DrugSpecUnit: s.DrugSpecUnit,
  3012. Groupno: s.Groupno,
  3013. RemindType: s.RemindType,
  3014. FrequencyType: s.FrequencyType,
  3015. DayCount: s.DayCount,
  3016. WeekDay: s.WeekDay,
  3017. TemplateId: s.TemplateId,
  3018. Modifier: s.Modifier,
  3019. DrugId: s.DrugId,
  3020. Price: s.Price,
  3021. PrescriptionId: s.PrescriptionId,
  3022. MedListCodg: s.MedListCodg,
  3023. FeedetlSn: s.FeedetlSn,
  3024. Day: s.DayCount,
  3025. ChildDoctorAdvice: nil,
  3026. Drug: models.Drug{},
  3027. Diagnosis: s.Diagnosis,
  3028. Way: s.Way,
  3029. HospApprFlag: s.HospApprFlag,
  3030. LmtUsedFlag: s.LmtUsedFlag,
  3031. HisOrderInfo: models.HisOrderInfo{},
  3032. IsMedicine: s.IsMedicine,
  3033. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3034. Child: nil,
  3035. IsSettle: s.IsSettle,
  3036. IsMobile: s.IsMobile,
  3037. IsSelfDrug: s.IsSelfDrug,
  3038. DrugWayCount: s.DrugWayCount,
  3039. }
  3040. var history_count int64
  3041. var local_count int64
  3042. //查找已经开过的医嘱信息
  3043. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3044. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3045. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3046. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3047. local_count += prescribingNumberSevenTy * drug.MinNumber
  3048. }
  3049. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3050. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3051. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3052. local_count += prescribingNumberSevenTy
  3053. }
  3054. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3055. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3056. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3057. local_count += prescribingNumberSevenTy
  3058. }
  3059. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3060. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3061. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3062. history_count += prescribingNumberSevenTy * drug.MinNumber
  3063. }
  3064. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. history_count += prescribingNumberSevenTy
  3068. }
  3069. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. history_count += prescribingNumberSevenTy
  3073. }
  3074. //fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
  3075. //
  3076. //fmt.Println("history_count999999999999999999999999999999999999999", history_count)
  3077. //如果当前出库数量大于历史出库数量则需要出库
  3078. if local_count > history_count {
  3079. //按最小单位出库
  3080. var cha_count = local_count - history_count
  3081. //fmt.Println("cha_count000000000000000000000000000", cha_count)
  3082. newadviceInfo.PrescribingNumber = float64(cha_count)
  3083. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3084. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3085. }
  3086. //如果当前出库数量小于历史出库数量则需要退库
  3087. if local_count < history_count {
  3088. var cha_count = history_count - local_count
  3089. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3090. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3091. }
  3092. }
  3093. //更新字典里面的库存
  3094. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3095. var sum_count int64
  3096. for _, its := range stockInfo {
  3097. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3098. if its.MaxUnit == baseDrug.MaxUnit {
  3099. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3100. }
  3101. sum_count += its.StockMaxNumber + its.StockMinNumber
  3102. }
  3103. //更新基础库存
  3104. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3105. //剩余库存
  3106. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3107. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3108. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3109. //创建医嘱
  3110. service.CreateHisDoctorAdviceOne(&s, tx)
  3111. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3112. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3113. if len(outInfoTwo) > 0 {
  3114. for _, item := range outInfoTwo {
  3115. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3116. }
  3117. }
  3118. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3119. if len(drugAutoDetail) > 0 {
  3120. for _, item := range drugAutoDetail {
  3121. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3122. }
  3123. }
  3124. }
  3125. }
  3126. }
  3127. //记录日志
  3128. byterequest, _ := json.Marshal(s)
  3129. adviceLog := models.XtDoctorAdviceLog{
  3130. UserOrgId: s.UserOrgId,
  3131. PatientId: s.PatientId,
  3132. AdminUserId: adminInfo.AdminUser.Id,
  3133. Module: 1,
  3134. ErrLog: string(byterequest),
  3135. Status: 1,
  3136. Ctime: time.Now().Unix(),
  3137. Mtime: 0,
  3138. Source: "电脑端新建his医嘱",
  3139. RecordDate: s.AdviceDate,
  3140. }
  3141. service.CreateDoctorAdviceLog(adviceLog)
  3142. //存储切片中
  3143. adviceList = append(adviceList, s)
  3144. redis := service.RedisClient()
  3145. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3146. redis.Set(key, "", time.Second)
  3147. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3148. redis.Set(keyOne, "", time.Second)
  3149. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3150. redis.Set(keySeven, "", time.Second)
  3151. var randNum int
  3152. randNum = rand.Intn(10000) + 1000
  3153. timestamp := time.Now().Unix()
  3154. tempTime := time.Unix(timestamp, 0)
  3155. timeFormat := tempTime.Format("20060102150405")
  3156. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3157. //查询改药品是否已经停用
  3158. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3159. if base.ID > 0 {
  3160. tx.Rollback()
  3161. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3162. return
  3163. }
  3164. service.CreateHisDoctorAdviceOne(&s, tx)
  3165. tx.Commit()
  3166. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(keySix, "", time.Second)
  3168. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyFive, "", time.Second)
  3170. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keyEight, "", time.Second)
  3172. defer redis.Close()
  3173. }
  3174. }
  3175. }
  3176. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3177. projects := items["project"].([]interface{})
  3178. if len(projects) > 0 {
  3179. for _, project := range projects {
  3180. tx := db.Begin()
  3181. // 在函数结束时处理事务回滚
  3182. defer func() {
  3183. if r := recover(); r != nil {
  3184. tx.Rollback()
  3185. }
  3186. }()
  3187. var p models.HisPrescriptionProject
  3188. p.PrescriptionId = tempPrescription.ID
  3189. p.PatientId = patient_id
  3190. p.RecordDate = theTime3.Unix()
  3191. p.Doctor = doctor_id
  3192. p.UserOrgId = adminInfo.CurrentOrgId
  3193. p.HisPatientId = his_patient_id
  3194. p.Status = 1
  3195. p.StartTime = pTime
  3196. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3197. if errcode > 0 {
  3198. c.ServeFailJSONWithSGJErrorCode(errcode)
  3199. return
  3200. }
  3201. if p.ID == 0 {
  3202. p.IsOut = 2
  3203. }
  3204. if p.ID > 0 {
  3205. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3206. p.IsOut = projectDetail.IsOut
  3207. }
  3208. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3209. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3210. if p.Type == 3 {
  3211. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3212. if p.Price != lastWarehouse.PackingPrice {
  3213. p.Price = lastWarehouse.PackingPrice
  3214. }
  3215. if p.Price == 0 {
  3216. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3217. p.Price = lastWarehouseTwo.PackingPrice
  3218. }
  3219. if p.Unit == "" {
  3220. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3221. p.Unit = goodInfoOne.PackingUnit
  3222. }
  3223. }
  3224. }
  3225. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3226. //
  3227. // if p.Type == 3 {
  3228. // //查询该耗材是否停用
  3229. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3230. // //表示该耗材已经停用,不能保存
  3231. // if goodInfoSeven.ID == 0 {
  3232. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3233. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3234. // return
  3235. // }
  3236. // }
  3237. //
  3238. //}
  3239. //查询保存耗材出库开关是否打开
  3240. if p.PatientId != 30038 {
  3241. if goodOutConfig.IsOpen == 1 {
  3242. //耗材出库
  3243. if p.Type == 3 {
  3244. //对比当前数据和历史出库数据
  3245. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3246. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3247. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3248. //如果当前处方数量大于历史数据,则需要出库
  3249. if nowCount > historyCount {
  3250. var cha_count int64
  3251. cha_count = nowCount - historyCount
  3252. timeStr := time.Now().Format("2006-01-02")
  3253. timeArr := strings.Split(timeStr, "-")
  3254. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3255. total = total + 1
  3256. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3257. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3258. number = number + total
  3259. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3260. operation_time := time.Now().Unix()
  3261. creater := c.GetAdminUserInfo().AdminUser.Id
  3262. recordDateStr := time.Now().Format("2006-01-02")
  3263. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3264. nowtime := recordDate.Unix()
  3265. warehouseOut := models.WarehouseOut{
  3266. WarehouseOutOrderNumber: warehousing_out_order,
  3267. OperationTime: operation_time,
  3268. OrgId: adminInfo.CurrentOrgId,
  3269. Creater: creater,
  3270. Ctime: time.Now().Unix(),
  3271. Status: 1,
  3272. WarehouseOutTime: nowtime,
  3273. Type: 1,
  3274. StorehouseId: storeConfig.StorehouseOutInfo,
  3275. IsCheck: 1,
  3276. IsSys: 1,
  3277. }
  3278. //查询是否生成出库单
  3279. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3280. if out.ID == 0 {
  3281. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3282. }
  3283. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3284. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3285. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3286. dialyPrepareOne := models.DialysisBeforePrepare{
  3287. GoodTypeId: goodObj.GoodTypeId,
  3288. GoodId: p.ProjectId,
  3289. PatientId: p.PatientId,
  3290. RecordDate: p.RecordDate,
  3291. UserOrgId: adminInfo.CurrentOrgId,
  3292. Count: cha_count,
  3293. Ctime: time.Now().Unix(),
  3294. Creater: creater,
  3295. Status: 1,
  3296. StorehouseId: houseConfig.StorehouseOutInfo,
  3297. ProjectId: p.ID,
  3298. }
  3299. //出库
  3300. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3301. }
  3302. //如果当前处方数量小于历史数据,怎需要退库
  3303. if nowCount < historyCount {
  3304. var cha_count int64
  3305. cha_count = historyCount - nowCount
  3306. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3307. creater := c.GetAdminUserInfo().AdminUser.Id
  3308. newPrescriptionProject := &models.HisPrescriptionProject{
  3309. ID: p.ID,
  3310. ProjectId: p.ProjectId,
  3311. Price: p.Price,
  3312. UserOrgId: p.UserOrgId,
  3313. Status: 1,
  3314. Ctime: time.Now().Unix(),
  3315. Mtime: time.Now().Unix(),
  3316. PatientId: p.PatientId,
  3317. HisPatientId: p.HisPatientId,
  3318. RecordDate: p.RecordDate,
  3319. PrescriptionId: p.PrescriptionId,
  3320. Count: p.Count,
  3321. FeedetlSn: p.FeedetlSn,
  3322. MedListCodg: p.MedListCodg,
  3323. SingleDose: p.SingleDose,
  3324. DeliveryWay: p.DeliveryWay,
  3325. ExecutionFrequency: p.ExecutionFrequency,
  3326. Day: p.Day,
  3327. HisProject: models.HisProject{},
  3328. GoodInfo: models.GoodInfo{},
  3329. Remark: p.Remark,
  3330. Unit: p.Unit,
  3331. Type: p.Type,
  3332. Doctor: p.Doctor,
  3333. ExecutionTime: p.ExecutionTime,
  3334. ExecutionStaff: p.ExecutionStaff,
  3335. ExecutionState: p.ExecutionState,
  3336. CheckTime: p.CheckTime,
  3337. CheckState: p.CheckState,
  3338. Checker: p.Checker,
  3339. StartTime: p.StartTime,
  3340. TeamId: p.TeamId,
  3341. XtHisProjectTeam: models.XtHisProjectTeam{},
  3342. FrequencyType: p.FrequencyType,
  3343. DayCount: p.DayCount,
  3344. WeekDay: p.WeekDay,
  3345. IsCheckTeam: p.IsCheckTeam,
  3346. HisOrderInfo: models.HisOrderInfo{},
  3347. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3348. IsOut: p.IsOut,
  3349. YbSyncStatus: p.YbSyncStatus,
  3350. }
  3351. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3352. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3353. }
  3354. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3355. ////查询历史出库数据
  3356. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3357. //
  3358. //var out_count_five int64
  3359. //for _, item := range flowGood {
  3360. // out_count_five += item.Count
  3361. //}
  3362. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3363. //
  3364. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3365. //if out_count_five != parseIntCount {
  3366. // //查询耗材最后一次出库记录
  3367. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3368. // //查询默认出库仓库库存
  3369. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3370. // if len(wareOut) > 0 {
  3371. //
  3372. // for _, it := range wareOut {
  3373. // //回退库存
  3374. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3375. //
  3376. // //删除出库记录
  3377. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3378. //
  3379. // }
  3380. // }
  3381. //
  3382. // timeStr := time.Now().Format("2006-01-02")
  3383. // timeArr := strings.Split(timeStr, "-")
  3384. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3385. //
  3386. // total = total + 1
  3387. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3388. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3389. // number = number + total
  3390. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3391. //
  3392. // operation_time := time.Now().Unix()
  3393. // creater := c.GetAdminUserInfo().AdminUser.Id
  3394. //
  3395. // recordDateStr := time.Now().Format("2006-01-02")
  3396. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3397. // nowtime := recordDate.Unix()
  3398. // warehouseOut := models.WarehouseOut{
  3399. // WarehouseOutOrderNumber: warehousing_out_order,
  3400. // OperationTime: operation_time,
  3401. // OrgId: adminInfo.CurrentOrgId,
  3402. // Creater: creater,
  3403. // Ctime: time.Now().Unix(),
  3404. // Status: 1,
  3405. // WarehouseOutTime: nowtime,
  3406. // Type: 1,
  3407. // StorehouseId: storeConfig.StorehouseOutInfo,
  3408. // IsCheck: 1,
  3409. // IsSys: 1,
  3410. // }
  3411. // //查询是否生成出库单
  3412. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3413. // if out.ID == 0 {
  3414. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3415. // }
  3416. //
  3417. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3418. //
  3419. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3420. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3421. //
  3422. // dialyPrepareOne := models.DialysisBeforePrepare{
  3423. // GoodTypeId: goodObj.GoodTypeId,
  3424. // GoodId: p.ProjectId,
  3425. // PatientId: p.PatientId,
  3426. // RecordDate: p.RecordDate,
  3427. // UserOrgId: adminInfo.CurrentOrgId,
  3428. // Count: parseIntCount,
  3429. // Ctime: time.Now().Unix(),
  3430. // Creater: creater,
  3431. // Status: 1,
  3432. // StorehouseId: houseConfig.StorehouseOutInfo,
  3433. // ProjectId: lastHisProject.ID,
  3434. // }
  3435. // //判断是否是零用耗材(非零用)
  3436. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3437. //
  3438. // //查询历史出库数据
  3439. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3440. // var out_count int64
  3441. // for _, item := range flowGood {
  3442. // out_count += item.Count
  3443. // }
  3444. // //如果历史数和当前数据不想等才进行退库出库
  3445. // if out_count != parseIntCount {
  3446. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3447. //
  3448. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3449. // detail := models.AutomaticReduceDetail{
  3450. // WarehouseOutId: 0,
  3451. // WarehouseOutOrderNumber: "",
  3452. // PatientId: p.PatientId,
  3453. // Ctime: time.Now().Unix(),
  3454. // Mtime: 0,
  3455. // Status: 1,
  3456. // RecordTime: p.RecordDate,
  3457. // OrgId: p.UserOrgId,
  3458. // GoodId: p.ProjectId,
  3459. // GoodTypeId: 0,
  3460. // Count: parseIntCount,
  3461. // Type: 0,
  3462. // ProjectId: lastHisProject.ID,
  3463. // StorehouseId: 0,
  3464. // }
  3465. //
  3466. // service.CreateNewAutoDetail(detail, tx)
  3467. //
  3468. // //查询剩余库存
  3469. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3470. // var sum_count int64
  3471. // for _, item := range goodList {
  3472. // sum_count += item.StockCount
  3473. // }
  3474. //
  3475. // //更新剩余库存
  3476. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3477. //
  3478. // //耗材
  3479. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3480. //
  3481. // }
  3482. // //判断是否是零用耗材(零用但是是出库耗材)
  3483. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3484. //
  3485. // //查询历史出库数据
  3486. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3487. // var out_count int64
  3488. // for _, item := range flowGood {
  3489. // out_count += item.Count
  3490. // }
  3491. // //如果历史数和当前数据不想等才进行退库出库
  3492. // if out_count != parseIntCount {
  3493. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3494. //
  3495. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3496. // detail := models.AutomaticReduceDetail{
  3497. // WarehouseOutId: 0,
  3498. // WarehouseOutOrderNumber: "",
  3499. // PatientId: p.PatientId,
  3500. // Ctime: time.Now().Unix(),
  3501. // Mtime: 0,
  3502. // Status: 1,
  3503. // RecordTime: p.RecordDate,
  3504. // OrgId: p.UserOrgId,
  3505. // GoodId: p.ProjectId,
  3506. // GoodTypeId: 0,
  3507. // Count: parseIntCount,
  3508. // Type: 0,
  3509. // ProjectId: p.ID,
  3510. // StorehouseId: 0,
  3511. // }
  3512. //
  3513. // service.CreateNewAutoDetail(detail, tx)
  3514. //
  3515. // //查询剩余库存
  3516. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3517. // var sum_count int64
  3518. // for _, item := range goodList {
  3519. // sum_count += item.StockCount
  3520. // }
  3521. //
  3522. // //更新剩余库存
  3523. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3524. //
  3525. // //耗材
  3526. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3527. // }
  3528. //
  3529. // }
  3530. //
  3531. // }
  3532. //
  3533. //}
  3534. //记录日志
  3535. byterequest, _ := json.Marshal(p)
  3536. adviceLog := models.XtDoctorAdviceLog{
  3537. UserOrgId: p.UserOrgId,
  3538. PatientId: p.PatientId,
  3539. AdminUserId: adminInfo.AdminUser.Id,
  3540. Module: 1,
  3541. ErrLog: string(byterequest),
  3542. Status: 1,
  3543. Ctime: time.Now().Unix(),
  3544. Mtime: 0,
  3545. Source: "电脑端新建his项目",
  3546. RecordDate: p.RecordDate,
  3547. }
  3548. service.CreateDoctorAdviceLog(adviceLog)
  3549. projectList = append(projectList, p)
  3550. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3551. //新增或者编辑项目,修改对应的标签数据
  3552. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3553. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3554. var label models.HisLabelPrintInfo
  3555. project, _ := service.GetProjectDetail(p.ProjectId)
  3556. if project.CostClassify == 3 { //类别为检验检查
  3557. if p.TeamId > 0 { //检验检查组套
  3558. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3559. if tempLabel.ID == 0 {
  3560. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3561. label.Number = tempPrescription.PrescriptionNumber
  3562. label.ProjectId = project.ID
  3563. label.Status = 1
  3564. label.IsPrint = 2
  3565. label.DoctorId = info.DoctorId
  3566. label.UserOrgId = p.UserOrgId
  3567. label.PatientId = patient_id
  3568. label.RecordDate = recordDateTime
  3569. label.Ctime = time.Now().Unix()
  3570. label.Mtime = time.Now().Unix()
  3571. label.ItemId = p.TeamId
  3572. label.FeedetlSn = p.FeedetlSn
  3573. label.PProjectId = p.ID
  3574. label.ProjectName = team.ProjectTeam
  3575. label.PatientName = patient.Name
  3576. service.CreateNewHisLabelRecord(&label, tx)
  3577. }
  3578. } else { //单条检验检查项目
  3579. label.Number = tempPrescription.PrescriptionNumber
  3580. label.ProjectId = project.ID
  3581. label.Status = 1
  3582. label.DoctorId = info.DoctorId
  3583. label.UserOrgId = p.UserOrgId
  3584. label.PatientId = patient_id
  3585. label.RecordDate = recordDateTime
  3586. label.IsPrint = 2
  3587. label.Ctime = time.Now().Unix()
  3588. label.Mtime = time.Now().Unix()
  3589. label.FeedetlSn = p.FeedetlSn
  3590. label.PProjectId = p.ID
  3591. label.ItemId = p.TeamId
  3592. label.ProjectName = project.ProjectName
  3593. label.PatientName = patient.Name
  3594. service.CreateNewHisLabelRecord(&label, tx)
  3595. }
  3596. }
  3597. }
  3598. }
  3599. }
  3600. }
  3601. }
  3602. service.CreateNewHisProjectTwo(&p, tx)
  3603. var randNum int
  3604. randNum = rand.Intn(10000) + 1000
  3605. timestamp := time.Now().Unix()
  3606. tempTime := time.Unix(timestamp, 0)
  3607. timeFormat := tempTime.Format("20060102150405")
  3608. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3609. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3610. if goodBase.ID > 0 {
  3611. tx.Rollback()
  3612. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3613. return
  3614. }
  3615. service.CreateNewHisProjectTwo(&p, tx)
  3616. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3617. //查询剩余库存
  3618. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3619. var sum_count int64
  3620. for _, item := range goodList {
  3621. sum_count += item.StockCount
  3622. }
  3623. //更新剩余库存
  3624. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3625. //耗材
  3626. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3627. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3628. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3629. if len(outInfoTwo) > 0 {
  3630. for _, item := range outInfoTwo {
  3631. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3632. }
  3633. }
  3634. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3635. if len(drugAutoDetail) > 0 {
  3636. for _, item := range drugAutoDetail {
  3637. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3638. }
  3639. }
  3640. tx.Commit()
  3641. }
  3642. }
  3643. }
  3644. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3645. // addition := items["addition"].([]interface{})
  3646. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3647. // ctime := time.Now().Unix()
  3648. // mtime := ctime
  3649. // if len(addition) > 0 {
  3650. // for _, item := range addition {
  3651. // var s models.HisAdditionalCharge
  3652. // s.PrescriptionId = tempPrescription.ID
  3653. // s.Status = 1
  3654. // s.UserOrgId = adminInfo.CurrentOrgId
  3655. // s.RecordDate = recordDateTime
  3656. // s.CreatedTime = ctime
  3657. // s.UpdatedTime = mtime
  3658. // s.PatientId = patient_id
  3659. // s.HisPatientId = his_patient_id
  3660. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3661. // if errcode > 0 {
  3662. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3663. // return
  3664. // }
  3665. // service.CreateAdditionalCharge(&s)
  3666. // var randNum int
  3667. // randNum = rand.Intn(10000) + 1000
  3668. // timestamp := time.Now().Unix()
  3669. // tempTime := time.Unix(timestamp, 0)
  3670. // timeFormat := tempTime.Format("20060102150405")
  3671. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3672. // service.CreateAdditionalCharge(&s)
  3673. //
  3674. // }
  3675. // }
  3676. //}
  3677. }
  3678. }
  3679. }
  3680. tx.Commit()
  3681. if err == nil {
  3682. c.ServeSuccessJSON(map[string]interface{}{
  3683. "msg": "保存成功",
  3684. })
  3685. return
  3686. } else {
  3687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3688. return
  3689. }
  3690. } else {
  3691. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3692. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3693. var tempPrescription *models.HisPrescription
  3694. if len(prescriptions) > 0 {
  3695. for _, item := range prescriptions {
  3696. items := item.(map[string]interface{})
  3697. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3698. utils.ErrorLog("id")
  3699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3700. return
  3701. }
  3702. id := int64(items["id"].(float64))
  3703. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3704. tempPrescription = &new_prescription
  3705. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3706. utils.ErrorLog("type")
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3708. return
  3709. }
  3710. types := int64(items["type"].(float64))
  3711. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3712. utils.ErrorLog("med_type")
  3713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3714. return
  3715. }
  3716. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3717. if med_type == "0" {
  3718. med_type = "14"
  3719. }
  3720. //if order_status == 0 {
  3721. // order_status = 1
  3722. //}
  3723. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3724. utils.ErrorLog("pre_time")
  3725. }
  3726. preTime, _ := items["pre_time"].(string)
  3727. timeLayout := "2006-01-02"
  3728. loc, _ := time.LoadLocation("Local")
  3729. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3730. result := strings.Split(preTime, " ")
  3731. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3732. if err != nil {
  3733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3734. return
  3735. }
  3736. pTime := theTime2.Unix()
  3737. ctime := time.Now().Unix()
  3738. if tempPrescription.ID == 0 {
  3739. prescription := &models.HisPrescription{
  3740. ID: 0,
  3741. PatientId: patient_id,
  3742. UserOrgId: adminInfo.CurrentOrgId,
  3743. RecordDate: recordDateTime,
  3744. Ctime: ctime,
  3745. Mtime: ctime,
  3746. Type: types,
  3747. Modifier: adminInfo.AdminUser.Id,
  3748. Creator: adminInfo.AdminUser.Id,
  3749. Status: 1,
  3750. Doctor: role.UserName,
  3751. HisPatientId: his_patient_id,
  3752. OrderStatus: 1,
  3753. BatchNumber: "",
  3754. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3755. PreTime: pTime,
  3756. PType: p_type,
  3757. MedType: med_type,
  3758. }
  3759. tempPrescription = prescription
  3760. service.SaveHisPrescription(tempPrescription)
  3761. redis := service.RedisClient()
  3762. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3763. redis.Set(key, "", time.Second)
  3764. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3765. redis.Set(keyOne, "", time.Second)
  3766. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3767. redis.Set(keySeven, "", time.Second)
  3768. defer redis.Close()
  3769. } else {
  3770. tempPrescription.ID = id
  3771. tempPrescription.Type = types
  3772. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3773. tempPrescription.Mtime = time.Now().Unix()
  3774. tempPrescription.Doctor = role.UserName
  3775. //tempPrescription.OrderStatus = order_status
  3776. tempPrescription.PreTime = pTime
  3777. tempPrescription.MedType = med_type
  3778. service.SaveHisPrescription(tempPrescription)
  3779. redis := service.RedisClient()
  3780. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3781. redis.Set(key, "", time.Second)
  3782. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3783. redis.Set(keyOne, "", time.Second)
  3784. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3785. redis.Set(keySeven, "", time.Second)
  3786. defer redis.Close()
  3787. }
  3788. //service.SaveHisPrescription(prescription)
  3789. //更改患者挂号状态
  3790. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3791. fmt.Println("更改失败", err2)
  3792. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3793. advices := items["advices"].([]interface{})
  3794. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3795. groupNo := int64(0)
  3796. if len(advices) > 0 {
  3797. for _, advice := range advices {
  3798. var s models.HisDoctorAdviceInfo
  3799. s.PrescriptionId = tempPrescription.ID
  3800. s.AdviceType = 2
  3801. s.AdviceDoctor = doctor_id
  3802. s.StopState = 2
  3803. s.ExecutionState = 2
  3804. s.AdviceDate = theTime3.Unix()
  3805. s.Status = 1
  3806. s.UserOrgId = adminInfo.CurrentOrgId
  3807. s.RecordDate = theTime3.Unix()
  3808. s.StartTime = tempPrescription.PreTime
  3809. s.Groupno = groupNo
  3810. s.PatientId = patient_id
  3811. s.HisPatientId = his_patient_id
  3812. s.StartTime = pTime
  3813. s.IsSettle = 2
  3814. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3815. if errcode > 0 {
  3816. c.ServeFailJSONWithSGJErrorCode(errcode)
  3817. return
  3818. }
  3819. s.StartTime = pTime
  3820. var total_count int64 //处方总库存
  3821. //查询改药品信息
  3822. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3823. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3824. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3825. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3826. total_count += prescribingNumberSeven * medical.MinNumber
  3827. }
  3828. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3829. total_count += prescribingNumberSeven
  3830. }
  3831. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3832. total_count += prescribingNumberSeven
  3833. }
  3834. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3835. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3836. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3837. if s.Price != lastWarehouse.RetailPrice {
  3838. s.Price = lastWarehouse.RetailPrice
  3839. }
  3840. if s.Price == 0 {
  3841. s.Price = lastWarehouse.RetailPrice
  3842. }
  3843. }
  3844. service.CreateHisDoctorAdvice(&s)
  3845. //记录日志
  3846. byterequest, _ := json.Marshal(s)
  3847. adviceLog := models.XtDoctorAdviceLog{
  3848. UserOrgId: s.UserOrgId,
  3849. PatientId: s.PatientId,
  3850. AdminUserId: adminInfo.AdminUser.Id,
  3851. Module: 1,
  3852. ErrLog: string(byterequest),
  3853. Status: 1,
  3854. Ctime: time.Now().Unix(),
  3855. Mtime: 0,
  3856. Source: "电脑端新建his医嘱",
  3857. RecordDate: s.AdviceDate,
  3858. }
  3859. service.CreateDoctorAdviceLog(adviceLog)
  3860. //存储切片中
  3861. adviceList = append(adviceList, s)
  3862. redis := service.RedisClient()
  3863. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3864. redis.Set(key, "", time.Second)
  3865. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3866. redis.Set(keyOne, "", time.Second)
  3867. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3868. redis.Set(keySeven, "", time.Second)
  3869. var randNum int
  3870. randNum = rand.Intn(10000) + 1000
  3871. timestamp := time.Now().Unix()
  3872. tempTime := time.Unix(timestamp, 0)
  3873. timeFormat := tempTime.Format("20060102150405")
  3874. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3875. service.CreateHisDoctorAdvice(&s)
  3876. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3877. redis.Set(keySix, "", time.Second)
  3878. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3879. redis.Set(keyFive, "", time.Second)
  3880. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3881. redis.Set(keyEight, "", time.Second)
  3882. defer redis.Close()
  3883. }
  3884. }
  3885. }
  3886. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3887. projects := items["project"].([]interface{})
  3888. if len(projects) > 0 {
  3889. for _, project := range projects {
  3890. var p models.HisPrescriptionProject
  3891. p.PrescriptionId = tempPrescription.ID
  3892. p.PatientId = patient_id
  3893. p.RecordDate = theTime3.Unix()
  3894. p.Doctor = doctor_id
  3895. p.UserOrgId = adminInfo.CurrentOrgId
  3896. p.HisPatientId = his_patient_id
  3897. p.Status = 1
  3898. p.StartTime = pTime
  3899. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3900. if errcode > 0 {
  3901. c.ServeFailJSONWithSGJErrorCode(errcode)
  3902. return
  3903. }
  3904. if p.ID == 0 {
  3905. p.IsOut = 2
  3906. }
  3907. if p.ID > 0 {
  3908. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3909. p.IsOut = projectDetail.IsOut
  3910. }
  3911. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3912. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3913. if p.Type == 3 {
  3914. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3915. if p.Price != lastWarehouse.PackingPrice {
  3916. p.Price = lastWarehouse.PackingPrice
  3917. }
  3918. if p.Unit == "" {
  3919. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3920. p.Unit = goodInfoOne.PackingUnit
  3921. }
  3922. }
  3923. }
  3924. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3925. //
  3926. // if p.Type == 3 {
  3927. // //查询该耗材是否停用
  3928. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3929. // //表示该耗材已经停用,不能保存
  3930. // if goodInfoSeven.ID == 0 {
  3931. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3932. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3933. // return
  3934. // }
  3935. // }
  3936. //
  3937. //}
  3938. service.CreateHisProjectTwo(&p)
  3939. //记录日志
  3940. byterequest, _ := json.Marshal(p)
  3941. adviceLog := models.XtDoctorAdviceLog{
  3942. UserOrgId: p.UserOrgId,
  3943. PatientId: p.PatientId,
  3944. AdminUserId: adminInfo.AdminUser.Id,
  3945. Module: 1,
  3946. ErrLog: string(byterequest),
  3947. Status: 1,
  3948. Ctime: time.Now().Unix(),
  3949. Mtime: 0,
  3950. Source: "电脑端新建his项目",
  3951. RecordDate: p.RecordDate,
  3952. }
  3953. service.CreateDoctorAdviceLog(adviceLog)
  3954. projectList = append(projectList, p)
  3955. var randNum int
  3956. randNum = rand.Intn(10000) + 1000
  3957. timestamp := time.Now().Unix()
  3958. tempTime := time.Unix(timestamp, 0)
  3959. timeFormat := tempTime.Format("20060102150405")
  3960. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3961. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3962. //新增或者编辑项目,修改对应的标签数据
  3963. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3964. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3965. var label models.HisLabelPrintInfo
  3966. project, _ := service.GetProjectDetail(p.ProjectId)
  3967. if project.CostClassify == 3 { //类别为检验检查
  3968. if p.TeamId > 0 { //检验检查组套
  3969. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3970. if tempLabel.ID == 0 {
  3971. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3972. label.Number = tempPrescription.PrescriptionNumber
  3973. label.ProjectId = project.ID
  3974. label.Status = 1
  3975. label.IsPrint = 2
  3976. label.DoctorId = info.DoctorId
  3977. label.UserOrgId = p.UserOrgId
  3978. label.PatientId = patient_id
  3979. label.RecordDate = recordDateTime
  3980. label.Ctime = time.Now().Unix()
  3981. label.Mtime = time.Now().Unix()
  3982. label.ItemId = p.TeamId
  3983. label.FeedetlSn = p.FeedetlSn
  3984. label.PProjectId = p.ID
  3985. label.ProjectName = team.ProjectTeam
  3986. label.PatientName = patient.Name
  3987. service.CreateHisLabelRecord(&label)
  3988. }
  3989. } else { //单条检验检查项目
  3990. label.Number = tempPrescription.PrescriptionNumber
  3991. label.ProjectId = project.ID
  3992. label.Status = 1
  3993. label.DoctorId = info.DoctorId
  3994. label.UserOrgId = p.UserOrgId
  3995. label.PatientId = patient_id
  3996. label.RecordDate = recordDateTime
  3997. label.IsPrint = 2
  3998. label.Ctime = time.Now().Unix()
  3999. label.Mtime = time.Now().Unix()
  4000. label.FeedetlSn = p.FeedetlSn
  4001. label.PProjectId = p.ID
  4002. label.ItemId = p.TeamId
  4003. label.ProjectName = project.ProjectName
  4004. label.PatientName = patient.Name
  4005. service.CreateHisLabelRecord(&label)
  4006. }
  4007. }
  4008. }
  4009. }
  4010. service.SaveHisProjectTwo(&p)
  4011. }
  4012. }
  4013. }
  4014. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4015. // addition := items["addition"].([]interface{})
  4016. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4017. // ctime := time.Now().Unix()
  4018. // mtime := ctime
  4019. // if len(addition) > 0 {
  4020. // for _, item := range addition {
  4021. // var s models.HisAdditionalCharge
  4022. // s.PrescriptionId = tempPrescription.ID
  4023. // s.Status = 1
  4024. // s.UserOrgId = adminInfo.CurrentOrgId
  4025. // s.RecordDate = recordDateTime
  4026. // s.CreatedTime = ctime
  4027. // s.UpdatedTime = mtime
  4028. // s.PatientId = patient_id
  4029. // s.HisPatientId = his_patient_id
  4030. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4031. // if errcode > 0 {
  4032. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4033. // return
  4034. // }
  4035. // service.CreateAdditionalCharge(&s)
  4036. // var randNum int
  4037. // randNum = rand.Intn(10000) + 1000
  4038. // timestamp := time.Now().Unix()
  4039. // tempTime := time.Unix(timestamp, 0)
  4040. // timeFormat := tempTime.Format("20060102150405")
  4041. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4042. // service.CreateAdditionalCharge(&s)
  4043. //
  4044. // }
  4045. // }
  4046. //}
  4047. }
  4048. }
  4049. //查询今日该患者开的药品处方
  4050. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4051. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4052. //药品出库
  4053. if drugOutConfig.IsOpen == 1 {
  4054. for _, item := range hisdoctorlist {
  4055. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4056. // 查询该药品最后一次出库记录
  4057. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4058. if len(druginfo) > 0 {
  4059. //回退库存
  4060. for _, it := range druginfo {
  4061. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4062. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4063. }
  4064. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4065. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4066. }
  4067. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4068. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4069. }
  4070. }
  4071. }
  4072. //删除记录
  4073. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4074. //查询最后一次数据
  4075. if drugOutConfig.IsOpen == 1 {
  4076. //出库
  4077. if drug.IsUse == 2 {
  4078. creater := adminInfo.AdminUser.Id
  4079. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4080. }
  4081. //更新字典里面的库存
  4082. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4083. var sum_count int64
  4084. for _, its := range stockInfo {
  4085. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4086. if its.MaxUnit == baseDrug.MaxUnit {
  4087. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4088. }
  4089. sum_count += its.StockMaxNumber + its.StockMinNumber
  4090. }
  4091. //更新基础库存
  4092. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4093. //剩余库存
  4094. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4095. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4096. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4097. }
  4098. }
  4099. }
  4100. //耗材保存处方出库
  4101. if goodOutConfig.IsOpen == 1 {
  4102. //查询今日耗材出库数量
  4103. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4104. for _, item := range hisgoodlist {
  4105. //查询历史出库数据
  4106. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4107. var out_count_five int64
  4108. for _, item := range flowGood {
  4109. out_count_five += item.Count
  4110. }
  4111. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4112. if out_count_five != parseIntCount {
  4113. //查询耗材最后一次出库记录
  4114. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4115. //查询默认出库仓库库存
  4116. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4117. if len(wareOut) > 0 {
  4118. for _, it := range wareOut {
  4119. //回退库存
  4120. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4121. //删除出库记录
  4122. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4123. }
  4124. }
  4125. timeStr := time.Now().Format("2006-01-02")
  4126. timeArr := strings.Split(timeStr, "-")
  4127. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4128. total = total + 1
  4129. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4130. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4131. number = number + total
  4132. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4133. operation_time := time.Now().Unix()
  4134. creater := c.GetAdminUserInfo().AdminUser.Id
  4135. recordDateStr := time.Now().Format("2006-01-02")
  4136. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4137. nowtime := recordDate.Unix()
  4138. warehouseOut := models.WarehouseOut{
  4139. WarehouseOutOrderNumber: warehousing_out_order,
  4140. OperationTime: operation_time,
  4141. OrgId: adminInfo.CurrentOrgId,
  4142. Creater: creater,
  4143. Ctime: time.Now().Unix(),
  4144. Status: 1,
  4145. WarehouseOutTime: nowtime,
  4146. Type: 1,
  4147. StorehouseId: storeConfig.StorehouseOutInfo,
  4148. IsCheck: 1,
  4149. IsSys: 1,
  4150. }
  4151. //查询是否生成出库单
  4152. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4153. if out.ID == 0 {
  4154. service.AddSigleWarehouseOut(&warehouseOut)
  4155. }
  4156. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4157. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4158. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4159. dialyPrepareOne := models.DialysisBeforePrepare{
  4160. GoodTypeId: goodObj.GoodTypeId,
  4161. GoodId: item.ProjectId,
  4162. PatientId: item.PatientId,
  4163. RecordDate: item.RecordDate,
  4164. UserOrgId: adminInfo.CurrentOrgId,
  4165. Count: parseIntCount,
  4166. Ctime: time.Now().Unix(),
  4167. Creater: creater,
  4168. Status: 1,
  4169. StorehouseId: houseConfig.StorehouseOutInfo,
  4170. ProjectId: item.ID,
  4171. }
  4172. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4173. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4174. //查询历史出库数据
  4175. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4176. var out_count int64
  4177. for _, item := range flowGood {
  4178. out_count += item.Count
  4179. }
  4180. //如果历史数和当前数据不想等才进行退库出库
  4181. if out_count != parseIntCount {
  4182. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4183. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4184. detail := models.AutomaticReduceDetail{
  4185. WarehouseOutId: 0,
  4186. WarehouseOutOrderNumber: "",
  4187. PatientId: item.PatientId,
  4188. Ctime: time.Now().Unix(),
  4189. Mtime: 0,
  4190. Status: 1,
  4191. RecordTime: item.RecordDate,
  4192. OrgId: item.UserOrgId,
  4193. GoodId: item.ProjectId,
  4194. GoodTypeId: 0,
  4195. Count: parseIntCount,
  4196. Type: 0,
  4197. ProjectId: item.ID,
  4198. StorehouseId: 0,
  4199. }
  4200. service.CreateAutoDetail(detail)
  4201. //查询剩余库存
  4202. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4203. var sum_count int64
  4204. for _, item := range goodList {
  4205. sum_count += item.StockCount
  4206. }
  4207. //更新剩余库存
  4208. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4209. //耗材
  4210. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4211. }
  4212. }
  4213. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4214. //查询历史出库数据
  4215. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4216. var out_count int64
  4217. for _, item := range flowGood {
  4218. out_count += item.Count
  4219. }
  4220. //如果历史数和当前数据不想等才进行退库出库
  4221. if out_count != parseIntCount {
  4222. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4223. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4224. detail := models.AutomaticReduceDetail{
  4225. WarehouseOutId: 0,
  4226. WarehouseOutOrderNumber: "",
  4227. PatientId: item.PatientId,
  4228. Ctime: time.Now().Unix(),
  4229. Mtime: 0,
  4230. Status: 1,
  4231. RecordTime: item.RecordDate,
  4232. OrgId: item.UserOrgId,
  4233. GoodId: item.ProjectId,
  4234. GoodTypeId: 0,
  4235. Count: parseIntCount,
  4236. Type: 0,
  4237. ProjectId: item.ID,
  4238. StorehouseId: 0,
  4239. }
  4240. service.CreateAutoDetail(detail)
  4241. //查询剩余库存
  4242. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4243. var sum_count int64
  4244. for _, item := range goodList {
  4245. sum_count += item.StockCount
  4246. }
  4247. //更新剩余库存
  4248. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4249. //耗材
  4250. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4251. }
  4252. }
  4253. }
  4254. }
  4255. }
  4256. }
  4257. tx.Commit()
  4258. if err == nil {
  4259. c.ServeSuccessJSON(map[string]interface{}{
  4260. "msg": "保存成功",
  4261. })
  4262. return
  4263. } else {
  4264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4265. return
  4266. }
  4267. }
  4268. }
  4269. //func (c *HisApiController) EditHisPrescription() {
  4270. // record_date := c.GetString("record_date")
  4271. // patient_id, _ := c.GetInt64("patient_id")
  4272. // reg_type, _ := c.GetInt64("reg_type")
  4273. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4274. // diagnose := c.GetString("diagnose")
  4275. // sick_type, _ := c.GetInt64("sick_type")
  4276. // sick_history := c.GetString("sick_history")
  4277. // doctor_id, _ := c.GetInt64("doctor", 0)
  4278. // department, _ := c.GetInt64("department", 0)
  4279. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4280. // p_type, _ := c.GetInt64("p_type")
  4281. //
  4282. // dataBody := make(map[string]interface{}, 0)
  4283. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4284. // if err != nil {
  4285. // utils.ErrorLog(err.Error())
  4286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4287. // return
  4288. // }
  4289. //
  4290. // timeLayout := "2006-01-02"
  4291. // loc, _ := time.LoadLocation("Local")
  4292. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4293. // if err != nil {
  4294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4295. // return
  4296. // }
  4297. // adminInfo := c.GetAdminUserInfo()
  4298. // recordDateTime := theTime.Unix()
  4299. //
  4300. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4301. //
  4302. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4303. // var hpInfo models.HisPrescriptionInfo
  4304. // if info.ID == 0 {
  4305. // var randNum int
  4306. // randNum = rand.Intn(10000) + 1000
  4307. // timestamp := time.Now().Unix()
  4308. // tempTime := time.Unix(timestamp, 0)
  4309. // timeFormat := tempTime.Format("20060102150405")
  4310. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4311. //
  4312. // hpInfo = models.HisPrescriptionInfo{
  4313. // UserOrgId: adminInfo.CurrentOrgId,
  4314. // RecordDate: theTime.Unix(),
  4315. // PatientId: patient_id,
  4316. // Status: 1,
  4317. // Ctime: time.Now().Unix(),
  4318. // Mtime: time.Now().Unix(),
  4319. // Creator: adminInfo.AdminUser.Id,
  4320. // Modifier: adminInfo.AdminUser.Id,
  4321. // Diagnosis: diagnose,
  4322. // SickHistory: sick_history,
  4323. // Departments: department,
  4324. // RegisterType: reg_type,
  4325. // PrescriptionNumber: p_number,
  4326. // PrescriptionStatus: 1,
  4327. // Doctor: role.UserName,
  4328. // DoctorId: doctor_id,
  4329. // SickType: sick_type,
  4330. // PType: p_type,
  4331. // }
  4332. // service.SavePatientPrescriptionInfo(hpInfo)
  4333. //
  4334. // } else {
  4335. // hpInfo = models.HisPrescriptionInfo{
  4336. // ID: info.ID,
  4337. // UserOrgId: adminInfo.CurrentOrgId,
  4338. // RecordDate: info.RecordDate,
  4339. // PatientId: info.PatientId,
  4340. // Status: 1,
  4341. // Ctime: info.Ctime,
  4342. // Mtime: time.Now().Unix(),
  4343. // Creator: info.Creator,
  4344. // Modifier: adminInfo.AdminUser.Id,
  4345. // Diagnosis: diagnose,
  4346. // SickHistory: sick_history,
  4347. // Departments: department,
  4348. // RegisterType: reg_type,
  4349. // PrescriptionNumber: info.PrescriptionNumber,
  4350. // Doctor: role.UserName,
  4351. // PrescriptionStatus: info.PrescriptionStatus,
  4352. // DoctorId: doctor_id,
  4353. // SickType: sick_type,
  4354. // PType: info.PType,
  4355. // }
  4356. // service.SavePatientPrescriptionInfo(hpInfo)
  4357. // }
  4358. //
  4359. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4360. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4361. //
  4362. // if len(prescriptions) > 0 {
  4363. // for _, item := range prescriptions {
  4364. // items := item.(map[string]interface{})
  4365. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4366. // utils.ErrorLog("id")
  4367. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4368. // return
  4369. // }
  4370. // id := int64(items["id"].(float64))
  4371. //
  4372. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4373. // utils.ErrorLog("type")
  4374. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4375. // return
  4376. // }
  4377. // types := int64(items["type"].(float64))
  4378. //
  4379. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4380. // utils.ErrorLog("med_type")
  4381. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4382. // return
  4383. // }
  4384. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4385. //
  4386. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4387. //
  4388. // ctime := time.Now().Unix()
  4389. //
  4390. // prescription := &models.HisPrescription{
  4391. // ID: id,
  4392. // PatientId: patient_id,
  4393. // UserOrgId: adminInfo.CurrentOrgId,
  4394. // RecordDate: recordDateTime,
  4395. // Ctime: ctime,
  4396. // Mtime: ctime,
  4397. // Type: types,
  4398. // Modifier: adminInfo.AdminUser.Id,
  4399. // Creator: adminInfo.AdminUser.Id,
  4400. // Status: 1,
  4401. // Doctor: role.UserName,
  4402. // HisPatientId: his_patient_id,
  4403. // OrderStatus: 1,
  4404. // BatchNumber: "",
  4405. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4406. // PType: hpInfo.PType,
  4407. // MedType: med_type,
  4408. // }
  4409. //
  4410. // if historyPrescription.ID > 0 {
  4411. // prescription.PreTime = historyPrescription.PreTime
  4412. //
  4413. // }
  4414. //
  4415. // service.SaveHisPrescription(prescription)
  4416. //
  4417. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4418. // advices := items["advices"].([]interface{})
  4419. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4420. // groupNo := int64(0)
  4421. // ctime := time.Now().Unix()
  4422. // mtime := ctime
  4423. // if len(advices) > 0 {
  4424. // for _, advice := range advices {
  4425. // var s models.HisDoctorAdviceInfo
  4426. // s.PrescriptionId = prescription.ID
  4427. // s.AdviceType = 2
  4428. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4429. // s.StopState = 2
  4430. // s.ExecutionState = 2
  4431. // s.AdviceDate = recordDateTime
  4432. // s.Status = 1
  4433. // s.UserOrgId = adminInfo.CurrentOrgId
  4434. // s.RecordDate = recordDateTime
  4435. // s.StartTime = prescription.PreTime
  4436. // s.Groupno = groupNo
  4437. // s.CreatedTime = ctime
  4438. // s.UpdatedTime = mtime
  4439. // s.PatientId = patient_id
  4440. // s.HisPatientId = his_patient_id
  4441. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4442. // if errcode > 0 {
  4443. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4444. // return
  4445. // }
  4446. //
  4447. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4448. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4449. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4450. // if s.Price == 0 {
  4451. // s.Price = lastWarehouse.RetailPrice
  4452. // }
  4453. // }
  4454. //
  4455. // service.CreateHisDoctorAdvice(&s)
  4456. // //记录日志
  4457. // byterequest, _ := json.Marshal(s)
  4458. // adviceLog := models.XtDoctorAdviceLog{
  4459. // UserOrgId: s.UserOrgId,
  4460. // PatientId: s.PatientId,
  4461. // AdminUserId: adminInfo.AdminUser.Id,
  4462. // Module: 1,
  4463. // ErrLog: string(byterequest),
  4464. // Status: 1,
  4465. // Ctime: time.Now().Unix(),
  4466. // Mtime: 0,
  4467. // Source: "电脑端his医嘱修改",
  4468. // RecordDate: s.AdviceDate,
  4469. // }
  4470. // service.CreateDoctorAdviceLog(adviceLog)
  4471. // redis := service.RedisClient()
  4472. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4473. // redis.Set(key, "", time.Second)
  4474. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4475. // fmt.Println("keyOne", keyOne)
  4476. // redis.Set(keyOne, "", time.Second)
  4477. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4478. // redis.Set(keySeven, "", time.Second)
  4479. // redis.Close()
  4480. //
  4481. // }
  4482. // }
  4483. // }
  4484. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4485. // projects := items["project"].([]interface{})
  4486. // if len(projects) > 0 {
  4487. // for _, project := range projects {
  4488. // var p models.HisPrescriptionProject
  4489. // p.PrescriptionId = prescription.ID
  4490. // p.Ctime = time.Now().Unix()
  4491. // p.Mtime = time.Now().Unix()
  4492. // p.PatientId = patient_id
  4493. // p.RecordDate = recordDateTime
  4494. // p.UserOrgId = adminInfo.CurrentOrgId
  4495. // p.HisPatientId = his_patient_id
  4496. // p.Status = 1
  4497. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4498. // if errcode > 0 {
  4499. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4500. // return
  4501. // }
  4502. // service.CreateHisProjectTwo(&p)
  4503. //
  4504. // //记录日志
  4505. // byterequest, _ := json.Marshal(p)
  4506. // adviceLog := models.XtDoctorAdviceLog{
  4507. // UserOrgId: p.UserOrgId,
  4508. // PatientId: p.PatientId,
  4509. // AdminUserId: adminInfo.AdminUser.Id,
  4510. // Module: 1,
  4511. // ErrLog: string(byterequest),
  4512. // Status: 1,
  4513. // Ctime: time.Now().Unix(),
  4514. // Mtime: 0,
  4515. // Source: "电脑端his项目修改",
  4516. // RecordDate: p.RecordDate,
  4517. // }
  4518. // service.CreateDoctorAdviceLog(adviceLog)
  4519. // }
  4520. // }
  4521. // }
  4522. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4523. // addition := items["addition"].([]interface{})
  4524. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4525. // ctime := time.Now().Unix()
  4526. // mtime := ctime
  4527. // if len(addition) > 0 {
  4528. // for _, item := range addition {
  4529. // var s models.HisAdditionalCharge
  4530. // s.PrescriptionId = prescription.ID
  4531. // s.Status = 1
  4532. // s.UserOrgId = adminInfo.CurrentOrgId
  4533. // s.RecordDate = recordDateTime
  4534. // s.CreatedTime = ctime
  4535. // s.UpdatedTime = mtime
  4536. // s.PatientId = patient_id
  4537. // s.HisPatientId = his_patient_id
  4538. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4539. // if errcode > 0 {
  4540. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4541. // return
  4542. // }
  4543. // service.CreateAdditionalCharge(&s)
  4544. // }
  4545. // }
  4546. // }
  4547. //
  4548. // }
  4549. // }
  4550. // }
  4551. // if err == nil {
  4552. // c.ServeSuccessJSON(map[string]interface{}{
  4553. // "msg": "保存成功",
  4554. // })
  4555. // return
  4556. //
  4557. // } else {
  4558. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4559. // return
  4560. // }
  4561. //}
  4562. func (c *HisApiController) DeletePrescription() {
  4563. prescription_id, _ := c.GetInt64("id")
  4564. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4565. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4566. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4567. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4568. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4569. //耗材保存处方出库
  4570. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4571. //已收费和已发药限制逻辑
  4572. isCharge := false
  4573. isMedicine := false
  4574. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4575. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4576. for _, item := range new_prescriptions {
  4577. if item.IsMedicine == 1 {
  4578. isMedicine = true
  4579. }
  4580. }
  4581. for _, item := range new_prescriptions {
  4582. if item.OrderStatus == 4 {
  4583. isCharge = true
  4584. }
  4585. }
  4586. if p_err != nil {
  4587. if new_prescription.ID > 0 {
  4588. if new_prescription.OrderStatus == 2 {
  4589. isCharge = true
  4590. }
  4591. }
  4592. }
  4593. for _, item := range advices {
  4594. if item.IsMedicine == 1 {
  4595. isMedicine = true
  4596. }
  4597. }
  4598. if isCharge {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4600. return
  4601. }
  4602. if isMedicine {
  4603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4604. return
  4605. }
  4606. //已收费和已发药限制逻辑
  4607. if len(projects) > 0 {
  4608. for _, item := range projects {
  4609. service.DeletePrintInfo(item.ID) //删除打印信息
  4610. if goodOutConfig.IsOpen != 1 {
  4611. if stockConfig.IsOpen == 1 {
  4612. if item.Type == 3 && item.IsOut == 1 {
  4613. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4614. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4615. good.Total = good.Total + f_count
  4616. service.UpdateGoodInfo(&good)
  4617. operation_time := time.Now().Unix()
  4618. creater := c.GetAdminUserInfo().AdminUser.Id
  4619. //创建退库单
  4620. timeStr := time.Now().Format("2006-01-02")
  4621. timeArr := strings.Split(timeStr, "-")
  4622. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4623. total = total + 1
  4624. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4625. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4626. cancelStock := models.CancelStock{
  4627. OrderNumber: orderNumber,
  4628. OperaTime: operation_time,
  4629. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4630. Creater: creater,
  4631. Ctime: time.Now().Unix(),
  4632. Status: 1,
  4633. ReturnTime: item.RecordDate,
  4634. Type: 1,
  4635. StorehouseId: houseConfig.StorehouseOutInfo,
  4636. IsCheck: 1,
  4637. }
  4638. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4639. if msgerrkonde == gorm.ErrRecordNotFound {
  4640. service.AddSigleCancelStock(&cancelStock)
  4641. }
  4642. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4643. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4644. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4645. //查询该耗材是否出库
  4646. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4647. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4648. deaerler, _ := service.GetDealerById(info.Dealer)
  4649. var total_count int64
  4650. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4651. total_count += count
  4652. if info.ID > 0 {
  4653. if info.Count >= total_count {
  4654. //回退库存
  4655. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4656. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4657. var flush_count int64
  4658. for _, it := range goodList {
  4659. flush_count += it.StockCount
  4660. }
  4661. cancelStockInfo := models.CancelStockInfo{
  4662. GoodId: item.ProjectId,
  4663. CancelStockId: cancel.ID,
  4664. GoodTypeId: good.GoodTypeId,
  4665. Count: prescribingNumber,
  4666. Price: info.Price,
  4667. Total: 0,
  4668. ProductDate: info.ProductDate,
  4669. ExpiryDate: info.ExpiryDate,
  4670. Ctime: time.Now().Unix(),
  4671. Status: 1,
  4672. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4673. OrderNumber: cancel.OrderNumber,
  4674. Type: 0,
  4675. Dealer: deaerler.DealerName,
  4676. Manufacturer: manufacturer.ManufacturerName,
  4677. Number: info.Number,
  4678. RegisterAccount: "",
  4679. Remark: "",
  4680. WarehouseInfoId: info.WarehouseInfotId,
  4681. PatientId: info.PatientId,
  4682. RecordDate: info.SysRecordTime,
  4683. StorehouseId: houseConfig.StorehouseOutInfo,
  4684. IsCheck: 1,
  4685. }
  4686. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4687. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4688. flow := models.VmStockFlow{
  4689. WarehousingId: info.WarehouseInfotId,
  4690. GoodId: item.ProjectId,
  4691. Number: info.Number,
  4692. LicenseNumber: info.LicenseNumber,
  4693. Count: prescribingNumber,
  4694. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4695. PatientId: item.PatientId,
  4696. SystemTime: info.SysRecordTime,
  4697. ConsumableType: 7,
  4698. IsSys: 0,
  4699. WarehousingOrder: "",
  4700. WarehouseOutId: info.WarehouseOutId,
  4701. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4702. IsEdit: 0,
  4703. CancelStockId: cancel.ID,
  4704. CancelOrderNumber: cancel.OrderNumber,
  4705. Manufacturer: manufacturer.ID,
  4706. Dealer: 0,
  4707. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4708. UpdateCreator: 0,
  4709. Status: 1,
  4710. Ctime: time.Now().Unix(),
  4711. Mtime: 0,
  4712. Price: info.Price,
  4713. WarehousingDetailId: info.WarehouseInfotId,
  4714. WarehouseOutDetailId: info.ID,
  4715. CancelOutDetailId: cancelInfo.ID,
  4716. ProductDate: info.ProductDate,
  4717. ExpireDate: info.ExpiryDate,
  4718. StorehouseId: houseConfig.StorehouseOutInfo,
  4719. OverCount: flush_count,
  4720. OperateTime: time.Now().Unix(),
  4721. }
  4722. service.CreateStockFlowOne(flow)
  4723. //退库数量增加
  4724. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4725. //出库数量减少
  4726. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4727. }
  4728. if info.Count < total_count {
  4729. //回退库存
  4730. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4731. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4732. var flush_count int64
  4733. for _, it := range goodList {
  4734. flush_count += it.StockCount
  4735. }
  4736. cancelStockInfo := models.CancelStockInfo{
  4737. GoodId: item.ProjectId,
  4738. CancelStockId: cancel.ID,
  4739. GoodTypeId: good.GoodTypeId,
  4740. Count: info.Count,
  4741. Price: info.Price,
  4742. Total: 0,
  4743. ProductDate: info.ProductDate,
  4744. ExpiryDate: info.ExpiryDate,
  4745. Ctime: time.Now().Unix(),
  4746. Status: 1,
  4747. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4748. OrderNumber: cancel.OrderNumber,
  4749. Type: 0,
  4750. Dealer: deaerler.DealerName,
  4751. Manufacturer: manufacturer.ManufacturerName,
  4752. Number: info.Number,
  4753. RegisterAccount: "",
  4754. Remark: "",
  4755. WarehouseInfoId: info.WarehouseInfotId,
  4756. PatientId: info.PatientId,
  4757. RecordDate: info.SysRecordTime,
  4758. StorehouseId: houseConfig.StorehouseOutInfo,
  4759. IsCheck: 1,
  4760. }
  4761. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4762. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4763. flow := models.VmStockFlow{
  4764. WarehousingId: info.WarehouseInfotId,
  4765. GoodId: item.ProjectId,
  4766. Number: info.Number,
  4767. LicenseNumber: info.LicenseNumber,
  4768. Count: info.Count,
  4769. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4770. PatientId: item.PatientId,
  4771. SystemTime: info.SysRecordTime,
  4772. ConsumableType: 7,
  4773. IsSys: 0,
  4774. WarehousingOrder: "",
  4775. WarehouseOutId: info.WarehouseOutId,
  4776. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4777. IsEdit: 0,
  4778. CancelStockId: cancel.ID,
  4779. CancelOrderNumber: cancel.OrderNumber,
  4780. Manufacturer: manufacturer.ID,
  4781. Dealer: 0,
  4782. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4783. UpdateCreator: 0,
  4784. Status: 1,
  4785. Ctime: time.Now().Unix(),
  4786. Mtime: 0,
  4787. Price: info.Price,
  4788. WarehousingDetailId: info.WarehouseInfotId,
  4789. WarehouseOutDetailId: info.ID,
  4790. CancelOutDetailId: cancelInfo.ID,
  4791. ProductDate: info.ProductDate,
  4792. ExpireDate: info.ExpiryDate,
  4793. StorehouseId: houseConfig.StorehouseOutInfo,
  4794. OverCount: flush_count,
  4795. OperateTime: time.Now().Unix(),
  4796. }
  4797. service.CreateStockFlowOne(flow)
  4798. //退库数量增加
  4799. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4800. //出库数量减少
  4801. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4802. }
  4803. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4804. var flush_count int64
  4805. for _, it := range goodList {
  4806. flush_count += it.StockCount
  4807. }
  4808. //查询已出库数量
  4809. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4810. if prescribingNumber < dialysisInfo.Count {
  4811. //改变数量
  4812. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4813. }
  4814. if prescribingNumber >= dialysisInfo.Count {
  4815. //删除出库表
  4816. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4817. }
  4818. //更新库存
  4819. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4820. //更新基础库库存
  4821. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4822. }
  4823. }
  4824. }
  4825. }
  4826. //保存耗材出库
  4827. if goodOutConfig.IsOpen == 1 {
  4828. if item.Type == 3 {
  4829. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4830. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4831. good.Total = good.Total + f_count
  4832. service.UpdateGoodInfo(&good)
  4833. operation_time := time.Now().Unix()
  4834. creater := c.GetAdminUserInfo().AdminUser.Id
  4835. //创建退库单
  4836. timeStr := time.Now().Format("2006-01-02")
  4837. timeArr := strings.Split(timeStr, "-")
  4838. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4839. total = total + 1
  4840. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4841. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4842. cancelStock := models.CancelStock{
  4843. OrderNumber: orderNumber,
  4844. OperaTime: operation_time,
  4845. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4846. Creater: creater,
  4847. Ctime: time.Now().Unix(),
  4848. Status: 1,
  4849. ReturnTime: item.RecordDate,
  4850. Type: 1,
  4851. StorehouseId: houseConfig.StorehouseOutInfo,
  4852. IsCheck: 1,
  4853. }
  4854. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4855. if msgerrkonde == gorm.ErrRecordNotFound {
  4856. service.AddSigleCancelStock(&cancelStock)
  4857. }
  4858. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4859. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4860. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4861. //查询该耗材是否出库
  4862. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4863. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4864. deaerler, _ := service.GetDealerById(info.Dealer)
  4865. var total_count int64
  4866. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4867. total_count += count
  4868. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4869. var flush_count int64
  4870. for _, it := range goodList {
  4871. flush_count += it.StockCount
  4872. }
  4873. fmt.Println("历史出库数据", info.Count)
  4874. fmt.Println("出库数量", total_count)
  4875. if info.ID > 0 {
  4876. cancelStockInfo := models.CancelStockInfo{
  4877. GoodId: item.ProjectId,
  4878. CancelStockId: cancel.ID,
  4879. GoodTypeId: good.GoodTypeId,
  4880. Count: prescribingNumber,
  4881. Price: info.Price,
  4882. Total: 0,
  4883. ProductDate: info.ProductDate,
  4884. ExpiryDate: info.ExpiryDate,
  4885. Ctime: time.Now().Unix(),
  4886. Status: 1,
  4887. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4888. OrderNumber: cancel.OrderNumber,
  4889. Type: 0,
  4890. Dealer: deaerler.DealerName,
  4891. Manufacturer: manufacturer.ManufacturerName,
  4892. Number: info.Number,
  4893. RegisterAccount: "",
  4894. Remark: "",
  4895. WarehouseInfoId: info.WarehouseInfotId,
  4896. PatientId: info.PatientId,
  4897. RecordDate: info.SysRecordTime,
  4898. StorehouseId: houseConfig.StorehouseOutInfo,
  4899. IsCheck: 1,
  4900. }
  4901. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4902. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4903. //查询出库数量
  4904. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4905. //出库数据 大于 退库数量
  4906. if len(list) > 0 {
  4907. for _, it := range list {
  4908. //回退库存
  4909. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4910. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4911. var flush_count_one int64
  4912. for _, it := range goodList {
  4913. flush_count_one += it.StockCount
  4914. }
  4915. //查询该批次是否有退库数据
  4916. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4917. creater := c.GetAdminUserInfo().AdminUser.Id
  4918. flow := models.VmStockFlow{
  4919. WarehousingId: it.WarehouseInfotId,
  4920. GoodId: it.GoodId,
  4921. Number: it.Number,
  4922. LicenseNumber: it.LicenseNumber,
  4923. Count: it.Count,
  4924. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4925. PatientId: it.PatientId,
  4926. SystemTime: it.SysRecordTime,
  4927. ConsumableType: 7,
  4928. IsSys: 0,
  4929. WarehousingOrder: "",
  4930. WarehouseOutId: it.WarehouseOutId,
  4931. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4932. IsEdit: 0,
  4933. CancelStockId: cancel.ID,
  4934. CancelOrderNumber: cancel.OrderNumber,
  4935. Manufacturer: manufacturer.ID,
  4936. Dealer: 0,
  4937. Creator: creater,
  4938. UpdateCreator: 0,
  4939. Status: 1,
  4940. Ctime: time.Now().Unix(),
  4941. Mtime: 0,
  4942. Price: it.Price,
  4943. WarehousingDetailId: it.WarehouseInfotId,
  4944. WarehouseOutDetailId: it.ID,
  4945. CancelOutDetailId: cancelInfo.ID,
  4946. ProductDate: it.ProductDate,
  4947. ExpireDate: it.ExpiryDate,
  4948. StorehouseId: houseConfig.StorehouseOutInfo,
  4949. OverCount: flush_count_one,
  4950. }
  4951. service.CreateStockFlowOne(flow)
  4952. //if flow.ID > 0 {
  4953. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4954. //}
  4955. }
  4956. }
  4957. //flow := models.VmStockFlow{
  4958. // WarehousingId: info.WarehouseInfotId,
  4959. // GoodId: item.ProjectId,
  4960. // Number: info.Number,
  4961. // LicenseNumber: info.LicenseNumber,
  4962. // Count: prescribingNumber,
  4963. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4964. // PatientId: item.PatientId,
  4965. // SystemTime: info.SysRecordTime,
  4966. // ConsumableType: 7,
  4967. // IsSys: 0,
  4968. // WarehousingOrder: "",
  4969. // WarehouseOutId: info.WarehouseOutId,
  4970. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4971. // IsEdit: 0,
  4972. // CancelStockId: cancel.ID,
  4973. // CancelOrderNumber: cancel.OrderNumber,
  4974. // Manufacturer: manufacturer.ID,
  4975. // Dealer: 0,
  4976. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4977. // UpdateCreator: 0,
  4978. // Status: 1,
  4979. // Ctime: time.Now().Unix(),
  4980. // Mtime: 0,
  4981. // Price: info.Price,
  4982. // WarehousingDetailId: info.WarehouseInfotId,
  4983. // WarehouseOutDetailId: info.ID,
  4984. // CancelOutDetailId: cancelInfo.ID,
  4985. // ProductDate: info.ProductDate,
  4986. // ExpireDate: info.ExpiryDate,
  4987. // StorehouseId: houseConfig.StorehouseOutInfo,
  4988. // OverCount: flush_count,
  4989. //}
  4990. //service.CreateStockFlowOne(flow)
  4991. //退库数量增加
  4992. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4993. //出库数量减少
  4994. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4995. //查询已出库数量
  4996. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4997. if prescribingNumber < dialysisInfo.Count {
  4998. //改变数量
  4999. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5000. }
  5001. if prescribingNumber >= dialysisInfo.Count {
  5002. //删除出库表
  5003. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5004. }
  5005. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5006. var flush_count_one int64
  5007. for _, it := range goodList {
  5008. flush_count_one += it.StockCount
  5009. }
  5010. //更新库存
  5011. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5012. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5013. //更新基础库库存
  5014. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5015. }
  5016. }
  5017. }
  5018. }
  5019. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5020. fmt.Println(err)
  5021. }
  5022. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5023. fmt.Println(err)
  5024. if len(advices) > 0 {
  5025. for _, item := range advices {
  5026. redis := service.RedisClient()
  5027. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5028. redis.Set(keyFive, "", time.Second)
  5029. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5030. redis.Set(keyOne, "", time.Second)
  5031. redis.Close()
  5032. }
  5033. }
  5034. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5035. if len(advices) > 0 {
  5036. for _, item := range advices {
  5037. creater := c.GetAdminUserInfo().AdminUser.Id
  5038. service.DrugAutoAddCancelInfo(item, creater)
  5039. }
  5040. }
  5041. } else {
  5042. if drugOutConfig.IsOpen == 1 {
  5043. if len(advices) > 0 {
  5044. for _, item := range advices {
  5045. creater := c.GetAdminUserInfo().AdminUser.Id
  5046. service.DrugAutoAddCancelInfo(item, creater)
  5047. }
  5048. }
  5049. } else {
  5050. if len(advices) > 0 {
  5051. for _, item := range advices {
  5052. creater := c.GetAdminUserInfo().AdminUser.Id
  5053. service.DrugAutoAddCancelInfo(item, creater)
  5054. }
  5055. }
  5056. }
  5057. }
  5058. c.ServeSuccessJSON(map[string]interface{}{
  5059. "msg": "删除成功",
  5060. })
  5061. return
  5062. }
  5063. func (c *HisApiController) DeleteDoctorAdvice() {
  5064. id, _ := c.GetInt64("id")
  5065. advice, _ := service.GetHisDoctorAdvicesById(id)
  5066. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5067. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5068. //已收费和已发药的限制逻辑
  5069. isCharge := false
  5070. isMedicine := false
  5071. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5072. //获取今天该患者所有处方,判断是否发药或者收费
  5073. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5074. for _, item := range new_prescriptions {
  5075. if item.IsMedicine == 1 {
  5076. isMedicine = true
  5077. }
  5078. }
  5079. for _, item := range new_prescriptions {
  5080. if item.OrderStatus == 4 {
  5081. isCharge = true
  5082. }
  5083. }
  5084. if isMedicine {
  5085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5086. return
  5087. }
  5088. if isCharge {
  5089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5090. return
  5091. }
  5092. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5093. for _, item := range advices {
  5094. if item.IsMedicine == 1 {
  5095. isMedicine = true
  5096. }
  5097. }
  5098. if isMedicine {
  5099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5100. return
  5101. }
  5102. if new_prescription.ID > 0 {
  5103. if new_prescription.OrderStatus == 2 {
  5104. isCharge = true
  5105. }
  5106. }
  5107. if isCharge {
  5108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5109. return
  5110. }
  5111. //已收费和已发药的限制逻辑
  5112. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5113. redis := service.RedisClient()
  5114. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5115. redis.Set(keyFive, "", time.Second)
  5116. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5117. redis.Set(keyOne, "", time.Second)
  5118. defer redis.Close()
  5119. if err == nil {
  5120. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5121. //查询是否在处方中出库
  5122. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5123. if openConfig.IsOpen != 1 {
  5124. //判断该医嘱是否执行了
  5125. if advice.ExecutionState == 1 {
  5126. creater := c.GetAdminUserInfo().AdminUser.Id
  5127. service.DrugAutoAddCancelInfo(&advice, creater)
  5128. }
  5129. }
  5130. //开启保存处方扣减功能
  5131. if openConfig.IsOpen == 1 {
  5132. creater := c.GetAdminUserInfo().AdminUser.Id
  5133. service.DrugAutoAddCancelInfo(&advice, creater)
  5134. }
  5135. } else {
  5136. if drugOutConfig.IsOpen == 1 {
  5137. //查询是否在处方中出库
  5138. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5139. if openConfig.IsOpen != 1 {
  5140. //判断该医嘱是否执行了
  5141. if advice.ExecutionState == 1 {
  5142. creater := c.GetAdminUserInfo().AdminUser.Id
  5143. service.DrugAutoAddCancelInfo(&advice, creater)
  5144. }
  5145. }
  5146. //开启保存处方扣减功能
  5147. if openConfig.IsOpen == 1 {
  5148. creater := c.GetAdminUserInfo().AdminUser.Id
  5149. service.DrugAutoAddCancelInfo(&advice, creater)
  5150. }
  5151. } else {
  5152. //判断该医嘱是否执行了
  5153. if advice.ExecutionState == 1 {
  5154. creater := c.GetAdminUserInfo().AdminUser.Id
  5155. service.DrugAutoAddCancelInfo(&advice, creater)
  5156. }
  5157. }
  5158. }
  5159. c.ServeSuccessJSON(map[string]interface{}{
  5160. "msg": "删除成功",
  5161. })
  5162. return
  5163. } else {
  5164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5165. return
  5166. }
  5167. }
  5168. func (c *HisApiController) DeleteProject() {
  5169. id, _ := c.GetInt64("id")
  5170. adminInfo := c.GetAdminUserInfo()
  5171. project, _ := service.GetHisProjectByID(id)
  5172. // var consumable models.DialysisBeforePrepare
  5173. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5174. //耗材保存处方出库
  5175. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5176. isCharge := false
  5177. isMedicine := false
  5178. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5179. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5180. for _, item := range new_prescriptions {
  5181. if item.IsMedicine == 1 {
  5182. isMedicine = true
  5183. }
  5184. }
  5185. for _, item := range new_prescriptions {
  5186. if item.OrderStatus == 4 {
  5187. isCharge = true
  5188. }
  5189. }
  5190. if isMedicine {
  5191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5192. return
  5193. }
  5194. if isCharge {
  5195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5196. return
  5197. }
  5198. if new_prescription.ID > 0 {
  5199. if new_prescription.OrderStatus == 2 {
  5200. isCharge = true
  5201. }
  5202. }
  5203. if isCharge {
  5204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5205. return
  5206. }
  5207. service.DeletePrintInfo(id)
  5208. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5209. label.Status = 0
  5210. service.CreateHisLabelRecordTwo(&label)
  5211. fmt.Println(goodOutConfig.IsOpen)
  5212. if goodOutConfig.IsOpen != 1 {
  5213. if stockConfig.IsOpen == 1 {
  5214. if project.Type == 2 {
  5215. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5216. fmt.Println(err)
  5217. }
  5218. if project.Type == 3 && project.IsOut == 1 {
  5219. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5220. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5221. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5222. operation_time := time.Now().Unix()
  5223. creater := adminInfo.AdminUser.Id
  5224. //创建退库单
  5225. timeStr := time.Now().Format("2006-01-02")
  5226. timeArr := strings.Split(timeStr, "-")
  5227. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5228. total = total + 1
  5229. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5230. cancelStock := models.CancelStock{
  5231. OrderNumber: orderNumber,
  5232. OperaTime: operation_time,
  5233. OrgId: adminInfo.CurrentOrgId,
  5234. Creater: creater,
  5235. Ctime: time.Now().Unix(),
  5236. Status: 1,
  5237. ReturnTime: project.RecordDate,
  5238. Type: 1,
  5239. StorehouseId: houseConfig.StorehouseOutInfo,
  5240. IsCheck: 1,
  5241. }
  5242. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5243. if msgerrkonde == gorm.ErrRecordNotFound {
  5244. service.AddSigleCancelStock(&cancelStock)
  5245. }
  5246. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5247. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5248. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5249. //查询是否有出库
  5250. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5251. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5252. deaerler, _ := service.GetDealerById(info.Dealer)
  5253. if info.ID > 0 {
  5254. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5255. if info.Count >= prescribingNumber {
  5256. cancelStockInfo := models.CancelStockInfo{
  5257. GoodId: project.ProjectId,
  5258. CancelStockId: cancel.ID,
  5259. GoodTypeId: good.GoodTypeId,
  5260. Count: prescribingNumber,
  5261. Price: info.Price,
  5262. Total: 0,
  5263. ProductDate: info.ProductDate,
  5264. ExpiryDate: info.ExpiryDate,
  5265. Ctime: time.Now().Unix(),
  5266. Status: 1,
  5267. OrgId: adminInfo.CurrentOrgId,
  5268. OrderNumber: cancel.OrderNumber,
  5269. Type: 0,
  5270. Dealer: deaerler.DealerName,
  5271. Manufacturer: manufacturer.ManufacturerName,
  5272. Number: info.Number,
  5273. RegisterAccount: "",
  5274. Remark: "",
  5275. WarehouseInfoId: info.WarehouseInfotId,
  5276. PatientId: info.PatientId,
  5277. RecordDate: info.SysRecordTime,
  5278. StorehouseId: houseConfig.StorehouseOutInfo,
  5279. IsCheck: 1,
  5280. }
  5281. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5282. //回退库存
  5283. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5284. //退库数量增加
  5285. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5286. //出库数量减少
  5287. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5288. }
  5289. if info.Count < prescribingNumber {
  5290. cancelStockInfo := models.CancelStockInfo{
  5291. GoodId: project.ProjectId,
  5292. CancelStockId: cancel.ID,
  5293. GoodTypeId: good.GoodTypeId,
  5294. Count: info.Count,
  5295. Price: info.Price,
  5296. Total: 0,
  5297. ProductDate: info.ProductDate,
  5298. ExpiryDate: info.ExpiryDate,
  5299. Ctime: time.Now().Unix(),
  5300. Status: 1,
  5301. OrgId: adminInfo.CurrentOrgId,
  5302. OrderNumber: cancel.OrderNumber,
  5303. Type: 0,
  5304. Dealer: deaerler.DealerName,
  5305. Manufacturer: manufacturer.ManufacturerName,
  5306. Number: info.Number,
  5307. RegisterAccount: "",
  5308. Remark: "",
  5309. WarehouseInfoId: info.WarehouseInfotId,
  5310. PatientId: info.PatientId,
  5311. RecordDate: info.SysRecordTime,
  5312. StorehouseId: houseConfig.StorehouseOutInfo,
  5313. IsCheck: 1,
  5314. }
  5315. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5316. //回退库存
  5317. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5318. //退库数量增加
  5319. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5320. //出库数量减少
  5321. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5322. }
  5323. //查询剩余库存
  5324. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5325. var over_count int64
  5326. for _, it := range goodList {
  5327. over_count += it.StockCount
  5328. }
  5329. //出库数据 大于 退库数量
  5330. if info.Count >= prescribingNumber {
  5331. flow := models.VmStockFlow{
  5332. WarehousingId: info.WarehouseInfotId,
  5333. GoodId: project.ProjectId,
  5334. Number: info.Number,
  5335. LicenseNumber: info.LicenseNumber,
  5336. Count: prescribingNumber,
  5337. UserOrgId: adminInfo.CurrentOrgId,
  5338. PatientId: project.PatientId,
  5339. SystemTime: info.SysRecordTime,
  5340. ConsumableType: 7,
  5341. IsSys: 0,
  5342. WarehousingOrder: "",
  5343. WarehouseOutId: info.WarehouseOutId,
  5344. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5345. IsEdit: 0,
  5346. CancelStockId: cancel.ID,
  5347. CancelOrderNumber: cancel.OrderNumber,
  5348. Manufacturer: manufacturer.ID,
  5349. Dealer: 0,
  5350. Creator: adminInfo.AdminUser.Id,
  5351. UpdateCreator: 0,
  5352. Status: 1,
  5353. Ctime: time.Now().Unix(),
  5354. Mtime: 0,
  5355. Price: info.Price,
  5356. WarehousingDetailId: info.WarehouseInfotId,
  5357. WarehouseOutDetailId: info.ID,
  5358. CancelOutDetailId: cancelInfo.ID,
  5359. ProductDate: info.ProductDate,
  5360. ExpireDate: info.ExpiryDate,
  5361. StorehouseId: houseConfig.StorehouseOutInfo,
  5362. OverCount: over_count,
  5363. OperateTime: time.Now().Unix(),
  5364. }
  5365. service.CreateStockFlowOne(flow)
  5366. }
  5367. //出库数据小于退库数据
  5368. if info.Count < prescribingNumber {
  5369. flow := models.VmStockFlow{
  5370. WarehousingId: info.WarehouseInfotId,
  5371. GoodId: project.ProjectId,
  5372. Number: info.Number,
  5373. LicenseNumber: info.LicenseNumber,
  5374. Count: info.Count,
  5375. UserOrgId: adminInfo.CurrentOrgId,
  5376. PatientId: project.PatientId,
  5377. SystemTime: info.SysRecordTime,
  5378. ConsumableType: 7,
  5379. IsSys: 0,
  5380. WarehousingOrder: "",
  5381. WarehouseOutId: info.WarehouseOutId,
  5382. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5383. IsEdit: 0,
  5384. CancelStockId: cancel.ID,
  5385. CancelOrderNumber: cancel.OrderNumber,
  5386. Manufacturer: manufacturer.ID,
  5387. Dealer: 0,
  5388. Creator: adminInfo.AdminUser.Id,
  5389. UpdateCreator: 0,
  5390. Status: 1,
  5391. Ctime: time.Now().Unix(),
  5392. Mtime: 0,
  5393. Price: info.Price,
  5394. WarehousingDetailId: info.WarehouseInfotId,
  5395. WarehouseOutDetailId: info.ID,
  5396. CancelOutDetailId: cancelInfo.ID,
  5397. ProductDate: info.ProductDate,
  5398. ExpireDate: info.ExpiryDate,
  5399. StorehouseId: houseConfig.StorehouseOutInfo,
  5400. OverCount: over_count,
  5401. OperateTime: time.Now().Unix(),
  5402. }
  5403. service.CreateStockFlowOne(flow)
  5404. }
  5405. //查询已出库数量
  5406. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5407. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5408. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5409. if prescribingNumber < dialysisInfo.Count {
  5410. //改变数量
  5411. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5412. }
  5413. if prescribingNumber >= dialysisInfo.Count {
  5414. //删除出库表
  5415. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5416. }
  5417. //更新剩余库存
  5418. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5419. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5420. var total_count_one int64
  5421. for _, it := range stockList {
  5422. total_count_one += it.StockCount
  5423. }
  5424. //基础库插入数据
  5425. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5426. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5427. var flush_count int64
  5428. for _, it := range goodListOne {
  5429. flush_count += it.StockCount
  5430. }
  5431. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5432. if errs != nil {
  5433. goodErrcode := models.XtGoodErrcode{
  5434. UserOrgId: project.UserOrgId,
  5435. Errcode: "手动出库更新剩余出库失败",
  5436. GoodId: project.ProjectId,
  5437. Status: 1,
  5438. Ctime: time.Now().Unix(),
  5439. Mtime: 0,
  5440. Count: 0,
  5441. StockCount: 0,
  5442. Creater: creater,
  5443. BatchNumberId: 0,
  5444. WarehouseOutId: 0,
  5445. }
  5446. service.CreateGoodErrcode(goodErrcode)
  5447. }
  5448. }
  5449. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5450. fmt.Println(err)
  5451. } else {
  5452. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5453. fmt.Println(err)
  5454. }
  5455. } else {
  5456. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5457. fmt.Println(err)
  5458. }
  5459. }
  5460. //保存处方出库
  5461. if goodOutConfig.IsOpen == 1 {
  5462. if project.Type == 3 {
  5463. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5464. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5465. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5466. operation_time := time.Now().Unix()
  5467. creater := adminInfo.AdminUser.Id
  5468. //创建退库单
  5469. timeStr := time.Now().Format("2006-01-02")
  5470. timeArr := strings.Split(timeStr, "-")
  5471. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5472. total = total + 1
  5473. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5474. cancelStock := models.CancelStock{
  5475. OrderNumber: orderNumber,
  5476. OperaTime: operation_time,
  5477. OrgId: adminInfo.CurrentOrgId,
  5478. Creater: creater,
  5479. Ctime: time.Now().Unix(),
  5480. Status: 1,
  5481. ReturnTime: project.RecordDate,
  5482. Type: 1,
  5483. StorehouseId: houseConfig.StorehouseOutInfo,
  5484. IsCheck: 1,
  5485. }
  5486. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5487. if msgerrkonde == gorm.ErrRecordNotFound {
  5488. service.AddSigleCancelStock(&cancelStock)
  5489. }
  5490. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5491. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5492. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5493. //获取出库数据
  5494. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5495. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5496. deaerler, _ := service.GetDealerById(info.Dealer)
  5497. if info.ID > 0 {
  5498. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5499. if info.Count >= prescribingNumber {
  5500. cancelStockInfo := models.CancelStockInfo{
  5501. GoodId: project.ProjectId,
  5502. CancelStockId: cancel.ID,
  5503. GoodTypeId: good.GoodTypeId,
  5504. Count: prescribingNumber,
  5505. Price: info.Price,
  5506. Total: 0,
  5507. ProductDate: info.ProductDate,
  5508. ExpiryDate: info.ExpiryDate,
  5509. Ctime: time.Now().Unix(),
  5510. Status: 1,
  5511. OrgId: adminInfo.CurrentOrgId,
  5512. OrderNumber: cancel.OrderNumber,
  5513. Type: 0,
  5514. Dealer: deaerler.DealerName,
  5515. Manufacturer: manufacturer.ManufacturerName,
  5516. Number: info.Number,
  5517. RegisterAccount: "",
  5518. Remark: "",
  5519. WarehouseInfoId: info.WarehouseInfotId,
  5520. PatientId: info.PatientId,
  5521. RecordDate: info.SysRecordTime,
  5522. StorehouseId: houseConfig.StorehouseOutInfo,
  5523. IsCheck: 1,
  5524. }
  5525. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5526. //退库数量增加
  5527. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5528. //出库数量减少
  5529. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5530. }
  5531. if info.Count < prescribingNumber {
  5532. cancelStockInfo := models.CancelStockInfo{
  5533. GoodId: project.ProjectId,
  5534. CancelStockId: cancel.ID,
  5535. GoodTypeId: good.GoodTypeId,
  5536. Count: prescribingNumber,
  5537. Price: info.Price,
  5538. Total: 0,
  5539. ProductDate: info.ProductDate,
  5540. ExpiryDate: info.ExpiryDate,
  5541. Ctime: time.Now().Unix(),
  5542. Status: 1,
  5543. OrgId: adminInfo.CurrentOrgId,
  5544. OrderNumber: cancel.OrderNumber,
  5545. Type: 0,
  5546. Dealer: deaerler.DealerName,
  5547. Manufacturer: manufacturer.ManufacturerName,
  5548. Number: info.Number,
  5549. RegisterAccount: "",
  5550. Remark: "",
  5551. WarehouseInfoId: info.WarehouseInfotId,
  5552. PatientId: info.PatientId,
  5553. RecordDate: info.SysRecordTime,
  5554. StorehouseId: houseConfig.StorehouseOutInfo,
  5555. IsCheck: 1,
  5556. }
  5557. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5558. //回退库存
  5559. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5560. }
  5561. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5562. var over_count int64
  5563. for _, it := range goodList {
  5564. over_count += it.StockCount
  5565. }
  5566. //查询出库数量
  5567. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5568. //出库数据 大于 退库数量
  5569. if len(list) > 0 {
  5570. for _, it := range list {
  5571. //回退库存
  5572. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5573. //退库数量增加
  5574. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5575. //出库数量减少
  5576. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5577. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5578. var over_count_one int64
  5579. for _, it := range goodList {
  5580. over_count_one += it.StockCount
  5581. }
  5582. //查询该批次是否有退库数据
  5583. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5584. flow := models.VmStockFlow{
  5585. WarehousingId: it.WarehouseInfotId,
  5586. GoodId: it.GoodId,
  5587. Number: it.Number,
  5588. LicenseNumber: it.LicenseNumber,
  5589. Count: it.Count,
  5590. UserOrgId: adminInfo.CurrentOrgId,
  5591. PatientId: it.PatientId,
  5592. SystemTime: it.SysRecordTime,
  5593. ConsumableType: 7,
  5594. IsSys: 0,
  5595. WarehousingOrder: "",
  5596. WarehouseOutId: it.WarehouseOutId,
  5597. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5598. IsEdit: 0,
  5599. CancelStockId: cancel.ID,
  5600. CancelOrderNumber: cancel.OrderNumber,
  5601. Manufacturer: manufacturer.ID,
  5602. Dealer: 0,
  5603. Creator: adminInfo.AdminUser.Id,
  5604. UpdateCreator: 0,
  5605. Status: 1,
  5606. Ctime: time.Now().Unix(),
  5607. Mtime: 0,
  5608. Price: it.Price,
  5609. WarehousingDetailId: it.WarehouseInfotId,
  5610. WarehouseOutDetailId: it.ID,
  5611. CancelOutDetailId: cancelInfo.ID,
  5612. ProductDate: it.ProductDate,
  5613. ExpireDate: it.ExpiryDate,
  5614. StorehouseId: houseConfig.StorehouseOutInfo,
  5615. OverCount: over_count_one,
  5616. OperateTime: time.Now().Unix(),
  5617. }
  5618. service.CreateStockFlowOne(flow)
  5619. }
  5620. }
  5621. //查询已出库数量
  5622. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5623. if prescribingNumber < dialysisInfo.Count {
  5624. //改变数量
  5625. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5626. }
  5627. if prescribingNumber >= dialysisInfo.Count {
  5628. //删除出库表
  5629. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5630. }
  5631. //更新剩余库存
  5632. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5633. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5634. var total_count_one int64
  5635. for _, it := range stockList {
  5636. total_count_one += it.StockCount
  5637. }
  5638. //基础库插入数据
  5639. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5640. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5641. var flush_count int64
  5642. for _, it := range goodListOne {
  5643. flush_count += it.StockCount
  5644. }
  5645. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5646. if errs != nil {
  5647. goodErrcode := models.XtGoodErrcode{
  5648. UserOrgId: project.UserOrgId,
  5649. Errcode: "手动出库更新剩余出库失败",
  5650. GoodId: project.ProjectId,
  5651. Status: 1,
  5652. Ctime: time.Now().Unix(),
  5653. Mtime: 0,
  5654. Count: 0,
  5655. StockCount: 0,
  5656. Creater: creater,
  5657. BatchNumberId: 0,
  5658. WarehouseOutId: 0,
  5659. }
  5660. service.CreateGoodErrcode(goodErrcode)
  5661. }
  5662. }
  5663. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5664. fmt.Println(err)
  5665. } else {
  5666. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5667. fmt.Println(err)
  5668. }
  5669. }
  5670. c.ServeSuccessJSON(map[string]interface{}{
  5671. "msg": "删除成功",
  5672. })
  5673. return
  5674. }
  5675. func (c *HisApiController) CreateHisAdditionalCharge() {
  5676. his_patient_id, _ := c.GetInt64("his_patient_id")
  5677. patient_id, _ := c.GetInt64("patient_id")
  5678. record_date := c.GetString("record_date")
  5679. timeLayout := "2006-01-02"
  5680. loc, _ := time.LoadLocation("Local")
  5681. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5682. if err != nil {
  5683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5684. return
  5685. }
  5686. adminInfo := c.GetAdminUserInfo()
  5687. recordDateTime := theTime.Unix()
  5688. dataBody := make(map[string]interface{}, 0)
  5689. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5690. if err != nil {
  5691. utils.ErrorLog(err.Error())
  5692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5693. return
  5694. }
  5695. var additions []*models.HisAdditionalCharge
  5696. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5697. additions, _ := dataBody["addition"].([]interface{})
  5698. if len(additions) > 0 {
  5699. for _, item := range additions {
  5700. items := item.(map[string]interface{})
  5701. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5702. utils.ErrorLog("item_id")
  5703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5704. return
  5705. }
  5706. item_id := int64(items["item_id"].(float64))
  5707. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5708. utils.ErrorLog("item_name")
  5709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5710. return
  5711. }
  5712. item_name := items["item_name"].(string)
  5713. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5714. utils.ErrorLog("price")
  5715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5716. return
  5717. }
  5718. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5719. ctime := time.Now().Unix()
  5720. additional := &models.HisAdditionalCharge{
  5721. PatientId: patient_id,
  5722. HisPatientId: his_patient_id,
  5723. UserOrgId: adminInfo.CurrentOrgId,
  5724. RecordDate: recordDateTime,
  5725. CreatedTime: ctime,
  5726. UpdatedTime: ctime,
  5727. Modifier: adminInfo.AdminUser.Id,
  5728. Creator: adminInfo.AdminUser.Id,
  5729. Price: price,
  5730. ItemName: item_name,
  5731. ItemId: item_id,
  5732. Status: 1,
  5733. }
  5734. additions = append(additions, additional)
  5735. }
  5736. }
  5737. }
  5738. for _, item := range additions {
  5739. service.CreateAddtionalCharge(item)
  5740. }
  5741. c.ServeSuccessJSON(map[string]interface{}{
  5742. "msg": "创建成功",
  5743. })
  5744. }
  5745. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5746. blood_fat := c.GetString("blood_fat")
  5747. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5748. blood_sugar := c.GetString("blood_sugar")
  5749. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5750. chief_conplaint := c.GetString("chief_conplaint")
  5751. dbp := c.GetString("dbp")
  5752. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5753. delivery_way, _ := c.GetInt64("delivery_way")
  5754. diagnostic := c.GetString("diagnostic")
  5755. family_history := c.GetString("family_history")
  5756. height := c.GetString("height")
  5757. history_of_present_illness := c.GetString("history_of_present_illness")
  5758. is_infect, _ := c.GetInt64("is_infect")
  5759. past_history := c.GetString("past_history")
  5760. patient_id, _ := c.GetInt64("patient_id")
  5761. his_patient_id, _ := c.GetInt64("his_patient_id")
  5762. personal_history := c.GetString("personal_history")
  5763. pulse := c.GetString("pulse")
  5764. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5765. sbp := c.GetString("sbp")
  5766. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5767. heightfloat, _ := strconv.ParseFloat(height, 64)
  5768. sicktype := c.GetString("sick_type")
  5769. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5770. symptom := c.GetString("symptom")
  5771. sick_date := c.GetString("sick_date")
  5772. temperatures := c.GetString("temperature")
  5773. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5774. record_date := c.GetString("record_date")
  5775. breathing := c.GetString("breathing")
  5776. doctor_advice := c.GetString("doctor_advice")
  5777. remark := c.GetString("remark")
  5778. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5779. sick, _ := c.GetInt64("sick")
  5780. diagnose, _ := c.GetInt64("diagnose")
  5781. //id, _ := c.GetInt64("id")
  5782. timeLayout := "2006-01-02"
  5783. loc, _ := time.LoadLocation("Local")
  5784. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5785. allergic_history := c.GetString("allergic_history")
  5786. if err != nil {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5788. return
  5789. }
  5790. recordDateTime := theTime.Unix()
  5791. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5792. if err != nil {
  5793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5794. return
  5795. }
  5796. sickTimes := sickTime.Unix()
  5797. ctime := time.Now().Unix()
  5798. primary_disease := c.GetString("primary_disease")
  5799. confirm_failure_date := c.GetString("confirm_failure_date")
  5800. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5801. drug_allergy_history := c.GetString("drug_allergy_history")
  5802. physical_examination := c.GetString("physical_examination")
  5803. special_inspection := c.GetString("special_inspection")
  5804. lab_apparatus := c.GetString("lab_apparatus")
  5805. caseHistory := models.HisPatientCaseHistory{
  5806. HisPatientId: his_patient_id,
  5807. PatientId: patient_id,
  5808. Temperature: temperature,
  5809. BloodSugar: bloodsugarfloat,
  5810. Pulse: pulsefloat,
  5811. Sbp: sbpfloat,
  5812. Dbp: dbpfloat,
  5813. Height: heightfloat,
  5814. BloodFat: bloodfatfloat,
  5815. SickType: sick_type,
  5816. Symptom: symptom,
  5817. SickDate: sickTimes,
  5818. IsInfect: is_infect,
  5819. HistoryOfPresentIllness: history_of_present_illness,
  5820. PastHistory: past_history,
  5821. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5822. ChiefConplaint: chief_conplaint,
  5823. PersonalHistory: personal_history,
  5824. FamilyHistory: family_history,
  5825. Diagnostic: diagnostic,
  5826. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5827. Status: 1,
  5828. Ctime: ctime,
  5829. Mtime: ctime,
  5830. RecordDate: recordDateTime,
  5831. DeliveryWay: delivery_way,
  5832. Breathing: breathingfloat,
  5833. DoctorAdvice: doctor_advice,
  5834. Remark: remark,
  5835. Sick: sick,
  5836. Diagnose: diagnose,
  5837. AllergicHistory: allergic_history,
  5838. PrimaryDisease: primary_disease,
  5839. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5840. DrugAllergyHistory: drug_allergy_history,
  5841. PhysicalExamination: physical_examination,
  5842. SpecialInspection: special_inspection,
  5843. LabApparatus: lab_apparatus,
  5844. }
  5845. //查询该患者是否有病历
  5846. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5847. if errcodes == gorm.ErrRecordNotFound {
  5848. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5849. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5850. if err != nil {
  5851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5852. return
  5853. }
  5854. c.ServeSuccessJSON(map[string]interface{}{
  5855. "caseHistory": caseHistory,
  5856. "historyInfo": historyInfo,
  5857. })
  5858. return
  5859. } else if errcodes == nil {
  5860. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5861. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5862. if err != nil {
  5863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5864. return
  5865. }
  5866. c.ServeSuccessJSON(map[string]interface{}{
  5867. "caseHistory": caseHistory,
  5868. "historyInfo": historyInfo,
  5869. })
  5870. }
  5871. //查询该患者是否有病历
  5872. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5873. //if errcode == gorm.ErrRecordNotFound {
  5874. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5875. // if err != nil {
  5876. // c.ServeSuccessJSON(map[string]interface{}{
  5877. // "msg": "保存成功",
  5878. // })
  5879. // }
  5880. //} else if errcode == nil {
  5881. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5882. // return
  5883. //}
  5884. }
  5885. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5886. patient_id, _ := c.GetInt64("patient_id", 0)
  5887. adminUser := c.GetAdminUserInfo()
  5888. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5889. c.ServeSuccessJSON(map[string]interface{}{
  5890. "list": caseHistorys,
  5891. })
  5892. }
  5893. func (c *HisApiController) GetHisPatientCaseHistory() {
  5894. record_date, _ := c.GetInt64("record_date", 0)
  5895. patient_id, _ := c.GetInt64("patient_id", 0)
  5896. admin := c.GetAdminUserInfo()
  5897. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5898. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5899. c.ServeSuccessJSON(map[string]interface{}{
  5900. "info": info,
  5901. "case_history": case_history,
  5902. })
  5903. }
  5904. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5905. template_name := c.GetString("template_name")
  5906. template_remark := c.GetString("template_remark")
  5907. doctor := c.GetAdminUserInfo().AdminUser.Id
  5908. diagnostic := c.GetString("diagnostic")
  5909. chief_conplaint := c.GetString("chief_conplain")
  5910. history_of_present_illness := c.GetString("history_of_present_illness")
  5911. past_history := c.GetString("past_history")
  5912. personal_history := c.GetString("personal_history")
  5913. family_history := c.GetString("family_history")
  5914. user_name := c.GetString("user_name")
  5915. doctor_advice := c.GetString("doctor_advice")
  5916. remark := c.GetString("remark")
  5917. //record_date := c.GetString("record_date")
  5918. //fmt.Println("record_date--------",record_date)
  5919. //timeLayout := "2006-01-02"
  5920. //loc, _ := time.LoadLocation("Local")
  5921. //
  5922. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5923. //if err != nil {
  5924. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5925. // return
  5926. //}
  5927. //recordDateTime := theTime.Unix()
  5928. ctime := time.Now().Unix()
  5929. template := models.HisCaseHistoryTemplate{
  5930. HistoryOfPresentIllness: history_of_present_illness,
  5931. PastHistory: past_history,
  5932. ChiefConplaint: chief_conplaint,
  5933. PersonalHistory: personal_history,
  5934. FamilyHistory: family_history,
  5935. Diagnostic: diagnostic,
  5936. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5937. Status: 1,
  5938. Ctime: ctime,
  5939. Mtime: ctime,
  5940. RecordDate: time.Now().Unix(),
  5941. TemplateName: template_name,
  5942. TemplateRemark: template_remark,
  5943. Creator: doctor,
  5944. Modifier: doctor,
  5945. UserName: user_name,
  5946. DoctorAdvice: doctor_advice,
  5947. Remark: remark,
  5948. }
  5949. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5950. if err == nil {
  5951. c.ServeSuccessJSON(map[string]interface{}{
  5952. "msg": "保存成功",
  5953. })
  5954. } else {
  5955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5956. return
  5957. }
  5958. }
  5959. func (c *HisApiController) GetCaseHistoryTemplate() {
  5960. timeLayout := "2006-01-02"
  5961. loc, _ := time.LoadLocation("Local")
  5962. keyword := c.GetString("keyword")
  5963. start_time := c.GetString("start_time")
  5964. end_time := c.GetString("end_time")
  5965. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5966. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5967. admin := c.GetAdminUserInfo()
  5968. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5969. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5970. c.ServeSuccessJSON(map[string]interface{}{
  5971. "template": template,
  5972. //"history": history,
  5973. })
  5974. }
  5975. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5976. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5977. utils.ErrorLog("drug_name")
  5978. return enums.ErrorCodeParamWrong
  5979. }
  5980. adviceName, _ := json["drug_name"].(string)
  5981. if len(adviceName) == 0 {
  5982. utils.ErrorLog("len(advice_name) == 0")
  5983. return enums.ErrorCodeParamWrong
  5984. }
  5985. advice.AdviceName = adviceName
  5986. adviceDesc, _ := json["advice_desc"].(string)
  5987. advice.AdviceDesc = adviceDesc
  5988. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5989. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5990. advice.DrugSpec = drugSpec
  5991. }
  5992. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5993. remark, _ := json["remark"].(string)
  5994. advice.Remark = remark
  5995. }
  5996. if json["id"] == nil {
  5997. advice.DrugId = 0
  5998. } else {
  5999. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6000. drug_id := int64(json["id"].(float64))
  6001. advice.DrugId = drug_id
  6002. }
  6003. }
  6004. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6005. advice_id := int64(json["advice_id"].(float64))
  6006. advice.ID = advice_id
  6007. if advice.ID > 0 {
  6008. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6009. if err == nil {
  6010. if hisAdvice.ID > 0 {
  6011. advice.ExecutionTime = hisAdvice.ExecutionTime
  6012. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6013. advice.ExecutionState = hisAdvice.ExecutionState
  6014. advice.CheckTime = hisAdvice.CheckTime
  6015. advice.Checker = hisAdvice.Checker
  6016. advice.CheckState = hisAdvice.CheckState
  6017. advice.StartTime = hisAdvice.StartTime
  6018. advice.FeedetlSn = hisAdvice.FeedetlSn
  6019. }
  6020. }
  6021. }
  6022. }
  6023. //
  6024. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6025. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6026. // advice.ExecutionTime = execution_time
  6027. //}
  6028. //
  6029. //
  6030. //
  6031. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6032. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6033. // advice.ExecutionStaff = execution_staff
  6034. //}
  6035. //
  6036. //
  6037. //
  6038. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6039. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6040. // advice.ExecutionState = execution_state
  6041. //}
  6042. //
  6043. //
  6044. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6045. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6046. // advice.CheckTime = check_time
  6047. //}
  6048. //
  6049. //
  6050. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6051. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6052. // advice.CheckState = check_state
  6053. //}
  6054. //
  6055. //
  6056. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6057. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6058. // advice.Checker = checker
  6059. //}
  6060. //
  6061. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6062. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6063. // advice.StartTime = start_time
  6064. //}
  6065. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6066. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6067. advice.IsSelfDrug = is_self_drug
  6068. }
  6069. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6070. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6071. drug_way_count, _ := json["drug_way_count"].(string)
  6072. advice.DrugWayCount = drug_way_count
  6073. }
  6074. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6075. drugSpecUnit, _ := json["min_unit"].(string)
  6076. advice.DrugSpecUnit = drugSpecUnit
  6077. }
  6078. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6079. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6080. advice.SingleDose = singleDose
  6081. }
  6082. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6083. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6084. advice.SingleDoseUnit = singleDoseUnit
  6085. }
  6086. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6087. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6088. advice.PrescribingNumber = prescribingNumber
  6089. }
  6090. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6091. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6092. advice.PrescribingNumberUnit = prescribingNumberUnit
  6093. }
  6094. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6095. deliveryWay, _ := json["delivery_way"].(string)
  6096. advice.DeliveryWay = deliveryWay
  6097. }
  6098. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6099. executionFrequency, _ := json["execution_frequency"].(string)
  6100. advice.ExecutionFrequency = executionFrequency
  6101. }
  6102. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6103. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6104. advice.Price = price
  6105. }
  6106. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6107. med_list_codg, _ := json["medical_insurance_number"].(string)
  6108. advice.MedListCodg = med_list_codg
  6109. }
  6110. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6111. day := int64(json["day"].(float64))
  6112. advice.Day = day
  6113. }
  6114. return 0
  6115. }
  6116. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6117. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6118. id := int64(json["id"].(float64))
  6119. project.ID = id
  6120. historyProject, _ := service.GetHisProjectByID(id)
  6121. project.FeedetlSn = historyProject.FeedetlSn
  6122. }
  6123. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6124. project_id := int64(json["project_id"].(float64))
  6125. project.ProjectId = project_id
  6126. }
  6127. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6128. // price := int64(json["price"].(float64))
  6129. // formatInt_price := strconv.FormatInt(price, 10)
  6130. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6131. // project.Price = float_price
  6132. // }
  6133. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6134. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6135. project.Price = price
  6136. }
  6137. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6138. total, _ := json["total"].(string)
  6139. project.Count = total
  6140. }
  6141. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6142. medical_code, _ := json["medical_code"].(string)
  6143. project.MedListCodg = medical_code
  6144. }
  6145. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6146. single_dose, _ := json["single_dose"].(string)
  6147. project.SingleDose = single_dose
  6148. }
  6149. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6150. delivery_way, _ := json["delivery_way"].(string)
  6151. project.DeliveryWay = delivery_way
  6152. }
  6153. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6154. execution_frequency, _ := json["execution_frequency"].(string)
  6155. project.ExecutionFrequency = execution_frequency
  6156. }
  6157. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6158. remark, _ := json["remark"].(string)
  6159. project.Remark = remark
  6160. }
  6161. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6162. day, _ := json["number_days"].(string)
  6163. project.Day = day
  6164. }
  6165. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6166. unit, _ := json["unit"].(string)
  6167. project.Unit = unit
  6168. }
  6169. return 0
  6170. }
  6171. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6172. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6173. id := int64(json["id"].(float64))
  6174. historyAddtions, _ := service.GetHisAdditionByID(id)
  6175. additionalCharge.ID = id
  6176. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6177. }
  6178. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6179. item_id := int64(json["item_id"].(float64))
  6180. additionalCharge.ItemId = item_id
  6181. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6182. if config.ID > 0 {
  6183. if len(config.Code) > 0 {
  6184. additionalCharge.MedListCodg = config.Code
  6185. }
  6186. }
  6187. }
  6188. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6189. // price := int64(json["price"].(float64))
  6190. // formatInt_price := strconv.FormatInt(price, 10)
  6191. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6192. // additionalCharge.Price = float_price
  6193. // }
  6194. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6195. // price := int64(json["price"].(float64))
  6196. // formatInt_price := strconv.FormatInt(price, 10)
  6197. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6198. // additionalCharge.Price = float_price
  6199. //}
  6200. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6201. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6202. additionalCharge.Price = price
  6203. }
  6204. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6205. count, _ := json["count"].(string)
  6206. counts, _ := strconv.ParseInt(count, 10, 64)
  6207. additionalCharge.Count = counts
  6208. }
  6209. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6210. item_name, _ := json["item_name"].(string)
  6211. additionalCharge.ItemName = item_name
  6212. }
  6213. return 0
  6214. }
  6215. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6216. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6217. utils.ErrorLog("drug_name")
  6218. return enums.ErrorCodeParamWrong
  6219. }
  6220. adviceName, _ := json["drug_name"].(string)
  6221. if len(adviceName) == 0 {
  6222. utils.ErrorLog("len(advice_name) == 0")
  6223. return enums.ErrorCodeParamWrong
  6224. }
  6225. advice.AdviceName = adviceName
  6226. adviceDesc, _ := json["advice_desc"].(string)
  6227. advice.AdviceDesc = adviceDesc
  6228. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6229. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6230. advice.DrugSpec = drugSpec
  6231. }
  6232. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6233. remark, _ := json["remark"].(string)
  6234. advice.Remark = remark
  6235. }
  6236. if json["id"] == nil {
  6237. advice.DrugId = 0
  6238. } else {
  6239. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6240. drug_id := int64(json["id"].(float64))
  6241. advice.DrugId = drug_id
  6242. }
  6243. }
  6244. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6245. groupno := int64(json["groupno"].(float64))
  6246. advice.Groupno = groupno
  6247. }
  6248. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6249. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6250. advice.IsSelfDrug = is_self_drug
  6251. }
  6252. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6253. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6254. drug_way_count, _ := json["drug_way_count"].(string)
  6255. advice.DrugWayCount = drug_way_count
  6256. }
  6257. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6258. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6259. advice.HospApprFlag = hosp_appr_flag
  6260. }
  6261. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6262. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6263. advice.PrescribingNumber = prescribingNumber
  6264. }
  6265. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6266. // frequency_type := int64(json["frequency_type"].(float64))
  6267. // advice.FrequencyType = frequency_type
  6268. //}
  6269. //
  6270. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6271. // day_count := int64(json["day_count"].(float64))
  6272. // advice.DayCount = day_count
  6273. //}
  6274. //
  6275. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6276. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6277. // week_day, _ := json["week_day"].(string)
  6278. // advice.WeekDay = week_day
  6279. //}
  6280. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6281. drugSpecUnit, _ := json["min_unit"].(string)
  6282. advice.DrugSpecUnit = drugSpecUnit
  6283. }
  6284. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6285. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6286. advice.SingleDose = singleDose
  6287. }
  6288. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6289. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6290. advice.SingleDoseUnit = singleDoseUnit
  6291. }
  6292. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6293. deliveryWay, _ := json["delivery_way"].(string)
  6294. advice.DeliveryWay = deliveryWay
  6295. }
  6296. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6297. executionFrequency, _ := json["execution_frequency"].(string)
  6298. advice.ExecutionFrequency = executionFrequency
  6299. }
  6300. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6301. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6302. advice.Price = price
  6303. }
  6304. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6305. med_list_codg, _ := json["medical_insurance_number"].(string)
  6306. advice.MedListCodg = med_list_codg
  6307. }
  6308. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6309. day := int64(json["day"].(float64))
  6310. advice.Day = day
  6311. }
  6312. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6313. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6314. advice.PrescribingNumberUnit = prescribingNumberUnit
  6315. }
  6316. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6317. advice_id := int64(json["advice_id"].(float64))
  6318. advice.ID = advice_id
  6319. if advice.ID > 0 {
  6320. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6321. if err == nil {
  6322. if hisAdvice.ID > 0 {
  6323. advice.ExecutionTime = hisAdvice.ExecutionTime
  6324. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6325. advice.ExecutionState = hisAdvice.ExecutionState
  6326. advice.CheckTime = hisAdvice.CheckTime
  6327. advice.Checker = hisAdvice.Checker
  6328. advice.CheckState = hisAdvice.CheckState
  6329. advice.StartTime = hisAdvice.StartTime
  6330. advice.HospApprFlag = hisAdvice.HospApprFlag
  6331. advice.IsMedicine = hisAdvice.IsMedicine
  6332. if hisAdvice.UserOrgId == 10028 {
  6333. if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  6334. advice.ExecutionTime = 0
  6335. advice.ExecutionStaff = 0
  6336. advice.ExecutionState = 2
  6337. advice.CheckTime = 0
  6338. advice.Checker = 0
  6339. advice.CheckState = 2
  6340. }
  6341. } else {
  6342. if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  6343. advice.ExecutionTime = 0
  6344. advice.ExecutionStaff = 0
  6345. advice.ExecutionState = 2
  6346. advice.CheckTime = 0
  6347. advice.Checker = 0
  6348. advice.CheckState = 2
  6349. advice.UpdatedTime = time.Now().Unix()
  6350. }
  6351. }
  6352. //advice.Groupno = hisAdvice.Groupno
  6353. }
  6354. }
  6355. }
  6356. }
  6357. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6358. //
  6359. //if drugStockConfig.IsOpen == 1 {
  6360. //
  6361. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6362. // if advice.ID == 0 { //医嘱不存在
  6363. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6364. // drug.Total = drug.Total - advice.PrescribingNumber
  6365. // service.UpdateBaseDrugLib(&drug)
  6366. //
  6367. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6368. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6369. // drug.Total = drug.Total - num
  6370. // service.UpdateBaseDrugLib(&drug)
  6371. // }
  6372. //
  6373. // } else if advice.ID > 0 { //医嘱存在
  6374. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6375. // var num float64
  6376. //
  6377. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6378. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6379. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6380. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6381. // drug.Total = drug.Total + num
  6382. // service.UpdateBaseDrugLib(&drug)
  6383. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6384. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6385. // drug.Total = drug.Total - num
  6386. // service.UpdateBaseDrugLib(&drug)
  6387. // }
  6388. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6389. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6390. // if num2 > advice.PrescribingNumber {
  6391. // num = num2 - advice.PrescribingNumber
  6392. // drug.Total = drug.Total + num
  6393. // service.UpdateBaseDrugLib(&drug)
  6394. // } else if num2 < advice.PrescribingNumber {
  6395. // num = advice.PrescribingNumber - num2
  6396. // drug.Total = drug.Total - num
  6397. // service.UpdateBaseDrugLib(&drug)
  6398. // }
  6399. //
  6400. // }
  6401. //
  6402. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6403. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6404. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6405. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6406. // if num1 > num2 {
  6407. // num = num1 - num2
  6408. // drug.Total = drug.Total + num
  6409. // service.UpdateBaseDrugLib(&drug)
  6410. // } else if num1 < num2 {
  6411. // num = num2 - num1
  6412. // drug.Total = drug.Total - num
  6413. // service.UpdateBaseDrugLib(&drug)
  6414. // }
  6415. //
  6416. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6417. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6418. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6419. // if hisAdvice.PrescribingNumber > num2 {
  6420. // num = hisAdvice.PrescribingNumber - num2
  6421. // drug.Total = drug.Total + num
  6422. // service.UpdateBaseDrugLib(&drug)
  6423. // } else if num2 < advice.PrescribingNumber {
  6424. // num = num2 - hisAdvice.PrescribingNumber
  6425. // drug.Total = drug.Total - num
  6426. // service.UpdateBaseDrugLib(&drug)
  6427. // }
  6428. //
  6429. // }
  6430. // }
  6431. // }
  6432. //}
  6433. //
  6434. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6435. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6436. // advice.ExecutionTime = execution_time
  6437. //}
  6438. //
  6439. //
  6440. //
  6441. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6442. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6443. // advice.ExecutionStaff = execution_staff
  6444. //}
  6445. //
  6446. //
  6447. //
  6448. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6449. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6450. // advice.ExecutionState = execution_state
  6451. //}
  6452. //
  6453. //
  6454. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6455. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6456. // advice.CheckTime = check_time
  6457. //}
  6458. //
  6459. //
  6460. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6461. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6462. // advice.CheckState = check_state
  6463. //}
  6464. //
  6465. //
  6466. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6467. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6468. // advice.Checker = checker
  6469. //}
  6470. //
  6471. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6472. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6473. // advice.StartTime = start_time
  6474. //}
  6475. return 0
  6476. }
  6477. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6478. project.ExecutionStaff = 0
  6479. project.ExecutionState = 2
  6480. project.ExecutionTime = 0
  6481. project.Checker = 0
  6482. project.CheckState = 2
  6483. project.CheckTime = 0
  6484. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6485. id := int64(json["id"].(float64))
  6486. project.ID = id
  6487. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6488. project.ExecutionStaff = temp_project.ExecutionStaff
  6489. project.ExecutionState = temp_project.ExecutionState
  6490. project.ExecutionTime = temp_project.ExecutionTime
  6491. project.Checker = temp_project.Checker
  6492. project.CheckState = temp_project.CheckState
  6493. project.CheckTime = temp_project.CheckTime
  6494. project.TeamId = temp_project.TeamId
  6495. }
  6496. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6497. types := int64(json["type"].(float64))
  6498. project.Type = types
  6499. }
  6500. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6501. project_id := int64(json["project_id"].(float64))
  6502. project.ProjectId = project_id
  6503. }
  6504. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6505. team_id := int64(json["team_id"].(float64))
  6506. project.TeamId = team_id
  6507. }
  6508. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6509. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6510. project.Price = price
  6511. }
  6512. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6513. total, _ := json["total"].(string)
  6514. //totals, _ := strconv.ParseInt(total, 10, 64)
  6515. project.Count = total
  6516. }
  6517. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6518. medical_code, _ := json["medical_code"].(string)
  6519. project.MedListCodg = medical_code
  6520. }
  6521. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6522. single_dose, _ := json["single_dose"].(string)
  6523. project.SingleDose = single_dose
  6524. }
  6525. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6526. delivery_way, _ := json["delivery_way"].(string)
  6527. project.DeliveryWay = delivery_way
  6528. }
  6529. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6530. execution_frequency, _ := json["execution_frequency"].(string)
  6531. project.ExecutionFrequency = execution_frequency
  6532. }
  6533. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6534. remark, _ := json["remark"].(string)
  6535. project.Remark = remark
  6536. }
  6537. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6538. day, _ := json["number_days"].(string)
  6539. project.Day = day
  6540. }
  6541. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6542. unit, _ := json["unit"].(string)
  6543. project.Unit = unit
  6544. }
  6545. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6546. // frequency_type := int64(json["frequency_type"].(float64))
  6547. // project.FrequencyType = frequency_type
  6548. //}
  6549. //
  6550. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6551. // day_count := int64(json["day_count"].(float64))
  6552. // project.DayCount = day_count
  6553. //}
  6554. //
  6555. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6556. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6557. // week_day, _ := json["week_day"].(string)
  6558. // project.WeekDay = week_day
  6559. //}
  6560. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6561. //
  6562. //if project.ID == 0 {
  6563. // if stockConfig.IsOpen == 1 {
  6564. // if project.Type == 3 {
  6565. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6566. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6567. // good.Total = good.Total - f_count
  6568. // service.UpdateGoodInfo(&good)
  6569. // }
  6570. // }
  6571. //
  6572. //} else {
  6573. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6574. //
  6575. // if stockConfig.IsOpen == 1 {
  6576. // if project.Type == 3 {
  6577. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6578. // if project.Count < temp_project.Count {
  6579. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6580. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6581. //
  6582. // other_count := f_count_two - f_count_one
  6583. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6584. // good.Total = good.Total + other_count_two
  6585. // service.UpdateGoodInfo(&good)
  6586. // } else if project.Count > temp_project.Count {
  6587. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6588. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6589. //
  6590. // other_count := f_count_one - f_count_two
  6591. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6592. // good.Total = good.Total - other_count_two
  6593. // service.UpdateGoodInfo(&good)
  6594. // }
  6595. //
  6596. // }
  6597. // }
  6598. //
  6599. //}
  6600. return 0
  6601. }
  6602. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6603. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6604. utils.ErrorLog("drug_name")
  6605. return enums.ErrorCodeParamWrong
  6606. }
  6607. adviceName, _ := json["drug_name"].(string)
  6608. if len(adviceName) == 0 {
  6609. utils.ErrorLog("len(advice_name) == 0")
  6610. return enums.ErrorCodeParamWrong
  6611. }
  6612. advice.AdviceName = adviceName
  6613. adviceDesc, _ := json["advice_desc"].(string)
  6614. advice.AdviceDesc = adviceDesc
  6615. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6616. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6617. advice.DrugSpec = drugSpec
  6618. }
  6619. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6620. remark, _ := json["remark"].(string)
  6621. advice.Remark = remark
  6622. }
  6623. if json["id"] == nil {
  6624. advice.DrugId = 0
  6625. } else {
  6626. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6627. drug_id := int64(json["id"].(float64))
  6628. advice.DrugId = drug_id
  6629. }
  6630. }
  6631. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6632. groupno := int64(json["groupno"].(float64))
  6633. advice.Groupno = groupno
  6634. }
  6635. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6636. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6637. advice.IsSelfDrug = is_self_drug
  6638. }
  6639. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6640. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6641. drug_way_count, _ := json["drug_way_count"].(string)
  6642. advice.DrugWayCount = drug_way_count
  6643. }
  6644. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6645. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6646. advice.HospApprFlag = hosp_appr_flag
  6647. }
  6648. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6649. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6650. advice.PrescribingNumber = prescribingNumber
  6651. }
  6652. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6653. // frequency_type := int64(json["frequency_type"].(float64))
  6654. // advice.FrequencyType = frequency_type
  6655. //}
  6656. //
  6657. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6658. // day_count := int64(json["day_count"].(float64))
  6659. // advice.DayCount = day_count
  6660. //}
  6661. //
  6662. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6663. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6664. // week_day, _ := json["week_day"].(string)
  6665. // advice.WeekDay = week_day
  6666. //}
  6667. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6668. drugSpecUnit, _ := json["min_unit"].(string)
  6669. advice.DrugSpecUnit = drugSpecUnit
  6670. }
  6671. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6672. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6673. advice.SingleDose = singleDose
  6674. }
  6675. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6676. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6677. advice.SingleDoseUnit = singleDoseUnit
  6678. }
  6679. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6680. deliveryWay, _ := json["delivery_way"].(string)
  6681. advice.DeliveryWay = deliveryWay
  6682. }
  6683. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6684. executionFrequency, _ := json["execution_frequency"].(string)
  6685. advice.ExecutionFrequency = executionFrequency
  6686. }
  6687. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6688. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6689. advice.Price = price
  6690. }
  6691. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6692. med_list_codg, _ := json["medical_insurance_number"].(string)
  6693. advice.MedListCodg = med_list_codg
  6694. }
  6695. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6696. day := int64(json["day"].(float64))
  6697. advice.Day = day
  6698. }
  6699. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6700. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6701. advice.PrescribingNumberUnit = prescribingNumberUnit
  6702. }
  6703. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6704. advice_id := int64(json["advice_id"].(float64))
  6705. advice.ID = advice_id
  6706. if advice.ID > 0 {
  6707. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6708. if err == nil {
  6709. if hisAdvice.ID > 0 {
  6710. advice.ExecutionTime = hisAdvice.ExecutionTime
  6711. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6712. advice.ExecutionState = hisAdvice.ExecutionState
  6713. advice.CheckTime = hisAdvice.CheckTime
  6714. advice.Checker = hisAdvice.Checker
  6715. advice.CheckState = hisAdvice.CheckState
  6716. advice.StartTime = hisAdvice.StartTime
  6717. advice.HospApprFlag = hisAdvice.HospApprFlag
  6718. advice.IsMedicine = hisAdvice.IsMedicine
  6719. if hisAdvice.UserOrgId == 10028 {
  6720. if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  6721. advice.ExecutionTime = 0
  6722. advice.ExecutionStaff = 0
  6723. advice.ExecutionState = 2
  6724. advice.CheckTime = 0
  6725. advice.Checker = 0
  6726. advice.CheckState = 2
  6727. }
  6728. } else {
  6729. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  6730. advice.ExecutionTime = 0
  6731. advice.ExecutionStaff = 0
  6732. advice.ExecutionState = 2
  6733. advice.CheckTime = 0
  6734. advice.Checker = 0
  6735. advice.CheckState = 2
  6736. //advice.UpdatedTime = time.Now().Unix()
  6737. advice.CreatedTime = hisAdvice.CreatedTime
  6738. advice.UpdatedTime = time.Now().Unix()
  6739. } else {
  6740. advice.CreatedTime = hisAdvice.CreatedTime
  6741. advice.UpdatedTime = hisAdvice.UpdatedTime
  6742. }
  6743. }
  6744. //advice.Groupno = hisAdvice.Groupno
  6745. } else {
  6746. ctime := time.Now().Unix()
  6747. advice.CreatedTime = ctime
  6748. advice.UpdatedTime = ctime
  6749. }
  6750. }
  6751. } else {
  6752. ctime := time.Now().Unix()
  6753. advice.CreatedTime = ctime
  6754. advice.UpdatedTime = ctime
  6755. }
  6756. }
  6757. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6758. //
  6759. //if drugStockConfig.IsOpen == 1 {
  6760. //
  6761. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6762. // if advice.ID == 0 { //医嘱不存在
  6763. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6764. // drug.Total = drug.Total - advice.PrescribingNumber
  6765. // service.UpdateBaseDrugLib(&drug)
  6766. //
  6767. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6768. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6769. // drug.Total = drug.Total - num
  6770. // service.UpdateBaseDrugLib(&drug)
  6771. // }
  6772. //
  6773. // } else if advice.ID > 0 { //医嘱存在
  6774. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6775. // var num float64
  6776. //
  6777. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6778. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6779. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6780. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6781. // drug.Total = drug.Total + num
  6782. // service.UpdateBaseDrugLib(&drug)
  6783. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6784. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6785. // drug.Total = drug.Total - num
  6786. // service.UpdateBaseDrugLib(&drug)
  6787. // }
  6788. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6789. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6790. // if num2 > advice.PrescribingNumber {
  6791. // num = num2 - advice.PrescribingNumber
  6792. // drug.Total = drug.Total + num
  6793. // service.UpdateBaseDrugLib(&drug)
  6794. // } else if num2 < advice.PrescribingNumber {
  6795. // num = advice.PrescribingNumber - num2
  6796. // drug.Total = drug.Total - num
  6797. // service.UpdateBaseDrugLib(&drug)
  6798. // }
  6799. //
  6800. // }
  6801. //
  6802. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6803. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6804. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6805. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6806. // if num1 > num2 {
  6807. // num = num1 - num2
  6808. // drug.Total = drug.Total + num
  6809. // service.UpdateBaseDrugLib(&drug)
  6810. // } else if num1 < num2 {
  6811. // num = num2 - num1
  6812. // drug.Total = drug.Total - num
  6813. // service.UpdateBaseDrugLib(&drug)
  6814. // }
  6815. //
  6816. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6817. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6818. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6819. // if hisAdvice.PrescribingNumber > num2 {
  6820. // num = hisAdvice.PrescribingNumber - num2
  6821. // drug.Total = drug.Total + num
  6822. // service.UpdateBaseDrugLib(&drug)
  6823. // } else if num2 < advice.PrescribingNumber {
  6824. // num = num2 - hisAdvice.PrescribingNumber
  6825. // drug.Total = drug.Total - num
  6826. // service.UpdateBaseDrugLib(&drug)
  6827. // }
  6828. //
  6829. // }
  6830. // }
  6831. // }
  6832. //}
  6833. //
  6834. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6835. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6836. // advice.ExecutionTime = execution_time
  6837. //}
  6838. //
  6839. //
  6840. //
  6841. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6842. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6843. // advice.ExecutionStaff = execution_staff
  6844. //}
  6845. //
  6846. //
  6847. //
  6848. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6849. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6850. // advice.ExecutionState = execution_state
  6851. //}
  6852. //
  6853. //
  6854. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6855. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6856. // advice.CheckTime = check_time
  6857. //}
  6858. //
  6859. //
  6860. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6861. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6862. // advice.CheckState = check_state
  6863. //}
  6864. //
  6865. //
  6866. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6867. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6868. // advice.Checker = checker
  6869. //}
  6870. //
  6871. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6872. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6873. // advice.StartTime = start_time
  6874. //}
  6875. return 0
  6876. }
  6877. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6878. project.ExecutionStaff = 0
  6879. project.ExecutionState = 2
  6880. project.ExecutionTime = 0
  6881. project.Checker = 0
  6882. project.CheckState = 2
  6883. project.CheckTime = 0
  6884. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6885. id := int64(json["id"].(float64))
  6886. project.ID = id
  6887. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6888. project.ExecutionStaff = temp_project.ExecutionStaff
  6889. project.ExecutionState = temp_project.ExecutionState
  6890. project.ExecutionTime = temp_project.ExecutionTime
  6891. project.Checker = temp_project.Checker
  6892. project.CheckState = temp_project.CheckState
  6893. project.CheckTime = temp_project.CheckTime
  6894. project.TeamId = temp_project.TeamId
  6895. }
  6896. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6897. types := int64(json["type"].(float64))
  6898. project.Type = types
  6899. }
  6900. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6901. project_id := int64(json["project_id"].(float64))
  6902. project.ProjectId = project_id
  6903. }
  6904. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6905. team_id := int64(json["team_id"].(float64))
  6906. project.TeamId = team_id
  6907. }
  6908. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6909. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6910. project.Price = price
  6911. }
  6912. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6913. total, _ := json["total"].(string)
  6914. //totals, _ := strconv.ParseInt(total, 10, 64)
  6915. project.Count = total
  6916. }
  6917. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6918. medical_code, _ := json["medical_code"].(string)
  6919. project.MedListCodg = medical_code
  6920. }
  6921. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6922. single_dose, _ := json["single_dose"].(string)
  6923. project.SingleDose = single_dose
  6924. }
  6925. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6926. delivery_way, _ := json["delivery_way"].(string)
  6927. project.DeliveryWay = delivery_way
  6928. }
  6929. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6930. execution_frequency, _ := json["execution_frequency"].(string)
  6931. project.ExecutionFrequency = execution_frequency
  6932. }
  6933. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6934. remark, _ := json["remark"].(string)
  6935. project.Remark = remark
  6936. }
  6937. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6938. day, _ := json["number_days"].(string)
  6939. project.Day = day
  6940. }
  6941. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6942. unit, _ := json["unit"].(string)
  6943. project.Unit = unit
  6944. }
  6945. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6946. // frequency_type := int64(json["frequency_type"].(float64))
  6947. // project.FrequencyType = frequency_type
  6948. //}
  6949. //
  6950. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6951. // day_count := int64(json["day_count"].(float64))
  6952. // project.DayCount = day_count
  6953. //}
  6954. //
  6955. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6956. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6957. // week_day, _ := json["week_day"].(string)
  6958. // project.WeekDay = week_day
  6959. //}
  6960. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6961. //
  6962. //if project.ID == 0 {
  6963. // if stockConfig.IsOpen == 1 {
  6964. // if project.Type == 3 {
  6965. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6966. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6967. // good.Total = good.Total - f_count
  6968. // service.UpdateGoodInfo(&good)
  6969. // }
  6970. // }
  6971. //
  6972. //} else {
  6973. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6974. //
  6975. // if stockConfig.IsOpen == 1 {
  6976. // if project.Type == 3 {
  6977. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6978. // if project.Count < temp_project.Count {
  6979. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6980. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6981. //
  6982. // other_count := f_count_two - f_count_one
  6983. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6984. // good.Total = good.Total + other_count_two
  6985. // service.UpdateGoodInfo(&good)
  6986. // } else if project.Count > temp_project.Count {
  6987. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6988. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6989. //
  6990. // other_count := f_count_one - f_count_two
  6991. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6992. // good.Total = good.Total - other_count_two
  6993. // service.UpdateGoodInfo(&good)
  6994. // }
  6995. //
  6996. // }
  6997. // }
  6998. //
  6999. //}
  7000. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7001. id := int64(json["id"].(float64))
  7002. if id > 0 {
  7003. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7004. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7005. fmt.Println("666666")
  7006. project.Mtime = time.Now().Unix()
  7007. project.Ctime = temp_project.Ctime
  7008. } else {
  7009. project.Mtime = temp_project.Mtime
  7010. project.Ctime = temp_project.Ctime
  7011. }
  7012. } else {
  7013. ctime := time.Now().Unix()
  7014. project.Mtime = ctime
  7015. project.Ctime = ctime
  7016. }
  7017. }
  7018. return 0
  7019. }
  7020. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7021. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7022. id := int64(json["id"].(float64))
  7023. additionalCharge.ID = id
  7024. }
  7025. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7026. item_id := int64(json["item_id"].(float64))
  7027. additionalCharge.ItemId = item_id
  7028. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7029. if config.ID > 0 {
  7030. if len(config.Code) > 0 {
  7031. additionalCharge.MedListCodg = config.Code
  7032. }
  7033. }
  7034. }
  7035. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7036. // price := int64(json["price"].(float64))
  7037. // formatInt_price := strconv.FormatInt(price, 10)
  7038. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7039. // additionalCharge.Price = float_price
  7040. // }
  7041. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7042. // price := int64(json["price"].(float64))
  7043. // formatInt_price := strconv.FormatInt(price, 10)
  7044. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7045. // additionalCharge.Price = float_price
  7046. //}
  7047. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7048. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7049. additionalCharge.Price = price
  7050. }
  7051. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7052. count, _ := json["count"].(string)
  7053. counts, _ := strconv.ParseInt(count, 10, 64)
  7054. additionalCharge.Count = counts
  7055. }
  7056. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7057. item_name, _ := json["item_name"].(string)
  7058. additionalCharge.ItemName = item_name
  7059. }
  7060. return 0
  7061. }
  7062. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7063. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7064. utils.ErrorLog("drug_name")
  7065. return enums.ErrorCodeParamWrong
  7066. }
  7067. adviceName, _ := json["drug_name"].(string)
  7068. if len(adviceName) == 0 {
  7069. utils.ErrorLog("len(advice_name) == 0")
  7070. return enums.ErrorCodeParamWrong
  7071. }
  7072. advice.AdviceName = adviceName
  7073. adviceDesc, _ := json["advice_desc"].(string)
  7074. advice.AdviceDesc = adviceDesc
  7075. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7076. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7077. advice.DrugSpec = drugSpec
  7078. }
  7079. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7080. remark, _ := json["remark"].(string)
  7081. advice.Remark = remark
  7082. }
  7083. if json["id"] == nil {
  7084. advice.DrugId = 0
  7085. } else {
  7086. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7087. drug_id := int64(json["id"].(float64))
  7088. advice.DrugId = drug_id
  7089. }
  7090. }
  7091. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7092. groupno := int64(json["groupno"].(float64))
  7093. advice.Groupno = groupno
  7094. }
  7095. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7096. drugSpecUnit, _ := json["min_unit"].(string)
  7097. advice.DrugSpecUnit = drugSpecUnit
  7098. }
  7099. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7100. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7101. advice.SingleDose = singleDose
  7102. }
  7103. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7104. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7105. advice.SingleDoseUnit = singleDoseUnit
  7106. }
  7107. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7108. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7109. advice.PrescribingNumber = prescribingNumber
  7110. }
  7111. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7112. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7113. advice.PrescribingNumberUnit = prescribingNumberUnit
  7114. }
  7115. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7116. deliveryWay, _ := json["delivery_way"].(string)
  7117. advice.DeliveryWay = deliveryWay
  7118. }
  7119. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7120. executionFrequency, _ := json["execution_frequency"].(string)
  7121. advice.ExecutionFrequency = executionFrequency
  7122. }
  7123. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7124. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7125. advice.Price = price
  7126. }
  7127. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7128. med_list_codg, _ := json["medical_insurance_number"].(string)
  7129. advice.MedListCodg = med_list_codg
  7130. }
  7131. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7132. day := int64(json["day"].(float64))
  7133. advice.Day = day
  7134. }
  7135. advice.FrequencyType = 1
  7136. return 0
  7137. }
  7138. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7139. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7140. types := int64(json["type"].(float64))
  7141. project.Type = types
  7142. }
  7143. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7144. project_id := int64(json["project_id"].(float64))
  7145. project.ProjectId = project_id
  7146. }
  7147. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7148. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7149. project.Price = price
  7150. }
  7151. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7152. total, _ := json["total"].(string)
  7153. //totals, _ := strconv.ParseInt(total, 10, 64)
  7154. project.Count = total
  7155. }
  7156. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7157. medical_code, _ := json["medical_code"].(string)
  7158. project.MedListCodg = medical_code
  7159. }
  7160. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7161. single_dose, _ := json["single_dose"].(string)
  7162. project.SingleDose = single_dose
  7163. }
  7164. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7165. delivery_way, _ := json["delivery_way"].(string)
  7166. project.DeliveryWay = delivery_way
  7167. }
  7168. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7169. execution_frequency, _ := json["execution_frequency"].(string)
  7170. project.ExecutionFrequency = execution_frequency
  7171. }
  7172. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7173. remark, _ := json["remark"].(string)
  7174. project.Remark = remark
  7175. }
  7176. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7177. day, _ := json["number_days"].(string)
  7178. project.Day = day
  7179. }
  7180. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7181. unit, _ := json["unit"].(string)
  7182. project.Unit = unit
  7183. }
  7184. project.FrequencyType = 1
  7185. return 0
  7186. }
  7187. func (c *HisApiController) GetHisOrderListTwo() {
  7188. start_time := c.GetString("start_time")
  7189. end_time := c.GetString("end_time")
  7190. timeLayout := "2006-01-02"
  7191. loc, _ := time.LoadLocation("Local")
  7192. var startTime int64
  7193. if len(start_time) > 0 {
  7194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7195. if err != nil {
  7196. //fmt.Println(err)
  7197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7198. return
  7199. }
  7200. startTime = theTime.Unix()
  7201. }
  7202. var endTime int64
  7203. if len(end_time) > 0 {
  7204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7205. if err != nil {
  7206. utils.ErrorLog(err.Error())
  7207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7208. return
  7209. }
  7210. endTime = theTime.Unix()
  7211. }
  7212. adminUser := c.GetAdminUserInfo()
  7213. org_id := adminUser.CurrentOrgId
  7214. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7215. if err == nil {
  7216. c.ServeSuccessJSON(map[string]interface{}{
  7217. "order2": order,
  7218. })
  7219. } else {
  7220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7221. return
  7222. }
  7223. }
  7224. func (c *HisApiController) GetHisOrderList() {
  7225. page, _ := c.GetInt64("page", -1)
  7226. limit, _ := c.GetInt64("limit", -1)
  7227. start_time := c.GetString("start_time")
  7228. end_time := c.GetString("end_time")
  7229. types, _ := c.GetInt64("type", 0)
  7230. keywords := c.GetString("keywords")
  7231. p_type, _ := c.GetInt64("p_type", 0)
  7232. sort_type, _ := c.GetInt64("sort_type", 0)
  7233. charge_type, _ := c.GetInt64("charge_type", 0)
  7234. sch_type, _ := c.GetInt64("sch_type", 0)
  7235. zone_type, _ := c.GetInt64("zone_type", 0)
  7236. med_type, _ := c.GetInt64("med_type", 0)
  7237. timeLayout := "2006-01-02"
  7238. loc, _ := time.LoadLocation("Local")
  7239. var startTime int64
  7240. if len(start_time) > 0 {
  7241. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7242. if err != nil {
  7243. //fmt.Println(err)
  7244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7245. return
  7246. }
  7247. startTime = theTime.Unix()
  7248. }
  7249. var endTime int64
  7250. if len(end_time) > 0 {
  7251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7252. if err != nil {
  7253. utils.ErrorLog(err.Error())
  7254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7255. return
  7256. }
  7257. endTime = theTime.Unix()
  7258. }
  7259. adminUser := c.GetAdminUserInfo()
  7260. org_id := adminUser.CurrentOrgId
  7261. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  7262. for _, item := range order {
  7263. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7264. item.DoctorName = info.Doctor
  7265. item.DepartmentName = info.XtHisDepartment.Name
  7266. }
  7267. if err == nil {
  7268. c.ServeSuccessJSON(map[string]interface{}{
  7269. "order": order,
  7270. "total": total,
  7271. })
  7272. } else {
  7273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7274. return
  7275. }
  7276. }
  7277. func (c *HisApiController) GetHisOrder() {
  7278. patient_id, _ := c.GetInt64("patient_id", 0)
  7279. number := c.GetString("number")
  7280. adminInfo := c.GetAdminUserInfo()
  7281. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7282. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7283. if err == nil {
  7284. c.ServeSuccessJSON(map[string]interface{}{
  7285. "order": order,
  7286. "prescription": prescriptions,
  7287. })
  7288. } else {
  7289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7290. return
  7291. }
  7292. }
  7293. func (c *HisApiController) GetHisPrescriptionList() {
  7294. record_date := c.GetString("record_date")
  7295. keywords := c.GetString("keywords")
  7296. page, _ := c.GetInt64("page")
  7297. limit, _ := c.GetInt64("limit")
  7298. sch_type, _ := c.GetInt64("sch_type")
  7299. timeLayout := "2006-01-02"
  7300. loc, _ := time.LoadLocation("Local")
  7301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7302. if err != nil {
  7303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7304. return
  7305. }
  7306. recordDateTime := theTime.Unix()
  7307. adminInfo := c.GetAdminUserInfo()
  7308. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7309. //adminInfo := c.GetAdminUserInfo()
  7310. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7311. //fmt.Println(prescriptionOrder)
  7312. if err == nil {
  7313. c.ServeSuccessJSON(map[string]interface{}{
  7314. "order": prescriptionOrder,
  7315. "total": total,
  7316. })
  7317. } else {
  7318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7319. return
  7320. }
  7321. }
  7322. func (c *HisApiController) GetHisPrescriptionInfo() {
  7323. id, _ := c.GetInt64("id")
  7324. adminInfo := c.GetAdminUserInfo()
  7325. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7326. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7327. if err == nil {
  7328. c.ServeSuccessJSON(map[string]interface{}{
  7329. "order": prescriptionOrder,
  7330. "prescription": prescription,
  7331. })
  7332. } else {
  7333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7334. return
  7335. }
  7336. }
  7337. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7338. adminUser := c.GetAdminUserInfo()
  7339. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7340. c.ServeSuccessJSON(map[string]interface{}{
  7341. "config": config,
  7342. })
  7343. }
  7344. type ResultTwo struct {
  7345. ErrMsg interface{} `json:"err_msg"`
  7346. InfRefmsgid string `json:"inf_refmsgid"`
  7347. Infcode int64 `json:"infcode"`
  7348. Output struct {
  7349. Baseinfo struct {
  7350. Age float64 `json:"age"`
  7351. Brdy string `json:"brdy"`
  7352. Certno string `json:"certno"`
  7353. Gend string `json:"gend"`
  7354. Naty string `json:"naty"`
  7355. PsnCertType string `json:"psn_cert_type"`
  7356. PsnName string `json:"psn_name"`
  7357. PsnNo string `json:"psn_no"`
  7358. } `json:"baseinfo"`
  7359. Idetinfo []interface{} `json:"idetinfo"`
  7360. Iinfo []struct {
  7361. Balc float64 `json:"balc"`
  7362. CvlservFlag string `json:"cvlserv_flag"`
  7363. EmpName string `json:"emp_name"`
  7364. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7365. Insutype string `json:"insutype"`
  7366. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7367. PausInsuDate interface{} `json:"paus_insu_date"`
  7368. PsnInsuDate string `json:"psn_insu_date"`
  7369. PsnInsuStas string `json:"psn_insu_stas"`
  7370. PsnType string `json:"psn_type"`
  7371. } `json:"insuinfo"`
  7372. } `json:"output"`
  7373. RefmsgTime string `json:"refmsg_time"`
  7374. RespondTime string `json:"respond_time"`
  7375. Signtype interface{} `json:"signtype"`
  7376. WarnInfo interface{} `json:"warn_info"`
  7377. }
  7378. type ResultThree struct {
  7379. Cainfo interface{} `json:"cainfo"`
  7380. ErrMsg interface{} `json:"err_msg"`
  7381. InfRefmsgid string `json:"inf_refmsgid"`
  7382. Infcode int64 `json:"infcode"`
  7383. Output struct {
  7384. Data struct {
  7385. IptOtpNo string `json:"ipt_otp_no"`
  7386. MdtrtID string `json:"mdtrt_id"`
  7387. PsnNo string `json:"psn_no"`
  7388. } `json:"data"`
  7389. } `json:"output"`
  7390. RefmsgTime string `json:"refmsg_time"`
  7391. RespondTime string `json:"respond_time"`
  7392. Signtype interface{} `json:"signtype"`
  7393. WarnMsg interface{} `json:"warn_msg"`
  7394. }
  7395. type ResultFour struct {
  7396. Cainfo string `json:"cainfo"`
  7397. ErrMsg string `json:"err_msg"`
  7398. InfRefmsgid string `json:"inf_refmsgid"`
  7399. Infcode int64 `json:"infcode"`
  7400. Output struct {
  7401. Result []struct {
  7402. BasMednFlag string `json:"bas_medn_flag"`
  7403. ChldMedcFlag string `json:"chld_medc_flag"`
  7404. ChrgitmLv string `json:"chrgitm_lv"`
  7405. Cnt float64 `json:"cnt"`
  7406. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7407. DrtReimFlag string `json:"drt_reim_flag"`
  7408. FeedetlSn string `json:"feedetl_sn"`
  7409. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7410. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7411. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7412. ListSpItemFlag string `json:"list_sp_item_flag"`
  7413. LmtUsedFlag string `json:"lmt_used_flag"`
  7414. MedChrgitmType string `json:"med_chrgitm_type"`
  7415. Memo string `json:"memo"`
  7416. OverlmtAmt float64 `json:"overlmt_amt"`
  7417. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7418. Pric float64 `json:"pric"`
  7419. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7420. SelfpayProp float64 `json:"selfpay_prop"`
  7421. } `json:"result"`
  7422. } `json:"output"`
  7423. RefmsgTime string `json:"refmsg_time"`
  7424. RespondTime string `json:"respond_time"`
  7425. Signtype string `json:"signtype"`
  7426. WarnMsg string `json:"warn_msg"`
  7427. }
  7428. type ResultFive struct {
  7429. Insutype string `json:"insutype"`
  7430. }
  7431. type ResultSix struct {
  7432. Cainfo interface{} `json:"cainfo"`
  7433. ErrMsg interface{} `json:"err_msg"`
  7434. InfRefmsgid string `json:"inf_refmsgid"`
  7435. Infcode int64 `json:"infcode"`
  7436. Output struct {
  7437. } `json:"output"`
  7438. RefmsgTime string `json:"refmsg_time"`
  7439. RespondTime string `json:"respond_time"`
  7440. Signtype interface{} `json:"signtype"`
  7441. WarnMsg interface{} `json:"warn_msg"`
  7442. }
  7443. type ResultSeven struct {
  7444. Cainfo string `json:"cainfo"`
  7445. ErrMsg string `json:"err_msg"`
  7446. InfRefmsgid string `json:"inf_refmsgid"`
  7447. Infcode int64 `json:"infcode"`
  7448. Output struct {
  7449. Setldetail []interface{} `json:"setldetail"`
  7450. Setlinfo struct {
  7451. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7452. AcctPay float64 `json:"acct_pay"`
  7453. ActPayDedc float64 `json:"act_pay_dedc"`
  7454. Age float64 `json:"age"`
  7455. Balc float64 `json:"balc"`
  7456. Brdy string `json:"brdy"`
  7457. Certno string `json:"certno"`
  7458. ClrOptins string `json:"clr_optins"`
  7459. ClrType string `json:"clr_type"`
  7460. ClrWay string `json:"clr_way"`
  7461. CvlservFlag string `json:"cvlserv_flag"`
  7462. CvlservPay float64 `json:"cvlserv_pay"`
  7463. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7464. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7465. Gend string `json:"gend"`
  7466. HifesPay float64 `json:"hifes_pay"`
  7467. HifmiPay float64 `json:"hifmi_pay"`
  7468. HifobPay float64 `json:"hifob_pay"`
  7469. HifpPay float64 `json:"hifp_pay"`
  7470. HospPartAmt float64 `json:"hosp_part_amt"`
  7471. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7472. Insutype string `json:"insutype"`
  7473. MafPay float64 `json:"maf_pay"`
  7474. MdtrtCertType string `json:"mdtrt_cert_type"`
  7475. MdtrtID string `json:"mdtrt_id"`
  7476. MedType string `json:"med_type"`
  7477. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7478. MedinsSetlID string `json:"medins_setl_id"`
  7479. Naty string `json:"naty"`
  7480. OthPay float64 `json:"oth_pay"`
  7481. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7482. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7483. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7484. PsnCashPay float64 `json:"psn_cash_pay"`
  7485. PsnCertType string `json:"psn_cert_type"`
  7486. PsnName string `json:"psn_name"`
  7487. PsnNo string `json:"psn_no"`
  7488. PsnPartAmt float64 `json:"psn_part_amt"`
  7489. PsnType string `json:"psn_type"`
  7490. SetlID string `json:"setl_id"`
  7491. SetlTime string `json:"setl_time"`
  7492. } `json:"setlinfo"`
  7493. } `json:"output"`
  7494. RefmsgTime string `json:"refmsg_time"`
  7495. RespondTime string `json:"respond_time"`
  7496. Signtype interface{} `json:"signtype"`
  7497. WarnMsg interface{} `json:"warn_msg"`
  7498. }
  7499. type ResultEight struct {
  7500. Cainfo string `json:"cainfo"`
  7501. ErrMsg string `json:"err_msg"`
  7502. InfRefmsgid string `json:"inf_refmsgid"`
  7503. Infcode int64 `json:"infcode"`
  7504. Output struct {
  7505. Stmtinfo struct {
  7506. SetlOptins string `json:"setl_optins"`
  7507. StmtRslt string `json:"stmt_rslt"`
  7508. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7509. } `json:"stmtinfo"`
  7510. } `json:"output"`
  7511. RefmsgTime string `json:"refmsg_time"`
  7512. RespondTime string `json:"respond_time"`
  7513. Signtype interface{} `json:"signtype"`
  7514. WarnMsg interface{} `json:"warn_msg"`
  7515. }
  7516. type ResultNine struct {
  7517. Cainfo string `json:"cainfo"`
  7518. ErrMsg string `json:"err_msg"`
  7519. InfRefmsgid string `json:"inf_refmsgid"`
  7520. Infcode int64 `json:"infcode"`
  7521. Output struct {
  7522. FileQuryNo string `json:"file_qury_no"`
  7523. } `json:"output"`
  7524. RefmsgTime string `json:"refmsg_time"`
  7525. RespondTime string `json:"respond_time"`
  7526. Signtype interface{} `json:"signtype"`
  7527. WarnMsg interface{} `json:"warn_msg"`
  7528. }
  7529. type ResultTen struct {
  7530. Cainfo string `json:"cainfo"`
  7531. ErrMsg string `json:"err_msg"`
  7532. InfRefmsgid string `json:"inf_refmsgid"`
  7533. Infcode int64 `json:"infcode"`
  7534. Output struct {
  7535. DldEndtime string `json:"dld_endtime"`
  7536. FileQuryNo string `json:"file_qury_no"`
  7537. Filename string `json:"filename"`
  7538. } `json:"output"`
  7539. RefmsgTime string `json:"refmsg_time"`
  7540. RespondTime string `json:"respond_time"`
  7541. Signtype interface{} `json:"signtype"`
  7542. WarnMsg interface{} `json:"warn_msg"`
  7543. }
  7544. type ResultEleven struct {
  7545. Cainfo string `json:"cainfo"`
  7546. ErrMsg string `json:"err_msg"`
  7547. InfRefmsgid string `json:"inf_refmsgid"`
  7548. Infcode int64 `json:"infcode"`
  7549. Output struct {
  7550. Setlinfo struct {
  7551. FixmedinsName string `json:"fixmedins_name"`
  7552. FixmedinsCode string `json:"fixmedins_code"`
  7553. PsnNo string `json:"psn_no"`
  7554. PsnName string `json:"psn_name"`
  7555. HifobPay float64 `json:"hifob_pay"`
  7556. Gend string `json:"gend"`
  7557. Brdy string `json:"brdy"`
  7558. PsnCertType string `json:"psn_cert_type"`
  7559. PsnType string `json:"psn_type"`
  7560. EmpName string `json:"emp_name"`
  7561. Certno string `json:"certno"`
  7562. Insutype string `json:"insutype"`
  7563. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7564. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7565. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7566. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7567. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7568. ActPayDedc float64 `json:"act_pay_dedc"`
  7569. HifpPay float64 `json:"hifp_pay"`
  7570. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7571. CvlservPay float64 `json:"cvlserv_pay"`
  7572. HifesPay float64 `json:"hifes_pay"`
  7573. HifmiPay float64 `json:"hifmi_pay"`
  7574. MafPay float64 `json:"maf_pay"`
  7575. OthPay float64 `json:"oth_pay"`
  7576. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7577. PsnPay float64 `json:"psn_pay"`
  7578. AcctPay float64 `json:"acct_pay"`
  7579. CashPayamt float64 `json:"cash_payamt"`
  7580. Balc float64 `json:"balc"`
  7581. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7582. MedinsSetlId string `json:"medins_setl_id"`
  7583. RefdSetlFlag string `json:"refd_setl_flag"`
  7584. SetlTime string `json:"setl_time"`
  7585. MedType string `json:"med_type"`
  7586. } `json:"setlinfo"`
  7587. } `json:"output"`
  7588. RefmsgTime string `json:"refmsg_time"`
  7589. RespondTime string `json:"respond_time"`
  7590. Signtype interface{} `json:"signtype"`
  7591. WarnMsg interface{} `json:"warn_msg"`
  7592. }
  7593. type Custom struct {
  7594. DetItemFeeSumamt string
  7595. Cut string
  7596. FeedetlSn string
  7597. Price string
  7598. MedListCodg string
  7599. Type int64
  7600. AdviceId int64
  7601. ProjectId int64
  7602. ItemId int64
  7603. }
  7604. // 获取个人信息----挂号-----上传就诊信息
  7605. func (c *HisApiController) GetRegisterInfo() {
  7606. id, _ := c.GetInt64("id")
  7607. record_time := c.GetString("record_time")
  7608. settlementValue, _ := c.GetInt64("settlement_value")
  7609. medical_insurance_card := c.GetString("medical_insurance_card")
  7610. name := c.GetString("name")
  7611. id_card_type, _ := c.GetInt64("id_card_type")
  7612. certificates, _ := c.GetInt64("certificates")
  7613. medical_care, _ := c.GetInt64("medical_care")
  7614. birthday := c.GetString("birthday")
  7615. age, _ := c.GetInt64("age")
  7616. id_card := c.GetString("id_card")
  7617. register_type, _ := c.GetInt64("register")
  7618. doctor, _ := c.GetInt64("doctor")
  7619. department, _ := c.GetInt64("department")
  7620. gender, _ := c.GetInt64("sex")
  7621. phone := c.GetString("phone")
  7622. registration_fee, _ := c.GetFloat("registration_fee")
  7623. medical_expenses, _ := c.GetFloat("medical_expenses")
  7624. social_type, _ := c.GetInt64("social_type")
  7625. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7626. diagnosis_ids := c.GetString("diagnosis")
  7627. sick_type, _ := c.GetInt64("sick_type")
  7628. reg_type := c.GetString("p_type")
  7629. timeLayout := "2006-01-02"
  7630. loc, _ := time.LoadLocation("Local")
  7631. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7632. birthUnix := birthdays.Unix()
  7633. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7634. if err != nil {
  7635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7636. return
  7637. }
  7638. recordDateTime := theTime.Unix()
  7639. adminInfo := c.GetAdminUserInfo()
  7640. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7641. if tempPatient.ID == 0 {
  7642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7643. return
  7644. }
  7645. var patient service.Patients
  7646. if id == 0 {
  7647. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7648. } else {
  7649. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7650. }
  7651. if patient.ID == 0 {
  7652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7653. return
  7654. }
  7655. if len(patient.IdCardNo) == 0 {
  7656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7657. return
  7658. }
  7659. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7660. if len(his) >= 1 {
  7661. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7662. if len(his) >= 1 && order.ID == 0 {
  7663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7664. return
  7665. }
  7666. }
  7667. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7668. fmt.Println(timeStr)
  7669. timeArr := strings.Split(timeStr, " ")
  7670. fmt.Println(timeArr)
  7671. timeArrTwo := strings.Split(timeArr[0], "-")
  7672. timeArrThree := strings.Split(timeArr[1], ":")
  7673. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7674. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7675. if len(lists) == 0 {
  7676. var hisPatient models.XtHisPatient
  7677. hisPatient = models.XtHisPatient{
  7678. Name: name,
  7679. Age: age,
  7680. Gender: gender,
  7681. Birthday: birthUnix,
  7682. Phone: phone,
  7683. MedicalTreatmentType: medical_care,
  7684. IdType: certificates,
  7685. IdCardNo: id_card,
  7686. BalanceAccountsType: settlementValue,
  7687. SocialType: social_type,
  7688. MedicalInsuranceNumber: medical_insurance_card,
  7689. RegisterType: register_type,
  7690. RegisterCost: registration_fee,
  7691. TreatmentCost: medical_expenses,
  7692. AdminUserId: adminInfo.AdminUser.Id,
  7693. UserOrgId: adminInfo.CurrentOrgId,
  7694. Status: 1,
  7695. RecordDate: recordDateTime,
  7696. IsReturn: 1,
  7697. PatientId: patient.ID,
  7698. Ctime: time.Now().Unix(),
  7699. Mtime: time.Now().Unix(),
  7700. Number: str,
  7701. IdCardType: id_card_type,
  7702. Departments: department,
  7703. Doctor: doctor,
  7704. PType: reg_type,
  7705. Diagnosis: diagnosis_ids,
  7706. SickType: sick_type,
  7707. }
  7708. service.CreateHisPatient(&hisPatient)
  7709. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7710. c.ServeSuccessJSON(map[string]interface{}{
  7711. "his_info": hisPatient,
  7712. })
  7713. } else {
  7714. //chrgBchno := rand.Intn(1000000) + 10000
  7715. var hisPatient models.XtHisPatient
  7716. hisPatient = models.XtHisPatient{
  7717. Name: name,
  7718. Age: age,
  7719. Gender: gender,
  7720. Birthday: birthUnix,
  7721. Phone: phone,
  7722. MedicalTreatmentType: medical_care,
  7723. IdType: certificates,
  7724. IdCardNo: id_card,
  7725. BalanceAccountsType: settlementValue,
  7726. SocialType: social_type,
  7727. MedicalInsuranceNumber: medical_insurance_card,
  7728. RegisterType: register_type,
  7729. RegisterCost: registration_fee,
  7730. TreatmentCost: medical_expenses,
  7731. AdminUserId: adminInfo.AdminUser.Id,
  7732. UserOrgId: adminInfo.CurrentOrgId,
  7733. Status: 1,
  7734. RecordDate: recordDateTime,
  7735. IsReturn: 1,
  7736. PatientId: patient.ID,
  7737. Ctime: time.Now().Unix(),
  7738. Mtime: time.Now().Unix(),
  7739. Number: str,
  7740. IdCardType: id_card_type,
  7741. Departments: department,
  7742. Doctor: doctor,
  7743. PType: reg_type,
  7744. Diagnosis: diagnosis_ids,
  7745. SickType: sick_type,
  7746. }
  7747. service.CreateHisPatient(&hisPatient)
  7748. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7749. c.ServeSuccessJSON(map[string]interface{}{
  7750. "his_info": hisPatient,
  7751. })
  7752. }
  7753. }
  7754. // 上传明细----结算
  7755. func (c *HisApiController) GetUploadInfo() {
  7756. id, _ := c.GetInt64("id")
  7757. record_time := c.GetString("record_time")
  7758. his_patient_id, _ := c.GetInt64("his_patient_id")
  7759. oth_desc := c.GetString("oth_desc")
  7760. pay_way, _ := c.GetInt64("pay_way")
  7761. pay_ways := c.GetString("pay_ways")
  7762. pay_price, _ := c.GetFloat("pay_price")
  7763. pay_card_no := c.GetString("pay_card_no")
  7764. discount_price, _ := c.GetFloat("discount_price")
  7765. preferential_price, _ := c.GetFloat("preferential_price")
  7766. reality_price, _ := c.GetFloat("reality_price")
  7767. found_price, _ := c.GetFloat("found_price")
  7768. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7769. private_price, _ := c.GetFloat("private_price")
  7770. timeLayout := "2006-01-02"
  7771. loc, _ := time.LoadLocation("Local")
  7772. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7773. fapiao_code := c.GetString("fapiao_code")
  7774. fapiao_number := c.GetString("fapiao_number")
  7775. diagnosis_id := c.GetString("diagnosis")
  7776. sick_type, _ := c.GetInt64("sick_type")
  7777. reg_type, _ := c.GetInt64("p_type")
  7778. order_id, _ := c.GetInt64("order_id")
  7779. cash_pay := c.GetString("cash_pay")
  7780. wechat_pay := c.GetString("wechat_pay")
  7781. ali_pay := c.GetString("ali_pay")
  7782. jifen_pay := c.GetString("jifen_pay")
  7783. band_card_pay := c.GetString("band_card_pay")
  7784. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7785. tmp_decimal := c.GetString("tmp_decimal")
  7786. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7787. var decimal float64 //本次使用的押金
  7788. var errmsg error
  7789. tx := service.XTWriteDB().Begin() //开了事务
  7790. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7791. defer func() {
  7792. if errmsg != nil {
  7793. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7794. tx.Rollback()
  7795. } else {
  7796. tx.Commit()
  7797. }
  7798. }()
  7799. fmt.Println("dec_way", dec_way)
  7800. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7801. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7802. return
  7803. }
  7804. if len(tmp_decimal) > 0 {
  7805. if tmp_decimal[0] == 45 {
  7806. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7807. return
  7808. }
  7809. }
  7810. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7811. fmt.Println(errs)
  7812. decimal = tt
  7813. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7814. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7816. if err != nil {
  7817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7818. return
  7819. }
  7820. recordDateTime := theTime.Unix()
  7821. adminUser := c.GetAdminUserInfo()
  7822. var prescriptions []*models.HisPrescription
  7823. var prescriptionsOne []*models.HisPrescription
  7824. var start_time int64
  7825. var end_time int64
  7826. ids_str := c.GetString("ids")
  7827. ids_arr := strings.Split(ids_str, ",")
  7828. if tempOrder.ID == 0 {
  7829. if settle_accounts_type == 1 { //日结
  7830. fmt.Println(reg_type)
  7831. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7832. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7833. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7834. } else {
  7835. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7836. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7837. }
  7838. } else { //月结
  7839. start_time_str := c.GetString("start_time")
  7840. end_time_str := c.GetString("end_time")
  7841. timeLayout := "2006-01-02"
  7842. loc, _ := time.LoadLocation("Local")
  7843. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7844. if err != nil {
  7845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7846. return
  7847. }
  7848. recordStartTime := theStartTime.Unix()
  7849. start_time = recordStartTime
  7850. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7851. if err != nil {
  7852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7853. return
  7854. }
  7855. recordEndTime := theEndTime.Unix()
  7856. end_time = recordEndTime
  7857. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7858. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7859. }
  7860. var goods []*models.DialysisBeforePrepareGoods
  7861. var newGoods []*models.NewDialysisBeforePrepareGoods
  7862. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7863. var infos []*models.HisDoctorAdviceInfo
  7864. var infoList []*models.HisDoctorAdviceInfo
  7865. var hisAdvice []*models.HisDoctorAdviceInfo
  7866. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7867. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7868. //判断库存不足
  7869. //结算出库开关
  7870. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7871. if settConfig.IsOpen == 1 {
  7872. //判断库存的地方
  7873. for _, info := range prescriptions {
  7874. if info.Type == 1 {
  7875. infos = append(infos, info.HisDoctorAdviceInfo...)
  7876. }
  7877. if info.Type == 2 {
  7878. for _, sumItem := range info.HisPrescriptionProject {
  7879. if sumItem.Type == 3 {
  7880. var good models.DialysisBeforePrepareGoods
  7881. var newGood models.NewDialysisBeforePrepareGoods
  7882. good.GoodId = sumItem.GoodInfo.ID
  7883. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7884. count, _ := strconv.Atoi(sumItem.Count)
  7885. good.Count = int64(count)
  7886. good.StorehouseId = houseConfig.StorehouseOutInfo
  7887. good.ProjectId = sumItem.ID
  7888. goods = append(goods, &good)
  7889. newGood.GoodId = sumItem.GoodInfo.ID
  7890. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7891. count2, _ := strconv.Atoi(sumItem.Count)
  7892. newGood.Count = int64(count2)
  7893. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7894. newGood.ProjectId = sumItem.ID
  7895. newGoods = append(newGoods, &newGood)
  7896. }
  7897. }
  7898. }
  7899. }
  7900. for _, info := range prescriptionsOne {
  7901. if info.Type == 1 {
  7902. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7903. }
  7904. if info.Type == 2 {
  7905. for _, sumItem := range info.HisPrescriptionProject {
  7906. if sumItem.Type == 3 {
  7907. var newGood models.NewDialysisBeforePrepareGoods
  7908. newGood.GoodId = sumItem.GoodInfo.ID
  7909. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7910. count2, _ := strconv.Atoi(sumItem.Count)
  7911. newGood.Count = int64(count2)
  7912. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7913. newGood.ProjectId = sumItem.ID
  7914. newGoodOne = append(newGoodOne, &newGood)
  7915. }
  7916. }
  7917. }
  7918. }
  7919. //判断
  7920. for _, itemOne := range infos {
  7921. for _, itemTwo := range hisAdvice {
  7922. if itemOne.DrugId == itemTwo.DrugId {
  7923. itemTwo.Child = append(itemTwo.Child, itemOne)
  7924. }
  7925. }
  7926. }
  7927. for _, itemTwo := range hisAdvice {
  7928. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7929. var sum_out_count int64
  7930. for _, itemThree := range itemTwo.Child {
  7931. var prescribing_number int64
  7932. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7933. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7934. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7935. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7936. }
  7937. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7938. prescribing_number = parseIntPrescribingNumber
  7939. }
  7940. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7941. prescribing_number = parseIntPrescribingNumber
  7942. }
  7943. sum_out_count += prescribing_number
  7944. }
  7945. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7946. if sum_out_count > drugStockOut.FlushCount {
  7947. c.ServeSuccessJSON(map[string]interface{}{
  7948. "msg": "2",
  7949. "drug": medical,
  7950. })
  7951. return
  7952. }
  7953. }
  7954. for _, itemOne := range newGoods {
  7955. for _, item := range newGoodOne {
  7956. if itemOne.GoodId == item.GoodId {
  7957. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7958. }
  7959. }
  7960. }
  7961. for _, item := range newGoodOne {
  7962. var sum_out_count_one int64
  7963. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7964. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7965. sum_out_count_one += itemOne.Count
  7966. }
  7967. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7968. fmt.Println("sum_out_count_one", sum_out_count_one)
  7969. fmt.Println("list.FlushCount", list.FlushCount)
  7970. if sum_out_count_one > list.FlushCount {
  7971. c.ServeSuccessJSON(map[string]interface{}{
  7972. "msg": "3",
  7973. "good": good,
  7974. })
  7975. return
  7976. }
  7977. }
  7978. }
  7979. timestamp := time.Now().Unix()
  7980. tempTime := time.Unix(timestamp, 0)
  7981. timeFormat := tempTime.Format("20060102150405")
  7982. chrgBchno := rand.Intn(100000) + 10000
  7983. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7984. strconv.FormatInt(his.PatientId, 10)
  7985. var ids []int64
  7986. for _, item := range prescriptions {
  7987. ids = append(ids, item.ID)
  7988. }
  7989. var total float64
  7990. for _, item := range prescriptions {
  7991. fmt.Println(item)
  7992. if item.Type == 1 { //药品
  7993. for _, subItem := range item.HisDoctorAdviceInfo {
  7994. total = total + (subItem.Price * subItem.PrescribingNumber)
  7995. }
  7996. }
  7997. if item.Type == 2 { //项目
  7998. for _, subItem := range item.HisPrescriptionProject {
  7999. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8000. total = total + (subItem.Price * cnt)
  8001. }
  8002. }
  8003. for _, subItem := range item.HisAdditionalCharge {
  8004. total = total + (subItem.Price * float64(subItem.Count))
  8005. }
  8006. }
  8007. if reg_type == 1111 || reg_type == 1112 {
  8008. reg_type = 11
  8009. }
  8010. tm := time.Unix(time.Now().Unix(), 0)
  8011. allTotal := fmt.Sprintf("%.4f", total)
  8012. totals, _ := strconv.ParseFloat(allTotal, 64)
  8013. order := &models.HisOrder{
  8014. UserOrgId: adminUser.CurrentOrgId,
  8015. HisPatientId: his.ID,
  8016. PatientId: id,
  8017. SettleAccountsDate: recordDateTime,
  8018. Ctime: time.Now().Unix(),
  8019. Mtime: time.Now().Unix(),
  8020. Status: 1,
  8021. OrderStatus: 2,
  8022. MdtrtId: his.Number,
  8023. Number: chrg_bchno,
  8024. MedfeeSumamt: totals,
  8025. PayWay: pay_way,
  8026. PayWays: pay_ways,
  8027. PayPrice: pay_price,
  8028. MedType: strconv.Itoa(int(reg_type)),
  8029. PayCardNo: pay_card_no,
  8030. DiscountPrice: discount_price,
  8031. PreferentialPrice: preferential_price,
  8032. RealityPrice: reality_price,
  8033. FoundPrice: found_price,
  8034. MedicalInsurancePrice: medical_insurance_price,
  8035. PrivatePrice: private_price,
  8036. SettleEndTime: end_time,
  8037. SettleStartTime: start_time,
  8038. PsnPartAmt: totals,
  8039. PsnCashPay: totals,
  8040. SettleType: settle_accounts_type,
  8041. FaPiaoCode: fapiao_code,
  8042. FaPiaoNumber: fapiao_number,
  8043. Diagnosis: diagnosis_id,
  8044. PType: 2,
  8045. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8046. Decimal: decimal,
  8047. OthDesc: oth_desc,
  8048. CashPay: cash_pay,
  8049. WechatPay: wechat_pay,
  8050. AliPay: ali_pay,
  8051. JifenPay: jifen_pay,
  8052. BandCardPay: band_card_pay,
  8053. Creator: adminUser.AdminUser.Id,
  8054. }
  8055. err = service.CreateOrderTX(order, tx)
  8056. if err != nil {
  8057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8058. return
  8059. }
  8060. var customs []*Custom
  8061. for _, item := range prescriptions {
  8062. if item.Type == 1 { //药品a
  8063. for _, subItem := range item.HisDoctorAdviceInfo {
  8064. cus := &Custom{
  8065. AdviceId: subItem.ID,
  8066. ProjectId: 0,
  8067. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8068. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8069. FeedetlSn: subItem.FeedetlSn,
  8070. Price: fmt.Sprintf("%.4f", subItem.Price),
  8071. MedListCodg: subItem.MedListCodg,
  8072. Type: 1,
  8073. }
  8074. customs = append(customs, cus)
  8075. }
  8076. }
  8077. if item.Type == 2 { //项目
  8078. for _, subItem := range item.HisPrescriptionProject {
  8079. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8080. cus := &Custom{
  8081. AdviceId: 0,
  8082. ProjectId: subItem.ID,
  8083. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8084. Cut: fmt.Sprintf("%.4f", cnt),
  8085. FeedetlSn: subItem.FeedetlSn,
  8086. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8087. MedListCodg: subItem.MedListCodg,
  8088. Type: 2,
  8089. }
  8090. customs = append(customs, cus)
  8091. }
  8092. }
  8093. for _, item := range item.HisAdditionalCharge {
  8094. cus := &Custom{
  8095. ItemId: item.ID,
  8096. AdviceId: 0,
  8097. ProjectId: 0,
  8098. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8099. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8100. FeedetlSn: item.FeedetlSn,
  8101. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8102. MedListCodg: item.XtHisAddtionConfig.Code,
  8103. Type: 3,
  8104. }
  8105. customs = append(customs, cus)
  8106. }
  8107. }
  8108. for _, item := range customs {
  8109. var advice_id int64 = 0
  8110. var project_id int64 = 0
  8111. var item_id int64 = 0
  8112. var types int64 = 0
  8113. if item.Type == 1 {
  8114. advice_id = item.AdviceId
  8115. project_id = 0
  8116. item_id = 0
  8117. } else if item.Type == 2 {
  8118. advice_id = 0
  8119. item_id = 0
  8120. project_id = item.ProjectId
  8121. } else if item.Type == 3 {
  8122. advice_id = 0
  8123. item_id = item.ItemId
  8124. project_id = 0
  8125. }
  8126. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8127. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8128. pric, _ := strconv.ParseFloat(item.Price, 32)
  8129. info := &models.HisOrderInfo{
  8130. OrderNumber: order.Number,
  8131. UploadDate: time.Now().Unix(),
  8132. AdviceId: advice_id,
  8133. DetItemFeeSumamt: detItemFeeSumamt,
  8134. Cnt: cut,
  8135. Pric: pric,
  8136. PatientId: id,
  8137. Status: 1,
  8138. Mtime: time.Now().Unix(),
  8139. Ctime: time.Now().Unix(),
  8140. UserOrgId: adminUser.CurrentOrgId,
  8141. HisPatientId: his.ID,
  8142. OrderId: order.ID,
  8143. ProjectId: project_id,
  8144. Type: types,
  8145. ItemId: item_id,
  8146. }
  8147. service.CreateOrderInfoTX(info, tx)
  8148. }
  8149. his.Diagnosis = diagnosis_id
  8150. his.SickType = sick_type
  8151. his.RegisterType = reg_type
  8152. his.MedicalTreatmentType = reg_type
  8153. service.UpdataHisPateintTX(&his, tx)
  8154. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8155. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8156. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8157. //判断是否使用了押金
  8158. if dec_way == "true" {
  8159. tmpstring := strconv.FormatInt(order.ID, 10)
  8160. //扣押金
  8161. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8162. order.Decimal = decimal
  8163. service.UpDateOrderTwo(order, tx)
  8164. if errmsg != nil {
  8165. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8166. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8167. return
  8168. }
  8169. }
  8170. if err == nil {
  8171. for _, info := range prescriptions {
  8172. if info.Type == 1 {
  8173. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8174. }
  8175. if info.Type == 2 {
  8176. for _, sumItem := range info.HisPrescriptionProject {
  8177. if sumItem.Type == 3 {
  8178. var good models.DialysisBeforePrepareGoods
  8179. var newGood models.NewDialysisBeforePrepareGoods
  8180. var oldGood models.OldDialysisBeforePrepareGoods
  8181. good.GoodId = sumItem.GoodInfo.ID
  8182. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8183. count, _ := strconv.Atoi(sumItem.Count)
  8184. good.Count = int64(count)
  8185. good.StorehouseId = houseConfig.StorehouseOutInfo
  8186. good.ProjectId = sumItem.ID
  8187. good.PatientId = sumItem.PatientId
  8188. goods = append(goods, &good)
  8189. newGood.GoodId = sumItem.GoodInfo.ID
  8190. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8191. count2, _ := strconv.Atoi(sumItem.Count)
  8192. newGood.Count = int64(count2)
  8193. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8194. newGood.ProjectId = sumItem.ID
  8195. newGood.PatientId = sumItem.HisPatientId
  8196. newGoods = append(newGoods, &newGood)
  8197. oldGood.GoodId = sumItem.GoodInfo.ID
  8198. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8199. count3, _ := strconv.Atoi(sumItem.Count)
  8200. oldGood.Count = int64(count3)
  8201. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8202. oldGood.ProjectId = sumItem.ID
  8203. oldGood.RecordDate = sumItem.RecordDate
  8204. oldGood.PatientId = sumItem.HisPatientId
  8205. oldGoods = append(oldGoods, &oldGood)
  8206. }
  8207. }
  8208. }
  8209. }
  8210. if settConfig.IsOpen == 1 {
  8211. for _, item := range infoList {
  8212. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8213. if medical.IsUse == 2 {
  8214. //药品出库
  8215. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8216. //查询默认仓库
  8217. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8218. //查询默认仓库剩余多少库存
  8219. var sum_count int64
  8220. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8221. for _, its := range stockInfo {
  8222. if its.MaxUnit == medical.MaxUnit {
  8223. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8224. }
  8225. sum_count += its.StockMaxNumber + its.StockMinNumber
  8226. }
  8227. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8228. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8229. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8230. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8231. }
  8232. }
  8233. orgId := c.GetAdminUserInfo().CurrentOrgId
  8234. if len(oldGoods) > 0 {
  8235. timeStr := time.Now().Format("2006-01-02")
  8236. timeArr := strings.Split(timeStr, "-")
  8237. total, _ := service.FindAllWarehouseOut(orgId)
  8238. total = total + 1
  8239. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8240. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8241. number = number + total
  8242. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8243. operation_time := time.Now().Unix()
  8244. creater := c.GetAdminUserInfo().AdminUser.Id
  8245. //查询默认出库仓库库存
  8246. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8247. recordDateStr := time.Now().Format("2006-01-02")
  8248. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8249. nowtime := recordDate.Unix()
  8250. warehouseOut := models.WarehouseOut{
  8251. WarehouseOutOrderNumber: warehousing_out_order,
  8252. OperationTime: operation_time,
  8253. OrgId: orgId,
  8254. Creater: creater,
  8255. Ctime: time.Now().Unix(),
  8256. Status: 1,
  8257. WarehouseOutTime: nowtime,
  8258. Type: 1,
  8259. StorehouseId: storeConfig.StorehouseOutInfo,
  8260. IsCheck: 1,
  8261. OrderId: order.ID,
  8262. IsSys: 5,
  8263. }
  8264. //查询是否生成出库单
  8265. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8266. if out.ID == 0 {
  8267. service.AddSigleWarehouseOut(&warehouseOut)
  8268. }
  8269. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8270. for _, item := range oldGoods {
  8271. dialyPrepareOne := models.DialysisBeforePrepare{
  8272. GoodTypeId: item.GoodTypeId,
  8273. GoodId: item.GoodId,
  8274. PatientId: his.PatientId,
  8275. RecordDate: item.RecordDate,
  8276. UserOrgId: adminUser.CurrentOrgId,
  8277. Count: item.Count,
  8278. Ctime: time.Now().Unix(),
  8279. Creater: adminUser.AdminUser.Id,
  8280. CommdityCode: item.CommdityCode,
  8281. Status: 1,
  8282. StorehouseId: houseConfig.StorehouseOutInfo,
  8283. }
  8284. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8285. //非零用
  8286. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8287. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8288. //查询剩余库存
  8289. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8290. var sum_count int64
  8291. for _, item := range goodList {
  8292. sum_count += item.StockCount
  8293. }
  8294. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8295. //耗材
  8296. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8297. }
  8298. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8299. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8300. //查询剩余库存
  8301. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8302. var sum_count int64
  8303. for _, item := range goodList {
  8304. sum_count += item.StockCount
  8305. }
  8306. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8307. //耗材
  8308. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8309. }
  8310. }
  8311. }
  8312. }
  8313. c.ServeSuccessJSON(map[string]interface{}{
  8314. "msg": "结算成功",
  8315. })
  8316. }
  8317. }
  8318. }
  8319. // 退款
  8320. func (c *HisApiController) Refund() {
  8321. order_id, _ := c.GetInt64("order_id")
  8322. order, _ := service.GetHisOrderByID(order_id)
  8323. adminUser := c.GetAdminUserInfo()
  8324. orgid := c.GetAdminUserInfo().CurrentOrgId
  8325. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8326. if err != nil {
  8327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8328. return
  8329. }
  8330. tmp := strconv.FormatInt(order.ID, 10)
  8331. //当押金不为零时产生退费记录
  8332. if order.Decimal != 0 {
  8333. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8334. if err != nil {
  8335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8336. return
  8337. }
  8338. }
  8339. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8340. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8341. var goods []*models.DialysisBeforePrepareGoods
  8342. var newGoods []*models.NewDialysisBeforePrepareGoods
  8343. var infos []*models.HisDoctorAdviceInfo
  8344. for _, info := range orders {
  8345. if info.AdviceId > 0 && info.ProjectId == 0 {
  8346. infos = append(infos, &info.HisDoctorAdviceInfo)
  8347. }
  8348. if info.ProjectId > 0 && info.AdviceId == 0 {
  8349. if info.HisPrescriptionProject.Type == 3 {
  8350. var good models.DialysisBeforePrepareGoods
  8351. var newGood models.NewDialysisBeforePrepareGoods
  8352. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8353. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8354. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8355. good.Count = int64(count)
  8356. good.StorehouseId = houseConfig.StorehouseOutInfo
  8357. good.ProjectId = info.HisPrescriptionProject.ID
  8358. good.PatientId = info.PatientId
  8359. good.OrderId = order_id
  8360. goods = append(goods, &good)
  8361. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8362. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8363. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8364. newGood.Count = int64(count2)
  8365. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8366. newGood.ProjectId = info.HisPrescriptionProject.ID
  8367. newGood.RecordDate = order.SettleAccountsDate
  8368. newGood.UserOrgId = order.UserOrgId
  8369. newGood.PatientId = info.PatientId
  8370. newGood.OrderId = order_id
  8371. newGoods = append(newGoods, &newGood)
  8372. }
  8373. }
  8374. }
  8375. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8376. if settConfig.IsOpen == 1 {
  8377. for _, item := range infos {
  8378. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8379. }
  8380. for _, item := range newGoods {
  8381. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8382. }
  8383. }
  8384. c.ServeSuccessJSON(map[string]interface{}{
  8385. "msg": "退费成功",
  8386. })
  8387. }
  8388. func (c *HisApiController) RefundNumber() {
  8389. his_patient_id, _ := c.GetInt64("id")
  8390. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8391. info.Status = 0
  8392. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8393. if count > 0 {
  8394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8395. return
  8396. }
  8397. err := service.SaveHisPatient(info)
  8398. if err == nil {
  8399. c.ServeSuccessJSON(map[string]interface{}{
  8400. "msg": "退号成功",
  8401. })
  8402. } else {
  8403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8404. return
  8405. }
  8406. }
  8407. func (this *HisApiController) AdditionalCharge() {
  8408. dataBody := make(map[string]interface{}, 0)
  8409. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8410. fmt.Println(err)
  8411. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8412. patient_id := int64(dataBody["patient_id"].(float64))
  8413. medicineData, _ := dataBody["medicineData"].([]interface{})
  8414. adminUserInfo := this.GetAdminUserInfo()
  8415. orgId := adminUserInfo.CurrentOrgId
  8416. admin_user_id := adminUserInfo.AdminUser.Id
  8417. timeStr := time.Now().Format("2006-01-02")
  8418. timeLayout := "2006-01-02 15:04:05"
  8419. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8420. timenow := timeStringToTime.Unix()
  8421. var additionalCharges []*models.HisAdditionalCharge
  8422. for _, item := range medicineData {
  8423. var randNum int
  8424. randNum = rand.Intn(10000) + 1000
  8425. timestamp := time.Now().Unix()
  8426. tempTime := time.Unix(timestamp, 0)
  8427. timeFormat := tempTime.Format("20060102150405")
  8428. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8429. items := item.(map[string]interface{})
  8430. money := items["price"].(string)
  8431. item_id_str := items["item_id"].(string)
  8432. name := items["name"].(string)
  8433. id_str := items["id"].(string)
  8434. moneys, _ := strconv.ParseInt(money, 10, 64)
  8435. monStr := strconv.FormatInt(moneys, 10)
  8436. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8437. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8438. id, _ := strconv.ParseInt(id_str, 10, 64)
  8439. additionalCharge := &models.HisAdditionalCharge{
  8440. ID: id,
  8441. HisPatientId: his_patient_id,
  8442. UserOrgId: orgId,
  8443. PatientId: patient_id,
  8444. RecordDate: timenow,
  8445. Price: monneyStr,
  8446. Status: 1,
  8447. ItemName: name,
  8448. ItemId: item_id,
  8449. AdminUserId: admin_user_id,
  8450. CreatedTime: time.Now().Unix(),
  8451. OrderStatus: 0,
  8452. PrescriptionNumber: "",
  8453. BatchNumber: "",
  8454. FeedetlSn: p_number,
  8455. }
  8456. service.CreateAdditionalCharge(additionalCharge)
  8457. additionalCharges = append(additionalCharges, additionalCharge)
  8458. }
  8459. this.ServeSuccessJSON(map[string]interface{}{
  8460. "msg": "添加成功",
  8461. "additional_charges": additionalCharges,
  8462. })
  8463. }
  8464. func (this *HisApiController) DeleteAddition() {
  8465. id, _ := this.GetInt64("id")
  8466. //TODO 需要判断是否已经结算
  8467. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8468. if err == nil {
  8469. this.ServeSuccessJSON(map[string]interface{}{
  8470. "msg": "删除成功",
  8471. })
  8472. return
  8473. } else {
  8474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8475. return
  8476. }
  8477. }
  8478. func (this *HisApiController) GetAdminUsers() {
  8479. adminUser := this.GetAdminUserInfo()
  8480. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8481. this.ServeSuccessJSON(map[string]interface{}{
  8482. "doctors": doctors,
  8483. })
  8484. }
  8485. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8486. change_type, _ := this.GetInt64("type", 0)
  8487. record_date := this.GetString("record_time")
  8488. patient_id, _ := this.GetInt64("patient_id", 0)
  8489. p_type, _ := this.GetInt64("p_type", 0)
  8490. timeLayout := "2006-01-02"
  8491. loc, _ := time.LoadLocation("Local")
  8492. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8493. record_time := theAdviceRecordTime.Unix()
  8494. adminUserInfo := this.GetAdminUserInfo()
  8495. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8496. if err == nil {
  8497. if len(prescriptions) == 0 {
  8498. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8499. return
  8500. } else {
  8501. this.ServeSuccessJSON(map[string]interface{}{
  8502. "prescriptions": prescriptions,
  8503. })
  8504. return
  8505. }
  8506. } else {
  8507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8508. return
  8509. }
  8510. }
  8511. func (this *HisApiController) GetCallHisPrescription() {
  8512. patient_id, _ := this.GetInt64("patient_id", 0)
  8513. timeLayout := "2006-01-02"
  8514. loc, _ := time.LoadLocation("Local")
  8515. start_time := this.GetString("start_time")
  8516. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8517. end_time := this.GetString("end_time")
  8518. p_type, _ := this.GetInt64("p_type")
  8519. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8520. adminUserInfo := this.GetAdminUserInfo()
  8521. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8522. if err == nil {
  8523. this.ServeSuccessJSON(map[string]interface{}{
  8524. "prescriptions": prescriptions,
  8525. })
  8526. return
  8527. } else {
  8528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8529. return
  8530. }
  8531. }
  8532. func (this *HisApiController) GetHisDayPrescription() {
  8533. timeLayout := "2006-01-02"
  8534. loc, _ := time.LoadLocation("Local")
  8535. start_time := this.GetString("start_time")
  8536. patient_id, _ := this.GetInt64("patient_id", 0)
  8537. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8538. end_time := this.GetString("end_time")
  8539. p_type, _ := this.GetInt64("p_type")
  8540. order_status, _ := this.GetInt64("type")
  8541. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8542. adminUserInfo := this.GetAdminUserInfo()
  8543. var dayHisPrescription []*models.HisPrescription
  8544. var err error
  8545. if order_status == 1 || order_status == 0 {
  8546. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8547. } else if order_status == 2 {
  8548. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8549. }
  8550. var settle_total float64
  8551. for _, item := range dayHisPrescription {
  8552. if len(item.HisPrescriptionProject) > 0 {
  8553. for _, subItem := range item.HisPrescriptionProject {
  8554. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8555. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8556. settle_total = settle_total + total
  8557. }
  8558. }
  8559. if len(item.HisDoctorAdviceInfo) > 0 {
  8560. for _, subItem := range item.HisDoctorAdviceInfo {
  8561. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8562. settle_total = settle_total + total
  8563. }
  8564. }
  8565. }
  8566. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8567. if err == nil {
  8568. this.ServeSuccessJSON(map[string]interface{}{
  8569. "day_prescription": dayHisPrescription,
  8570. "settle_total": settle_total,
  8571. })
  8572. return
  8573. } else {
  8574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8575. return
  8576. }
  8577. }
  8578. func (c *HisApiController) GetHisChargePatientList() {
  8579. record_date := c.GetString("record_date")
  8580. order_status, _ := c.GetInt64("type")
  8581. sch_type, _ := c.GetInt64("sch_type")
  8582. timeLayout := "2006-01-02"
  8583. loc, _ := time.LoadLocation("Local")
  8584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8585. if err != nil {
  8586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8587. return
  8588. }
  8589. recordDateTime := theTime.Unix()
  8590. adminInfo := c.GetAdminUserInfo()
  8591. var tempPatients []*service.NewTempPatients
  8592. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8593. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8594. if order_status != 2 {
  8595. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8596. } else {
  8597. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8598. }
  8599. } else {
  8600. if order_status != 2 {
  8601. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8602. } else {
  8603. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8604. }
  8605. }
  8606. var patients []*service.NewTempPatients
  8607. var patients_two []*service.NewTempPatients
  8608. for _, item := range tempPatients {
  8609. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8610. //过滤掉没挂号的和没开处方的
  8611. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8612. patients = append(patients, item)
  8613. }
  8614. //过滤掉没挂号的
  8615. if len(item.HisPatient) > 0 {
  8616. patients_two = append(patients_two, item)
  8617. }
  8618. } else {
  8619. if len(item.HisPrescription) > 0 {
  8620. patients = append(patients, item)
  8621. }
  8622. }
  8623. }
  8624. c.ServeSuccessJSON(map[string]interface{}{
  8625. "list": patients,
  8626. "list_two": patients_two,
  8627. })
  8628. }
  8629. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8630. record_date := c.GetString("record_date")
  8631. timeLayout := "2006-01-02"
  8632. loc, _ := time.LoadLocation("Local")
  8633. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8634. if err != nil {
  8635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8636. return
  8637. }
  8638. recordDateTime := theTime.Unix()
  8639. adminUser := c.GetAdminUserInfo()
  8640. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8641. var patients []*service.Patients
  8642. for _, item := range tempPatients {
  8643. if item.HisPatient.ID == 0 {
  8644. patients = append(patients, item)
  8645. }
  8646. }
  8647. c.ServeSuccessJSON(map[string]interface{}{
  8648. "list": patients,
  8649. //"list_two": patients_two,
  8650. })
  8651. }
  8652. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8653. newArr = make([]*service.Patients, 0)
  8654. for i := 0; i < len(patient); i++ {
  8655. repeat := false
  8656. for j := i + 1; j < len(patient); j++ {
  8657. if patient[i].ID == patient[j].ID {
  8658. repeat = true
  8659. break
  8660. }
  8661. }
  8662. if !repeat {
  8663. newArr = append(newArr, patient[i])
  8664. }
  8665. }
  8666. return
  8667. }
  8668. func (c *HisApiController) GetHisChargePatientInfo() {
  8669. patient_id, _ := c.GetInt64("patient_id")
  8670. his_patient_id, _ := c.GetInt64("his_patient_id")
  8671. record_date := c.GetString("record_date")
  8672. //start_time := c.GetString("start_time")
  8673. //end_time := c.GetString("end_time")
  8674. order_status, _ := c.GetInt64("type", 0)
  8675. p_type, _ := c.GetInt64("p_type", 0)
  8676. order_id, _ := c.GetInt64("order_id", 0)
  8677. timeLayout := "2006-01-02"
  8678. loc, _ := time.LoadLocation("Local")
  8679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8680. if err != nil {
  8681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8682. return
  8683. }
  8684. recordDateTime := theTime.Unix()
  8685. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8686. //if err != nil {
  8687. //
  8688. //}
  8689. //startRecordDateTime := startTime.Unix()
  8690. //
  8691. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8692. //if err != nil {
  8693. //
  8694. //}
  8695. //endRecordDateTime := endTime.Unix()
  8696. admin := c.GetAdminUserInfo()
  8697. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8698. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8699. var prescriptions []*models.HisPrescription
  8700. //var unChargeMonthPrescriptions []*models.HisPrescription
  8701. order, _ := service.GetHisOrderByID(order_id)
  8702. if order_status == 1 || order_status == 0 {
  8703. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8704. } else if order_status == 2 {
  8705. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8706. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8707. }
  8708. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8709. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8710. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8711. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8712. //获取所有科室信息
  8713. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8714. c.ServeSuccessJSON(map[string]interface{}{
  8715. "his_info": his_patient_info,
  8716. "xt_info": xt_patient_info,
  8717. "prescription": prescriptions,
  8718. "case_history": case_history,
  8719. "info": patientPrescriptionInfo,
  8720. "last_info": lastPatientPrescriptionInfo,
  8721. "order": order,
  8722. "doctors": doctors,
  8723. "department": department,
  8724. })
  8725. return
  8726. }
  8727. func (c *HisApiController) GetAllOrderDetail() {
  8728. order_id, _ := c.GetInt64("id", 0)
  8729. order, _ := service.GetHisOrderByID(order_id)
  8730. if order.ID == 0 {
  8731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8732. return
  8733. }
  8734. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8735. org_id := c.GetAdminUserInfo().CurrentOrgId
  8736. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8737. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8738. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8739. c.ServeSuccessJSON(map[string]interface{}{
  8740. "order": order,
  8741. "order_info": order_info,
  8742. "patient": patient,
  8743. "admin_info": adminInfo,
  8744. "hospital_record": record,
  8745. })
  8746. return
  8747. }
  8748. func (c *HisApiController) GetAllOrderDetailCollect() {
  8749. order_id, _ := c.GetInt64("id", 0)
  8750. order, _ := service.GetHisOrderByID(order_id)
  8751. if order.ID == 0 {
  8752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8753. return
  8754. }
  8755. org_id := c.GetAdminUserInfo().CurrentOrgId
  8756. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8757. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8758. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8759. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8760. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8761. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8762. var bedCostTotal float64 = 0 //床位总费
  8763. //var bedCostSelfTotal float64 = 0 //床位自费
  8764. var operationCostTotal float64 = 0 //手术费
  8765. //var operationCostSelfTotal float64 = 0 //手术费
  8766. var otherCostTotal float64 = 0 //其他费用
  8767. //var otherCostSelfTotal float64 = 0 //其他费用
  8768. var materialCostTotal float64 = 0 //材料费
  8769. //var materialCostSelfTotal float64 = 0 //材料费
  8770. var westernMedicineCostTotal float64 = 0 //西药费
  8771. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8772. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8773. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8774. var checkCostTotal float64 = 0 //检查费
  8775. //var checkCostSelfTotal float64 = 0 //检查费
  8776. var laboratoryCostTotal float64 = 0 //化验费
  8777. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8778. var treatCostTotal float64 = 0 //治疗费用
  8779. //var treatCostSelfTotal float64 = 0 //治疗费用
  8780. var zhenChaCostTotal float64 = 0 //其他费用
  8781. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8782. decimal.DivisionPrecision = 2
  8783. var BalanceAccountsType int64
  8784. if his.ID > 0 {
  8785. BalanceAccountsType = his.BalanceAccountsType
  8786. } else {
  8787. BalanceAccountsType = record.BalanceAccountsType
  8788. }
  8789. if BalanceAccountsType != 2 {
  8790. for _, item := range order_info {
  8791. if org_id == 10215 {
  8792. if item.MedChrgitmType == "01" { //床位费
  8793. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8794. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8795. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8796. }
  8797. if item.MedChrgitmType == "02" { //诊察费
  8798. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8799. //zhenChaCostSelfTotal = zhenChaCostTotal
  8800. }
  8801. if item.MedChrgitmType == "03" { //检查费
  8802. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8803. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8804. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8805. }
  8806. //if item.MedChrgitmType == "02" { //检查费
  8807. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8808. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8809. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8810. //}
  8811. if item.MedChrgitmType == "04" { //化验费
  8812. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8813. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8814. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8815. }
  8816. if item.MedChrgitmType == "05" { //治疗费
  8817. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8818. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8819. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8820. }
  8821. if item.MedChrgitmType == "06" { //手术费
  8822. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8823. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8824. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8825. }
  8826. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8827. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8828. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8829. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8830. }
  8831. if item.MedChrgitmType == "09" { //西药费
  8832. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8833. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8834. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8835. }
  8836. if item.MedChrgitmType == "11" { //中成费
  8837. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8838. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8839. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8840. }
  8841. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8842. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8843. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8844. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8845. }
  8846. } else if org_id == 10188 || org_id == 10217 {
  8847. if item.MedChrgitmType == "01" { //床位费
  8848. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8849. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8850. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8851. }
  8852. if item.MedChrgitmType == "02" { //诊察费
  8853. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8854. //zhenChaCostSelfTotal = zhenChaCostTotal
  8855. }
  8856. if item.MedChrgitmType == "03" { //检查费
  8857. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8858. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8859. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8860. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8861. }
  8862. //if item.MedChrgitmType == "02" { //检查费
  8863. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8864. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8865. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8866. //}
  8867. if item.MedChrgitmType == "04" { //化验费
  8868. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8869. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8870. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8871. }
  8872. if item.MedChrgitmType == "05" { //治疗费
  8873. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8874. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8875. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8876. }
  8877. if item.MedChrgitmType == "06" { //手术费
  8878. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8879. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8880. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8881. }
  8882. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8883. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8884. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8885. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8886. }
  8887. if item.MedChrgitmType == "09" { //西药费
  8888. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8889. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8890. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8891. }
  8892. if item.MedChrgitmType == "11" { //中成费
  8893. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8894. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8895. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8896. }
  8897. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8898. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8899. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8900. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8901. }
  8902. } else {
  8903. if item.MedChrgitmType == "01" { //床位费
  8904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8907. }
  8908. //if item.MedChrgitmType == "02" { //诊察费
  8909. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8910. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8911. //}
  8912. if item.MedChrgitmType == "03" { //检查费
  8913. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8914. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8915. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8916. }
  8917. //if item.MedChrgitmType == "02" { //检查费
  8918. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8919. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8920. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8921. //}
  8922. if item.MedChrgitmType == "04" { //化验费
  8923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8924. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8925. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8926. }
  8927. if item.MedChrgitmType == "05" { //治疗费
  8928. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8929. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8930. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8931. }
  8932. if item.MedChrgitmType == "06" { //手术费
  8933. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8934. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8935. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8936. }
  8937. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8938. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8939. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8940. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8941. }
  8942. if item.MedChrgitmType == "09" { //西药费
  8943. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8944. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8945. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8946. }
  8947. if item.MedChrgitmType == "11" { //中成费
  8948. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8949. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8950. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8951. }
  8952. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8953. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8954. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8955. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8956. }
  8957. }
  8958. }
  8959. c.ServeSuccessJSON(map[string]interface{}{
  8960. "order": order,
  8961. "order_info": order_info,
  8962. "patient": patient,
  8963. "admin_info": adminInfo,
  8964. "his_hospital": record,
  8965. "bedCostTotal": bedCostTotal,
  8966. "operationCostTotal": operationCostTotal,
  8967. "otherCostTotal": otherCostTotal,
  8968. "materialCostTotal": materialCostTotal,
  8969. "westernMedicineCostTotal": westernMedicineCostTotal,
  8970. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8971. "checkCostTotal": checkCostTotal,
  8972. "zhenChaCostTotal": zhenChaCostTotal,
  8973. "laboratoryCostTotal": laboratoryCostTotal,
  8974. "treatCostTotal": treatCostTotal,
  8975. })
  8976. } else {
  8977. for _, item := range order_info {
  8978. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8979. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8980. item.MedChrgitmType = "09"
  8981. }
  8982. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8983. if item.HisPrescriptionProject.Type == 2 {
  8984. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8985. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8986. case 0:
  8987. item.MedChrgitmType = "0"
  8988. break
  8989. case 1:
  8990. item.MedChrgitmType = "14"
  8991. break
  8992. case 2:
  8993. item.MedChrgitmType = "05"
  8994. break
  8995. case 3:
  8996. item.MedChrgitmType = "03"
  8997. break
  8998. case 4:
  8999. item.MedChrgitmType = "03"
  9000. break
  9001. case 5:
  9002. item.MedChrgitmType = "08"
  9003. break
  9004. case 6:
  9005. item.MedChrgitmType = "14"
  9006. break
  9007. case 7:
  9008. item.MedChrgitmType = "14"
  9009. break
  9010. case 8:
  9011. item.MedChrgitmType = "03"
  9012. break
  9013. case 9:
  9014. item.MedChrgitmType = "14"
  9015. break
  9016. case 10:
  9017. item.MedChrgitmType = "14"
  9018. break
  9019. case 11:
  9020. item.MedChrgitmType = "06"
  9021. break
  9022. case 12:
  9023. item.MedChrgitmType = "12"
  9024. break
  9025. case 13:
  9026. item.MedChrgitmType = "01"
  9027. break
  9028. case 14:
  9029. item.MedChrgitmType = "04"
  9030. break
  9031. case 15:
  9032. item.MedChrgitmType = "14"
  9033. break
  9034. }
  9035. } else {
  9036. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9037. case 1:
  9038. item.MedChrgitmType = "14"
  9039. break
  9040. case 2:
  9041. item.MedChrgitmType = "05"
  9042. break
  9043. case 3:
  9044. item.MedChrgitmType = "04"
  9045. break
  9046. case 4:
  9047. item.MedChrgitmType = "14"
  9048. break
  9049. case 5:
  9050. item.MedChrgitmType = "08"
  9051. break
  9052. case 6:
  9053. item.MedChrgitmType = "14"
  9054. break
  9055. case 7:
  9056. item.MedChrgitmType = "14"
  9057. break
  9058. case 8:
  9059. item.MedChrgitmType = "03"
  9060. break
  9061. case 9:
  9062. item.MedChrgitmType = "14"
  9063. break
  9064. }
  9065. }
  9066. } else if item.HisPrescriptionProject.Type == 3 {
  9067. item.MedChrgitmType = "08"
  9068. }
  9069. }
  9070. }
  9071. for _, item := range order_info {
  9072. if org_id == 10215 {
  9073. if item.MedChrgitmType == "01" { //床位费
  9074. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9075. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9076. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9077. }
  9078. if item.MedChrgitmType == "02" { //诊察费
  9079. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9080. //zhenChaCostSelfTotal = zhenChaCostTotal
  9081. }
  9082. if item.MedChrgitmType == "03" { //检查费
  9083. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9084. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9085. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9086. }
  9087. //if item.MedChrgitmType == "02" { //检查费
  9088. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9089. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9090. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9091. //}
  9092. if item.MedChrgitmType == "04" { //化验费
  9093. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9094. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9095. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9096. }
  9097. if item.MedChrgitmType == "05" { //治疗费
  9098. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9099. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9100. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9101. }
  9102. if item.MedChrgitmType == "06" { //手术费
  9103. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9104. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9105. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9106. }
  9107. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9108. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9109. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9110. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9111. }
  9112. if item.MedChrgitmType == "09" { //西药费
  9113. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9114. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9115. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9116. }
  9117. if item.MedChrgitmType == "11" { //中成费
  9118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9119. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9120. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9121. }
  9122. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9123. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9124. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9125. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9126. }
  9127. } else {
  9128. if item.MedChrgitmType == "01" { //床位费
  9129. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9130. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9131. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9132. }
  9133. //if item.MedChrgitmType == "02" { //诊察费
  9134. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9135. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9136. //}
  9137. if item.MedChrgitmType == "03" { //检查费
  9138. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9139. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9140. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9141. }
  9142. //if item.MedChrgitmType == "02" { //检查费
  9143. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9144. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9145. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9146. //}
  9147. if item.MedChrgitmType == "04" { //化验费
  9148. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9149. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9150. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9151. }
  9152. if item.MedChrgitmType == "05" { //治疗费
  9153. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9154. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9155. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9156. }
  9157. if item.MedChrgitmType == "06" { //手术费
  9158. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9159. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9160. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9161. }
  9162. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9163. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9164. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9165. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9166. }
  9167. if item.MedChrgitmType == "09" { //西药费
  9168. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9169. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9170. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9171. }
  9172. if item.MedChrgitmType == "11" { //中成费
  9173. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9174. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9175. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9176. }
  9177. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9178. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9179. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9180. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9181. }
  9182. }
  9183. }
  9184. c.ServeSuccessJSON(map[string]interface{}{
  9185. "order": order,
  9186. "order_info": order_info,
  9187. "patient": patient,
  9188. "admin_info": adminInfo,
  9189. "his_hospital": record,
  9190. "bedCostTotal": bedCostTotal,
  9191. "operationCostTotal": operationCostTotal,
  9192. "otherCostTotal": otherCostTotal,
  9193. "materialCostTotal": materialCostTotal,
  9194. "westernMedicineCostTotal": westernMedicineCostTotal,
  9195. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9196. "checkCostTotal": checkCostTotal,
  9197. "zhenChaCostTotal": zhenChaCostTotal,
  9198. "laboratoryCostTotal": laboratoryCostTotal,
  9199. "treatCostTotal": treatCostTotal,
  9200. })
  9201. }
  9202. }
  9203. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9204. page, _ := c.GetInt64("page")
  9205. limit, _ := c.GetInt64("limit")
  9206. keywords := c.GetString("keywords")
  9207. start_time := c.GetString("start_time")
  9208. end_time := c.GetString("end_time")
  9209. //clr_type := c.GetString("clr_type")
  9210. insutype := c.GetString("insutype")
  9211. timeLayout := "2006-01-02"
  9212. loc, _ := time.LoadLocation("Local")
  9213. var theStartTIme int64
  9214. if len(start_time) > 0 {
  9215. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9216. theStartTIme = theTime.Unix()
  9217. }
  9218. var theEndtTIme int64
  9219. if len(end_time) > 0 {
  9220. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9221. theEndtTIme = theTime.Unix()
  9222. }
  9223. if page <= 0 {
  9224. page = 1
  9225. }
  9226. if limit <= 0 {
  9227. limit = 10
  9228. }
  9229. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9230. c.ServeSuccessJSON(map[string]interface{}{
  9231. "total": total,
  9232. "list": list,
  9233. })
  9234. return
  9235. }
  9236. func (c *HisApiController) GetPutOnRecordList() {
  9237. page, _ := c.GetInt64("page")
  9238. limit, _ := c.GetInt64("limit")
  9239. keywords := c.GetString("keywords")
  9240. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9241. if page <= 0 {
  9242. page = 1
  9243. }
  9244. if limit <= 0 {
  9245. limit = 10
  9246. }
  9247. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9248. c.ServeSuccessJSON(map[string]interface{}{
  9249. "total": total,
  9250. "list": list,
  9251. })
  9252. return
  9253. }
  9254. func (c *HisApiController) GetCompareData() {
  9255. start_time := c.GetString("start_time")
  9256. end_time := c.GetString("end_time")
  9257. insutype := c.GetString("insutype")
  9258. clr_type := c.GetString("clr_type")
  9259. timeLayout := "2006-01-02"
  9260. loc, _ := time.LoadLocation("Local")
  9261. var theStartTIme int64
  9262. if len(start_time) > 0 {
  9263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9264. if err != nil {
  9265. theStartTIme = 0
  9266. }
  9267. theStartTIme = theTime.Unix()
  9268. }
  9269. var theEndtTIme int64
  9270. if len(end_time) > 0 {
  9271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9272. if err != nil {
  9273. theEndtTIme = 0
  9274. }
  9275. theEndtTIme = theTime.Unix()
  9276. }
  9277. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9278. fmt.Println(err)
  9279. if err == nil {
  9280. c.ServeSuccessJSON(map[string]interface{}{
  9281. "list": formData,
  9282. })
  9283. } else {
  9284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9285. return
  9286. }
  9287. }
  9288. func (c *HisApiController) GetFaPiaoData() {
  9289. order_id, _ := c.GetInt64("order_id")
  9290. patient_id, _ := c.GetInt64("patient_id")
  9291. //number := c.GetString("number")
  9292. adminUser := c.GetAdminUserInfo()
  9293. order, _ := service.GetHisOrderByID(order_id)
  9294. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9295. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9296. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9297. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9298. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9299. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9300. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9301. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9302. var bedCostTotal float64 = 0 //床位总费
  9303. var bedCostSelfTotal float64 = 0 //床位自费
  9304. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9305. var operationCostTotal float64 = 0 //手术费
  9306. var operationCostSelfTotal float64 = 0 //手术费
  9307. var operationCostPartSelfTotal float64 = 0 //手术费
  9308. var otherCostTotal float64 = 0 //其他费用
  9309. var otherCostSelfTotal float64 = 0 //其他费用
  9310. var otherCostPartSelfTotal float64 = 0 //其他费用
  9311. var materialCostTotal float64 = 0 //材料费
  9312. var materialCostSelfTotal float64 = 0 //材料费
  9313. var materialCostPartSelfTotal float64 = 0 //材料费
  9314. var westernMedicineCostTotal float64 = 0 //西药费
  9315. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9316. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9317. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9318. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9319. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9320. var checkCostTotal float64 = 0 //检查费
  9321. var checkCostSelfTotal float64 = 0 //检查费
  9322. var checkCostPartSelfTotal float64 = 0 //检查费
  9323. var hiliCostTotal float64 = 0 //护理费
  9324. var hiliCostSelfTotal float64 = 0 //护理费
  9325. var hiliCostPartSelfTotal float64 = 0 //护理费
  9326. var laboratoryCostTotal float64 = 0 //化验费
  9327. var laboratoryCostSelfTotal float64 = 0 //化验费
  9328. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9329. var treatCostTotal float64 = 0 //治疗费用
  9330. var treatCostSelfTotal float64 = 0 //治疗费用
  9331. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9332. var zhenChaCostTotal float64 = 0 //其他费用
  9333. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9334. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9335. decimal.DivisionPrecision = 2
  9336. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9337. var balanceAccountsType int64
  9338. if his.ID > 0 {
  9339. balanceAccountsType = his.BalanceAccountsType
  9340. } else {
  9341. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9342. }
  9343. if balanceAccountsType == 2 {
  9344. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9345. for _, item := range orderInfos_two {
  9346. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9347. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9348. item.MedChrgitmType = "09"
  9349. }
  9350. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9351. if item.HisPrescriptionProject.Type == 2 {
  9352. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9353. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9354. case 0:
  9355. item.MedChrgitmType = "0"
  9356. break
  9357. case 1:
  9358. item.MedChrgitmType = "14"
  9359. break
  9360. case 2:
  9361. item.MedChrgitmType = "05"
  9362. break
  9363. case 3:
  9364. item.MedChrgitmType = "03"
  9365. break
  9366. case 4:
  9367. item.MedChrgitmType = "03"
  9368. break
  9369. case 5:
  9370. item.MedChrgitmType = "08"
  9371. break
  9372. case 6:
  9373. item.MedChrgitmType = "14"
  9374. break
  9375. case 7:
  9376. item.MedChrgitmType = "14"
  9377. break
  9378. case 8:
  9379. item.MedChrgitmType = "03"
  9380. break
  9381. case 9:
  9382. item.MedChrgitmType = "14"
  9383. break
  9384. case 10:
  9385. item.MedChrgitmType = "14"
  9386. break
  9387. case 11:
  9388. item.MedChrgitmType = "06"
  9389. break
  9390. case 12:
  9391. item.MedChrgitmType = "12"
  9392. break
  9393. case 13:
  9394. item.MedChrgitmType = "01"
  9395. break
  9396. case 14:
  9397. item.MedChrgitmType = "04"
  9398. break
  9399. case 15:
  9400. item.MedChrgitmType = "02"
  9401. break
  9402. }
  9403. } else {
  9404. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9405. case 1:
  9406. item.MedChrgitmType = "14"
  9407. break
  9408. case 2:
  9409. item.MedChrgitmType = "05"
  9410. break
  9411. case 3:
  9412. item.MedChrgitmType = "04"
  9413. break
  9414. case 4:
  9415. item.MedChrgitmType = "03"
  9416. break
  9417. case 5:
  9418. item.MedChrgitmType = "08"
  9419. break
  9420. case 6:
  9421. item.MedChrgitmType = "14"
  9422. break
  9423. case 7:
  9424. item.MedChrgitmType = "14"
  9425. break
  9426. case 8:
  9427. item.MedChrgitmType = "03"
  9428. break
  9429. case 9:
  9430. item.MedChrgitmType = "14"
  9431. break
  9432. }
  9433. }
  9434. } else if item.HisPrescriptionProject.Type == 3 {
  9435. item.MedChrgitmType = "08"
  9436. }
  9437. }
  9438. }
  9439. for _, item := range orderInfos_two {
  9440. fmt.Println(item.MedChrgitmType)
  9441. if item.MedChrgitmType == "07" { //床位费
  9442. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9443. hiliCostSelfTotal = hiliCostTotal
  9444. }
  9445. if item.MedChrgitmType == "01" { //床位费
  9446. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9447. bedCostSelfTotal = bedCostTotal
  9448. }
  9449. if item.MedChrgitmType == "02" { //诊察费
  9450. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9451. zhenChaCostSelfTotal = zhenChaCostTotal
  9452. }
  9453. if item.MedChrgitmType == "03" { //检查费
  9454. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9455. checkCostSelfTotal = checkCostTotal
  9456. }
  9457. if item.MedChrgitmType == "04" { //化验费
  9458. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9459. laboratoryCostSelfTotal = laboratoryCostTotal
  9460. }
  9461. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9462. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9463. treatCostSelfTotal = treatCostTotal
  9464. }
  9465. if item.MedChrgitmType == "06" { //手术费
  9466. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9467. operationCostSelfTotal = treatCostTotal
  9468. }
  9469. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9470. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9471. materialCostSelfTotal = materialCostTotal
  9472. }
  9473. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9474. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9475. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9476. }
  9477. if item.MedChrgitmType == "11" { //中成费
  9478. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9479. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9480. }
  9481. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9482. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9483. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9484. otherCostSelfTotal = otherCostTotal
  9485. }
  9486. } else {
  9487. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9488. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9489. otherCostSelfTotal = otherCostTotal
  9490. }
  9491. }
  9492. }
  9493. } else {
  9494. for _, item := range orderInfos {
  9495. if item.MedChrgitmType == "01" { //床位费
  9496. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9497. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9498. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9499. }
  9500. if item.MedChrgitmType == "02" { //诊察费
  9501. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9502. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9503. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9504. }
  9505. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9506. if item.MedChrgitmType == "03" { //检查费
  9507. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9508. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9509. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9510. }
  9511. } else {
  9512. if item.MedChrgitmType == "03" { //检查费
  9513. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9514. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9515. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9516. }
  9517. }
  9518. if item.MedChrgitmType == "04" { //化验费
  9519. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9520. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9521. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9522. }
  9523. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9524. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9525. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9526. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9527. }
  9528. if item.MedChrgitmType == "06" { //手术费
  9529. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9530. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9531. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9532. }
  9533. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9534. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9535. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9536. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9537. }
  9538. if item.MedChrgitmType == "07" { //护理
  9539. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9540. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9541. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9542. }
  9543. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9544. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9545. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9546. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9547. }
  9548. if item.MedChrgitmType == "11" { //中成费
  9549. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9550. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9551. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9552. }
  9553. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9554. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9555. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9556. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9557. }
  9558. }
  9559. }
  9560. timeLayout := "2006-01-02"
  9561. loc, _ := time.LoadLocation("Local")
  9562. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9563. if err != nil {
  9564. }
  9565. startRecordDateTime := startTime.Unix()
  9566. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9567. if err != nil {
  9568. }
  9569. endRecordDateTime := endTime.Unix()
  9570. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9571. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9572. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9573. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9574. c.ServeSuccessJSON(map[string]interface{}{
  9575. "charge_admin_name": charge_admin.UserName,
  9576. "order_number": order.Number, //业务流水号
  9577. "id_card_no": his.IdCardNo, //社会保障号
  9578. "patient": patient,
  9579. "department_name": department.Name, //科室
  9580. "number": his.Number, //门诊号
  9581. "date": order.SettleAccountsDate, //结算日期
  9582. "name": order.PsnName, //姓名
  9583. "gender": patient.Gender, //性别
  9584. "psn_cash_money": order.PsnCashPay, //个人支付
  9585. "pay_way": "门诊", //结算方式
  9586. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9587. "admin_user_name": admin.UserName, //收款员
  9588. "order": order,
  9589. "order_info": orderInfos_two,
  9590. "his": his,
  9591. "bedCostTotal": bedCostTotal,
  9592. "bedCostSelfTotal": bedCostSelfTotal,
  9593. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9594. "operationCostTotal": operationCostTotal,
  9595. "operationCostSelfTotal": operationCostSelfTotal,
  9596. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9597. "otherCostTotal": otherCostTotal,
  9598. "otherCostSelfTotal": otherCostSelfTotal,
  9599. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9600. "materialCostTotal": materialCostTotal,
  9601. "materialCostSelfTotal": materialCostSelfTotal,
  9602. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9603. "westernMedicineCostTotal": westernMedicineCostTotal,
  9604. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9605. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9606. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9607. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9608. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9609. "checkCostTotal": checkCostTotal,
  9610. "checkCostSelfTotal": checkCostSelfTotal,
  9611. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9612. "laboratoryCostTotal": laboratoryCostTotal,
  9613. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9614. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9615. "treatCostTotal": treatCostTotal,
  9616. "treatCostSelfTotal": treatCostSelfTotal,
  9617. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9618. "zhenChaCostTotal": zhenChaCostTotal,
  9619. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9620. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9621. "his_hospital_record": his_hospital_record,
  9622. "pre_pay_money": pre_pay_money,
  9623. "refund_sum": sum,
  9624. "doctor_info": doctor_info,
  9625. "hiliCostTotal": hiliCostTotal,
  9626. "hiliCostSelfTotal": hiliCostSelfTotal,
  9627. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9628. })
  9629. }
  9630. //func (c *HisApiController) GetFaPiaoDatas() {
  9631. // order_ids := c.GetString("order_ids")
  9632. // patient_id, _ := c.GetInt64("patient_id")
  9633. // adminUser := c.GetAdminUserInfo()
  9634. //
  9635. // orders := strings.Split(order_ids, ",")
  9636. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9637. //
  9638. // for _, item := range orders {
  9639. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9640. // order, _ := service.GetHisOrderByID(order_id)
  9641. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9642. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9643. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9644. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9645. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9646. //
  9647. // }
  9648. //
  9649. // var bedCostTotal float64 = 0 //床位总费
  9650. // var bedCostSelfTotal float64 = 0 //床位自费
  9651. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9652. //
  9653. // var operationCostTotal float64 = 0 //手术费
  9654. // var operationCostSelfTotal float64 = 0 //手术费
  9655. // var operationCostPartSelfTotal float64 = 0 //手术费
  9656. //
  9657. // var otherCostTotal float64 = 0 //其他费用
  9658. // var otherCostSelfTotal float64 = 0 //其他费用
  9659. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9660. //
  9661. // var materialCostTotal float64 = 0 //材料费
  9662. // var materialCostSelfTotal float64 = 0 //材料费
  9663. // var materialCostPartSelfTotal float64 = 0 //材料费
  9664. //
  9665. // var westernMedicineCostTotal float64 = 0 //西药费
  9666. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9667. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9668. //
  9669. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9670. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9671. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9672. //
  9673. // var checkCostTotal float64 = 0 //检查费
  9674. // var checkCostSelfTotal float64 = 0 //检查费
  9675. // var checkCostPartSelfTotal float64 = 0 //检查费
  9676. //
  9677. // var laboratoryCostTotal float64 = 0 //化验费
  9678. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9679. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9680. //
  9681. // var treatCostTotal float64 = 0 //治疗费用
  9682. // var treatCostSelfTotal float64 = 0 //治疗费用
  9683. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9684. //
  9685. // var zhenChaCostTotal float64 = 0 //其他费用
  9686. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9687. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9688. //
  9689. // decimal.DivisionPrecision = 2
  9690. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9691. //
  9692. // var balanceAccountsType int64
  9693. // if his.ID > 0 {
  9694. // balanceAccountsType = his.BalanceAccountsType
  9695. // } else {
  9696. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9697. // }
  9698. // if balanceAccountsType == 2 {
  9699. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9700. // for _, item := range orderInfos_two {
  9701. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9702. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9703. // item.MedChrgitmType = "09"
  9704. // }
  9705. //
  9706. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9707. // if item.HisPrescriptionProject.Type == 2 {
  9708. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9709. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9710. // case 0:
  9711. // item.MedChrgitmType = "0"
  9712. // break
  9713. // case 1:
  9714. // item.MedChrgitmType = "14"
  9715. // break
  9716. // case 2:
  9717. // item.MedChrgitmType = "05"
  9718. //
  9719. // break
  9720. // case 3:
  9721. // item.MedChrgitmType = "03"
  9722. //
  9723. // break
  9724. // case 4:
  9725. // item.MedChrgitmType = "03"
  9726. //
  9727. // break
  9728. // case 5:
  9729. // item.MedChrgitmType = "08"
  9730. //
  9731. // break
  9732. // case 6:
  9733. // item.MedChrgitmType = "14"
  9734. //
  9735. // break
  9736. // case 7:
  9737. // item.MedChrgitmType = "14"
  9738. //
  9739. // break
  9740. // case 8:
  9741. // item.MedChrgitmType = "03"
  9742. // break
  9743. // case 9:
  9744. // item.MedChrgitmType = "14"
  9745. // break
  9746. // case 10:
  9747. // item.MedChrgitmType = "14"
  9748. // break
  9749. // case 11:
  9750. // item.MedChrgitmType = "06"
  9751. // break
  9752. // case 12:
  9753. // item.MedChrgitmType = "12"
  9754. // break
  9755. // case 13:
  9756. // item.MedChrgitmType = "01"
  9757. // break
  9758. // case 14:
  9759. // item.MedChrgitmType = "04"
  9760. // break
  9761. // case 15:
  9762. // item.MedChrgitmType = "02"
  9763. // break
  9764. //
  9765. // }
  9766. //
  9767. // } else {
  9768. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9769. //
  9770. // case 1:
  9771. // item.MedChrgitmType = "14"
  9772. // break
  9773. // case 2:
  9774. // item.MedChrgitmType = "05"
  9775. //
  9776. // break
  9777. // case 3:
  9778. // item.MedChrgitmType = "03"
  9779. //
  9780. // break
  9781. // case 4:
  9782. // item.MedChrgitmType = "03"
  9783. //
  9784. // break
  9785. // case 5:
  9786. // item.MedChrgitmType = "08"
  9787. //
  9788. // break
  9789. // case 6:
  9790. // item.MedChrgitmType = "14"
  9791. //
  9792. // break
  9793. // case 7:
  9794. // item.MedChrgitmType = "14"
  9795. //
  9796. // break
  9797. // case 8:
  9798. // item.MedChrgitmType = "03"
  9799. // break
  9800. // case 9:
  9801. // item.MedChrgitmType = "14"
  9802. // break
  9803. //
  9804. // }
  9805. //
  9806. // }
  9807. //
  9808. // } else if item.HisPrescriptionProject.Type == 3 {
  9809. // item.MedChrgitmType = "08"
  9810. // }
  9811. // }
  9812. // }
  9813. //
  9814. // for _, item := range orderInfos_two {
  9815. // fmt.Println(item.MedChrgitmType)
  9816. // if item.MedChrgitmType == "01" { //床位费
  9817. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9818. // bedCostSelfTotal = bedCostTotal
  9819. // }
  9820. //
  9821. // if item.MedChrgitmType == "02" { //诊察费
  9822. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9823. // zhenChaCostSelfTotal = zhenChaCostTotal
  9824. // }
  9825. //
  9826. // if item.MedChrgitmType == "03" { //检查费
  9827. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9828. // checkCostSelfTotal = checkCostTotal
  9829. // }
  9830. //
  9831. // if item.MedChrgitmType == "04" { //化验费
  9832. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9833. // laboratoryCostSelfTotal = laboratoryCostTotal
  9834. // }
  9835. //
  9836. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9837. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9838. // treatCostSelfTotal = treatCostTotal
  9839. // }
  9840. //
  9841. // if item.MedChrgitmType == "06" { //手术费
  9842. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9843. // operationCostSelfTotal = treatCostTotal
  9844. // }
  9845. //
  9846. // if item.MedChrgitmType == "08" { //材料费
  9847. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9848. // materialCostSelfTotal = materialCostTotal
  9849. // }
  9850. //
  9851. // if item.MedChrgitmType == "09" { //西药费
  9852. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9853. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9854. // }
  9855. //
  9856. // if item.MedChrgitmType == "11" { //中成费
  9857. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9858. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9859. // }
  9860. //
  9861. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9862. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9863. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9864. // otherCostSelfTotal = otherCostTotal
  9865. // }
  9866. // } else {
  9867. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9868. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9869. // otherCostSelfTotal = otherCostTotal
  9870. // }
  9871. //
  9872. // }
  9873. //
  9874. // }
  9875. //
  9876. // } else {
  9877. // for _, item := range orderInfos {
  9878. // if item.MedChrgitmType == "01" { //床位费
  9879. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9880. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9881. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9882. // }
  9883. //
  9884. // if item.MedChrgitmType == "02" { //诊察费
  9885. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9886. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9887. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9888. // }
  9889. //
  9890. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9891. // if item.MedChrgitmType == "03" { //检查费
  9892. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9893. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9894. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9895. //
  9896. // }
  9897. // } else {
  9898. // if item.MedChrgitmType == "03" { //检查费
  9899. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9900. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9901. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9902. // }
  9903. //
  9904. // }
  9905. //
  9906. // if item.MedChrgitmType == "04" { //化验费
  9907. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9908. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9909. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9910. //
  9911. // }
  9912. //
  9913. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9914. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9915. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9916. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9917. //
  9918. // }
  9919. //
  9920. // if item.MedChrgitmType == "06" { //手术费
  9921. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9922. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9923. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9924. // }
  9925. //
  9926. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9927. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9928. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9929. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9930. // }
  9931. //
  9932. // if item.MedChrgitmType == "09" { //西药费
  9933. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9934. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9935. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9936. // }
  9937. //
  9938. // if item.MedChrgitmType == "11" { //中成费
  9939. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9940. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9941. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9942. // }
  9943. //
  9944. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9945. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9946. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9947. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9948. // }
  9949. //
  9950. // }
  9951. // }
  9952. // timeLayout := "2006-01-02"
  9953. // loc, _ := time.LoadLocation("Local")
  9954. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9955. // if err != nil {
  9956. // }
  9957. // startRecordDateTime := startTime.Unix()
  9958. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9959. // if err != nil {
  9960. // }
  9961. // endRecordDateTime := endTime.Unix()
  9962. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9963. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9964. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9965. //
  9966. // c.ServeSuccessJSON(map[string]interface{}{
  9967. // "order_number": order.Number, //业务流水号
  9968. // "id_card_no": his.IdCardNo, //社会保障号
  9969. // "department_name": department.Name, //科室
  9970. // "number": his.Number, //门诊号
  9971. // "date": order.SettleAccountsDate, //结算日期
  9972. // "name": order.PsnName, //姓名
  9973. // "gender": patient.Gender, //性别
  9974. // "psn_cash_money": order.PsnCashPay, //个人支付
  9975. // "pay_way": "门诊", //结算方式
  9976. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9977. // "admin_user_name": admin.UserName, //收款员
  9978. // "order": order,
  9979. // "order_info": orderInfos_two,
  9980. // "his": his,
  9981. // "bedCostTotal": bedCostTotal,
  9982. // "bedCostSelfTotal": bedCostSelfTotal,
  9983. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9984. // "operationCostTotal": operationCostTotal,
  9985. // "operationCostSelfTotal": operationCostSelfTotal,
  9986. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9987. // "otherCostTotal": otherCostTotal,
  9988. // "otherCostSelfTotal": otherCostSelfTotal,
  9989. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9990. // "materialCostTotal": materialCostTotal,
  9991. // "materialCostSelfTotal": materialCostSelfTotal,
  9992. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9993. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9994. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9995. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9996. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9997. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9998. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9999. // "checkCostTotal": checkCostTotal,
  10000. // "checkCostSelfTotal": checkCostSelfTotal,
  10001. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10002. // "laboratoryCostTotal": laboratoryCostTotal,
  10003. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10004. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10005. // "treatCostTotal": treatCostTotal,
  10006. // "treatCostSelfTotal": treatCostSelfTotal,
  10007. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10008. // "zhenChaCostTotal": zhenChaCostTotal,
  10009. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10010. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10011. // "his_hospital_record": his_hospital_record,
  10012. // "pre_pay_money": pre_pay_money,
  10013. // "refund_sum": sum,
  10014. // })
  10015. //
  10016. //}
  10017. func (this *HisApiController) GetIncomeStatisticsData() {
  10018. start_time := this.GetString("start_time")
  10019. end_time := this.GetString("end_time")
  10020. key_words := this.GetString("key_words")
  10021. limit, _ := this.GetInt64("limit")
  10022. page, _ := this.GetInt64("page")
  10023. if page <= 0 {
  10024. page = 1
  10025. }
  10026. if limit <= 0 {
  10027. limit = 10
  10028. }
  10029. statistics_type, _ := this.GetInt64("statistics_type")
  10030. admin := this.GetAdminUserInfo()
  10031. timeLayout := "2006-01-02"
  10032. loc, _ := time.LoadLocation("Local")
  10033. var theStartTIme int64
  10034. if len(start_time) > 0 {
  10035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10036. if err != nil {
  10037. theStartTIme = 0
  10038. }
  10039. theStartTIme = theTime.Unix()
  10040. }
  10041. var theEndtTIme int64
  10042. if len(end_time) > 0 {
  10043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10044. if err != nil {
  10045. theEndtTIme = 0
  10046. }
  10047. theEndtTIme = theTime.Unix()
  10048. }
  10049. if statistics_type == 1 {
  10050. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10051. this.ServeSuccessJSON(map[string]interface{}{
  10052. "list": list,
  10053. "total": total,
  10054. })
  10055. } else {
  10056. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10057. this.ServeSuccessJSON(map[string]interface{}{
  10058. "list": list,
  10059. "total": total,
  10060. })
  10061. }
  10062. }
  10063. func (c *HisApiController) PostProjectInformation() {
  10064. adminUser := c.GetAdminUserInfo()
  10065. orgId := adminUser.CurrentOrgId
  10066. dataBody := make(map[string]interface{}, 0)
  10067. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10068. if err != nil {
  10069. utils.ErrorLog(err.Error())
  10070. return
  10071. }
  10072. utils.ErrorLog("%v", dataBody)
  10073. var projectList []*models.HisProject
  10074. var total_goods []interface{}
  10075. tempProjects := dataBody["projects"].([]interface{})
  10076. total_goods = tempProjects
  10077. for index, projectMap := range tempProjects {
  10078. projectM := projectMap.(map[string]interface{})
  10079. var project models.HisProject
  10080. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10081. utils.ErrorLog("project_name")
  10082. return
  10083. }
  10084. project_name, _ := projectM["project_name"].(string)
  10085. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10086. err_log := models.ExportErrLog{
  10087. LogType: 6,
  10088. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10089. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10090. Status: 1,
  10091. CreateTime: time.Now().Unix(),
  10092. UpdateTime: time.Now().Unix(),
  10093. ExportTime: time.Now().Unix(),
  10094. }
  10095. service.CreateExportErrLog(&err_log)
  10096. continue
  10097. }
  10098. project.ProjectName = project_name
  10099. prices := projectM["price"].(string)
  10100. price, _ := strconv.ParseFloat(prices, 64)
  10101. if price <= 0 { //名字为空则生成一条导入错误日志
  10102. err_log := models.ExportErrLog{
  10103. LogType: 6,
  10104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10106. Status: 1,
  10107. CreateTime: time.Now().Unix(),
  10108. UpdateTime: time.Now().Unix(),
  10109. ExportTime: time.Now().Unix(),
  10110. }
  10111. service.CreateExportErrLog(&err_log)
  10112. continue
  10113. }
  10114. project.Price = price
  10115. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10116. utils.ErrorLog("unit_id")
  10117. return
  10118. }
  10119. unit := projectM["unit"].(string)
  10120. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10121. err_log := models.ExportErrLog{
  10122. LogType: 6,
  10123. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10124. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10125. Status: 1,
  10126. CreateTime: time.Now().Unix(),
  10127. UpdateTime: time.Now().Unix(),
  10128. ExportTime: time.Now().Unix(),
  10129. }
  10130. service.CreateExportErrLog(&err_log)
  10131. continue
  10132. }
  10133. project.Unit = unit
  10134. cost_classify := projectM["cost_classify"].(string)
  10135. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10136. err_log := models.ExportErrLog{
  10137. LogType: 6,
  10138. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10139. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10140. Status: 1,
  10141. CreateTime: time.Now().Unix(),
  10142. UpdateTime: time.Now().Unix(),
  10143. ExportTime: time.Now().Unix(),
  10144. }
  10145. service.CreateExportErrLog(&err_log)
  10146. continue
  10147. }
  10148. var costClassify = "费用类别"
  10149. var cost_classify_id int64
  10150. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10151. if len(cost_classify) != 0 {
  10152. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10153. if errcode == gorm.ErrRecordNotFound {
  10154. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10155. dataconfig := models.DictDataconfig{
  10156. ParentId: costClassifyConfig.ID,
  10157. Module: "system",
  10158. OrgId: orgId,
  10159. Name: cost_classify,
  10160. FieldName: "",
  10161. Value: costConfig.Value + 1,
  10162. CreatedTime: "",
  10163. UpdatedTime: "",
  10164. CreateUserId: adminUser.AdminUser.Id,
  10165. Status: 1,
  10166. Remark: "",
  10167. DeleteIdSystem: 0,
  10168. Title: "",
  10169. Content: "",
  10170. Order: 0,
  10171. Code: "",
  10172. }
  10173. service.CreatedDicConfig(&dataconfig)
  10174. }
  10175. }
  10176. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10177. for _, it := range costClassList {
  10178. if cost_classify == it.Name {
  10179. cost_classify_id = int64(it.Value)
  10180. }
  10181. }
  10182. project.CostClassify = cost_classify_id
  10183. executive_section := projectM["executive_section"].(string)
  10184. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10185. err_log := models.ExportErrLog{
  10186. LogType: 6,
  10187. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10188. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10189. Status: 1,
  10190. CreateTime: time.Now().Unix(),
  10191. UpdateTime: time.Now().Unix(),
  10192. ExportTime: time.Now().Unix(),
  10193. }
  10194. service.CreateExportErrLog(&err_log)
  10195. continue
  10196. }
  10197. if len(executive_section) != 0 {
  10198. //查找科室是否有内容
  10199. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10200. if errcodedepart == gorm.ErrRecordNotFound {
  10201. department := models.XtHisDepartment{
  10202. Name: executive_section,
  10203. Status: 1,
  10204. UserOrgId: adminUser.CurrentOrgId,
  10205. CreatedTime: time.Now().Unix(),
  10206. }
  10207. service.CreateDePartment(&department)
  10208. }
  10209. }
  10210. var executive_section_id int64
  10211. departMentList, _ := service.GetAllDepartMent(orgId)
  10212. for _, it := range departMentList {
  10213. if executive_section == it.Name {
  10214. executive_section_id = it.ID
  10215. }
  10216. }
  10217. project.ExecutiveSection = executive_section_id
  10218. medical_coverage := projectM["medical_coverage"].(string)
  10219. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10220. err_log := models.ExportErrLog{
  10221. LogType: 6,
  10222. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10223. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10224. Status: 1,
  10225. CreateTime: time.Now().Unix(),
  10226. UpdateTime: time.Now().Unix(),
  10227. ExportTime: time.Now().Unix(),
  10228. }
  10229. service.CreateExportErrLog(&err_log)
  10230. continue
  10231. }
  10232. var medicalCoverage = "医保等级"
  10233. var medical_coverage_id int64
  10234. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10235. if len(medical_coverage) != 0 {
  10236. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10237. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10238. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10239. dataconfig := models.DictDataconfig{
  10240. ParentId: medicalCoverageConfig.ID,
  10241. Module: "system",
  10242. OrgId: orgId,
  10243. Name: medical_coverage,
  10244. FieldName: "",
  10245. Value: medicalCoverageConfig.Value + 1,
  10246. CreatedTime: "",
  10247. UpdatedTime: "",
  10248. CreateUserId: adminUser.AdminUser.Id,
  10249. Status: 1,
  10250. Remark: "",
  10251. DeleteIdSystem: 0,
  10252. Title: "",
  10253. Content: "",
  10254. Order: 0,
  10255. Code: "",
  10256. }
  10257. service.CreatedDicConfig(&dataconfig)
  10258. }
  10259. }
  10260. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10261. for _, it := range medicalCoverageList {
  10262. if medical_coverage == it.Name {
  10263. medical_coverage_id = int64(it.Value)
  10264. }
  10265. }
  10266. project.MedicalCoverage = medical_coverage_id
  10267. pinyin := projectM["pinyin"].(string)
  10268. project.Pinyin = pinyin
  10269. wubi := projectM["wubi"].(string)
  10270. project.Wubi = wubi
  10271. statistical_classification := projectM["statistical_classification"].(string)
  10272. var statisticalClassification = "统计分类"
  10273. var statistical_classification_id int64
  10274. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10275. if len(statistical_classification) != 0 {
  10276. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10277. if classificationerrcodes == gorm.ErrRecordNotFound {
  10278. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10279. dataconfig := models.DictDataconfig{
  10280. ParentId: classiFication.ID,
  10281. Module: "system",
  10282. OrgId: orgId,
  10283. Name: statistical_classification,
  10284. FieldName: "",
  10285. Value: classiFicationConfig.Value + 1,
  10286. CreatedTime: "",
  10287. UpdatedTime: "",
  10288. CreateUserId: adminUser.AdminUser.Id,
  10289. Status: 1,
  10290. Remark: "",
  10291. DeleteIdSystem: 0,
  10292. Title: "",
  10293. Content: "",
  10294. Order: 0,
  10295. Code: "",
  10296. }
  10297. service.CreatedDicConfig(&dataconfig)
  10298. }
  10299. }
  10300. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10301. for _, it := range classiFicationList {
  10302. if statistical_classification == it.Name {
  10303. statistical_classification_id = int64(it.Value)
  10304. }
  10305. }
  10306. project.StatisticalClassification = statistical_classification_id
  10307. disease_directory := int64(projectM["disease_directory"].(float64))
  10308. project.DiseaseDirectory = disease_directory
  10309. is_record := int64(projectM["is_record"].(float64))
  10310. project.IsRecord = is_record
  10311. medical_code := projectM["medical_code"].(string)
  10312. project.MedicalCode = medical_code
  10313. tube_color := projectM["tube_color"].(string)
  10314. var tubeColor = "试管颜色"
  10315. var tube_color_id int64
  10316. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10317. if len(tube_color) != 0 {
  10318. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10319. if errcodetube == gorm.ErrRecordNotFound {
  10320. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10321. dataconfig := models.DictDataconfig{
  10322. ParentId: tubeColorConfig.ID,
  10323. Module: "system",
  10324. OrgId: orgId,
  10325. Name: tube_color,
  10326. FieldName: "",
  10327. Value: tubeConfig.Value + 1,
  10328. CreatedTime: "",
  10329. UpdatedTime: "",
  10330. CreateUserId: adminUser.AdminUser.Id,
  10331. Status: 1,
  10332. Remark: "",
  10333. DeleteIdSystem: 0,
  10334. Title: "",
  10335. Content: "",
  10336. Order: 0,
  10337. Code: "",
  10338. }
  10339. service.CreatedDicConfig(&dataconfig)
  10340. }
  10341. }
  10342. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10343. for _, it := range tubeColorList {
  10344. if tube_color == it.Name {
  10345. tube_color_id = int64(it.Value)
  10346. }
  10347. }
  10348. project.TubeColor = tube_color_id
  10349. single_dose := projectM["single_dose"].(string)
  10350. project.SingleDose = single_dose
  10351. execution_frequency := projectM["execution_frequency"].(string)
  10352. project.ExecutionFrequency = execution_frequency
  10353. delivery_way := projectM["delivery_way"].(string)
  10354. project.DeliveryWay = delivery_way
  10355. number_days := projectM["number_days"].(string)
  10356. project.NumberDays = number_days
  10357. total := projectM["total"].(string)
  10358. project.Total = total
  10359. medical_status := int64(projectM["medical_status"].(float64))
  10360. project.MedicalStatus = medical_status
  10361. category := int64(projectM["category"].(float64))
  10362. project.Category = category
  10363. specail_project := int64(projectM["specail_project"].(float64))
  10364. project.SpecailProject = specail_project
  10365. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10366. project.SocialSecurityDirectoryCode = social_security_directory_code
  10367. remark := projectM["remark"].(string)
  10368. project.Remark = remark
  10369. record_date := projectM["record_date"].(string)
  10370. timeLayout := "2006-01-02"
  10371. loc, _ := time.LoadLocation("Local")
  10372. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10373. project.RecordDate = theTime.Unix()
  10374. projectList = append(projectList, &project)
  10375. }
  10376. export_time := time.Now().Unix()
  10377. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10378. if len(projectList) > 0 {
  10379. for _, item := range projectList {
  10380. hans := item.ProjectName // 要转换的汉字字符串
  10381. // 创建一个拼音转换器
  10382. p := pinyin.NewArgs()
  10383. // 将汉字转为拼音
  10384. pinyinSlice := pinyin.Pinyin(hans, p)
  10385. // 输出拼音
  10386. fmt.Println("Pinyin:", pinyinSlice)
  10387. // 获取首字母
  10388. firstLetter := ""
  10389. for _, py := range pinyinSlice {
  10390. if len(py) > 0 {
  10391. firstLetter += string(py[0][0])
  10392. }
  10393. }
  10394. item.FirstLetter = firstLetter
  10395. project := models.HisProject{
  10396. ProjectName: item.ProjectName,
  10397. Price: item.Price,
  10398. Unit: item.Unit,
  10399. CostClassify: item.CostClassify,
  10400. ExecutiveSection: item.ExecutiveSection,
  10401. MedicalCoverage: item.MedicalCoverage,
  10402. UserOrgId: orgId,
  10403. Status: 1,
  10404. CreatedTime: time.Now().Unix(),
  10405. Pinyin: item.Pinyin,
  10406. Wubi: item.Wubi,
  10407. StatisticalClassification: item.StatisticalClassification,
  10408. DiseaseDirectory: item.DiseaseDirectory,
  10409. IsRecord: item.IsRecord,
  10410. MedicalCode: item.MedicalCode,
  10411. TubeColor: item.TubeColor,
  10412. SingleDose: item.SingleDose,
  10413. DeliveryWay: item.DeliveryWay,
  10414. NumberDays: item.NumberDays,
  10415. Total: item.Total,
  10416. Category: item.Category,
  10417. MedicalStatus: item.MedicalStatus,
  10418. SpecailProject: item.SpecailProject,
  10419. RecordDate: item.RecordDate,
  10420. Remark: item.Remark,
  10421. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10422. ExecutionFrequency: item.ExecutionFrequency,
  10423. FirstLetter: item.FirstLetter,
  10424. }
  10425. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10426. if errcodeproject == gorm.ErrRecordNotFound {
  10427. service.CreateProjectInfomation(&project)
  10428. } else if errcodeproject == nil {
  10429. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10430. }
  10431. log := models.ExportLog{
  10432. LogType: 6,
  10433. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10434. TotalNum: int64(len(total_goods)),
  10435. FailNum: int64(len(errLogs)),
  10436. SuccessNum: int64(len(projectList)),
  10437. CreateTime: time.Now().Unix(),
  10438. UpdateTime: time.Now().Unix(),
  10439. ExportTime: export_time,
  10440. Status: 1,
  10441. }
  10442. service.CreateExportLog(&log)
  10443. c.ServeSuccessJSON(map[string]interface{}{
  10444. "msg": "导入成功",
  10445. "total_num": len(total_goods),
  10446. "success_num": len(projectList),
  10447. "fail_num": int64(len(errLogs)),
  10448. })
  10449. }
  10450. } else {
  10451. log := models.ExportLog{
  10452. LogType: 6,
  10453. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10454. TotalNum: int64(len(total_goods)),
  10455. FailNum: int64(len(errLogs)),
  10456. SuccessNum: int64(len(projectList)),
  10457. CreateTime: time.Now().Unix(),
  10458. UpdateTime: time.Now().Unix(),
  10459. ExportTime: export_time,
  10460. Status: 1,
  10461. }
  10462. service.CreateExportLog(&log)
  10463. c.ServeSuccessJSON(map[string]interface{}{
  10464. "msg": "导入成功",
  10465. "total_num": len(total_goods),
  10466. "success_num": len(projectList),
  10467. "fail_num": int64(len(errLogs)),
  10468. })
  10469. }
  10470. }
  10471. //func (this *HisApiController) EditProjectInformation(){
  10472. //
  10473. // id, _ := this.GetInt64("id")
  10474. // project_team := this.GetString("project_team")
  10475. // price := this.GetString("price")
  10476. // price_float, _ := strconv.ParseFloat(price, 64)
  10477. // pinyin := this.GetString("pinyin")
  10478. // wubi := this.GetString("wubi")
  10479. // tube_color, _ := this.GetInt64("tube_color")
  10480. // team_type, _ := this.GetInt64("team_type")
  10481. // remark := this.GetString("remark")
  10482. // ids := this.GetString("ids")
  10483. // item_id := this.GetString("item_id")
  10484. // projectTeam := models.XtHisProjectTeam{
  10485. // ProjectTeam: project_team,
  10486. // Price: price_float,
  10487. // Pinyin: pinyin,
  10488. // Wubi: wubi,
  10489. // TubeColor: tube_color,
  10490. // TeamType: team_type,
  10491. // Remark: remark,
  10492. // ProjectId: ids,
  10493. // ItemId: item_id,
  10494. // }
  10495. //
  10496. //
  10497. // dataBody := make(map[string]interface{}, 0)
  10498. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10499. // if err != nil {
  10500. // utils.ErrorLog(err.Error())
  10501. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10502. // return
  10503. // }
  10504. //
  10505. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10506. //
  10507. //
  10508. // if err != nil {
  10509. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10510. // return
  10511. // }
  10512. //
  10513. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10514. // infos, _ := dataBody["info"].([]interface{})
  10515. // if len(infos) > 0 {
  10516. // var ids []string
  10517. //
  10518. // for _, item := range infos {
  10519. // items := item.(map[string]interface{})
  10520. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10521. // utils.ErrorLog("id")
  10522. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10523. // return
  10524. // }
  10525. // id := int64(items["id"].(float64))
  10526. //
  10527. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10528. // utils.ErrorLog("type")
  10529. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10530. // return
  10531. // }
  10532. // types := int64(items["type"].(float64))
  10533. //
  10534. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10535. // utils.ErrorLog("number")
  10536. // }
  10537. //
  10538. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10539. //
  10540. // projectList := models.XtHisProjectList{
  10541. // Number: number,
  10542. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10543. // ProjectId: id,
  10544. // Status: 1,
  10545. // CreatedTime: time.Now().Unix(),
  10546. // UpdatedTime: time.Now().Unix(),
  10547. // TeamId: projectTeam.ID,
  10548. // Type: types,
  10549. // }
  10550. // list := projectList
  10551. //
  10552. // service.CreateProjectList(&list)
  10553. //
  10554. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10555. //
  10556. // }
  10557. // ids_str := strings.Join(ids, ",")
  10558. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10559. // service.SaveProjectTeam(&projectTeam)
  10560. // this.ServeSuccessJSON(map[string]interface{}{
  10561. // "projectTeam": projectTeam,
  10562. // })
  10563. // }
  10564. // }
  10565. //}
  10566. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10567. name := c.GetString("name")
  10568. mode_id, _ := c.GetInt64("mode", 0)
  10569. types, _ := c.GetInt64("type", 0)
  10570. patient_id, _ := c.GetInt64("patient_id", 0)
  10571. types = 1
  10572. adminInfo := c.GetAdminUserInfo()
  10573. template := &models.HisPrescriptionTemplate{
  10574. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10575. PatientId: patient_id,
  10576. Type: types,
  10577. Status: 1,
  10578. Ctime: time.Now().Unix(),
  10579. Mtime: time.Now().Unix(),
  10580. Name: name,
  10581. Mode: mode_id,
  10582. }
  10583. dataBody := make(map[string]interface{}, 0)
  10584. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10585. if err != nil {
  10586. utils.ErrorLog(err.Error())
  10587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10588. return
  10589. }
  10590. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10591. //如果已经存在记录则删除处方
  10592. if template_one.ID > 0 {
  10593. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10594. var ids []int64
  10595. var org_id int64
  10596. for _, item := range ps {
  10597. org_id = c.GetAdminUserInfo().CurrentOrgId
  10598. ids = append(ids, item.ID)
  10599. }
  10600. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10601. if err2 == nil {
  10602. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10603. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10604. if len(prescriptions) > 0 {
  10605. for _, item := range prescriptions {
  10606. items := item.(map[string]interface{})
  10607. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10608. utils.ErrorLog("type")
  10609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10610. return
  10611. }
  10612. types := int64(items["type"].(float64))
  10613. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10614. utils.ErrorLog("med_type")
  10615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10616. return
  10617. }
  10618. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10619. ctime := time.Now().Unix()
  10620. prescription := &models.HisPrescriptionInfoTemplate{
  10621. PatientId: patient_id,
  10622. UserOrgId: adminInfo.CurrentOrgId,
  10623. Ctime: ctime,
  10624. Mtime: ctime,
  10625. Type: types,
  10626. Modifier: adminInfo.AdminUser.Id,
  10627. Creator: adminInfo.AdminUser.Id,
  10628. Status: 1,
  10629. PTemplateId: template_one.ID,
  10630. MedType: med_type,
  10631. }
  10632. service.CreateHisPrescriptionInfoTemplate(prescription)
  10633. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10634. advices := items["advices"].([]interface{})
  10635. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10636. ctime := time.Now().Unix()
  10637. mtime := ctime
  10638. if len(advices) > 0 {
  10639. for _, advice := range advices {
  10640. var s models.HisPrescriptionAdviceTemplate
  10641. s.PrescriptionId = prescription.ID
  10642. s.AdviceType = 2
  10643. s.StopState = 2
  10644. s.ExecutionState = 2
  10645. s.Status = 1
  10646. s.UserOrgId = adminInfo.CurrentOrgId
  10647. s.CreatedTime = ctime
  10648. s.UpdatedTime = mtime
  10649. s.PatientId = patient_id
  10650. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10651. if errcode > 0 {
  10652. c.ServeFailJSONWithSGJErrorCode(errcode)
  10653. return
  10654. }
  10655. service.CreateHisPrescriptionAdviceTemplate(&s)
  10656. }
  10657. }
  10658. }
  10659. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10660. projects := items["project"].([]interface{})
  10661. if len(projects) > 0 {
  10662. for _, project := range projects {
  10663. var p models.HisPrescriptionProjectTemplate
  10664. p.PrescriptionId = prescription.ID
  10665. p.Ctime = time.Now().Unix()
  10666. p.Mtime = time.Now().Unix()
  10667. p.PatientId = patient_id
  10668. p.UserOrgId = adminInfo.CurrentOrgId
  10669. p.Status = 1
  10670. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10671. if errcode > 0 {
  10672. c.ServeFailJSONWithSGJErrorCode(errcode)
  10673. return
  10674. }
  10675. service.CreateHisPrescriptionProjectTemplate(&p)
  10676. }
  10677. }
  10678. }
  10679. }
  10680. c.ServeSuccessJSON(map[string]interface{}{
  10681. "msg": "创建成功",
  10682. })
  10683. }
  10684. }
  10685. } else {
  10686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10687. return
  10688. }
  10689. } else {
  10690. err3 := service.CreateHisPrescriptionTemplate(template)
  10691. if err3 == nil {
  10692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10694. if len(prescriptions) > 0 {
  10695. for _, item := range prescriptions {
  10696. items := item.(map[string]interface{})
  10697. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10698. utils.ErrorLog("type")
  10699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10700. return
  10701. }
  10702. types := int64(items["type"].(float64))
  10703. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10704. utils.ErrorLog("med_type")
  10705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10706. return
  10707. }
  10708. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10709. ctime := time.Now().Unix()
  10710. prescription := &models.HisPrescriptionInfoTemplate{
  10711. PatientId: patient_id,
  10712. UserOrgId: adminInfo.CurrentOrgId,
  10713. Ctime: ctime,
  10714. Mtime: ctime,
  10715. Type: types,
  10716. Modifier: adminInfo.AdminUser.Id,
  10717. Creator: adminInfo.AdminUser.Id,
  10718. Status: 1,
  10719. PTemplateId: template.ID,
  10720. MedType: med_type,
  10721. }
  10722. service.CreateHisPrescriptionInfoTemplate(prescription)
  10723. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10724. advices := items["advices"].([]interface{})
  10725. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10726. ctime := time.Now().Unix()
  10727. mtime := ctime
  10728. if len(advices) > 0 {
  10729. for _, advice := range advices {
  10730. var s models.HisPrescriptionAdviceTemplate
  10731. s.PrescriptionId = prescription.ID
  10732. s.AdviceType = 2
  10733. s.StopState = 2
  10734. s.ExecutionState = 2
  10735. s.Status = 1
  10736. s.UserOrgId = adminInfo.CurrentOrgId
  10737. s.CreatedTime = ctime
  10738. s.UpdatedTime = mtime
  10739. s.PatientId = patient_id
  10740. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10741. if errcode > 0 {
  10742. c.ServeFailJSONWithSGJErrorCode(errcode)
  10743. return
  10744. }
  10745. service.CreateHisPrescriptionAdviceTemplate(&s)
  10746. }
  10747. }
  10748. }
  10749. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10750. projects := items["project"].([]interface{})
  10751. if len(projects) > 0 {
  10752. for _, project := range projects {
  10753. var p models.HisPrescriptionProjectTemplate
  10754. p.PrescriptionId = prescription.ID
  10755. p.Ctime = time.Now().Unix()
  10756. p.Mtime = time.Now().Unix()
  10757. p.PatientId = patient_id
  10758. p.UserOrgId = adminInfo.CurrentOrgId
  10759. p.Status = 1
  10760. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10761. if errcode > 0 {
  10762. c.ServeFailJSONWithSGJErrorCode(errcode)
  10763. return
  10764. }
  10765. service.CreateHisPrescriptionProjectTemplate(&p)
  10766. }
  10767. }
  10768. }
  10769. }
  10770. c.ServeSuccessJSON(map[string]interface{}{
  10771. "msg": "创建成功",
  10772. })
  10773. }
  10774. }
  10775. } else {
  10776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10777. return
  10778. }
  10779. }
  10780. }
  10781. func (c *HisApiController) PreSettle() {
  10782. id, _ := c.GetInt64("id")
  10783. record_time := c.GetString("record_time")
  10784. his_patient_id, _ := c.GetInt64("his_patient_id")
  10785. timeLayout := "2006-01-02"
  10786. loc, _ := time.LoadLocation("Local")
  10787. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10788. diagnosis_id := c.GetString("diagnosis")
  10789. sick_type, _ := c.GetInt64("sick_type")
  10790. reg_type, _ := c.GetInt64("p_type")
  10791. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10792. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10793. if err != nil {
  10794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10795. return
  10796. }
  10797. recordDateTime := theTime.Unix()
  10798. adminUser := c.GetAdminUserInfo()
  10799. var prescriptions []*models.HisPrescription
  10800. var start_time int64
  10801. var end_time int64
  10802. ids_str := c.GetString("ids")
  10803. ids_arr := strings.Split(ids_str, ",")
  10804. fmt.Println(reg_type)
  10805. if settle_accounts_type == 1 { //日结
  10806. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10807. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10808. } else {
  10809. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10810. }
  10811. fmt.Println(prescriptions)
  10812. } else { //月结
  10813. start_time_str := c.GetString("start_time")
  10814. end_time_str := c.GetString("end_time")
  10815. timeLayout := "2006-01-02"
  10816. loc, _ := time.LoadLocation("Local")
  10817. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10818. if err != nil {
  10819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10820. return
  10821. }
  10822. recordStartTime := theStartTime.Unix()
  10823. start_time = recordStartTime
  10824. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10825. if err != nil {
  10826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10827. return
  10828. }
  10829. recordEndTime := theEndTime.Unix()
  10830. end_time = recordEndTime
  10831. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10832. }
  10833. if reg_type == 1111 || reg_type == 1112 {
  10834. reg_type = 11
  10835. }
  10836. timestamp := time.Now().Unix()
  10837. tempTime := time.Unix(timestamp, 0)
  10838. timeFormat := tempTime.Format("20060102150405")
  10839. chrgBchno := rand.Intn(100000) + 10000
  10840. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10841. strconv.FormatInt(his.PatientId, 10)
  10842. var ids []int64
  10843. for _, item := range prescriptions {
  10844. ids = append(ids, item.ID)
  10845. }
  10846. fmt.Println(ids)
  10847. var total float64
  10848. for _, item := range prescriptions {
  10849. fmt.Println(item)
  10850. if item.Type == 1 { //药品
  10851. for _, subItem := range item.HisDoctorAdviceInfo {
  10852. total = total + (subItem.Price * subItem.PrescribingNumber)
  10853. }
  10854. }
  10855. if item.Type == 2 { //项目
  10856. for _, subItem := range item.HisPrescriptionProject {
  10857. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10858. total = total + (subItem.Price * cnt)
  10859. }
  10860. }
  10861. for _, subItem := range item.HisAdditionalCharge {
  10862. total = total + (subItem.Price * float64(subItem.Count))
  10863. }
  10864. }
  10865. allTotal := fmt.Sprintf("%.2f", total)
  10866. totals, _ := strconv.ParseFloat(allTotal, 64)
  10867. order := &models.HisOrder{
  10868. UserOrgId: adminUser.CurrentOrgId,
  10869. HisPatientId: his.ID,
  10870. PatientId: id,
  10871. SettleAccountsDate: recordDateTime,
  10872. Ctime: time.Now().Unix(),
  10873. Mtime: time.Now().Unix(),
  10874. Status: 1,
  10875. OrderStatus: 1,
  10876. MdtrtId: his.Number,
  10877. Number: chrg_bchno,
  10878. MedfeeSumamt: totals,
  10879. SettleEndTime: end_time,
  10880. SettleStartTime: start_time,
  10881. SettleType: settle_accounts_type,
  10882. PsnPartAmt: totals,
  10883. PsnCashPay: totals,
  10884. PType: 2,
  10885. IsPre: 1,
  10886. MedType: strconv.Itoa(int(reg_type)),
  10887. Diagnosis: diagnosis_id,
  10888. }
  10889. err = service.CreateOrder(order)
  10890. if err != nil {
  10891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10892. return
  10893. }
  10894. var customs []*Custom
  10895. for _, item := range prescriptions {
  10896. fmt.Println(item.Type)
  10897. if item.Type == 1 { //药品
  10898. for _, subItem := range item.HisDoctorAdviceInfo {
  10899. cus := &Custom{
  10900. AdviceId: subItem.ID,
  10901. ProjectId: 0,
  10902. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10903. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10904. FeedetlSn: subItem.FeedetlSn,
  10905. Price: fmt.Sprintf("%.2f", subItem.Price),
  10906. MedListCodg: subItem.MedListCodg,
  10907. Type: 1,
  10908. }
  10909. customs = append(customs, cus)
  10910. }
  10911. }
  10912. if item.Type == 2 { //项目
  10913. for _, subItem := range item.HisPrescriptionProject {
  10914. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10915. cus := &Custom{
  10916. AdviceId: 0,
  10917. ProjectId: subItem.ID,
  10918. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10919. Cut: fmt.Sprintf("%.2f", cnt),
  10920. FeedetlSn: subItem.FeedetlSn,
  10921. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10922. MedListCodg: subItem.MedListCodg,
  10923. Type: 2,
  10924. }
  10925. customs = append(customs, cus)
  10926. }
  10927. }
  10928. for _, item := range item.HisAdditionalCharge {
  10929. cus := &Custom{
  10930. ItemId: item.ID,
  10931. AdviceId: 0,
  10932. ProjectId: 0,
  10933. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10934. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10935. FeedetlSn: item.FeedetlSn,
  10936. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10937. MedListCodg: item.XtHisAddtionConfig.Code,
  10938. Type: 3,
  10939. }
  10940. customs = append(customs, cus)
  10941. }
  10942. }
  10943. fmt.Println(customs)
  10944. for _, item := range customs {
  10945. var advice_id int64 = 0
  10946. var project_id int64 = 0
  10947. var item_id int64 = 0
  10948. var types int64 = 0
  10949. if item.Type == 1 {
  10950. advice_id = item.AdviceId
  10951. project_id = 0
  10952. item_id = 0
  10953. } else if item.Type == 2 {
  10954. advice_id = 0
  10955. item_id = 0
  10956. project_id = item.ProjectId
  10957. } else if item.Type == 3 {
  10958. advice_id = 0
  10959. item_id = item.ItemId
  10960. project_id = 0
  10961. }
  10962. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10963. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10964. pric, _ := strconv.ParseFloat(item.Price, 32)
  10965. info := &models.HisOrderInfo{
  10966. OrderNumber: order.Number,
  10967. UploadDate: time.Now().Unix(),
  10968. AdviceId: advice_id,
  10969. DetItemFeeSumamt: detItemFeeSumamt,
  10970. Cnt: cut,
  10971. Pric: pric,
  10972. PatientId: id,
  10973. Status: 1,
  10974. Mtime: time.Now().Unix(),
  10975. Ctime: time.Now().Unix(),
  10976. UserOrgId: adminUser.CurrentOrgId,
  10977. HisPatientId: his.ID,
  10978. OrderId: order.ID,
  10979. ProjectId: project_id,
  10980. Type: types,
  10981. ItemId: item_id,
  10982. }
  10983. service.CreateOrderInfo(info)
  10984. }
  10985. his.SickType = sick_type
  10986. service.UpdataHisPateint(&his)
  10987. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10988. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10989. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10990. if err == nil {
  10991. c.ServeSuccessJSON(map[string]interface{}{
  10992. "msg": "结算成功",
  10993. })
  10994. }
  10995. }
  10996. type CustomOrderInfo struct {
  10997. Name string
  10998. Spec string
  10999. Unit string
  11000. Count float64
  11001. Price float64
  11002. Total float64
  11003. }
  11004. func (c *HisApiController) GetPrivateExpensesInfo() {
  11005. order_id, _ := c.GetInt64("id", 0)
  11006. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11007. order, _ := service.GetHisOrderByID(order_id)
  11008. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11009. if order.ID == 0 {
  11010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11011. return
  11012. }
  11013. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11014. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11015. org_id := c.GetAdminUserInfo().CurrentOrgId
  11016. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11017. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11018. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11019. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11020. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11021. //var orderInfos_four []*models.HisOrderInfoTwo
  11022. //for _, item := range orderInfos_three {
  11023. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11024. // item.HisPrescriptionProject.IsCheckTeam = 1
  11025. // orderInfos_four = append(orderInfos_four, item)
  11026. //
  11027. // }
  11028. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11029. // item.HisPrescriptionProject.IsCheckTeam = 2
  11030. // orderInfos_two = append(orderInfos_two, item)
  11031. // }
  11032. //}
  11033. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11034. //var cus_slice []CustomOrderInfo
  11035. //for _, item := range new_order_info {
  11036. // var cus CustomOrderInfo
  11037. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11038. // cus.Unit = ""
  11039. // cus.Spec = ""
  11040. // var total float64
  11041. // for _, subItem := range orderInfos_four {
  11042. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11043. // total = total + subItem.DetItemFeeSumamt
  11044. // fmt.Println(subItem.DetItemFeeSumamt)
  11045. // }
  11046. // }
  11047. // cus.Count = 1
  11048. // cus.Total = total
  11049. // cus_slice = append(cus_slice, cus)
  11050. //}
  11051. orderInfos = append(orderInfos, orderInfos_two...)
  11052. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11053. //orderInfos = append(orderInfos, orderInfos_three...)
  11054. //}/**/
  11055. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11056. c.ServeSuccessJSON(map[string]interface{}{
  11057. "order": order,
  11058. "order_info": orderInfos,
  11059. "patient": patient,
  11060. "admin_info": adminInfo,
  11061. "his": his,
  11062. "current_admin": role,
  11063. "org_config": miConfig,
  11064. //"new_order_info": cus_slice,
  11065. })
  11066. }
  11067. func (this *HisApiController) ChangeMedType() {
  11068. med_type := this.GetString("med_type")
  11069. old_med_type := this.GetString("old_med_type")
  11070. ids := this.GetString("ids")
  11071. settle_type, _ := this.GetInt64("settle_type")
  11072. start_time := this.GetString("start_time")
  11073. end_time := this.GetString("end_time")
  11074. ids_arr := strings.Split(ids, ",")
  11075. if settle_type == 1 { //日结
  11076. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11077. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11078. prescription.MedType = med_type
  11079. err := service.SaveHisPrescriptionTwo(&prescription)
  11080. if err == nil {
  11081. this.ServeSuccessJSON(map[string]interface{}{
  11082. "msg": "修改成功",
  11083. })
  11084. } else {
  11085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11086. return
  11087. }
  11088. } else if settle_type == 2 {
  11089. timeLayout := "2006-01-02"
  11090. loc, _ := time.LoadLocation("Local")
  11091. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11092. if err != nil {
  11093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11094. return
  11095. }
  11096. recordStartTime := theStartTime.Unix()
  11097. start_time_timestamp := recordStartTime
  11098. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11099. if err != nil {
  11100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11101. return
  11102. }
  11103. recordEndTime := theEndTime.Unix()
  11104. end_time_timestamp := recordEndTime
  11105. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11106. if updateErr == nil {
  11107. this.ServeSuccessJSON(map[string]interface{}{
  11108. "msg": "修改成功",
  11109. })
  11110. } else {
  11111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11112. return
  11113. }
  11114. }
  11115. }
  11116. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11117. patient_id, _ := c.GetInt64("patient_id")
  11118. his_patient_id, _ := c.GetInt64("his_patient_id")
  11119. record_date := c.GetString("record_date")
  11120. start_time := c.GetString("start_time")
  11121. end_time := c.GetString("end_time")
  11122. order_status, _ := c.GetInt64("type", 0)
  11123. p_type, _ := c.GetInt64("p_type", 0)
  11124. order_id, _ := c.GetInt64("order_id", 0)
  11125. timeLayout := "2006-01-02"
  11126. loc, _ := time.LoadLocation("Local")
  11127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11128. if err != nil {
  11129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11130. return
  11131. }
  11132. recordDateTime := theTime.Unix()
  11133. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11134. if err != nil {
  11135. }
  11136. startRecordDateTime := startTime.Unix()
  11137. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11138. if err != nil {
  11139. }
  11140. endRecordDateTime := endTime.Unix()
  11141. admin := c.GetAdminUserInfo()
  11142. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11143. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11144. order, _ := service.GetHisOrderByID(order_id)
  11145. var monthPrescriptions []*models.HisPrescription
  11146. if order_status == 1 || order_status == 0 {
  11147. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11148. } else if order_status == 2 {
  11149. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11150. }
  11151. var settle_total float64
  11152. for _, item := range monthPrescriptions {
  11153. if len(item.HisPrescriptionProject) > 0 {
  11154. for _, subItem := range item.HisPrescriptionProject {
  11155. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11156. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11157. settle_total = settle_total + total
  11158. }
  11159. }
  11160. if len(item.HisDoctorAdviceInfo) > 0 {
  11161. for _, subItem := range item.HisDoctorAdviceInfo {
  11162. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11163. settle_total = settle_total + total
  11164. }
  11165. }
  11166. }
  11167. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11168. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11169. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11170. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11171. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11172. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11173. //获取所有科室信息
  11174. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11175. var dia string
  11176. for _, item := range month_p_info {
  11177. if len(dia) == 0 {
  11178. dia = item.Diagnosis
  11179. } else {
  11180. dia = dia + "," + item.Diagnosis
  11181. }
  11182. }
  11183. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11184. dia_arr = removeEmptyStrings(dia_arr)
  11185. c.ServeSuccessJSON(map[string]interface{}{
  11186. "his_info": his_patient_info,
  11187. "xt_info": xt_patient_info,
  11188. "case_history": case_history,
  11189. "info": patientPrescriptionInfo,
  11190. "last_info": lastPatientPrescriptionInfo,
  11191. "month_prescriptions": monthPrescriptions,
  11192. "order": order,
  11193. "doctors": doctors,
  11194. "department": department,
  11195. "settle_total": settle_total,
  11196. "dia_arr": dia_arr,
  11197. })
  11198. return
  11199. }
  11200. func removeEmptyStrings(input []string) []string {
  11201. var output []string
  11202. for _, s := range input {
  11203. if s != "" {
  11204. output = append(output, s)
  11205. }
  11206. }
  11207. return output
  11208. }
  11209. func removeDuplicates(input []string) []string {
  11210. seen := make(map[string]bool)
  11211. output := []string{}
  11212. for _, s := range input {
  11213. if _, exists := seen[s]; !exists {
  11214. seen[s] = true
  11215. output = append(output, s)
  11216. }
  11217. }
  11218. return output
  11219. }
  11220. func (c *HisApiController) GetHisMonthPatientInfo() {
  11221. patient_id, _ := c.GetInt64("patient_id")
  11222. his_patient_id, _ := c.GetInt64("his_patient_id")
  11223. record_date := c.GetString("record_date")
  11224. number := c.GetString("number")
  11225. start_time := c.GetString("start_time")
  11226. end_time := c.GetString("end_time")
  11227. p_type, _ := c.GetInt64("p_type")
  11228. timeLayout := "2006-01-02"
  11229. loc, _ := time.LoadLocation("Local")
  11230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11231. if err != nil {
  11232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11233. return
  11234. }
  11235. recordDateTime := theTime.Unix()
  11236. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11237. if err != nil {
  11238. }
  11239. startRecordDateTime := startTime.Unix()
  11240. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11241. if err != nil {
  11242. }
  11243. endRecordDateTime := endTime.Unix()
  11244. admin := c.GetAdminUserInfo()
  11245. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11246. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11247. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11248. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11249. var settle_total float64
  11250. for _, item := range monthPrescriptions {
  11251. if len(item.HisPrescriptionProject) > 0 {
  11252. for _, subItem := range item.HisPrescriptionProject {
  11253. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11254. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11255. settle_total = settle_total + total
  11256. }
  11257. }
  11258. if len(item.HisDoctorAdviceInfo) > 0 {
  11259. for _, subItem := range item.HisDoctorAdviceInfo {
  11260. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11261. settle_total = settle_total + total
  11262. }
  11263. }
  11264. }
  11265. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11266. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11267. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11268. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11269. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11270. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11271. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11272. //获取所有科室信息
  11273. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11274. c.ServeSuccessJSON(map[string]interface{}{
  11275. "his_info": his_patient_info,
  11276. "xt_info": xt_patient_info,
  11277. "case_history": case_history,
  11278. "info": patientPrescriptionInfo,
  11279. "month_prescriptions": monthPrescriptions,
  11280. "order": order,
  11281. "doctors": doctors,
  11282. "department": department,
  11283. "count": count,
  11284. "drugStockConfig": drugStockConfig,
  11285. "last_info": lastPatientPrescriptionInfo,
  11286. "settle_total": settle_total,
  11287. })
  11288. return
  11289. }
  11290. func (c *HisApiController) GetAllOrder() {
  11291. org_id := c.GetAdminUserInfo().CurrentOrgId
  11292. orders, _ := service.GetNewHisOrderList(org_id)
  11293. c.ServeSuccessJSON(map[string]interface{}{
  11294. "order": orders,
  11295. })
  11296. return
  11297. }
  11298. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11299. newArr = make([]*models.HisOrderInfoTwo, 0)
  11300. for i := 0; i < len(arr); i++ {
  11301. repeat := false
  11302. for j := i + 1; j < len(arr); j++ {
  11303. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11304. repeat = true
  11305. break
  11306. }
  11307. }
  11308. if !repeat {
  11309. newArr = append(newArr, arr[i])
  11310. }
  11311. }
  11312. return
  11313. }
  11314. // 修改处方退库操作 参数传修改之前的处方数据
  11315. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11316. if advice.ExecutionState == 1 {
  11317. //查询该病人该药品是否有库存记录
  11318. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11319. if errcode == gorm.ErrRecordNotFound {
  11320. } else {
  11321. //退库
  11322. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11323. if advice.PrescribingNumberUnit == drug.MinUnit {
  11324. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11325. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11326. //退库
  11327. warehouseInfo := models.DrugWarehouseInfo{
  11328. StockMinNumber: prescribingNumber,
  11329. }
  11330. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11331. operation_time := time.Now().Unix()
  11332. creater := advice.AdviceDoctor
  11333. ctime := time.Now().Unix()
  11334. timeStr := time.Now().Format("2006-01-02")
  11335. timeArr := strings.Split(timeStr, "-")
  11336. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11337. total = total + 1
  11338. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11339. cancelStock := models.DrugCancelStock{
  11340. OrderNumber: orderNumber,
  11341. OperaTime: operation_time,
  11342. OrgId: advice.UserOrgId,
  11343. Creater: creater,
  11344. Ctime: ctime,
  11345. Status: 1,
  11346. ReturnTime: advice.AdviceDate,
  11347. Dealer: info.Dealer,
  11348. Manufacturer: info.Manufacturer,
  11349. Type: 1,
  11350. }
  11351. service.AddSigleDrugCancelStock(&cancelStock)
  11352. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11353. dealer, _ := service.GetDealerById(info.Dealer)
  11354. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11355. cancelStockInfo := models.DrugCancelStockInfo{
  11356. OrderNumber: cancelInfo.OrderNumber,
  11357. CancelStockId: cancelInfo.ID,
  11358. DrugId: info.DrugId,
  11359. Count: info.Count,
  11360. Status: 1,
  11361. Ctime: ctime,
  11362. OrgId: advice.UserOrgId,
  11363. Type: 1,
  11364. Manufacturer: manufactureName.ManufacturerName,
  11365. Dealer: dealer.DealerName,
  11366. Total: 0,
  11367. RetailPrice: info.RetailPrice,
  11368. RetailTotalPrice: info.RetailTotalPrice,
  11369. Price: info.Price,
  11370. RegisterAccount: "",
  11371. Remark: info.Remark,
  11372. BatchNumber: info.BatchNumber,
  11373. MaxUnit: info.CountUnit,
  11374. ProductDate: info.ProductDate,
  11375. ExpiryDate: info.ExpiryDate,
  11376. BatchNumberId: info.WarehouseInfoId,
  11377. }
  11378. flow := models.DrugFlow{
  11379. WarehousingId: 0,
  11380. DrugId: info.DrugId,
  11381. Number: "",
  11382. BatchNumber: info.BatchNumber,
  11383. Count: info.Count,
  11384. UserOrgId: advice.UserOrgId,
  11385. PatientId: 0,
  11386. SystemTime: ctime,
  11387. ConsumableType: 4,
  11388. IsSys: 0,
  11389. WarehousingOrder: "",
  11390. WarehouseOutId: 0,
  11391. WarehouseOutOrderNumber: "",
  11392. IsEdit: 0,
  11393. CancelStockId: cancelStock.ID,
  11394. CancelOrderNumber: cancelStock.OrderNumber,
  11395. Manufacturer: info.Manufacturer,
  11396. Dealer: info.Dealer,
  11397. Creator: advice.UserOrgId,
  11398. UpdateCreator: 0,
  11399. Status: 1,
  11400. Ctime: time.Now().Unix(),
  11401. Mtime: 0,
  11402. Price: info.Price,
  11403. WarehousingDetailId: 0,
  11404. WarehouseOutDetailId: 0,
  11405. CancelOutDetailId: 0,
  11406. ExpireDate: info.ExpiryDate,
  11407. ProductDate: info.ProductDate,
  11408. MaxUnit: info.CountUnit,
  11409. MinUnit: "",
  11410. }
  11411. service.CreatedCancelStock(cancelStockInfo)
  11412. service.CreateDrugFlowOne(flow)
  11413. } else {
  11414. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11415. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11416. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11417. warehouseInfo := models.DrugWarehouseInfo{
  11418. StockMinNumber: prescribingNumber,
  11419. }
  11420. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11421. }
  11422. operation_time := time.Now().Unix()
  11423. creater := advice.AdviceDoctor
  11424. ctime := time.Now().Unix()
  11425. timeStr := time.Now().Format("2006-01-02")
  11426. timeArr := strings.Split(timeStr, "-")
  11427. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11428. total = total + 1
  11429. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11430. cancelStock := models.DrugCancelStock{
  11431. OrderNumber: orderNumber,
  11432. OperaTime: operation_time,
  11433. OrgId: advice.UserOrgId,
  11434. Creater: creater,
  11435. Ctime: ctime,
  11436. Status: 1,
  11437. ReturnTime: advice.AdviceDate,
  11438. Dealer: info.Dealer,
  11439. Manufacturer: info.Manufacturer,
  11440. Type: 1,
  11441. }
  11442. service.AddSigleDrugCancelStock(&cancelStock)
  11443. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11444. dealer, _ := service.GetDealerById(info.Dealer)
  11445. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11446. cancelStockInfo := models.DrugCancelStockInfo{
  11447. OrderNumber: cancelInfo.OrderNumber,
  11448. CancelStockId: cancelInfo.ID,
  11449. DrugId: info.DrugId,
  11450. Count: info.Count,
  11451. Status: 1,
  11452. Ctime: ctime,
  11453. OrgId: advice.UserOrgId,
  11454. Type: 1,
  11455. Manufacturer: manufactureName.ManufacturerName,
  11456. Dealer: dealer.DealerName,
  11457. Total: 0,
  11458. RetailPrice: info.RetailPrice,
  11459. RetailTotalPrice: info.RetailTotalPrice,
  11460. Price: info.Price,
  11461. RegisterAccount: "",
  11462. Remark: info.Remark,
  11463. BatchNumber: info.BatchNumber,
  11464. MaxUnit: info.CountUnit,
  11465. ProductDate: info.ProductDate,
  11466. ExpiryDate: info.ExpiryDate,
  11467. BatchNumberId: info.WarehouseInfoId,
  11468. }
  11469. flow := models.DrugFlow{
  11470. WarehousingId: 0,
  11471. DrugId: info.DrugId,
  11472. Number: "",
  11473. BatchNumber: info.BatchNumber,
  11474. Count: info.Count,
  11475. UserOrgId: advice.UserOrgId,
  11476. PatientId: 0,
  11477. SystemTime: ctime,
  11478. ConsumableType: 4,
  11479. IsSys: 0,
  11480. WarehousingOrder: "",
  11481. WarehouseOutId: 0,
  11482. WarehouseOutOrderNumber: "",
  11483. IsEdit: 0,
  11484. CancelStockId: cancelStock.ID,
  11485. CancelOrderNumber: cancelStock.OrderNumber,
  11486. Manufacturer: info.Manufacturer,
  11487. Dealer: info.Dealer,
  11488. Creator: advice.AdviceDoctor,
  11489. UpdateCreator: 0,
  11490. Status: 1,
  11491. Ctime: time.Now().Unix(),
  11492. Mtime: 0,
  11493. Price: info.Price,
  11494. WarehousingDetailId: 0,
  11495. WarehouseOutDetailId: 0,
  11496. CancelOutDetailId: 0,
  11497. ExpireDate: info.ExpiryDate,
  11498. ProductDate: info.ProductDate,
  11499. MaxUnit: info.CountUnit,
  11500. MinUnit: "",
  11501. }
  11502. service.CreatedCancelStock(cancelStockInfo)
  11503. service.CreateDrugFlowOne(flow)
  11504. }
  11505. }
  11506. }
  11507. return err
  11508. }
  11509. func (this *HisApiController) DeleteNCDS() {
  11510. id, _ := this.GetInt64("id", 0)
  11511. if id > 0 {
  11512. service.DeletePsnNCDSRecordById(id)
  11513. this.ServeSuccessJSON(map[string]interface{}{
  11514. "msg": "删除成功",
  11515. })
  11516. } else {
  11517. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11518. return
  11519. }
  11520. }
  11521. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11522. id, _ := c.GetInt64("id")
  11523. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11524. c.ServeSuccessJSON(map[string]interface{}{
  11525. "advice": advice,
  11526. })
  11527. return
  11528. }
  11529. func (c *HisApiController) GetHisMonthChargePatientList() {
  11530. record_date := c.GetString("record_date")
  11531. start_time := c.GetString("start_time")
  11532. end_time := c.GetString("end_time")
  11533. timeLayout := "2006-01-02"
  11534. loc, _ := time.LoadLocation("Local")
  11535. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11536. if err != nil {
  11537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11538. return
  11539. }
  11540. if err != nil {
  11541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11542. return
  11543. }
  11544. recordDateTime := theTime.Unix()
  11545. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11546. if err != nil {
  11547. }
  11548. startRecordDateTime := startTime.Unix()
  11549. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11550. if err != nil {
  11551. }
  11552. endRecordDateTime := endTime.Unix()
  11553. adminInfo := c.GetAdminUserInfo()
  11554. var tempMonthChargePatients []*service.MonthChargePatients
  11555. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11556. for _, item := range tempPatients {
  11557. //过滤没有处方的
  11558. if len(item.HisPrescription) == 0 {
  11559. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11560. }
  11561. }
  11562. c.ServeSuccessJSON(map[string]interface{}{
  11563. "list": tempMonthChargePatients,
  11564. })
  11565. }
  11566. // PrescriptionDifference 医嘱数量差值结构体
  11567. type PrescriptionDrugDifference struct {
  11568. DrugID int64 //基础库药品id
  11569. ID int64 //医嘱id
  11570. Difference float64 //差值
  11571. Unit string //单位
  11572. }
  11573. type PrescriptionGoodDifference struct {
  11574. GoodID int64 //基础库项目耗材id
  11575. ID int64 //医嘱id
  11576. Difference int64 //差值
  11577. Unit string //单位
  11578. Type int64 //类型
  11579. }
  11580. type EditCustomData struct {
  11581. adviceList []*models.HisDoctorAdviceInfo
  11582. projectList []*models.HisPrescriptionProject
  11583. }
  11584. type SrcCustomData struct {
  11585. adviceList []*models.HisDoctorAdviceInfo
  11586. projectList []*models.HisPrescriptionProject
  11587. }
  11588. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11589. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11590. differences := make([]*PrescriptionDrugDifference, 0)
  11591. // 创建一个 map 来存储第一个切片中的药品信息
  11592. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11593. for _, advice := range firstPrescription {
  11594. firstMap[advice.DrugId] = advice
  11595. }
  11596. // 遍历第二个切片中的药品信息,并比较数量差值
  11597. for _, advice := range secondPrescription {
  11598. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11599. diff := &PrescriptionDrugDifference{
  11600. DrugID: advice.DrugId,
  11601. ID: firstAdvice.ID,
  11602. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11603. Unit: firstAdvice.PrescribingNumberUnit,
  11604. }
  11605. differences = append(differences, diff)
  11606. }
  11607. }
  11608. return differences
  11609. }
  11610. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11611. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11612. differences := make([]*PrescriptionGoodDifference, 0)
  11613. // 创建一个 map 来存储第一个切片中的耗材信息
  11614. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11615. for _, good := range firstPrescription {
  11616. firstMap[good.ProjectId] = good
  11617. }
  11618. // 遍历第二个切片中的耗材信息,并比较数量差值
  11619. for _, good := range secondPrescription {
  11620. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11621. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11622. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11623. diff := &PrescriptionGoodDifference{
  11624. GoodID: good.ProjectId,
  11625. ID: firstGood.ID,
  11626. Difference: count - firstCount,
  11627. Unit: firstGood.Unit,
  11628. Type: firstGood.Type,
  11629. }
  11630. differences = append(differences, diff)
  11631. }
  11632. }
  11633. return differences
  11634. }
  11635. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11636. var adviceList []*models.HisDoctorAdviceInfo
  11637. var projectList []*models.HisPrescriptionProject
  11638. var advice_ids []int64
  11639. var project_ids []int64
  11640. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11641. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11642. //var tempPrescription *models.HisPrescriptionProjectscription
  11643. if len(prescriptions) > 0 {
  11644. for _, item := range prescriptions {
  11645. items := item.(map[string]interface{})
  11646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11647. advices := items["advices"].([]interface{})
  11648. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11649. groupNo := int64(0)
  11650. ctime := time.Now().Unix()
  11651. mtime := ctime
  11652. if len(advices) > 0 {
  11653. for _, advice := range advices {
  11654. var s models.HisDoctorAdviceInfo
  11655. s.AdviceType = 2
  11656. s.StopState = 2
  11657. s.ExecutionState = 2
  11658. s.Status = 1
  11659. s.Groupno = groupNo
  11660. s.CreatedTime = ctime
  11661. s.UpdatedTime = mtime
  11662. s.IsSettle = 2
  11663. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11664. //存储切片中
  11665. if s.ID > 0 {
  11666. advice_ids = append(advice_ids, s.ID)
  11667. adviceList = append(adviceList, &s)
  11668. }
  11669. }
  11670. }
  11671. }
  11672. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11673. projects := items["project"].([]interface{})
  11674. if len(projects) > 0 {
  11675. for _, project := range projects {
  11676. var p models.HisPrescriptionProject
  11677. p.Ctime = time.Now().Unix()
  11678. p.Mtime = time.Now().Unix()
  11679. p.Status = 1
  11680. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11681. if p.ID > 0 {
  11682. project_ids = append(project_ids, p.ID)
  11683. projectList = append(projectList, &p)
  11684. }
  11685. }
  11686. }
  11687. }
  11688. }
  11689. }
  11690. }
  11691. editCustomData.projectList = projectList
  11692. editCustomData.adviceList = adviceList
  11693. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11694. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11695. srcCustomData.adviceList = list
  11696. srcCustomData.projectList = list2
  11697. return
  11698. }