his_api_controller.go 409KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. }
  87. func (c *HisApiController) ChangeOrderDesc() {
  88. id, _ := c.GetInt64("id")
  89. desc := c.GetString("desc")
  90. change_type := c.GetString("change_type")
  91. order, _ := service.GetHisOrderByID(id)
  92. if order.ID == 0 {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. switch change_type {
  97. case "oth_desc":
  98. order.OthDesc = desc
  99. break
  100. case "cash_pay":
  101. order.CashPay = desc
  102. break
  103. case "jifen_pay":
  104. order.JifenPay = desc
  105. break
  106. case "band_card_pay":
  107. order.BandCardPay = desc
  108. break
  109. case "ali_pay":
  110. order.AliPay = desc
  111. break
  112. case "wechat_pay":
  113. order.WechatPay = desc
  114. break
  115. }
  116. err := service.SaveHisOrder(&order)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "修改成功",
  120. })
  121. return
  122. } else {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. }
  127. func (c *HisApiController) GetMonthHisPatient() {
  128. record_date := c.GetString("record_date")
  129. //order_status, _ := c.GetInt64("type")
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. recordDateTime := theTime.Unix()
  138. adminInfo := c.GetAdminUserInfo()
  139. var tempPatients []service.NewTempPatients
  140. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  141. // 获取当前时间
  142. now := time.Now()
  143. // 获取本月的第一天
  144. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  145. // 获取下个月的第一天
  146. nextMonth := firstDay.AddDate(0, 1, 0)
  147. // 获取本月的最后一天
  148. lastDay := nextMonth.Add(-time.Nanosecond)
  149. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  150. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  151. var patients []service.NewTempPatients
  152. var patients_two []service.NewTempPatients
  153. for _, item := range tempPatients {
  154. //过滤掉没挂号的和没开处方的
  155. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  156. patients = append(patients, item)
  157. }
  158. ////过滤掉没挂号的
  159. //if len(item.HisPatient) > 0 {
  160. // patients_two = append(patients_two, item)
  161. //}
  162. }
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "list": patients,
  165. "list_two": patients_two,
  166. "chargePatients": chargePatients,
  167. })
  168. }
  169. func (c *HisApiController) GetBatchSettleAccounts() {
  170. order_ids := c.GetString("order_ids")
  171. admin_user_id, _ := c.GetInt64("admin_user_id")
  172. adminUser := c.GetAdminUserInfo()
  173. orders := strings.Split(order_ids, ",")
  174. var newOrders []models.Orders
  175. for _, item := range orders {
  176. order, _ := service.GetHisOrderByIDTenOne(item)
  177. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  178. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  179. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  180. orderInfos = append(orderInfos, orderInfos_two...)
  181. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  182. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  183. var diagnosis_ids []string
  184. if his.ID > 0 {
  185. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  186. } else {
  187. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  188. }
  189. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  190. var dia_config []*models.HisXtDiagnoseConfig
  191. var name string
  192. for _, item := range diagnosis_ids {
  193. id, _ := strconv.ParseInt(item, 10, 64)
  194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  195. dia_config = append(dia_config, diagnosisConfig)
  196. if len(name) == 0 {
  197. name = diagnosisConfig.ClassName
  198. } else {
  199. name = name + "," + diagnosisConfig.ClassName
  200. }
  201. }
  202. var bedCostTotal float64 = 0 //床位总费
  203. var bedCostSelfTotal float64 = 0 //床位自费
  204. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  205. var bedSelfTotal float64 = 0 //床位部分项目自费
  206. var bedInscpTotal float64 = 0 //床位部分项目自费
  207. var operationCostTotal float64 = 0 //手术费
  208. var operationCostSelfTotal float64 = 0 //手术费
  209. var operationCostPartSelfTotal float64 = 0 //手术费
  210. var operationSelfTotal float64 = 0 //床位部分项目自费
  211. var operationInscpTotal float64 = 0 //床位部分项目自费
  212. var otherCostTotal float64 = 0 //其他费用
  213. var otherCostSelfTotal float64 = 0 //其他费用
  214. var otherCostPartSelfTotal float64 = 0 //其他费用
  215. var otherSelfTotal float64 = 0 //床位部分项目自费
  216. var otherInscpTotal float64 = 0 //床位部分项目自费
  217. var materialCostTotal float64 = 0 //材料费
  218. var materialCostSelfTotal float64 = 0 //材料费
  219. var materialCostPartSelfTotal float64 = 0 //材料费
  220. var materialSelfTotal float64 = 0 //床位部分项目自费
  221. var materialInscpTotal float64 = 0 //床位部分项目自费
  222. var westernMedicineCostTotal float64 = 0 //西药费
  223. var westernMedicineCostSelfTotal float64 = 0 //西药费
  224. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  225. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  226. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  227. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  228. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  229. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  230. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  231. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  232. var checkCostTotal float64 = 0 //检查费
  233. var checkCostSelfTotal float64 = 0 //检查费
  234. var checkCostPartSelfTotal float64 = 0 //检查费
  235. var checkSelfTotal float64 = 0 //床位部分项目自费
  236. var checkInscpTotal float64 = 0 //床位部分项目自费
  237. var laboratoryCostTotal float64 = 0 //化验费
  238. var laboratoryCostSelfTotal float64 = 0 //化验费
  239. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  240. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  241. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  242. var treatCostTotal float64 = 0 //治疗费用
  243. var treatCostSelfTotal float64 = 0 //治疗费用
  244. var treatCostPartSelfTotal float64 = 0 //治疗费用
  245. var treatSelfTotal float64 = 0 //床位部分项目自费
  246. var treatInscpTotal float64 = 0 //床位部分项目自费
  247. decimal.DivisionPrecision = 2
  248. for _, item := range orderInfos {
  249. if item.MedChrgitmType == "01" { //床位费
  250. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  251. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  253. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  254. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  255. }
  256. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  257. if item.MedChrgitmType == "03" { //检查费
  258. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  259. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  260. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  261. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  262. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  263. }
  264. } else {
  265. if item.MedChrgitmType == "03" { //检查费
  266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  269. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  270. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  271. }
  272. }
  273. if item.MedChrgitmType == "04" { //化验费
  274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  275. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  276. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  277. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  278. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  279. }
  280. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  281. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. if item.MedChrgitmType == "06" { //手术费
  288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  289. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  290. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  291. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  292. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  293. }
  294. if item.MedChrgitmType == "08" { //材料费
  295. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  296. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  298. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  299. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  300. }
  301. if item.MedChrgitmType == "09" { //西药费
  302. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. if item.MedChrgitmType == "11" { //中成费
  309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  313. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. }
  323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  324. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  325. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  326. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  328. var doctor_name string
  329. if roles.ID == 0 {
  330. doctor_name = "管理员"
  331. } else {
  332. doctor_name = roles.UserName
  333. }
  334. yiliao_leibie := ""
  335. switch order.MedType {
  336. case "11":
  337. yiliao_leibie = "普通门诊"
  338. break
  339. case "12":
  340. yiliao_leibie = "门诊挂号"
  341. break
  342. case "13":
  343. yiliao_leibie = "急诊"
  344. break
  345. case "14":
  346. yiliao_leibie = "门诊特殊病"
  347. break
  348. case "15":
  349. yiliao_leibie = "门诊统筹"
  350. break
  351. case "16":
  352. yiliao_leibie = "门诊慢性病"
  353. break
  354. case "21":
  355. yiliao_leibie = "普通住院"
  356. break
  357. }
  358. var newOrder models.Orders
  359. newOrder.Diagnosis = name
  360. newOrder.OrderInfos = orderInfos
  361. newOrder.Number = order.MdtrtId
  362. newOrder.Date = order.SettleAccountsDate
  363. newOrder.ChargeAdmin = charge_admin
  364. newOrder.PrintorAdmin = printor_admin
  365. newOrder.Order = order
  366. newOrder.BedCostTotal = bedCostTotal
  367. newOrder.BedCostSelfTotal = bedCostSelfTotal
  368. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  369. newOrder.BedSelfTotal = bedSelfTotal
  370. newOrder.BedInscpTotal = bedInscpTotal
  371. newOrder.OperationCostTotal = operationCostTotal
  372. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  373. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  374. newOrder.OperationSelfTotal = operationSelfTotal
  375. newOrder.OperationInscpTotal = operationInscpTotal
  376. newOrder.OtherCostTotal = otherCostTotal
  377. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  378. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  379. newOrder.OtherSelfTotal = otherSelfTotal
  380. newOrder.OtherInscpTotal = otherInscpTotal
  381. newOrder.MaterialCostTotal = materialCostTotal
  382. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  383. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  384. newOrder.MaterialSelfTotal = materialSelfTotal
  385. newOrder.MaterialInscpTotal = materialInscpTotal
  386. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  387. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  388. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  389. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  390. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  391. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  392. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  393. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  394. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  395. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  396. newOrder.CheckCostTotal = checkCostTotal
  397. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  398. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  399. newOrder.CheckSelfTotal = checkSelfTotal
  400. newOrder.CheckInscpTotal = checkInscpTotal
  401. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  402. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  403. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  404. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  405. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  406. newOrder.TreatCostTotal = treatCostTotal
  407. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  408. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  409. newOrder.TreatSelfTotal = treatSelfTotal
  410. newOrder.TreatInscpTotal = treatInscpTotal
  411. newOrder.DoctorInfo = doctor_info
  412. newOrder.DoctorName = doctor_name
  413. newOrder.HealthCardNo = order.PsnNo
  414. newOrder.YiliaoLeibie = yiliao_leibie
  415. newOrder.Patient = patient
  416. newOrder.OrgName = miConfig.OrgName
  417. newOrder.OrgCode = miConfig.Code
  418. newOrder.OrderNumber = order.Number
  419. newOrder.HisPatient = his
  420. newOrder.DiaConfig = dia_config
  421. newOrders = append(newOrders, newOrder)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "orders": newOrders,
  425. })
  426. }
  427. func (c *HisApiController) GetTestOrder() {
  428. order_id, _ := c.GetInt64("order_id")
  429. admin_user_id, _ := c.GetInt64("admin_user_id")
  430. adminUser := c.GetAdminUserInfo()
  431. order, _ := service.GetHisOrderByID(order_id)
  432. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  433. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  434. orderInfos = append(orderInfos, orderInfos_two...)
  435. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  436. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  437. var dia_config []*models.HisXtDiagnoseConfig
  438. var name string
  439. var bedCostTotal float64 = 0 //床位总费
  440. var bedCostSelfTotal float64 = 0 //床位自费
  441. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  442. var bedSelfTotal float64 = 0 //床位部分项目自费
  443. var bedInscpTotal float64 = 0 //床位部分项目自费
  444. var operationCostTotal float64 = 0 //手术费
  445. var operationCostSelfTotal float64 = 0 //手术费
  446. var operationCostPartSelfTotal float64 = 0 //手术费
  447. var operationSelfTotal float64 = 0 //床位部分项目自费
  448. var operationInscpTotal float64 = 0 //床位部分项目自费
  449. var otherCostTotal float64 = 0 //其他费用
  450. var otherCostSelfTotal float64 = 0 //其他费用
  451. var otherCostPartSelfTotal float64 = 0 //其他费用
  452. var otherSelfTotal float64 = 0 //床位部分项目自费
  453. var otherInscpTotal float64 = 0 //床位部分项目自费
  454. var materialCostTotal float64 = 0 //材料费
  455. var materialCostSelfTotal float64 = 0 //材料费
  456. var materialCostPartSelfTotal float64 = 0 //材料费
  457. var materialSelfTotal float64 = 0 //床位部分项目自费
  458. var materialInscpTotal float64 = 0 //床位部分项目自费
  459. var westernMedicineCostTotal float64 = 0 //西药费
  460. var westernMedicineCostSelfTotal float64 = 0 //西药费
  461. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  462. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  463. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  464. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  465. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  466. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  467. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  468. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  469. var checkCostTotal float64 = 0 //检查费
  470. var checkCostSelfTotal float64 = 0 //检查费
  471. var checkCostPartSelfTotal float64 = 0 //检查费
  472. var checkSelfTotal float64 = 0 //床位部分项目自费
  473. var checkInscpTotal float64 = 0 //床位部分项目自费
  474. var laboratoryCostTotal float64 = 0 //化验费
  475. var laboratoryCostSelfTotal float64 = 0 //化验费
  476. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  477. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  478. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  479. var treatCostTotal float64 = 0 //治疗费用
  480. var treatCostSelfTotal float64 = 0 //治疗费用
  481. var treatCostPartSelfTotal float64 = 0 //治疗费用
  482. var treatSelfTotal float64 = 0 //床位部分项目自费
  483. var treatInscpTotal float64 = 0 //床位部分项目自费
  484. decimal.DivisionPrecision = 2
  485. for _, item := range orderInfos {
  486. if item.MedChrgitmType == "01" { //床位费
  487. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  488. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  489. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  490. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  491. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  492. }
  493. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  494. if item.MedChrgitmType == "03" { //检查费
  495. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  496. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  497. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  498. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  499. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  500. }
  501. } else {
  502. if item.MedChrgitmType == "03" { //检查费
  503. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  508. }
  509. }
  510. if item.MedChrgitmType == "04" { //化验费
  511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  514. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  515. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  516. }
  517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. if item.MedChrgitmType == "06" { //手术费
  525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  528. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  529. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  530. }
  531. if item.MedChrgitmType == "08" { //材料费
  532. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  533. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  534. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  535. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  536. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  537. }
  538. if item.MedChrgitmType == "09" { //西药费
  539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. if item.MedChrgitmType == "11" { //中成费
  546. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  550. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  551. }
  552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. }
  560. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  561. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  563. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  564. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  565. var doctor_name string
  566. if roles.ID == 0 {
  567. doctor_name = "管理员"
  568. } else {
  569. doctor_name = roles.UserName
  570. }
  571. yiliao_leibie := ""
  572. switch order.MedType {
  573. case "11":
  574. yiliao_leibie = "普通门诊"
  575. break
  576. case "12":
  577. yiliao_leibie = "门诊挂号"
  578. break
  579. case "13":
  580. yiliao_leibie = "急诊"
  581. break
  582. case "14":
  583. yiliao_leibie = "门诊特殊病"
  584. break
  585. case "15":
  586. yiliao_leibie = "门诊统筹"
  587. break
  588. case "16":
  589. yiliao_leibie = "门诊慢性病"
  590. break
  591. case "21":
  592. yiliao_leibie = "普通住院"
  593. break
  594. }
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "diagnosis": name,
  597. "order_infos": orderInfos,
  598. "number": order.MdtrtId,
  599. "date": order.SettleAccountsDate,
  600. "charge_admin": charge_admin,
  601. "printor_admin": printor_admin,
  602. "info": order,
  603. "order": order,
  604. "bedCostTotal": bedCostTotal,
  605. "bedCostSelfTotal": bedCostSelfTotal,
  606. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  607. "bedSelfTotal": bedSelfTotal,
  608. "bedInscpTotal": bedInscpTotal,
  609. "operationCostTotal": operationCostTotal,
  610. "operationCostSelfTotal": operationCostSelfTotal,
  611. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  612. "operationSelfTotal": operationSelfTotal,
  613. "operationInscpTotal": operationInscpTotal,
  614. "otherCostTotal": otherCostTotal,
  615. "otherCostSelfTotal": otherCostSelfTotal,
  616. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  617. "otherSelfTotal": otherSelfTotal,
  618. "otherInscpTotal": otherInscpTotal,
  619. "materialCostTotal": materialCostTotal,
  620. "materialCostSelfTotal": materialCostSelfTotal,
  621. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  622. "materialSelfTotal": materialSelfTotal,
  623. "materialInscpTotal": materialInscpTotal,
  624. "westernMedicineCostTotal": westernMedicineCostTotal,
  625. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  626. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  627. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  628. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  632. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  633. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  634. "checkCostTotal": checkCostTotal,
  635. "checkCostSelfTotal": checkCostSelfTotal,
  636. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  637. "checkSelfTotal": checkSelfTotal,
  638. "checkInscpTotal": checkInscpTotal,
  639. "laboratoryCostTotal": laboratoryCostTotal,
  640. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  641. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  642. "laboratorySelfTotal": laboratorySelfTotal,
  643. "laboratoryInscpTotal": laboratoryInscpTotal,
  644. "treatCostTotal": treatCostTotal,
  645. "treatCostSelfTotal": treatCostSelfTotal,
  646. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  647. "treatSelfTotal": treatSelfTotal,
  648. "treatInscpTotal": treatInscpTotal,
  649. "doctor_info": doctor_info,
  650. "doctor_name": doctor_name,
  651. "health_card_no": order.PsnNo,
  652. "yiliao_leibie": yiliao_leibie,
  653. "patient": patient,
  654. "org_name": miConfig.OrgName,
  655. "org_code": miConfig.Code,
  656. "order_number": order.Number,
  657. "his_hospital": his_hospital,
  658. "dia_config": dia_config,
  659. })
  660. }
  661. func (c *PublicApiController) GetBaiLinExportData() {
  662. data := service.GetBaiLinOrderData()
  663. fmt.Println(len(data))
  664. var new_data []*models.NewCustomHisOrder
  665. for _, item := range data {
  666. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  667. new_data = append(new_data, item)
  668. }
  669. }
  670. fmt.Println(len(new_data))
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "list": new_data,
  673. })
  674. }
  675. func (c *HisApiController) GetHisUnChargePatientList() {
  676. record_date := c.GetString("record_date")
  677. timeLayout := "2006-01-02"
  678. loc, _ := time.LoadLocation("Local")
  679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  680. if err != nil {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. recordDateTime := theTime.Unix()
  685. adminInfo := c.GetAdminUserInfo()
  686. var tempPatients []*service.NewTempPatients
  687. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  688. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  689. var patients []*service.NewTempPatients
  690. var patients_two []*service.NewTempPatients
  691. for _, item := range tempPatients {
  692. //过滤掉没挂号的和没开处方的
  693. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  694. patients = append(patients, item)
  695. }
  696. //过滤掉没挂号的
  697. if len(item.HisPatient) > 0 {
  698. patients_two = append(patients_two, item)
  699. }
  700. }
  701. c.ServeSuccessJSON(map[string]interface{}{
  702. "list": patients,
  703. "list_two": patients_two,
  704. })
  705. }
  706. func (c *HisApiController) GetPrivateExpensesOrder() {
  707. //id, _ := c.GetInt64("id")
  708. //record_time := c.GetString("record_time")
  709. order_id, _ := c.GetInt64("order_id")
  710. admin_user_id, _ := c.GetInt64("admin_user_id")
  711. //timeLayout := "2006-01-02"
  712. //loc, _ := time.LoadLocation("Local")
  713. //
  714. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  715. //if err != nil {
  716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. // return
  718. //}
  719. //recordDateTime := theTime.Unix()
  720. adminUser := c.GetAdminUserInfo()
  721. order, _ := service.GetHisOrderByID(order_id)
  722. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  723. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  724. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  725. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  726. //var config []*models.HisXtDiagnoseConfig
  727. var name string
  728. if order.PType == 1 {
  729. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  730. for _, item := range diagnosis_ids {
  731. id, _ := strconv.ParseInt(item, 10, 64)
  732. diagnosisConfig, _ := service.FindDiagnoseById(id)
  733. if len(name) == 0 {
  734. name = diagnosisConfig.ClassName
  735. } else {
  736. name = name + "," + diagnosisConfig.ClassName
  737. }
  738. }
  739. } else {
  740. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  741. for _, item := range diagnosis_ids {
  742. id, _ := strconv.ParseInt(item, 10, 64)
  743. diagnosisConfig, _ := service.FindDiagnoseById(id)
  744. if len(name) == 0 {
  745. name = diagnosisConfig.ClassName
  746. } else {
  747. name = name + "," + diagnosisConfig.ClassName
  748. }
  749. }
  750. }
  751. var bedCostTotal float64 = 0 //床位总费
  752. //var bedCostSelfTotal float64 = 0 //床位自费
  753. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  754. var operationCostTotal float64 = 0 //手术费
  755. //var operationCostSelfTotal float64 = 0 //手术费
  756. var operationCostPartSelfTotal float64 = 0 //手术费
  757. var otherCostTotal float64 = 0 //其他费用
  758. //var otherCostSelfTotal float64 = 0 //其他费用
  759. var otherCostPartSelfTotal float64 = 0 //其他费用
  760. var materialCostTotal float64 = 0 //材料费
  761. //var materialCostSelfTotal float64 = 0 //材料费
  762. var materialCostPartSelfTotal float64 = 0 //材料费
  763. var westernMedicineCostTotal float64 = 0 //西药费
  764. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  765. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  766. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  767. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  768. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  769. var checkCostTotal float64 = 0 //检查费
  770. //var checkCostSelfTotal float64 = 0 //检查费
  771. var checkCostPartSelfTotal float64 = 0 //检查费
  772. var laboratoryCostTotal float64 = 0 //化验费
  773. //var laboratoryCostSelfTotal float64 = 0 //化验费
  774. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  775. var treatCostTotal float64 = 0 //治疗费用
  776. //var treatCostSelfTotal float64 = 0 //治疗费用
  777. var treatCostPartSelfTotal float64 = 0 //治疗费用
  778. var zhenChaCostTotal float64 = 0 //其他费用
  779. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  780. decimal.DivisionPrecision = 2
  781. for _, item := range orderInfos {
  782. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  783. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  784. item.MedChrgitmType = "09"
  785. }
  786. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  787. if item.HisPrescriptionProject.Type == 2 {
  788. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  789. fmt.Println("CostClassify")
  790. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  791. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  792. case 0:
  793. item.MedChrgitmType = "0"
  794. break
  795. case 1:
  796. item.MedChrgitmType = "14"
  797. break
  798. case 2:
  799. item.MedChrgitmType = "05"
  800. break
  801. case 3:
  802. item.MedChrgitmType = "03"
  803. break
  804. case 4:
  805. item.MedChrgitmType = "03"
  806. break
  807. case 5:
  808. item.MedChrgitmType = "08"
  809. break
  810. case 6:
  811. item.MedChrgitmType = "14"
  812. break
  813. case 7:
  814. item.MedChrgitmType = "14"
  815. break
  816. case 8:
  817. item.MedChrgitmType = "03"
  818. break
  819. case 9:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 10:
  823. item.MedChrgitmType = "14"
  824. break
  825. case 11:
  826. item.MedChrgitmType = "06"
  827. break
  828. case 12:
  829. item.MedChrgitmType = "12"
  830. break
  831. case 13:
  832. item.MedChrgitmType = "01"
  833. break
  834. case 14:
  835. item.MedChrgitmType = "04"
  836. break
  837. case 15:
  838. item.MedChrgitmType = "14"
  839. break
  840. }
  841. } else {
  842. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  843. case 1:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 2:
  847. item.MedChrgitmType = "05"
  848. break
  849. case 3:
  850. item.MedChrgitmType = "04"
  851. break
  852. case 4:
  853. item.MedChrgitmType = "14"
  854. break
  855. case 5:
  856. item.MedChrgitmType = "08"
  857. break
  858. case 6:
  859. item.MedChrgitmType = "14"
  860. break
  861. case 7:
  862. item.MedChrgitmType = "14"
  863. break
  864. case 8:
  865. item.MedChrgitmType = "03"
  866. break
  867. case 9:
  868. item.MedChrgitmType = "14"
  869. break
  870. }
  871. }
  872. } else if item.HisPrescriptionProject.Type == 3 {
  873. item.MedChrgitmType = "08"
  874. }
  875. }
  876. }
  877. order.PsnCashPay = order.MedfeeSumamt
  878. for _, item := range orderInfos {
  879. if item.MedChrgitmType == "01" { //床位费
  880. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  881. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  882. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  883. }
  884. if item.MedChrgitmType == "02" { //诊察费
  885. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  886. //zhenChaCostSelfTotal = zhenChaCostTotal
  887. }
  888. if item.MedChrgitmType == "03" { //检查费
  889. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  890. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  891. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  892. }
  893. if item.MedChrgitmType == "02" { //检查费
  894. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  895. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  896. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  897. }
  898. if item.MedChrgitmType == "04" { //化验费
  899. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  900. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  901. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  902. }
  903. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  904. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "06" { //手术费
  909. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  911. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  912. }
  913. if item.MedChrgitmType == "08" { //材料费
  914. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  915. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  916. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  917. }
  918. if item.MedChrgitmType == "09" { //西药费
  919. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  920. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  921. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  922. }
  923. if item.MedChrgitmType == "11" { //中成费
  924. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  925. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  926. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  927. }
  928. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  929. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  930. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  931. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  932. }
  933. }
  934. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  935. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  936. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  937. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "patient": patient,
  940. "order_infos": orderInfos,
  941. "diagnosis": name,
  942. "bedCostTotal": bedCostTotal,
  943. "bedCostSelfTotal": bedCostTotal,
  944. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  945. "operationCostTotal": operationCostTotal,
  946. "operationCostSelfTotal": operationCostTotal,
  947. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  948. "otherCostTotal": otherCostTotal,
  949. "otherCostSelfTotal": otherCostTotal,
  950. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  951. "materialCostTotal": materialCostTotal,
  952. "materialCostSelfTotal": materialCostTotal,
  953. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  954. "westernMedicineCostTotal": westernMedicineCostTotal,
  955. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  956. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  957. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  958. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  959. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  960. "checkCostTotal": checkCostTotal,
  961. "checkCostSelfTotal": checkCostTotal,
  962. "zhenChaCostTotal": zhenChaCostTotal,
  963. "zhenChaCostSelfTotal": zhenChaCostTotal,
  964. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  965. "laboratoryCostTotal": laboratoryCostTotal,
  966. "laboratoryCostSelfTotal": laboratoryCostTotal,
  967. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  968. "treatCostTotal": treatCostTotal,
  969. "treatCostSelfTotal": treatCostTotal,
  970. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  971. "charge_admin": charge_admin,
  972. "printor_admin": printor_admin,
  973. "org_name": org.OrgName,
  974. "org_code": miConfig.Code,
  975. "name": patient.Name,
  976. "number": order.MdtrtId,
  977. "date": order.SettleAccountsDate,
  978. "info": order,
  979. "his_hospital": his_hospital,
  980. "his": his,
  981. })
  982. }
  983. func (c *HisApiController) RefudDetail() {
  984. order_id, _ := c.GetInt64("order_id")
  985. order, _ := service.GetHisOrderByID(order_id)
  986. adminUser := c.GetAdminUserInfo()
  987. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "撤销成功",
  990. })
  991. }
  992. func (c *HisApiController) Sscard() {
  993. //r := CardInit()
  994. //if r == 0 {
  995. // GetBaseInfo()
  996. //}
  997. //c.ServeSuccessJSON(map[string]interface{}{
  998. // "list": "11",
  999. //})
  1000. }
  1001. func GetBaseInfo() error {
  1002. //handle := syscall.MustLoadDLL("SSCard.dll")
  1003. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1004. //
  1005. //str := make([]byte, 256)
  1006. //str1 := make([]byte, 256)
  1007. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1008. //if ferr != nil {
  1009. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1010. // return ferr
  1011. //}
  1012. //
  1013. //fmt.Println(string(str))
  1014. //
  1015. //fmt.Println(r)
  1016. return nil
  1017. }
  1018. func CardInit() int {
  1019. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1020. //add := DllTestDef.MustFindProc("Init")
  1021. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1022. //if err != nil {
  1023. // fmt.Println("SSCard的运算结果为:", ret)
  1024. //}
  1025. //result := int(ret)
  1026. return 0
  1027. }
  1028. func IntPtr(n int) uintptr {
  1029. return uintptr(n)
  1030. }
  1031. func StrPtr(s string) uintptr {
  1032. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1033. }
  1034. func (c *HisApiController) GetHisPatientList() {
  1035. //types, _ := c.GetInt64("type", 0)
  1036. record_date := c.GetString("record_date")
  1037. sch_type, _ := c.GetInt64("sch_type")
  1038. timeLayout := "2006-01-02"
  1039. loc, _ := time.LoadLocation("Local")
  1040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1041. if err != nil {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. recordDateTime := theTime.Unix()
  1046. adminInfo := c.GetAdminUserInfo()
  1047. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1048. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1049. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1050. //获取当前用户的信息
  1051. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1052. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1053. //获取所有科室信息
  1054. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "list": patients,
  1057. "list_two": patients_two,
  1058. "info": adminUserInfo,
  1059. "doctors": doctors,
  1060. "department": department,
  1061. })
  1062. }
  1063. type CustomTemplate struct {
  1064. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1065. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1066. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1067. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1068. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1069. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1070. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1071. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1072. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1073. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1074. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1075. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1076. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1077. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1078. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1079. }
  1080. func (c *HisApiController) GetHisPatientInfo() {
  1081. patient_id, _ := c.GetInt64("patient_id")
  1082. his_patient_id, _ := c.GetInt64("his_patient_id")
  1083. record_date := c.GetString("record_date")
  1084. number := c.GetString("number")
  1085. //start_time := c.GetString("start_time")
  1086. //end_time := c.GetString("end_time")
  1087. p_type, _ := c.GetInt64("p_type")
  1088. timeLayout := "2006-01-02"
  1089. loc, _ := time.LoadLocation("Local")
  1090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1091. if err != nil {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. recordDateTime := theTime.Unix()
  1096. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1097. //if err != nil {
  1098. //
  1099. //}
  1100. //startRecordDateTime := startTime.Unix()
  1101. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1102. //if err != nil {
  1103. //
  1104. //}
  1105. //endRecordDateTime := endTime.Unix()
  1106. admin := c.GetAdminUserInfo()
  1107. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1108. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1109. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1110. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1111. var prescriptions []*models.HisPrescription
  1112. var last_prescriptions []*models.HisPrescription
  1113. var sch_prescriptions []CustomTemplate
  1114. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1115. if p_type == 1 { //住院
  1116. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1117. for _, item := range prescriptions {
  1118. for _, subItem := range item.HisDoctorAdviceInfo {
  1119. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1120. if info.RetailPrice > 0 {
  1121. subItem.Drug.MinPrice = info.RetailPrice
  1122. }
  1123. }
  1124. }
  1125. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1126. } else { //门诊
  1127. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1128. for _, item := range prescriptions {
  1129. for _, subItem := range item.HisDoctorAdviceInfo {
  1130. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1131. if info.RetailPrice > 0 {
  1132. subItem.Drug.MinPrice = info.RetailPrice
  1133. }
  1134. }
  1135. }
  1136. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1137. }
  1138. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1139. if sch.ID > 0 {
  1140. var week string
  1141. t := time.Now()
  1142. switch t.Weekday().String() {
  1143. case "Monday":
  1144. week = "周一"
  1145. break
  1146. case "Tuesday":
  1147. week = "周二"
  1148. break
  1149. case "Wednesday":
  1150. week = "周三"
  1151. break
  1152. case "Thursday":
  1153. week = "周四"
  1154. break
  1155. case "Friday":
  1156. week = "周五"
  1157. break
  1158. case "Saturday":
  1159. week = "周六"
  1160. break
  1161. case "Sunday":
  1162. week = "周日"
  1163. break
  1164. }
  1165. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1166. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1167. //根据推送频率组装新的数组
  1168. for _, item := range temp_sch_prescriptions {
  1169. var cus CustomTemplate
  1170. cus.ID = item.ID
  1171. cus.UserOrgId = item.UserOrgId
  1172. cus.PatientId = item.PatientId
  1173. cus.MedType = item.MedType
  1174. cus.RecordDate = item.RecordDate
  1175. cus.Type = item.Type
  1176. cus.PType = item.PType
  1177. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1178. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1179. if subItem.FrequencyType == 1 { //每次必推
  1180. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1181. }
  1182. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1183. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1184. }
  1185. if subItem.FrequencyType == 2 { //按照天数频率
  1186. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1187. now := p.Unix()
  1188. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1189. dayStr2 := "-" + dayStr
  1190. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1191. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1192. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1193. if len(advices) == 0 {
  1194. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1195. }
  1196. }
  1197. }
  1198. }
  1199. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1200. if subItem.Type == 2 {
  1201. if subItem.XtHisProject.MedicalStatus != 1 {
  1202. if subItem.FrequencyType == 1 {
  1203. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1204. }
  1205. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1206. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1207. }
  1208. if subItem.FrequencyType == 2 {
  1209. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1210. now := p.Unix()
  1211. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1212. dayStr2 := "-" + dayStr
  1213. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1214. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1215. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1216. if len(projects) == 0 {
  1217. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1218. }
  1219. }
  1220. }
  1221. } else if subItem.Type == 3 {
  1222. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1223. if subItem.FrequencyType == 1 {
  1224. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1225. }
  1226. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 2 {
  1230. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1231. now := p.Unix()
  1232. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1233. dayStr2 := "-" + dayStr
  1234. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1235. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1236. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1237. if len(projects) == 0 {
  1238. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. sch_prescriptions = append(sch_prescriptions, cus)
  1245. }
  1246. for _, item := range sch_prescriptions {
  1247. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1248. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1249. }
  1250. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1251. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1252. }
  1253. }
  1254. }
  1255. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1256. if config.ID > 0 && config.IsOpen == 1 {
  1257. for _, item := range sch_prescriptions {
  1258. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1259. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1260. if info.RetailPrice > 0 {
  1261. subItem.Drug.MinPrice = info.RetailPrice
  1262. }
  1263. }
  1264. }
  1265. }
  1266. if config.ID > 0 && config.IsOpen == 1 {
  1267. for _, item := range sch_prescriptions {
  1268. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1269. if subItem.Type == 3 {
  1270. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1271. if info.Price > 0 {
  1272. subItem.GoodInfo.PackingPrice = info.Price
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1279. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1280. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1281. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1282. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1283. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1284. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1285. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1286. //获取所有科室信息
  1287. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1288. c.ServeSuccessJSON(map[string]interface{}{
  1289. "his_info": his_patient_info,
  1290. "xt_info": xt_patient_info,
  1291. "prescription": prescriptions,
  1292. "case_history": case_history,
  1293. "info": patientPrescriptionInfo,
  1294. //"month_prescriptions": monthPrescriptions,
  1295. "order": order,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. "sch_prescriptions": sch_prescriptions,
  1299. "last_prescriptions": last_prescriptions,
  1300. "schedule": sch,
  1301. "count": count,
  1302. "drugStockConfig": drugStockConfig,
  1303. "last_info": lastPatientPrescriptionInfo,
  1304. })
  1305. return
  1306. }
  1307. func (c *HisApiController) GetHisPrescriptionConfig() {
  1308. adminInfo := c.GetAdminUserInfo()
  1309. //获取医嘱模版
  1310. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1311. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1312. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1313. //获取所有基础药
  1314. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1315. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1316. if config.ID > 0 && config.IsOpen == 1 {
  1317. for _, item := range drugs {
  1318. var index = 0
  1319. for _, subItem := range item.OtherDrugWarehouseInfo {
  1320. if index == 0 {
  1321. index = index + 1
  1322. if subItem.RetailPrice > 0 {
  1323. item.MinPrice = subItem.RetailPrice
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1330. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1331. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //获取诊断信息
  1336. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1337. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1338. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1339. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1340. //获取是否开启保存耗材出库的开关
  1341. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1342. c.ServeSuccessJSON(map[string]interface{}{
  1343. "drugs": drugs,
  1344. "advices_template": advices,
  1345. "drugways": drugways,
  1346. "efs": efs,
  1347. "doctors": doctors,
  1348. "department": department,
  1349. "sick": sick,
  1350. "additions": additions,
  1351. "diagnose": diagnose,
  1352. "manufacturers": manufacturers,
  1353. "goodOutOpen": goodOutOpen,
  1354. "patientDiagnose": patientDiagnose,
  1355. })
  1356. }
  1357. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1358. //获取所有基础药
  1359. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1360. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1361. if config.ID > 0 && config.IsOpen == 1 {
  1362. for _, item := range drugs {
  1363. var index = 0
  1364. for _, subItem := range item.OtherDrugWarehouseInfo {
  1365. if index == 0 {
  1366. index = index + 1
  1367. if subItem.RetailPrice > 0 {
  1368. item.MinPrice = subItem.RetailPrice
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1375. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1376. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1377. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1378. //获取所有科室信息
  1379. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1380. //获取诊断信息
  1381. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1382. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1383. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1384. //获取是否开启保存耗材出库的开关
  1385. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1386. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1387. c.ServeSuccessJSON(map[string]interface{}{
  1388. "drugs": drugs,
  1389. "advices_template": advices,
  1390. "drugways": drugways,
  1391. "efs": efs,
  1392. "doctors": doctors,
  1393. "department": department,
  1394. "sick": sick,
  1395. "additions": additions,
  1396. "diagnose": diagnose,
  1397. "manufacturers": manufacturers,
  1398. "goodOutOpen": goodOutOpen,
  1399. "patientDiagnose": patientDiagnose,
  1400. })
  1401. }
  1402. }
  1403. func (c *HisApiController) CreateHisPrescription() {
  1404. record_date := c.GetString("record_date")
  1405. patient_id, _ := c.GetInt64("patient_id")
  1406. reg_type, _ := c.GetInt64("reg_type")
  1407. diagnose := c.GetString("diagnose")
  1408. sick_type, _ := c.GetInt64("sick_type")
  1409. sick_history := c.GetString("sick_history")
  1410. doctor_id, _ := c.GetInt64("doctor", 0)
  1411. department, _ := c.GetInt64("department", 0)
  1412. his_patient_id, _ := c.GetInt64("his_patient_id")
  1413. p_type, _ := c.GetInt64("p_type")
  1414. patient_diagnose := c.GetString("patient_diagnose")
  1415. dataBody := make(map[string]interface{}, 0)
  1416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1417. if err != nil {
  1418. utils.ErrorLog(err.Error())
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. timeLayout := "2006-01-02"
  1423. loc, _ := time.LoadLocation("Local")
  1424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1425. if err != nil {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. adminInfo := c.GetAdminUserInfo()
  1430. recordDateTime := theTime.Unix()
  1431. //查询默认出库仓库库存
  1432. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1433. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1434. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1435. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1436. if len(lists) == 1 {
  1437. his_patient_id = lists[0].ID
  1438. }
  1439. }
  1440. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1441. //保存处方出库
  1442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1443. //自动出库
  1444. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1445. //耗材保存处方出库
  1446. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1447. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1448. //已发药和已收费限制逻辑
  1449. isMidicine := false
  1450. isCharge := false
  1451. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1452. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1453. if len(prescriptions) > 0 {
  1454. for _, item := range prescriptions {
  1455. items := item.(map[string]interface{})
  1456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1457. utils.ErrorLog("id")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. id := int64(items["id"].(float64))
  1462. if id > 0 {
  1463. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1464. if err != nil {
  1465. if new_prescription.OrderStatus == 4 {
  1466. isCharge = true
  1467. }
  1468. }
  1469. }
  1470. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1471. advices := items["advices"].([]interface{})
  1472. if len(advices) > 0 {
  1473. for _, advice := range advices {
  1474. var adviceId int64
  1475. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1476. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1477. }
  1478. if adviceId > 0 {
  1479. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1480. if err == nil {
  1481. if his_advice_info.IsMedicine == 1 {
  1482. isMidicine = true
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. if isMidicine == true {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1494. return
  1495. }
  1496. if isCharge == true {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1498. return
  1499. }
  1500. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1501. //药品发药出库
  1502. if pharmacyConfig.IsOpen == 1 {
  1503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1505. if len(prescriptions) > 0 {
  1506. for _, item := range prescriptions {
  1507. items := item.(map[string]interface{})
  1508. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1509. advices := items["advices"].([]interface{})
  1510. if len(advices) > 0 {
  1511. for _, advice := range advices {
  1512. var drug_id int64
  1513. var prescribing_number float64
  1514. var prescribingNumberUnit string
  1515. var adviceId int64
  1516. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1517. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1518. }
  1519. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1520. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1521. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1522. }
  1523. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1524. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1525. }
  1526. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1527. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1528. }
  1529. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1530. if drug.ID == 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. //查询药品的所有库存
  1535. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1536. var total_count int64
  1537. for _, it := range list {
  1538. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1539. }
  1540. totals := strconv.FormatInt(total_count, 10)
  1541. //查询该药品是否存在开药记录
  1542. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1543. //新增处方
  1544. if advicelist.ID == 0 {
  1545. all_count, _ := strconv.ParseFloat(totals, 64)
  1546. if prescribingNumberUnit == drug.MinUnit {
  1547. if drug.IsUse != 1 {
  1548. if prescribing_number > all_count {
  1549. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1550. return
  1551. }
  1552. }
  1553. }
  1554. if prescribingNumberUnit == drug.MaxUnit {
  1555. num := prescribing_number * float64(drug.MinNumber)
  1556. if drug.IsUse != 1 {
  1557. if num > all_count {
  1558. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1559. return
  1560. }
  1561. }
  1562. }
  1563. }
  1564. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1565. if drugOutConfig.IsOpen != 1 {
  1566. //修改处方
  1567. for _, advice := range advices {
  1568. var drug_id int64
  1569. var prescribing_number float64
  1570. var prescribingNumberUnit string
  1571. var prescribingNumber string
  1572. var adviceId int64
  1573. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1574. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1575. }
  1576. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1577. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1578. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1579. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1580. }
  1581. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1582. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1583. }
  1584. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1585. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1586. }
  1587. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1588. if drug.ID == 0 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1590. return
  1591. }
  1592. //查询药品的所有库存
  1593. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1594. var total_count int64
  1595. for _, it := range list {
  1596. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1597. }
  1598. totals := strconv.FormatInt(total_count, 10)
  1599. //查询该药品是否存在开药记录
  1600. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1601. //新增处方
  1602. if advicelist.ID == 0 {
  1603. all_count, _ := strconv.ParseFloat(totals, 64)
  1604. if prescribingNumberUnit == drug.MinUnit {
  1605. if drug.IsUse != 1 {
  1606. if prescribing_number > all_count {
  1607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1608. return
  1609. }
  1610. }
  1611. } else {
  1612. if prescribingNumberUnit == drug.MaxUnit {
  1613. num := prescribing_number * float64(drug.MinNumber)
  1614. if drug.IsUse != 1 {
  1615. if num > all_count {
  1616. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1617. return
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. //修改处方
  1624. if advicelist.ID > 0 {
  1625. var device_number int64
  1626. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1627. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1628. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1629. device_number = prescribingNumberInt * drug.MinNumber
  1630. }
  1631. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1632. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1633. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1634. device_number = prescribingNumberInt
  1635. }
  1636. var number_count int64
  1637. if prescribingNumberUnit == drug.MaxUnit {
  1638. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1639. number_count = prescribingNumberInt * drug.MinNumber
  1640. }
  1641. if prescribingNumberUnit == drug.MinUnit {
  1642. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1643. number_count = prescribingNumberInt
  1644. }
  1645. //如果修改的数量大于之前修改的数量
  1646. if (number_count - device_number) > 0 {
  1647. //如果修改的差数量 大于库存数量
  1648. if drug.IsUse != 1 {
  1649. if (number_count - device_number) > total_count {
  1650. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1651. return
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. //已发药和已收费限制逻辑
  1666. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1667. //校验库存总量
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. //查询最新批次库存
  1709. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1710. var batch_number_count int64
  1711. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1712. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1713. //新增处方
  1714. if advicelist.ID == 0 {
  1715. all_count, _ := strconv.ParseFloat(totals, 64)
  1716. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. if drug.IsUse != 1 {
  1719. if prescribing_number > all_count {
  1720. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1721. return
  1722. }
  1723. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1724. if prescribing_number > batch_number_all_count {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1726. return
  1727. }
  1728. }
  1729. }
  1730. }
  1731. if prescribingNumberUnit == drug.MaxUnit {
  1732. num := prescribing_number * float64(drug.MinNumber)
  1733. if drug.IsUse != 1 {
  1734. if num > all_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1739. if num > batch_number_all_count {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1748. if drugOutConfig.IsOpen != 1 {
  1749. //修改处方
  1750. for _, advice := range advices {
  1751. var drug_id int64
  1752. var prescribing_number float64
  1753. var prescribingNumberUnit string
  1754. var prescribingNumber string
  1755. var adviceId int64
  1756. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1757. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1758. }
  1759. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1760. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1761. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1762. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //新增处方
  1785. if advicelist.ID == 0 {
  1786. //查询最新批次库存
  1787. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1788. var batch_number_count int64
  1789. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1790. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. if prescribingNumberUnit == drug.MinUnit {
  1793. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1794. if drug.IsUse != 1 {
  1795. if prescribing_number > all_count {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1800. if prescribing_number > batch_number_all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1802. return
  1803. }
  1804. }
  1805. }
  1806. } else {
  1807. if prescribingNumberUnit == drug.MaxUnit {
  1808. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1809. num := prescribing_number * float64(drug.MinNumber)
  1810. if drug.IsUse != 1 {
  1811. if num > all_count {
  1812. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1813. return
  1814. }
  1815. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1816. if prescribing_number > batch_number_all_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. //修改处方
  1826. if advicelist.ID > 0 {
  1827. //查询最新批次库存
  1828. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1829. var batch_number_count int64
  1830. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1831. var device_number int64
  1832. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1833. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1834. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1835. device_number = prescribingNumberInt * drug.MinNumber
  1836. }
  1837. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt
  1841. }
  1842. var number_count int64
  1843. if prescribingNumberUnit == drug.MaxUnit {
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1845. number_count = prescribingNumberInt * drug.MinNumber
  1846. }
  1847. if prescribingNumberUnit == drug.MinUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt
  1850. }
  1851. //如果修改的数量大于之前修改的数量
  1852. if (number_count - device_number) > 0 {
  1853. //如果修改的差数量 大于库存数量
  1854. if drug.IsUse != 1 {
  1855. if (number_count - device_number) > total_count {
  1856. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1857. return
  1858. }
  1859. if (number_count - device_number) > batch_number_count {
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1861. return
  1862. }
  1863. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1864. // 查询该药品最后一次出库记录
  1865. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1866. var out_count int64
  1867. var in_count int64
  1868. var stock_max_number int64
  1869. var stock_min_number int64
  1870. for _, it := range outInfo {
  1871. if it.CountUnit == drug.MaxUnit {
  1872. it.Count = it.Count * drug.MinNumber
  1873. }
  1874. out_count += it.Count
  1875. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1876. stock_max_number = warehouseInfoList.StockMaxNumber
  1877. stock_min_number = warehouseInfoList.StockMinNumber
  1878. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1879. }
  1880. if out_count > 0 {
  1881. if (number_count - device_number) > in_count {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1883. return
  1884. }
  1885. }
  1886. // 未出库
  1887. if out_count == 0 {
  1888. var sum_in_count int64
  1889. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1890. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1891. fmt.Println("sum_in_count", sum_in_count)
  1892. //如果修改的数量大于有库存的第一个批次
  1893. if number_count > sum_in_count {
  1894. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1895. return
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1902. if pharmacyConfig.IsOpen != 1 {
  1903. if device_number != number_count {
  1904. // 查询该药品最后一次出库记录
  1905. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1906. //回退库存
  1907. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1908. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1909. }
  1910. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1911. var stock_max_number int64
  1912. var stock_min_number int64
  1913. if number_count >= drug.MinNumber {
  1914. stock_max_number = device_number / drug.MinNumber
  1915. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1916. stock_min_number = device_number % drug.MinNumber
  1917. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1918. } else {
  1919. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1920. }
  1921. }
  1922. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1923. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1924. }
  1925. //删除记录
  1926. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1927. //查询默认仓库剩余多少库存
  1928. var sum_count int64
  1929. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1930. for _, its := range stockInfo {
  1931. if its.MaxUnit == drug.MaxUnit {
  1932. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1933. }
  1934. sum_count += its.StockMaxNumber + its.StockMinNumber
  1935. }
  1936. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1937. }
  1938. }
  1939. }
  1940. }
  1941. }
  1942. //保存处方开药
  1943. if drugOutConfig.IsOpen == 1 {
  1944. //修改处方
  1945. for _, advice := range advices {
  1946. var drug_id int64
  1947. var prescribing_number float64
  1948. var prescribingNumberUnit string
  1949. var prescribingNumber string
  1950. var adviceId int64
  1951. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1952. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1953. }
  1954. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1955. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1956. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1957. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1958. }
  1959. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1960. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1961. }
  1962. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1963. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1964. }
  1965. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1966. if drug.ID == 0 {
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1968. return
  1969. }
  1970. //查询药品的所有库存
  1971. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1972. var total_count int64
  1973. for _, it := range list {
  1974. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1975. }
  1976. totals := strconv.FormatInt(total_count, 10)
  1977. //查询该药品是否存在开药记录
  1978. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1979. //新增处方
  1980. if advicelist.ID == 0 {
  1981. //查询最新批次库存
  1982. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1983. var batch_number_count int64
  1984. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1985. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1986. all_count, _ := strconv.ParseFloat(totals, 64)
  1987. if prescribingNumberUnit == drug.MinUnit {
  1988. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1989. if drug.IsUse != 1 {
  1990. if prescribing_number > all_count {
  1991. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1992. return
  1993. }
  1994. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1995. if prescribing_number > batch_number_all_count {
  1996. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1997. return
  1998. }
  1999. }
  2000. }
  2001. } else {
  2002. if prescribingNumberUnit == drug.MaxUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. num := prescribing_number * float64(drug.MinNumber)
  2005. if drug.IsUse != 1 {
  2006. if num > all_count {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2011. if prescribing_number > batch_number_all_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2013. return
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. //修改处方
  2021. if advicelist.ID > 0 {
  2022. //查询最新批次库存
  2023. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2024. var batch_number_count int64
  2025. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2026. var device_number int64
  2027. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2028. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2029. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2030. device_number = prescribingNumberInt * drug.MinNumber
  2031. }
  2032. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2033. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2034. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2035. device_number = prescribingNumberInt
  2036. }
  2037. var number_count int64
  2038. if prescribingNumberUnit == drug.MaxUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt * drug.MinNumber
  2041. }
  2042. if prescribingNumberUnit == drug.MinUnit {
  2043. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2044. number_count = prescribingNumberInt
  2045. }
  2046. //如果修改的数量大于之前修改的数量
  2047. if (number_count - device_number) > 0 {
  2048. //如果修改的差数量 大于库存数量
  2049. if drug.IsUse != 1 {
  2050. if (number_count - device_number) > total_count {
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2052. return
  2053. }
  2054. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2055. if (number_count - device_number) > batch_number_count {
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2061. //查询历史出库数据总批次
  2062. // 查询该药品最后一次出库记录
  2063. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2064. var out_count int64
  2065. var in_count int64
  2066. var stock_max_number int64
  2067. var stock_min_number int64
  2068. for _, it := range outInfo {
  2069. if it.CountUnit == drug.MaxUnit {
  2070. it.Count = it.Count * drug.MinNumber
  2071. }
  2072. out_count += it.Count
  2073. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2074. stock_max_number = warehouseInfoList.StockMaxNumber
  2075. stock_min_number = warehouseInfoList.StockMinNumber
  2076. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2077. }
  2078. if out_count > 0 {
  2079. if (number_count - device_number) > in_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. // 未出库
  2085. if out_count == 0 {
  2086. var sum_in_count int64
  2087. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2089. //如果修改的数量大于有库存的第一个批次
  2090. if number_count > sum_in_count {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. //校验耗材库存
  2109. if goodOutConfig.IsOpen == 1 {
  2110. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2111. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2112. if len(prescriptions) > 0 {
  2113. for _, item := range prescriptions {
  2114. items := item.(map[string]interface{})
  2115. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2116. projects := items["project"].([]interface{})
  2117. if len(projects) > 0 {
  2118. for _, project := range projects {
  2119. var project_id int64
  2120. var project_type int64
  2121. var totals float64
  2122. var project_name string
  2123. var parsetotal int64
  2124. var id int64
  2125. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2126. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2127. }
  2128. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2129. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2130. }
  2131. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2132. total, _ := project.(map[string]interface{})["total"].(string)
  2133. totals, _ = strconv.ParseFloat(total, 64)
  2134. }
  2135. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2136. project_name = project.(map[string]interface{})["project_name"].(string)
  2137. }
  2138. if project_type == 3 {
  2139. //查找该耗材的出库记录
  2140. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2141. if len(goodWarehouseInfo) == 0 {
  2142. //查询耗材库存
  2143. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2144. var stock_count int64
  2145. for _, it := range list {
  2146. stock_count += it.StockCount
  2147. }
  2148. stock_counts := strconv.FormatInt(stock_count, 10)
  2149. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2150. if totals > stock_total_count {
  2151. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2152. return
  2153. }
  2154. }
  2155. if len(goodWarehouseInfo) > 0 {
  2156. //查询该患者耗材的历史数据
  2157. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2158. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2159. //数量发生改变
  2160. if parsetotal != count {
  2161. //如果现在的数量大于历史数量,就要看库存是否足够
  2162. if parsetotal > count {
  2163. //查询耗材所有库存
  2164. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2165. var stock_count int64
  2166. for _, it := range list {
  2167. stock_count += it.StockCount
  2168. }
  2169. //库存不足
  2170. if (parsetotal - count) > stock_count {
  2171. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2172. return
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. //不使用耗材保存处方出库
  2186. if goodOutConfig.IsOpen != 1 {
  2187. if stockConfig.IsOpen == 1 {
  2188. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2189. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2190. if len(prescriptions) > 0 {
  2191. for _, item := range prescriptions {
  2192. items := item.(map[string]interface{})
  2193. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2194. projects := items["project"].([]interface{})
  2195. if len(projects) > 0 {
  2196. for _, project := range projects {
  2197. var project_id int64
  2198. var project_type int64
  2199. var totals float64
  2200. var project_name string
  2201. var parsetotal int64
  2202. var id int64
  2203. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2204. id = int64(project.(map[string]interface{})["id"].(float64))
  2205. }
  2206. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2207. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2208. }
  2209. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2210. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2211. }
  2212. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2213. total, _ := project.(map[string]interface{})["total"].(string)
  2214. totals, _ = strconv.ParseFloat(total, 64)
  2215. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2216. }
  2217. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2218. project_name = project.(map[string]interface{})["project_name"].(string)
  2219. }
  2220. if project_type == 3 {
  2221. //查找该耗材的出库记录
  2222. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2223. //没有出库记录
  2224. if len(goodWarehouseInfo) == 0 {
  2225. //查询耗材库存
  2226. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2227. var stock_count int64
  2228. for _, it := range list {
  2229. stock_count += it.StockCount
  2230. }
  2231. stock_counts := strconv.FormatInt(stock_count, 10)
  2232. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2233. if totals > stock_total_count {
  2234. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2235. return
  2236. }
  2237. //查找今日该患者已经出库的所有耗材
  2238. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2239. for _, item := range goodList {
  2240. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2241. var flush_count int64
  2242. for _, it := range goodListSix {
  2243. flush_count += it.StockCount
  2244. }
  2245. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2246. creater := adminInfo.AdminUser.Id
  2247. if errs != nil {
  2248. goodErrcode := models.XtGoodErrcode{
  2249. UserOrgId: item.OrgId,
  2250. Errcode: "手动出库更新剩余出库失败",
  2251. GoodId: item.GoodId,
  2252. Status: 1,
  2253. Ctime: time.Now().Unix(),
  2254. Mtime: 0,
  2255. Count: 0,
  2256. StockCount: 0,
  2257. Creater: creater,
  2258. BatchNumberId: 0,
  2259. WarehouseOutId: 0,
  2260. }
  2261. service.CreateGoodErrcode(goodErrcode)
  2262. }
  2263. }
  2264. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2265. }
  2266. //有出库记录
  2267. if len(goodWarehouseInfo) > 0 {
  2268. //查询该患者耗材的历史数据
  2269. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2270. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2271. //数量发生改变
  2272. if parsetotal != count {
  2273. //查找今日该患者已经出库的所有耗材
  2274. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2275. for _, item := range goodList {
  2276. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2277. var flush_count int64
  2278. for _, it := range goodListSix {
  2279. flush_count += it.StockCount
  2280. }
  2281. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2282. //减少出库数量
  2283. creater := adminInfo.AdminUser.Id
  2284. if errs != nil {
  2285. goodErrcode := models.XtGoodErrcode{
  2286. UserOrgId: item.OrgId,
  2287. Errcode: "手动出库更新剩余出库失败",
  2288. GoodId: item.GoodId,
  2289. Status: 1,
  2290. Ctime: time.Now().Unix(),
  2291. Mtime: 0,
  2292. Count: 0,
  2293. StockCount: 0,
  2294. Creater: creater,
  2295. BatchNumberId: 0,
  2296. WarehouseOutId: 0,
  2297. }
  2298. service.CreateGoodErrcode(goodErrcode)
  2299. }
  2300. //查询默认仓库
  2301. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2302. var total_count int64
  2303. for _, it := range stockList {
  2304. total_count += it.StockCount
  2305. }
  2306. //基础库插入数据
  2307. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2308. }
  2309. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2322. var hpInfo models.HisPrescriptionInfo
  2323. if info.ID == 0 {
  2324. var randNum int
  2325. randNum = rand.Intn(10000) + 1000
  2326. timestamp := time.Now().Unix()
  2327. tempTime := time.Unix(timestamp, 0)
  2328. timeFormat := tempTime.Format("20060102150405")
  2329. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2330. hpInfo = models.HisPrescriptionInfo{
  2331. HisPatientId: his_patient_id,
  2332. UserOrgId: adminInfo.CurrentOrgId,
  2333. RecordDate: theTime.Unix(),
  2334. PatientId: patient_id,
  2335. Status: 1,
  2336. Ctime: time.Now().Unix(),
  2337. Mtime: time.Now().Unix(),
  2338. Creator: adminInfo.AdminUser.Id,
  2339. Modifier: adminInfo.AdminUser.Id,
  2340. Diagnosis: diagnose,
  2341. SickHistory: sick_history,
  2342. Departments: department,
  2343. RegisterType: reg_type,
  2344. PrescriptionNumber: p_number,
  2345. PrescriptionStatus: 1,
  2346. Doctor: role.UserName,
  2347. DoctorId: doctor_id,
  2348. SickType: sick_type,
  2349. PType: p_type,
  2350. PatientDiagnosis: patient_diagnose,
  2351. }
  2352. service.SavePatientPrescriptionInfo(hpInfo)
  2353. //创建步骤表
  2354. finish := models.XtDialysisFinish{
  2355. IsFinish: 1,
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. Status: 1,
  2358. Ctime: time.Now().Unix(),
  2359. Mtime: 0,
  2360. Module: 4,
  2361. RecordDate: theTime.Unix(),
  2362. Sourse: 1,
  2363. PatientId: patient_id,
  2364. }
  2365. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2366. if dialysisFinish.ID == 0 {
  2367. service.CreateDialysisFinish(finish)
  2368. }
  2369. redis := service.RedisClient()
  2370. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2371. redis.Set(key, "", time.Second)
  2372. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2373. redis.Set(keyOne, "", time.Second)
  2374. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2375. redis.Set(keySeven, "", time.Second)
  2376. defer redis.Close()
  2377. } else {
  2378. hpInfo = models.HisPrescriptionInfo{
  2379. ID: info.ID,
  2380. UserOrgId: adminInfo.CurrentOrgId,
  2381. RecordDate: info.RecordDate,
  2382. PatientId: info.PatientId,
  2383. Status: 1,
  2384. Ctime: info.Ctime,
  2385. Mtime: time.Now().Unix(),
  2386. Creator: info.Creator,
  2387. Modifier: adminInfo.AdminUser.Id,
  2388. Diagnosis: diagnose,
  2389. SickHistory: sick_history,
  2390. Departments: department,
  2391. RegisterType: reg_type,
  2392. PrescriptionNumber: info.PrescriptionNumber,
  2393. Doctor: role.UserName,
  2394. PrescriptionStatus: info.PrescriptionStatus,
  2395. DoctorId: doctor_id,
  2396. SickType: sick_type,
  2397. PType: info.PType,
  2398. HisPatientId: info.HisPatientId,
  2399. PatientDiagnosis: patient_diagnose,
  2400. }
  2401. service.SavePatientPrescriptionInfo(hpInfo)
  2402. //创建步骤表
  2403. finish := models.XtDialysisFinish{
  2404. IsFinish: 1,
  2405. UserOrgId: adminInfo.CurrentOrgId,
  2406. Status: 1,
  2407. Ctime: time.Now().Unix(),
  2408. Mtime: 0,
  2409. Module: 4,
  2410. RecordDate: info.RecordDate,
  2411. Sourse: 1,
  2412. PatientId: info.PatientId,
  2413. }
  2414. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2415. if dialysisFinish.ID == 0 {
  2416. service.CreateDialysisFinish(finish)
  2417. }
  2418. redis := service.RedisClient()
  2419. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2420. redis.Set(key, "", time.Second)
  2421. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2422. redis.Set(keyOne, "", time.Second)
  2423. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2424. redis.Set(keySeven, "", time.Second)
  2425. defer redis.Close()
  2426. }
  2427. //定义切片
  2428. var adviceList []models.HisDoctorAdviceInfo
  2429. var projectList []models.HisPrescriptionProject
  2430. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2431. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2432. var tempPrescription *models.HisPrescription
  2433. if len(prescriptions) > 0 {
  2434. for _, item := range prescriptions {
  2435. items := item.(map[string]interface{})
  2436. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2437. utils.ErrorLog("id")
  2438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2439. return
  2440. }
  2441. id := int64(items["id"].(float64))
  2442. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2443. tempPrescription = &new_prescription
  2444. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2445. utils.ErrorLog("type")
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. types := int64(items["type"].(float64))
  2450. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2451. utils.ErrorLog("med_type")
  2452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2453. return
  2454. }
  2455. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2456. if med_type == "0" {
  2457. med_type = "14"
  2458. }
  2459. //if order_status == 0 {
  2460. // order_status = 1
  2461. //}
  2462. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2463. utils.ErrorLog("pre_time")
  2464. }
  2465. preTime, _ := items["pre_time"].(string)
  2466. timeLayout := "2006-01-02"
  2467. loc, _ := time.LoadLocation("Local")
  2468. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2469. if err != nil {
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. pTime := theTime2.Unix()
  2474. ctime := time.Now().Unix()
  2475. if tempPrescription.ID == 0 {
  2476. prescription := &models.HisPrescription{
  2477. ID: 0,
  2478. PatientId: patient_id,
  2479. UserOrgId: adminInfo.CurrentOrgId,
  2480. RecordDate: recordDateTime,
  2481. Ctime: ctime,
  2482. Mtime: ctime,
  2483. Type: types,
  2484. Modifier: adminInfo.AdminUser.Id,
  2485. Creator: adminInfo.AdminUser.Id,
  2486. Status: 1,
  2487. Doctor: role.UserName,
  2488. HisPatientId: his_patient_id,
  2489. OrderStatus: 1,
  2490. BatchNumber: "",
  2491. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2492. PreTime: pTime,
  2493. PType: p_type,
  2494. MedType: med_type,
  2495. }
  2496. tempPrescription = prescription
  2497. service.SaveHisPrescription(tempPrescription)
  2498. redis := service.RedisClient()
  2499. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2500. redis.Set(key, "", time.Second)
  2501. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2502. redis.Set(keyOne, "", time.Second)
  2503. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2504. redis.Set(keySeven, "", time.Second)
  2505. defer redis.Close()
  2506. } else {
  2507. tempPrescription.ID = id
  2508. tempPrescription.Type = types
  2509. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2510. tempPrescription.Mtime = time.Now().Unix()
  2511. tempPrescription.Doctor = role.UserName
  2512. //tempPrescription.OrderStatus = order_status
  2513. tempPrescription.PreTime = pTime
  2514. tempPrescription.MedType = med_type
  2515. service.SaveHisPrescription(tempPrescription)
  2516. redis := service.RedisClient()
  2517. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2518. redis.Set(key, "", time.Second)
  2519. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2520. redis.Set(keyOne, "", time.Second)
  2521. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2522. redis.Set(keySeven, "", time.Second)
  2523. defer redis.Close()
  2524. }
  2525. //service.SaveHisPrescription(prescription)
  2526. //更改患者挂号状态
  2527. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2528. fmt.Println("更改失败", err2)
  2529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2530. advices := items["advices"].([]interface{})
  2531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2532. groupNo := int64(0)
  2533. ctime := time.Now().Unix()
  2534. mtime := ctime
  2535. if len(advices) > 0 {
  2536. for _, advice := range advices {
  2537. var s models.HisDoctorAdviceInfo
  2538. s.PrescriptionId = tempPrescription.ID
  2539. s.AdviceType = 2
  2540. s.AdviceDoctor = doctor_id
  2541. s.StopState = 2
  2542. s.ExecutionState = 2
  2543. s.AdviceDate = recordDateTime
  2544. s.Status = 1
  2545. s.UserOrgId = adminInfo.CurrentOrgId
  2546. s.RecordDate = recordDateTime
  2547. s.StartTime = tempPrescription.PreTime
  2548. s.Groupno = groupNo
  2549. s.CreatedTime = ctime
  2550. s.UpdatedTime = mtime
  2551. s.PatientId = patient_id
  2552. s.HisPatientId = his_patient_id
  2553. s.StartTime = pTime
  2554. s.IsSettle = 2
  2555. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2556. if errcode > 0 {
  2557. c.ServeFailJSONWithSGJErrorCode(errcode)
  2558. return
  2559. }
  2560. s.StartTime = pTime
  2561. var total_count int64 //处方总库存
  2562. //查询改药品信息
  2563. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2564. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2565. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2566. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2567. total_count += prescribingNumberSeven * medical.MinNumber
  2568. }
  2569. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2570. total_count += prescribingNumberSeven
  2571. }
  2572. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2573. total_count += prescribingNumberSeven
  2574. }
  2575. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2576. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2577. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2578. if s.Price != lastWarehouse.RetailPrice {
  2579. s.Price = lastWarehouse.RetailPrice
  2580. }
  2581. }
  2582. service.CreateHisDoctorAdvice(&s)
  2583. //记录日志
  2584. byterequest, _ := json.Marshal(s)
  2585. adviceLog := models.XtDoctorAdviceLog{
  2586. UserOrgId: s.UserOrgId,
  2587. PatientId: s.PatientId,
  2588. AdminUserId: adminInfo.AdminUser.Id,
  2589. Module: 1,
  2590. ErrLog: string(byterequest),
  2591. Status: 1,
  2592. Ctime: time.Now().Unix(),
  2593. Mtime: 0,
  2594. Source: "电脑端新建his医嘱",
  2595. RecordDate: s.AdviceDate,
  2596. }
  2597. service.CreateDoctorAdviceLog(adviceLog)
  2598. //存储切片中
  2599. adviceList = append(adviceList, s)
  2600. redis := service.RedisClient()
  2601. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2602. redis.Set(key, "", time.Second)
  2603. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2604. redis.Set(keyOne, "", time.Second)
  2605. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2606. redis.Set(keySeven, "", time.Second)
  2607. var randNum int
  2608. randNum = rand.Intn(10000) + 1000
  2609. timestamp := time.Now().Unix()
  2610. tempTime := time.Unix(timestamp, 0)
  2611. timeFormat := tempTime.Format("20060102150405")
  2612. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2613. service.CreateHisDoctorAdvice(&s)
  2614. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2615. redis.Set(keySix, "", time.Second)
  2616. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2617. redis.Set(keyFive, "", time.Second)
  2618. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2619. redis.Set(keyEight, "", time.Second)
  2620. defer redis.Close()
  2621. }
  2622. }
  2623. }
  2624. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2625. projects := items["project"].([]interface{})
  2626. if len(projects) > 0 {
  2627. for _, project := range projects {
  2628. var p models.HisPrescriptionProject
  2629. p.PrescriptionId = tempPrescription.ID
  2630. p.Ctime = time.Now().Unix()
  2631. p.Mtime = time.Now().Unix()
  2632. p.PatientId = patient_id
  2633. p.RecordDate = recordDateTime
  2634. p.Doctor = doctor_id
  2635. p.UserOrgId = adminInfo.CurrentOrgId
  2636. p.HisPatientId = his_patient_id
  2637. p.Status = 1
  2638. p.StartTime = pTime
  2639. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2640. if errcode > 0 {
  2641. c.ServeFailJSONWithSGJErrorCode(errcode)
  2642. return
  2643. }
  2644. if p.ID == 0 {
  2645. p.IsOut = 2
  2646. }
  2647. if p.ID > 0 {
  2648. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2649. p.IsOut = projectDetail.IsOut
  2650. }
  2651. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2652. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2653. if p.Type == 3 {
  2654. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2655. if p.Price != lastWarehouse.PackingPrice {
  2656. p.Price = lastWarehouse.PackingPrice
  2657. }
  2658. }
  2659. }
  2660. service.CreateHisProjectTwo(&p)
  2661. //记录日志
  2662. byterequest, _ := json.Marshal(p)
  2663. adviceLog := models.XtDoctorAdviceLog{
  2664. UserOrgId: p.UserOrgId,
  2665. PatientId: p.PatientId,
  2666. AdminUserId: adminInfo.AdminUser.Id,
  2667. Module: 1,
  2668. ErrLog: string(byterequest),
  2669. Status: 1,
  2670. Ctime: time.Now().Unix(),
  2671. Mtime: 0,
  2672. Source: "电脑端新建his项目",
  2673. RecordDate: p.RecordDate,
  2674. }
  2675. service.CreateDoctorAdviceLog(adviceLog)
  2676. projectList = append(projectList, p)
  2677. var randNum int
  2678. randNum = rand.Intn(10000) + 1000
  2679. timestamp := time.Now().Unix()
  2680. tempTime := time.Unix(timestamp, 0)
  2681. timeFormat := tempTime.Format("20060102150405")
  2682. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2683. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2684. //新增或者编辑项目,修改对应的标签数据
  2685. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2686. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2687. var label models.HisLabelPrintInfo
  2688. project, _ := service.GetProjectDetail(p.ProjectId)
  2689. if project.CostClassify == 3 { //类别为检验检查
  2690. if p.TeamId > 0 { //检验检查组套
  2691. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2692. if tempLabel.ID == 0 {
  2693. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2694. label.Number = tempPrescription.PrescriptionNumber
  2695. label.ProjectId = project.ID
  2696. label.Status = 1
  2697. label.IsPrint = 2
  2698. label.DoctorId = info.DoctorId
  2699. label.UserOrgId = p.UserOrgId
  2700. label.PatientId = patient_id
  2701. label.RecordDate = recordDateTime
  2702. label.Ctime = time.Now().Unix()
  2703. label.Mtime = time.Now().Unix()
  2704. label.ItemId = p.TeamId
  2705. label.FeedetlSn = p.FeedetlSn
  2706. label.PProjectId = p.ID
  2707. label.ProjectName = team.ProjectTeam
  2708. label.PatientName = patient.Name
  2709. service.CreateHisLabelRecord(&label)
  2710. }
  2711. } else { //单条检验检查项目
  2712. label.Number = tempPrescription.PrescriptionNumber
  2713. label.ProjectId = project.ID
  2714. label.Status = 1
  2715. label.DoctorId = info.DoctorId
  2716. label.UserOrgId = p.UserOrgId
  2717. label.PatientId = patient_id
  2718. label.RecordDate = recordDateTime
  2719. label.IsPrint = 2
  2720. label.Ctime = time.Now().Unix()
  2721. label.Mtime = time.Now().Unix()
  2722. label.FeedetlSn = p.FeedetlSn
  2723. label.PProjectId = p.ID
  2724. label.ItemId = p.TeamId
  2725. label.ProjectName = project.ProjectName
  2726. label.PatientName = patient.Name
  2727. service.CreateHisLabelRecord(&label)
  2728. }
  2729. }
  2730. }
  2731. }
  2732. service.SaveHisProjectTwo(&p)
  2733. }
  2734. }
  2735. }
  2736. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2737. // addition := items["addition"].([]interface{})
  2738. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2739. // ctime := time.Now().Unix()
  2740. // mtime := ctime
  2741. // if len(addition) > 0 {
  2742. // for _, item := range addition {
  2743. // var s models.HisAdditionalCharge
  2744. // s.PrescriptionId = tempPrescription.ID
  2745. // s.Status = 1
  2746. // s.UserOrgId = adminInfo.CurrentOrgId
  2747. // s.RecordDate = recordDateTime
  2748. // s.CreatedTime = ctime
  2749. // s.UpdatedTime = mtime
  2750. // s.PatientId = patient_id
  2751. // s.HisPatientId = his_patient_id
  2752. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2753. // if errcode > 0 {
  2754. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2755. // return
  2756. // }
  2757. // service.CreateAdditionalCharge(&s)
  2758. // var randNum int
  2759. // randNum = rand.Intn(10000) + 1000
  2760. // timestamp := time.Now().Unix()
  2761. // tempTime := time.Unix(timestamp, 0)
  2762. // timeFormat := tempTime.Format("20060102150405")
  2763. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2764. // service.CreateAdditionalCharge(&s)
  2765. //
  2766. // }
  2767. // }
  2768. //}
  2769. }
  2770. }
  2771. //查询今日该患者开的药品处方
  2772. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2773. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2774. //药品出库
  2775. if drugOutConfig.IsOpen == 1 {
  2776. for _, item := range hisdoctorlist {
  2777. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2778. // 查询该药品最后一次出库记录
  2779. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2780. if len(druginfo) > 0 {
  2781. //回退库存
  2782. for _, it := range druginfo {
  2783. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2784. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2785. }
  2786. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2787. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2788. }
  2789. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2790. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2791. }
  2792. }
  2793. }
  2794. //删除记录
  2795. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2796. //查询最后一次数据
  2797. if drugOutConfig.IsOpen == 1 {
  2798. //出库
  2799. if drug.IsUse == 2 {
  2800. creater := adminInfo.AdminUser.Id
  2801. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2802. }
  2803. //更新字典里面的库存
  2804. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2805. var sum_count int64
  2806. for _, its := range stockInfo {
  2807. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2808. if its.MaxUnit == baseDrug.MaxUnit {
  2809. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2810. }
  2811. sum_count += its.StockMaxNumber + its.StockMinNumber
  2812. }
  2813. //更新基础库存
  2814. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2815. //剩余库存
  2816. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2817. }
  2818. }
  2819. }
  2820. //耗材保存处方出库
  2821. if goodOutConfig.IsOpen == 1 {
  2822. //查询今日耗材出库数量
  2823. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2824. for _, item := range hisgoodlist {
  2825. //查询历史出库数据
  2826. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2827. var out_count_five int64
  2828. for _, item := range flowGood {
  2829. out_count_five += item.Count
  2830. }
  2831. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2832. if out_count_five != parseIntCount {
  2833. //查询耗材最后一次出库记录
  2834. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2835. //查询默认出库仓库库存
  2836. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2837. if len(wareOut) > 0 {
  2838. for _, it := range wareOut {
  2839. //回退库存
  2840. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2841. //删除出库记录
  2842. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2843. }
  2844. }
  2845. timeStr := time.Now().Format("2006-01-02")
  2846. timeArr := strings.Split(timeStr, "-")
  2847. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2848. total = total + 1
  2849. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2850. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2851. number = number + total
  2852. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2853. operation_time := time.Now().Unix()
  2854. creater := c.GetAdminUserInfo().AdminUser.Id
  2855. recordDateStr := time.Now().Format("2006-01-02")
  2856. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2857. nowtime := recordDate.Unix()
  2858. warehouseOut := models.WarehouseOut{
  2859. WarehouseOutOrderNumber: warehousing_out_order,
  2860. OperationTime: operation_time,
  2861. OrgId: adminInfo.CurrentOrgId,
  2862. Creater: creater,
  2863. Ctime: time.Now().Unix(),
  2864. Status: 1,
  2865. WarehouseOutTime: nowtime,
  2866. Type: 1,
  2867. StorehouseId: storeConfig.StorehouseOutInfo,
  2868. IsCheck: 1,
  2869. IsSys: 1,
  2870. }
  2871. //查询是否生成出库单
  2872. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2873. if out.ID == 0 {
  2874. service.AddSigleWarehouseOut(&warehouseOut)
  2875. }
  2876. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2877. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2878. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2879. dialyPrepareOne := models.DialysisBeforePrepare{
  2880. GoodTypeId: goodObj.GoodTypeId,
  2881. GoodId: item.ProjectId,
  2882. PatientId: item.PatientId,
  2883. RecordDate: item.RecordDate,
  2884. UserOrgId: adminInfo.CurrentOrgId,
  2885. Count: parseIntCount,
  2886. Ctime: time.Now().Unix(),
  2887. Creater: creater,
  2888. Status: 1,
  2889. StorehouseId: houseConfig.StorehouseOutInfo,
  2890. ProjectId: item.ID,
  2891. }
  2892. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2893. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2894. //查询历史出库数据
  2895. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2896. var out_count int64
  2897. for _, item := range flowGood {
  2898. out_count += item.Count
  2899. }
  2900. //如果历史数和当前数据不想等才进行退库出库
  2901. if out_count != parseIntCount {
  2902. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2903. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2904. detail := models.AutomaticReduceDetail{
  2905. WarehouseOutId: 0,
  2906. WarehouseOutOrderNumber: "",
  2907. PatientId: item.PatientId,
  2908. Ctime: time.Now().Unix(),
  2909. Mtime: 0,
  2910. Status: 1,
  2911. RecordTime: item.RecordDate,
  2912. OrgId: item.UserOrgId,
  2913. GoodId: item.ProjectId,
  2914. GoodTypeId: 0,
  2915. Count: parseIntCount,
  2916. Type: 0,
  2917. ProjectId: item.ID,
  2918. StorehouseId: 0,
  2919. }
  2920. service.CreateAutoDetail(detail)
  2921. //查询剩余库存
  2922. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2923. var sum_count int64
  2924. for _, item := range goodList {
  2925. sum_count += item.StockCount
  2926. }
  2927. //更新剩余库存
  2928. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2929. //耗材
  2930. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2931. }
  2932. }
  2933. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2934. //查询历史出库数据
  2935. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2936. var out_count int64
  2937. for _, item := range flowGood {
  2938. out_count += item.Count
  2939. }
  2940. //如果历史数和当前数据不想等才进行退库出库
  2941. if out_count != parseIntCount {
  2942. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2943. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2944. detail := models.AutomaticReduceDetail{
  2945. WarehouseOutId: 0,
  2946. WarehouseOutOrderNumber: "",
  2947. PatientId: item.PatientId,
  2948. Ctime: time.Now().Unix(),
  2949. Mtime: 0,
  2950. Status: 1,
  2951. RecordTime: item.RecordDate,
  2952. OrgId: item.UserOrgId,
  2953. GoodId: item.ProjectId,
  2954. GoodTypeId: 0,
  2955. Count: parseIntCount,
  2956. Type: 0,
  2957. ProjectId: item.ID,
  2958. StorehouseId: 0,
  2959. }
  2960. service.CreateAutoDetail(detail)
  2961. //查询剩余库存
  2962. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2963. var sum_count int64
  2964. for _, item := range goodList {
  2965. sum_count += item.StockCount
  2966. }
  2967. //更新剩余库存
  2968. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2969. //耗材
  2970. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2971. }
  2972. }
  2973. }
  2974. }
  2975. }
  2976. }
  2977. //redisClient := service.RedisClient()
  2978. //defer redisClient.Close()
  2979. //
  2980. //list := models.HisList{
  2981. // Patient_id: patient_id,
  2982. // Advice_id:0,
  2983. // Record_date: 0,
  2984. // Advice: adviceList,
  2985. // Project: nil,
  2986. //}
  2987. //hisLis = append(hisLis, list)
  2988. //
  2989. //advice_json, _ := json.Marshal(&hisLis)
  2990. //redisClient.RPush("111", advice_json).Result()
  2991. //result, _ := redisClient.RPop("111").Result()
  2992. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2993. //
  2994. //var dat []map[string]interface{}
  2995. //json.Unmarshal([]byte(result), &dat)
  2996. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2997. //
  2998. //for k,v:=range dat{
  2999. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3000. //}
  3001. //project_json, _ := json.Marshal(&projectList)
  3002. //redisClient.LPush("222", project_json).Result()
  3003. if err == nil {
  3004. c.ServeSuccessJSON(map[string]interface{}{
  3005. "msg": "保存成功",
  3006. })
  3007. return
  3008. } else {
  3009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3010. return
  3011. }
  3012. }
  3013. func (c *HisApiController) EditHisPrescription() {
  3014. record_date := c.GetString("record_date")
  3015. patient_id, _ := c.GetInt64("patient_id")
  3016. reg_type, _ := c.GetInt64("reg_type")
  3017. //diagnose, _ := c.GetInt64("diagnose", 0)
  3018. diagnose := c.GetString("diagnose")
  3019. sick_type, _ := c.GetInt64("sick_type")
  3020. sick_history := c.GetString("sick_history")
  3021. doctor_id, _ := c.GetInt64("doctor", 0)
  3022. department, _ := c.GetInt64("department", 0)
  3023. his_patient_id, _ := c.GetInt64("his_patient_id")
  3024. p_type, _ := c.GetInt64("p_type")
  3025. dataBody := make(map[string]interface{}, 0)
  3026. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3027. if err != nil {
  3028. utils.ErrorLog(err.Error())
  3029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3030. return
  3031. }
  3032. timeLayout := "2006-01-02"
  3033. loc, _ := time.LoadLocation("Local")
  3034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3035. if err != nil {
  3036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3037. return
  3038. }
  3039. adminInfo := c.GetAdminUserInfo()
  3040. recordDateTime := theTime.Unix()
  3041. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3042. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3043. var hpInfo models.HisPrescriptionInfo
  3044. if info.ID == 0 {
  3045. var randNum int
  3046. randNum = rand.Intn(10000) + 1000
  3047. timestamp := time.Now().Unix()
  3048. tempTime := time.Unix(timestamp, 0)
  3049. timeFormat := tempTime.Format("20060102150405")
  3050. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3051. hpInfo = models.HisPrescriptionInfo{
  3052. UserOrgId: adminInfo.CurrentOrgId,
  3053. RecordDate: theTime.Unix(),
  3054. PatientId: patient_id,
  3055. Status: 1,
  3056. Ctime: time.Now().Unix(),
  3057. Mtime: time.Now().Unix(),
  3058. Creator: adminInfo.AdminUser.Id,
  3059. Modifier: adminInfo.AdminUser.Id,
  3060. Diagnosis: diagnose,
  3061. SickHistory: sick_history,
  3062. Departments: department,
  3063. RegisterType: reg_type,
  3064. PrescriptionNumber: p_number,
  3065. PrescriptionStatus: 1,
  3066. Doctor: role.UserName,
  3067. DoctorId: doctor_id,
  3068. SickType: sick_type,
  3069. PType: p_type,
  3070. }
  3071. service.SavePatientPrescriptionInfo(hpInfo)
  3072. } else {
  3073. hpInfo = models.HisPrescriptionInfo{
  3074. ID: info.ID,
  3075. UserOrgId: adminInfo.CurrentOrgId,
  3076. RecordDate: info.RecordDate,
  3077. PatientId: info.PatientId,
  3078. Status: 1,
  3079. Ctime: info.Ctime,
  3080. Mtime: time.Now().Unix(),
  3081. Creator: info.Creator,
  3082. Modifier: adminInfo.AdminUser.Id,
  3083. Diagnosis: diagnose,
  3084. SickHistory: sick_history,
  3085. Departments: department,
  3086. RegisterType: reg_type,
  3087. PrescriptionNumber: info.PrescriptionNumber,
  3088. Doctor: role.UserName,
  3089. PrescriptionStatus: info.PrescriptionStatus,
  3090. DoctorId: doctor_id,
  3091. SickType: sick_type,
  3092. PType: info.PType,
  3093. }
  3094. service.SavePatientPrescriptionInfo(hpInfo)
  3095. }
  3096. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3097. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3098. if len(prescriptions) > 0 {
  3099. for _, item := range prescriptions {
  3100. items := item.(map[string]interface{})
  3101. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3102. utils.ErrorLog("id")
  3103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. id := int64(items["id"].(float64))
  3107. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3108. utils.ErrorLog("type")
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3110. return
  3111. }
  3112. types := int64(items["type"].(float64))
  3113. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3114. utils.ErrorLog("med_type")
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3116. return
  3117. }
  3118. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3119. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3120. ctime := time.Now().Unix()
  3121. prescription := &models.HisPrescription{
  3122. ID: id,
  3123. PatientId: patient_id,
  3124. UserOrgId: adminInfo.CurrentOrgId,
  3125. RecordDate: recordDateTime,
  3126. Ctime: ctime,
  3127. Mtime: ctime,
  3128. Type: types,
  3129. Modifier: adminInfo.AdminUser.Id,
  3130. Creator: adminInfo.AdminUser.Id,
  3131. Status: 1,
  3132. Doctor: role.UserName,
  3133. HisPatientId: his_patient_id,
  3134. OrderStatus: 1,
  3135. BatchNumber: "",
  3136. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3137. PType: hpInfo.PType,
  3138. MedType: med_type,
  3139. }
  3140. if historyPrescription.ID > 0 {
  3141. prescription.PreTime = historyPrescription.PreTime
  3142. }
  3143. service.SaveHisPrescription(prescription)
  3144. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3145. advices := items["advices"].([]interface{})
  3146. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3147. groupNo := int64(0)
  3148. ctime := time.Now().Unix()
  3149. mtime := ctime
  3150. if len(advices) > 0 {
  3151. for _, advice := range advices {
  3152. var s models.HisDoctorAdviceInfo
  3153. s.PrescriptionId = prescription.ID
  3154. s.AdviceType = 2
  3155. s.AdviceDoctor = adminInfo.AdminUser.Id
  3156. s.StopState = 2
  3157. s.ExecutionState = 2
  3158. s.AdviceDate = recordDateTime
  3159. s.Status = 1
  3160. s.UserOrgId = adminInfo.CurrentOrgId
  3161. s.RecordDate = recordDateTime
  3162. s.StartTime = prescription.PreTime
  3163. s.Groupno = groupNo
  3164. s.CreatedTime = ctime
  3165. s.UpdatedTime = mtime
  3166. s.PatientId = patient_id
  3167. s.HisPatientId = his_patient_id
  3168. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3169. if errcode > 0 {
  3170. c.ServeFailJSONWithSGJErrorCode(errcode)
  3171. return
  3172. }
  3173. service.CreateHisDoctorAdvice(&s)
  3174. //记录日志
  3175. byterequest, _ := json.Marshal(s)
  3176. adviceLog := models.XtDoctorAdviceLog{
  3177. UserOrgId: s.UserOrgId,
  3178. PatientId: s.PatientId,
  3179. AdminUserId: adminInfo.AdminUser.Id,
  3180. Module: 1,
  3181. ErrLog: string(byterequest),
  3182. Status: 1,
  3183. Ctime: time.Now().Unix(),
  3184. Mtime: 0,
  3185. Source: "电脑端his医嘱修改",
  3186. RecordDate: s.AdviceDate,
  3187. }
  3188. service.CreateDoctorAdviceLog(adviceLog)
  3189. redis := service.RedisClient()
  3190. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3191. redis.Set(key, "", time.Second)
  3192. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3193. fmt.Println("keyOne", keyOne)
  3194. redis.Set(keyOne, "", time.Second)
  3195. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3196. redis.Set(keySeven, "", time.Second)
  3197. redis.Close()
  3198. }
  3199. }
  3200. }
  3201. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3202. projects := items["project"].([]interface{})
  3203. if len(projects) > 0 {
  3204. for _, project := range projects {
  3205. var p models.HisPrescriptionProject
  3206. p.PrescriptionId = prescription.ID
  3207. p.Ctime = time.Now().Unix()
  3208. p.Mtime = time.Now().Unix()
  3209. p.PatientId = patient_id
  3210. p.RecordDate = recordDateTime
  3211. p.UserOrgId = adminInfo.CurrentOrgId
  3212. p.HisPatientId = his_patient_id
  3213. p.Status = 1
  3214. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3215. if errcode > 0 {
  3216. c.ServeFailJSONWithSGJErrorCode(errcode)
  3217. return
  3218. }
  3219. service.CreateHisProjectTwo(&p)
  3220. //记录日志
  3221. byterequest, _ := json.Marshal(p)
  3222. adviceLog := models.XtDoctorAdviceLog{
  3223. UserOrgId: p.UserOrgId,
  3224. PatientId: p.PatientId,
  3225. AdminUserId: adminInfo.AdminUser.Id,
  3226. Module: 1,
  3227. ErrLog: string(byterequest),
  3228. Status: 1,
  3229. Ctime: time.Now().Unix(),
  3230. Mtime: 0,
  3231. Source: "电脑端his项目修改",
  3232. RecordDate: p.RecordDate,
  3233. }
  3234. service.CreateDoctorAdviceLog(adviceLog)
  3235. }
  3236. }
  3237. }
  3238. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3239. addition := items["addition"].([]interface{})
  3240. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3241. ctime := time.Now().Unix()
  3242. mtime := ctime
  3243. if len(addition) > 0 {
  3244. for _, item := range addition {
  3245. var s models.HisAdditionalCharge
  3246. s.PrescriptionId = prescription.ID
  3247. s.Status = 1
  3248. s.UserOrgId = adminInfo.CurrentOrgId
  3249. s.RecordDate = recordDateTime
  3250. s.CreatedTime = ctime
  3251. s.UpdatedTime = mtime
  3252. s.PatientId = patient_id
  3253. s.HisPatientId = his_patient_id
  3254. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3255. if errcode > 0 {
  3256. c.ServeFailJSONWithSGJErrorCode(errcode)
  3257. return
  3258. }
  3259. service.CreateAdditionalCharge(&s)
  3260. }
  3261. }
  3262. }
  3263. }
  3264. }
  3265. }
  3266. if err == nil {
  3267. c.ServeSuccessJSON(map[string]interface{}{
  3268. "msg": "保存成功",
  3269. })
  3270. return
  3271. } else {
  3272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3273. return
  3274. }
  3275. }
  3276. func (c *HisApiController) DeletePrescription() {
  3277. prescription_id, _ := c.GetInt64("id")
  3278. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3279. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3280. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3281. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3282. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3283. //耗材保存处方出库
  3284. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3285. //已收费和已发药限制逻辑
  3286. isCharge := false
  3287. isMedicine := false
  3288. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3289. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3290. for _, item := range new_prescriptions {
  3291. if item.IsMedicine == 1 {
  3292. isMedicine = true
  3293. }
  3294. }
  3295. for _, item := range new_prescriptions {
  3296. if item.OrderStatus == 4 {
  3297. isCharge = true
  3298. }
  3299. }
  3300. if p_err != nil {
  3301. if new_prescription.ID > 0 {
  3302. if new_prescription.OrderStatus == 2 {
  3303. isCharge = true
  3304. }
  3305. }
  3306. }
  3307. for _, item := range advices {
  3308. if item.IsMedicine == 1 {
  3309. isMedicine = true
  3310. }
  3311. }
  3312. if isCharge {
  3313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3314. return
  3315. }
  3316. if isMedicine {
  3317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3318. return
  3319. }
  3320. //已收费和已发药限制逻辑
  3321. if len(projects) > 0 {
  3322. for _, item := range projects {
  3323. service.DeletePrintInfo(item.ID) //删除打印信息
  3324. if goodOutConfig.IsOpen != 1 {
  3325. if stockConfig.IsOpen == 1 {
  3326. if item.Type == 3 && item.IsOut == 1 {
  3327. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3328. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3329. good.Total = good.Total + f_count
  3330. service.UpdateGoodInfo(&good)
  3331. operation_time := time.Now().Unix()
  3332. creater := c.GetAdminUserInfo().AdminUser.Id
  3333. //创建退库单
  3334. timeStr := time.Now().Format("2006-01-02")
  3335. timeArr := strings.Split(timeStr, "-")
  3336. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3337. total = total + 1
  3338. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3339. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3340. cancelStock := models.CancelStock{
  3341. OrderNumber: orderNumber,
  3342. OperaTime: operation_time,
  3343. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3344. Creater: creater,
  3345. Ctime: time.Now().Unix(),
  3346. Status: 1,
  3347. ReturnTime: item.RecordDate,
  3348. Type: 1,
  3349. StorehouseId: houseConfig.StorehouseOutInfo,
  3350. IsCheck: 1,
  3351. }
  3352. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3353. if msgerrkonde == gorm.ErrRecordNotFound {
  3354. service.AddSigleCancelStock(&cancelStock)
  3355. }
  3356. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3357. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3358. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3359. //查询该耗材是否出库
  3360. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3361. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3362. deaerler, _ := service.GetDealerById(info.Dealer)
  3363. var total_count int64
  3364. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3365. total_count += count
  3366. if info.ID > 0 {
  3367. if info.Count >= total_count {
  3368. //回退库存
  3369. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3370. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3371. var flush_count int64
  3372. for _, it := range goodList {
  3373. flush_count += it.StockCount
  3374. }
  3375. cancelStockInfo := models.CancelStockInfo{
  3376. GoodId: item.ProjectId,
  3377. CancelStockId: cancel.ID,
  3378. GoodTypeId: good.GoodTypeId,
  3379. Count: prescribingNumber,
  3380. Price: info.Price,
  3381. Total: 0,
  3382. ProductDate: info.ProductDate,
  3383. ExpiryDate: info.ExpiryDate,
  3384. Ctime: time.Now().Unix(),
  3385. Status: 1,
  3386. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3387. OrderNumber: cancel.OrderNumber,
  3388. Type: 0,
  3389. Dealer: deaerler.DealerName,
  3390. Manufacturer: manufacturer.ManufacturerName,
  3391. Number: info.Number,
  3392. RegisterAccount: "",
  3393. Remark: "",
  3394. WarehouseInfoId: info.WarehouseInfotId,
  3395. PatientId: info.PatientId,
  3396. RecordDate: info.SysRecordTime,
  3397. StorehouseId: houseConfig.StorehouseOutInfo,
  3398. IsCheck: 1,
  3399. }
  3400. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3401. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3402. flow := models.VmStockFlow{
  3403. WarehousingId: info.WarehouseInfotId,
  3404. GoodId: item.ProjectId,
  3405. Number: info.Number,
  3406. LicenseNumber: info.LicenseNumber,
  3407. Count: prescribingNumber,
  3408. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3409. PatientId: item.PatientId,
  3410. SystemTime: info.SysRecordTime,
  3411. ConsumableType: 7,
  3412. IsSys: 0,
  3413. WarehousingOrder: "",
  3414. WarehouseOutId: info.WarehouseOutId,
  3415. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3416. IsEdit: 0,
  3417. CancelStockId: cancel.ID,
  3418. CancelOrderNumber: cancel.OrderNumber,
  3419. Manufacturer: manufacturer.ID,
  3420. Dealer: 0,
  3421. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3422. UpdateCreator: 0,
  3423. Status: 1,
  3424. Ctime: time.Now().Unix(),
  3425. Mtime: 0,
  3426. Price: info.Price,
  3427. WarehousingDetailId: info.WarehouseInfotId,
  3428. WarehouseOutDetailId: info.ID,
  3429. CancelOutDetailId: cancelInfo.ID,
  3430. ProductDate: info.ProductDate,
  3431. ExpireDate: info.ExpiryDate,
  3432. StorehouseId: houseConfig.StorehouseOutInfo,
  3433. OverCount: flush_count,
  3434. }
  3435. service.CreateStockFlowOne(flow)
  3436. //退库数量增加
  3437. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3438. //出库数量减少
  3439. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3440. }
  3441. if info.Count < total_count {
  3442. //回退库存
  3443. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3444. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3445. var flush_count int64
  3446. for _, it := range goodList {
  3447. flush_count += it.StockCount
  3448. }
  3449. cancelStockInfo := models.CancelStockInfo{
  3450. GoodId: item.ProjectId,
  3451. CancelStockId: cancel.ID,
  3452. GoodTypeId: good.GoodTypeId,
  3453. Count: info.Count,
  3454. Price: info.Price,
  3455. Total: 0,
  3456. ProductDate: info.ProductDate,
  3457. ExpiryDate: info.ExpiryDate,
  3458. Ctime: time.Now().Unix(),
  3459. Status: 1,
  3460. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3461. OrderNumber: cancel.OrderNumber,
  3462. Type: 0,
  3463. Dealer: deaerler.DealerName,
  3464. Manufacturer: manufacturer.ManufacturerName,
  3465. Number: info.Number,
  3466. RegisterAccount: "",
  3467. Remark: "",
  3468. WarehouseInfoId: info.WarehouseInfotId,
  3469. PatientId: info.PatientId,
  3470. RecordDate: info.SysRecordTime,
  3471. StorehouseId: houseConfig.StorehouseOutInfo,
  3472. IsCheck: 1,
  3473. }
  3474. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3475. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3476. flow := models.VmStockFlow{
  3477. WarehousingId: info.WarehouseInfotId,
  3478. GoodId: item.ProjectId,
  3479. Number: info.Number,
  3480. LicenseNumber: info.LicenseNumber,
  3481. Count: info.Count,
  3482. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3483. PatientId: item.PatientId,
  3484. SystemTime: info.SysRecordTime,
  3485. ConsumableType: 7,
  3486. IsSys: 0,
  3487. WarehousingOrder: "",
  3488. WarehouseOutId: info.WarehouseOutId,
  3489. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3490. IsEdit: 0,
  3491. CancelStockId: cancel.ID,
  3492. CancelOrderNumber: cancel.OrderNumber,
  3493. Manufacturer: manufacturer.ID,
  3494. Dealer: 0,
  3495. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3496. UpdateCreator: 0,
  3497. Status: 1,
  3498. Ctime: time.Now().Unix(),
  3499. Mtime: 0,
  3500. Price: info.Price,
  3501. WarehousingDetailId: info.WarehouseInfotId,
  3502. WarehouseOutDetailId: info.ID,
  3503. CancelOutDetailId: cancelInfo.ID,
  3504. ProductDate: info.ProductDate,
  3505. ExpireDate: info.ExpiryDate,
  3506. StorehouseId: houseConfig.StorehouseOutInfo,
  3507. OverCount: flush_count,
  3508. }
  3509. service.CreateStockFlowOne(flow)
  3510. //退库数量增加
  3511. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3512. //出库数量减少
  3513. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3514. }
  3515. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3516. var flush_count int64
  3517. for _, it := range goodList {
  3518. flush_count += it.StockCount
  3519. }
  3520. //查询已出库数量
  3521. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3522. if prescribingNumber < dialysisInfo.Count {
  3523. //改变数量
  3524. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3525. }
  3526. if prescribingNumber >= dialysisInfo.Count {
  3527. //删除出库表
  3528. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3529. }
  3530. //更新库存
  3531. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3532. //更新基础库库存
  3533. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3534. }
  3535. }
  3536. }
  3537. }
  3538. //保存耗材出库
  3539. if goodOutConfig.IsOpen == 1 {
  3540. if item.Type == 3 {
  3541. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3542. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3543. good.Total = good.Total + f_count
  3544. service.UpdateGoodInfo(&good)
  3545. operation_time := time.Now().Unix()
  3546. creater := c.GetAdminUserInfo().AdminUser.Id
  3547. //创建退库单
  3548. timeStr := time.Now().Format("2006-01-02")
  3549. timeArr := strings.Split(timeStr, "-")
  3550. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3551. total = total + 1
  3552. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3553. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3554. cancelStock := models.CancelStock{
  3555. OrderNumber: orderNumber,
  3556. OperaTime: operation_time,
  3557. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3558. Creater: creater,
  3559. Ctime: time.Now().Unix(),
  3560. Status: 1,
  3561. ReturnTime: item.RecordDate,
  3562. Type: 1,
  3563. StorehouseId: houseConfig.StorehouseOutInfo,
  3564. IsCheck: 1,
  3565. }
  3566. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3567. if msgerrkonde == gorm.ErrRecordNotFound {
  3568. service.AddSigleCancelStock(&cancelStock)
  3569. }
  3570. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3571. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3572. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3573. //查询该耗材是否出库
  3574. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3575. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3576. deaerler, _ := service.GetDealerById(info.Dealer)
  3577. var total_count int64
  3578. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3579. total_count += count
  3580. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3581. var flush_count int64
  3582. for _, it := range goodList {
  3583. flush_count += it.StockCount
  3584. }
  3585. fmt.Println("历史出库数据", info.Count)
  3586. fmt.Println("出库数量", total_count)
  3587. if info.ID > 0 {
  3588. cancelStockInfo := models.CancelStockInfo{
  3589. GoodId: item.ProjectId,
  3590. CancelStockId: cancel.ID,
  3591. GoodTypeId: good.GoodTypeId,
  3592. Count: prescribingNumber,
  3593. Price: info.Price,
  3594. Total: 0,
  3595. ProductDate: info.ProductDate,
  3596. ExpiryDate: info.ExpiryDate,
  3597. Ctime: time.Now().Unix(),
  3598. Status: 1,
  3599. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3600. OrderNumber: cancel.OrderNumber,
  3601. Type: 0,
  3602. Dealer: deaerler.DealerName,
  3603. Manufacturer: manufacturer.ManufacturerName,
  3604. Number: info.Number,
  3605. RegisterAccount: "",
  3606. Remark: "",
  3607. WarehouseInfoId: info.WarehouseInfotId,
  3608. PatientId: info.PatientId,
  3609. RecordDate: info.SysRecordTime,
  3610. StorehouseId: houseConfig.StorehouseOutInfo,
  3611. IsCheck: 1,
  3612. }
  3613. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3614. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3615. //查询出库数量
  3616. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3617. //出库数据 大于 退库数量
  3618. if len(list) > 0 {
  3619. for _, it := range list {
  3620. //回退库存
  3621. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3622. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3623. var flush_count_one int64
  3624. for _, it := range goodList {
  3625. flush_count_one += it.StockCount
  3626. }
  3627. //查询该批次是否有退库数据
  3628. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3629. creater := c.GetAdminUserInfo().AdminUser.Id
  3630. flow := models.VmStockFlow{
  3631. WarehousingId: it.WarehouseInfotId,
  3632. GoodId: it.GoodId,
  3633. Number: it.Number,
  3634. LicenseNumber: it.LicenseNumber,
  3635. Count: it.Count,
  3636. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3637. PatientId: it.PatientId,
  3638. SystemTime: it.SysRecordTime,
  3639. ConsumableType: 7,
  3640. IsSys: 0,
  3641. WarehousingOrder: "",
  3642. WarehouseOutId: it.WarehouseOutId,
  3643. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3644. IsEdit: 0,
  3645. CancelStockId: cancel.ID,
  3646. CancelOrderNumber: cancel.OrderNumber,
  3647. Manufacturer: manufacturer.ID,
  3648. Dealer: 0,
  3649. Creator: creater,
  3650. UpdateCreator: 0,
  3651. Status: 1,
  3652. Ctime: time.Now().Unix(),
  3653. Mtime: 0,
  3654. Price: it.Price,
  3655. WarehousingDetailId: it.WarehouseInfotId,
  3656. WarehouseOutDetailId: it.ID,
  3657. CancelOutDetailId: cancelInfo.ID,
  3658. ProductDate: it.ProductDate,
  3659. ExpireDate: it.ExpiryDate,
  3660. StorehouseId: houseConfig.StorehouseOutInfo,
  3661. OverCount: flush_count_one,
  3662. }
  3663. service.CreateStockFlowOne(flow)
  3664. //if flow.ID > 0 {
  3665. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3666. //}
  3667. }
  3668. }
  3669. //flow := models.VmStockFlow{
  3670. // WarehousingId: info.WarehouseInfotId,
  3671. // GoodId: item.ProjectId,
  3672. // Number: info.Number,
  3673. // LicenseNumber: info.LicenseNumber,
  3674. // Count: prescribingNumber,
  3675. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3676. // PatientId: item.PatientId,
  3677. // SystemTime: info.SysRecordTime,
  3678. // ConsumableType: 7,
  3679. // IsSys: 0,
  3680. // WarehousingOrder: "",
  3681. // WarehouseOutId: info.WarehouseOutId,
  3682. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3683. // IsEdit: 0,
  3684. // CancelStockId: cancel.ID,
  3685. // CancelOrderNumber: cancel.OrderNumber,
  3686. // Manufacturer: manufacturer.ID,
  3687. // Dealer: 0,
  3688. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3689. // UpdateCreator: 0,
  3690. // Status: 1,
  3691. // Ctime: time.Now().Unix(),
  3692. // Mtime: 0,
  3693. // Price: info.Price,
  3694. // WarehousingDetailId: info.WarehouseInfotId,
  3695. // WarehouseOutDetailId: info.ID,
  3696. // CancelOutDetailId: cancelInfo.ID,
  3697. // ProductDate: info.ProductDate,
  3698. // ExpireDate: info.ExpiryDate,
  3699. // StorehouseId: houseConfig.StorehouseOutInfo,
  3700. // OverCount: flush_count,
  3701. //}
  3702. //service.CreateStockFlowOne(flow)
  3703. //退库数量增加
  3704. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3705. //出库数量减少
  3706. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3707. //查询已出库数量
  3708. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3709. if prescribingNumber < dialysisInfo.Count {
  3710. //改变数量
  3711. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3712. }
  3713. if prescribingNumber >= dialysisInfo.Count {
  3714. //删除出库表
  3715. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3716. }
  3717. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3718. var flush_count_one int64
  3719. for _, it := range goodList {
  3720. flush_count_one += it.StockCount
  3721. }
  3722. //更新库存
  3723. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3724. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3725. //更新基础库库存
  3726. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3727. }
  3728. }
  3729. }
  3730. }
  3731. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3732. fmt.Println(err)
  3733. }
  3734. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3735. fmt.Println(err)
  3736. if len(advices) > 0 {
  3737. for _, item := range advices {
  3738. redis := service.RedisClient()
  3739. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3740. redis.Set(keyFive, "", time.Second)
  3741. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3742. redis.Set(keyOne, "", time.Second)
  3743. redis.Close()
  3744. }
  3745. }
  3746. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3747. if len(advices) > 0 {
  3748. for _, item := range advices {
  3749. creater := c.GetAdminUserInfo().AdminUser.Id
  3750. service.DrugAutoAddCancelInfo(item, creater)
  3751. }
  3752. }
  3753. } else {
  3754. if drugOutConfig.IsOpen == 1 {
  3755. if len(advices) > 0 {
  3756. for _, item := range advices {
  3757. creater := c.GetAdminUserInfo().AdminUser.Id
  3758. service.DrugAutoAddCancelInfo(item, creater)
  3759. }
  3760. }
  3761. } else {
  3762. if len(advices) > 0 {
  3763. for _, item := range advices {
  3764. creater := c.GetAdminUserInfo().AdminUser.Id
  3765. service.DrugAutoAddCancelInfo(item, creater)
  3766. }
  3767. }
  3768. }
  3769. }
  3770. c.ServeSuccessJSON(map[string]interface{}{
  3771. "msg": "删除成功",
  3772. })
  3773. return
  3774. }
  3775. func (c *HisApiController) DeleteDoctorAdvice() {
  3776. id, _ := c.GetInt64("id")
  3777. advice, _ := service.GetHisDoctorAdvicesById(id)
  3778. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3779. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3780. //已收费和已发药的限制逻辑
  3781. isCharge := false
  3782. isMedicine := false
  3783. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3784. //获取今天该患者所有处方,判断是否发药或者收费
  3785. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3786. for _, item := range new_prescriptions {
  3787. if item.IsMedicine == 1 {
  3788. isMedicine = true
  3789. }
  3790. }
  3791. for _, item := range new_prescriptions {
  3792. if item.OrderStatus == 4 {
  3793. isCharge = true
  3794. }
  3795. }
  3796. if isMedicine {
  3797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3798. return
  3799. }
  3800. if isCharge {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3802. return
  3803. }
  3804. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3805. for _, item := range advices {
  3806. if item.IsMedicine == 1 {
  3807. isMedicine = true
  3808. }
  3809. }
  3810. if isMedicine {
  3811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3812. return
  3813. }
  3814. if new_prescription.ID > 0 {
  3815. if new_prescription.OrderStatus == 2 {
  3816. isCharge = true
  3817. }
  3818. }
  3819. if isCharge {
  3820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3821. return
  3822. }
  3823. //已收费和已发药的限制逻辑
  3824. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3825. redis := service.RedisClient()
  3826. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3827. redis.Set(keyFive, "", time.Second)
  3828. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3829. redis.Set(keyOne, "", time.Second)
  3830. defer redis.Close()
  3831. if err == nil {
  3832. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3833. //查询是否在处方中出库
  3834. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3835. if openConfig.IsOpen != 1 {
  3836. //判断该医嘱是否执行了
  3837. if advice.ExecutionState == 1 {
  3838. creater := c.GetAdminUserInfo().AdminUser.Id
  3839. service.DrugAutoAddCancelInfo(&advice, creater)
  3840. }
  3841. }
  3842. //开启保存处方扣减功能
  3843. if openConfig.IsOpen == 1 {
  3844. creater := c.GetAdminUserInfo().AdminUser.Id
  3845. service.DrugAutoAddCancelInfo(&advice, creater)
  3846. }
  3847. } else {
  3848. if drugOutConfig.IsOpen == 1 {
  3849. //查询是否在处方中出库
  3850. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3851. if openConfig.IsOpen != 1 {
  3852. //判断该医嘱是否执行了
  3853. if advice.ExecutionState == 1 {
  3854. creater := c.GetAdminUserInfo().AdminUser.Id
  3855. service.DrugAutoAddCancelInfo(&advice, creater)
  3856. }
  3857. }
  3858. //开启保存处方扣减功能
  3859. if openConfig.IsOpen == 1 {
  3860. creater := c.GetAdminUserInfo().AdminUser.Id
  3861. service.DrugAutoAddCancelInfo(&advice, creater)
  3862. }
  3863. } else {
  3864. //判断该医嘱是否执行了
  3865. if advice.ExecutionState == 1 {
  3866. creater := c.GetAdminUserInfo().AdminUser.Id
  3867. service.DrugAutoAddCancelInfo(&advice, creater)
  3868. }
  3869. }
  3870. }
  3871. c.ServeSuccessJSON(map[string]interface{}{
  3872. "msg": "删除成功",
  3873. })
  3874. return
  3875. } else {
  3876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3877. return
  3878. }
  3879. }
  3880. func (c *HisApiController) DeleteProject() {
  3881. id, _ := c.GetInt64("id")
  3882. adminInfo := c.GetAdminUserInfo()
  3883. project, _ := service.GetHisProjectByID(id)
  3884. // var consumable models.DialysisBeforePrepare
  3885. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3886. //耗材保存处方出库
  3887. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3888. isCharge := false
  3889. isMedicine := false
  3890. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3891. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3892. for _, item := range new_prescriptions {
  3893. if item.IsMedicine == 1 {
  3894. isMedicine = true
  3895. }
  3896. }
  3897. for _, item := range new_prescriptions {
  3898. if item.OrderStatus == 4 {
  3899. isCharge = true
  3900. }
  3901. }
  3902. if isMedicine {
  3903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3904. return
  3905. }
  3906. if isCharge {
  3907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3908. return
  3909. }
  3910. if new_prescription.ID > 0 {
  3911. if new_prescription.OrderStatus == 2 {
  3912. isCharge = true
  3913. }
  3914. }
  3915. if isCharge {
  3916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3917. return
  3918. }
  3919. service.DeletePrintInfo(id)
  3920. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3921. label.Status = 0
  3922. service.CreateHisLabelRecord(&label)
  3923. fmt.Println(goodOutConfig.IsOpen)
  3924. if goodOutConfig.IsOpen != 1 {
  3925. if stockConfig.IsOpen == 1 {
  3926. if project.Type == 2 {
  3927. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3928. fmt.Println(err)
  3929. }
  3930. if project.Type == 3 && project.IsOut == 1 {
  3931. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3932. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3933. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3934. operation_time := time.Now().Unix()
  3935. creater := adminInfo.AdminUser.Id
  3936. //创建退库单
  3937. timeStr := time.Now().Format("2006-01-02")
  3938. timeArr := strings.Split(timeStr, "-")
  3939. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3940. total = total + 1
  3941. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3942. cancelStock := models.CancelStock{
  3943. OrderNumber: orderNumber,
  3944. OperaTime: operation_time,
  3945. OrgId: adminInfo.CurrentOrgId,
  3946. Creater: creater,
  3947. Ctime: time.Now().Unix(),
  3948. Status: 1,
  3949. ReturnTime: project.RecordDate,
  3950. Type: 1,
  3951. StorehouseId: houseConfig.StorehouseOutInfo,
  3952. IsCheck: 1,
  3953. }
  3954. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3955. if msgerrkonde == gorm.ErrRecordNotFound {
  3956. service.AddSigleCancelStock(&cancelStock)
  3957. }
  3958. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3959. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3960. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3961. //查询是否有出库
  3962. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3963. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3964. deaerler, _ := service.GetDealerById(info.Dealer)
  3965. if info.ID > 0 {
  3966. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3967. if info.Count >= prescribingNumber {
  3968. cancelStockInfo := models.CancelStockInfo{
  3969. GoodId: project.ProjectId,
  3970. CancelStockId: cancel.ID,
  3971. GoodTypeId: good.GoodTypeId,
  3972. Count: prescribingNumber,
  3973. Price: info.Price,
  3974. Total: 0,
  3975. ProductDate: info.ProductDate,
  3976. ExpiryDate: info.ExpiryDate,
  3977. Ctime: time.Now().Unix(),
  3978. Status: 1,
  3979. OrgId: adminInfo.CurrentOrgId,
  3980. OrderNumber: cancel.OrderNumber,
  3981. Type: 0,
  3982. Dealer: deaerler.DealerName,
  3983. Manufacturer: manufacturer.ManufacturerName,
  3984. Number: info.Number,
  3985. RegisterAccount: "",
  3986. Remark: "",
  3987. WarehouseInfoId: info.WarehouseInfotId,
  3988. PatientId: info.PatientId,
  3989. RecordDate: info.SysRecordTime,
  3990. StorehouseId: houseConfig.StorehouseOutInfo,
  3991. IsCheck: 1,
  3992. }
  3993. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3994. //回退库存
  3995. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3996. //退库数量增加
  3997. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3998. //出库数量减少
  3999. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4000. }
  4001. if info.Count < prescribingNumber {
  4002. cancelStockInfo := models.CancelStockInfo{
  4003. GoodId: project.ProjectId,
  4004. CancelStockId: cancel.ID,
  4005. GoodTypeId: good.GoodTypeId,
  4006. Count: info.Count,
  4007. Price: info.Price,
  4008. Total: 0,
  4009. ProductDate: info.ProductDate,
  4010. ExpiryDate: info.ExpiryDate,
  4011. Ctime: time.Now().Unix(),
  4012. Status: 1,
  4013. OrgId: adminInfo.CurrentOrgId,
  4014. OrderNumber: cancel.OrderNumber,
  4015. Type: 0,
  4016. Dealer: deaerler.DealerName,
  4017. Manufacturer: manufacturer.ManufacturerName,
  4018. Number: info.Number,
  4019. RegisterAccount: "",
  4020. Remark: "",
  4021. WarehouseInfoId: info.WarehouseInfotId,
  4022. PatientId: info.PatientId,
  4023. RecordDate: info.SysRecordTime,
  4024. StorehouseId: houseConfig.StorehouseOutInfo,
  4025. IsCheck: 1,
  4026. }
  4027. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4028. //回退库存
  4029. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4030. //退库数量增加
  4031. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4032. //出库数量减少
  4033. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4034. }
  4035. //查询剩余库存
  4036. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4037. var over_count int64
  4038. for _, it := range goodList {
  4039. over_count += it.StockCount
  4040. }
  4041. //出库数据 大于 退库数量
  4042. if info.Count >= prescribingNumber {
  4043. flow := models.VmStockFlow{
  4044. WarehousingId: info.WarehouseInfotId,
  4045. GoodId: project.ProjectId,
  4046. Number: info.Number,
  4047. LicenseNumber: info.LicenseNumber,
  4048. Count: prescribingNumber,
  4049. UserOrgId: adminInfo.CurrentOrgId,
  4050. PatientId: project.PatientId,
  4051. SystemTime: info.SysRecordTime,
  4052. ConsumableType: 7,
  4053. IsSys: 0,
  4054. WarehousingOrder: "",
  4055. WarehouseOutId: info.WarehouseOutId,
  4056. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4057. IsEdit: 0,
  4058. CancelStockId: cancel.ID,
  4059. CancelOrderNumber: cancel.OrderNumber,
  4060. Manufacturer: manufacturer.ID,
  4061. Dealer: 0,
  4062. Creator: adminInfo.AdminUser.Id,
  4063. UpdateCreator: 0,
  4064. Status: 1,
  4065. Ctime: time.Now().Unix(),
  4066. Mtime: 0,
  4067. Price: info.Price,
  4068. WarehousingDetailId: info.WarehouseInfotId,
  4069. WarehouseOutDetailId: info.ID,
  4070. CancelOutDetailId: cancelInfo.ID,
  4071. ProductDate: info.ProductDate,
  4072. ExpireDate: info.ExpiryDate,
  4073. StorehouseId: houseConfig.StorehouseOutInfo,
  4074. OverCount: over_count,
  4075. }
  4076. service.CreateStockFlowOne(flow)
  4077. }
  4078. //出库数据小于退库数据
  4079. if info.Count < prescribingNumber {
  4080. flow := models.VmStockFlow{
  4081. WarehousingId: info.WarehouseInfotId,
  4082. GoodId: project.ProjectId,
  4083. Number: info.Number,
  4084. LicenseNumber: info.LicenseNumber,
  4085. Count: info.Count,
  4086. UserOrgId: adminInfo.CurrentOrgId,
  4087. PatientId: project.PatientId,
  4088. SystemTime: info.SysRecordTime,
  4089. ConsumableType: 7,
  4090. IsSys: 0,
  4091. WarehousingOrder: "",
  4092. WarehouseOutId: info.WarehouseOutId,
  4093. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4094. IsEdit: 0,
  4095. CancelStockId: cancel.ID,
  4096. CancelOrderNumber: cancel.OrderNumber,
  4097. Manufacturer: manufacturer.ID,
  4098. Dealer: 0,
  4099. Creator: adminInfo.AdminUser.Id,
  4100. UpdateCreator: 0,
  4101. Status: 1,
  4102. Ctime: time.Now().Unix(),
  4103. Mtime: 0,
  4104. Price: info.Price,
  4105. WarehousingDetailId: info.WarehouseInfotId,
  4106. WarehouseOutDetailId: info.ID,
  4107. CancelOutDetailId: cancelInfo.ID,
  4108. ProductDate: info.ProductDate,
  4109. ExpireDate: info.ExpiryDate,
  4110. StorehouseId: houseConfig.StorehouseOutInfo,
  4111. OverCount: over_count,
  4112. }
  4113. service.CreateStockFlowOne(flow)
  4114. }
  4115. //查询已出库数量
  4116. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4117. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4118. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4119. if prescribingNumber < dialysisInfo.Count {
  4120. //改变数量
  4121. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4122. }
  4123. if prescribingNumber >= dialysisInfo.Count {
  4124. //删除出库表
  4125. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4126. }
  4127. //更新剩余库存
  4128. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4129. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4130. var total_count_one int64
  4131. for _, it := range stockList {
  4132. total_count_one += it.StockCount
  4133. }
  4134. //基础库插入数据
  4135. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4136. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4137. var flush_count int64
  4138. for _, it := range goodListOne {
  4139. flush_count += it.StockCount
  4140. }
  4141. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4142. if errs != nil {
  4143. goodErrcode := models.XtGoodErrcode{
  4144. UserOrgId: project.UserOrgId,
  4145. Errcode: "手动出库更新剩余出库失败",
  4146. GoodId: project.ProjectId,
  4147. Status: 1,
  4148. Ctime: time.Now().Unix(),
  4149. Mtime: 0,
  4150. Count: 0,
  4151. StockCount: 0,
  4152. Creater: creater,
  4153. BatchNumberId: 0,
  4154. WarehouseOutId: 0,
  4155. }
  4156. service.CreateGoodErrcode(goodErrcode)
  4157. }
  4158. }
  4159. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4160. fmt.Println(err)
  4161. } else {
  4162. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4163. fmt.Println(err)
  4164. }
  4165. } else {
  4166. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4167. fmt.Println(err)
  4168. }
  4169. }
  4170. //保存处方出库
  4171. if goodOutConfig.IsOpen == 1 {
  4172. if project.Type == 3 {
  4173. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4174. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4175. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4176. operation_time := time.Now().Unix()
  4177. creater := adminInfo.AdminUser.Id
  4178. //创建退库单
  4179. timeStr := time.Now().Format("2006-01-02")
  4180. timeArr := strings.Split(timeStr, "-")
  4181. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4182. total = total + 1
  4183. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4184. cancelStock := models.CancelStock{
  4185. OrderNumber: orderNumber,
  4186. OperaTime: operation_time,
  4187. OrgId: adminInfo.CurrentOrgId,
  4188. Creater: creater,
  4189. Ctime: time.Now().Unix(),
  4190. Status: 1,
  4191. ReturnTime: project.RecordDate,
  4192. Type: 1,
  4193. StorehouseId: houseConfig.StorehouseOutInfo,
  4194. IsCheck: 1,
  4195. }
  4196. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4197. if msgerrkonde == gorm.ErrRecordNotFound {
  4198. service.AddSigleCancelStock(&cancelStock)
  4199. }
  4200. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4201. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4202. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4203. //获取出库数据
  4204. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4205. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4206. deaerler, _ := service.GetDealerById(info.Dealer)
  4207. if info.ID > 0 {
  4208. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4209. if info.Count >= prescribingNumber {
  4210. cancelStockInfo := models.CancelStockInfo{
  4211. GoodId: project.ProjectId,
  4212. CancelStockId: cancel.ID,
  4213. GoodTypeId: good.GoodTypeId,
  4214. Count: prescribingNumber,
  4215. Price: info.Price,
  4216. Total: 0,
  4217. ProductDate: info.ProductDate,
  4218. ExpiryDate: info.ExpiryDate,
  4219. Ctime: time.Now().Unix(),
  4220. Status: 1,
  4221. OrgId: adminInfo.CurrentOrgId,
  4222. OrderNumber: cancel.OrderNumber,
  4223. Type: 0,
  4224. Dealer: deaerler.DealerName,
  4225. Manufacturer: manufacturer.ManufacturerName,
  4226. Number: info.Number,
  4227. RegisterAccount: "",
  4228. Remark: "",
  4229. WarehouseInfoId: info.WarehouseInfotId,
  4230. PatientId: info.PatientId,
  4231. RecordDate: info.SysRecordTime,
  4232. StorehouseId: houseConfig.StorehouseOutInfo,
  4233. IsCheck: 1,
  4234. }
  4235. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4236. //退库数量增加
  4237. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4238. //出库数量减少
  4239. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4240. }
  4241. if info.Count < prescribingNumber {
  4242. cancelStockInfo := models.CancelStockInfo{
  4243. GoodId: project.ProjectId,
  4244. CancelStockId: cancel.ID,
  4245. GoodTypeId: good.GoodTypeId,
  4246. Count: prescribingNumber,
  4247. Price: info.Price,
  4248. Total: 0,
  4249. ProductDate: info.ProductDate,
  4250. ExpiryDate: info.ExpiryDate,
  4251. Ctime: time.Now().Unix(),
  4252. Status: 1,
  4253. OrgId: adminInfo.CurrentOrgId,
  4254. OrderNumber: cancel.OrderNumber,
  4255. Type: 0,
  4256. Dealer: deaerler.DealerName,
  4257. Manufacturer: manufacturer.ManufacturerName,
  4258. Number: info.Number,
  4259. RegisterAccount: "",
  4260. Remark: "",
  4261. WarehouseInfoId: info.WarehouseInfotId,
  4262. PatientId: info.PatientId,
  4263. RecordDate: info.SysRecordTime,
  4264. StorehouseId: houseConfig.StorehouseOutInfo,
  4265. IsCheck: 1,
  4266. }
  4267. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4268. //回退库存
  4269. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4270. }
  4271. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4272. var over_count int64
  4273. for _, it := range goodList {
  4274. over_count += it.StockCount
  4275. }
  4276. //查询出库数量
  4277. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4278. //出库数据 大于 退库数量
  4279. if len(list) > 0 {
  4280. for _, it := range list {
  4281. //回退库存
  4282. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4283. //退库数量增加
  4284. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4285. //出库数量减少
  4286. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4287. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4288. var over_count_one int64
  4289. for _, it := range goodList {
  4290. over_count_one += it.StockCount
  4291. }
  4292. //查询该批次是否有退库数据
  4293. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4294. flow := models.VmStockFlow{
  4295. WarehousingId: it.WarehouseInfotId,
  4296. GoodId: it.GoodId,
  4297. Number: it.Number,
  4298. LicenseNumber: it.LicenseNumber,
  4299. Count: it.Count,
  4300. UserOrgId: adminInfo.CurrentOrgId,
  4301. PatientId: it.PatientId,
  4302. SystemTime: it.SysRecordTime,
  4303. ConsumableType: 7,
  4304. IsSys: 0,
  4305. WarehousingOrder: "",
  4306. WarehouseOutId: it.WarehouseOutId,
  4307. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4308. IsEdit: 0,
  4309. CancelStockId: cancel.ID,
  4310. CancelOrderNumber: cancel.OrderNumber,
  4311. Manufacturer: manufacturer.ID,
  4312. Dealer: 0,
  4313. Creator: adminInfo.AdminUser.Id,
  4314. UpdateCreator: 0,
  4315. Status: 1,
  4316. Ctime: time.Now().Unix(),
  4317. Mtime: 0,
  4318. Price: it.Price,
  4319. WarehousingDetailId: it.WarehouseInfotId,
  4320. WarehouseOutDetailId: it.ID,
  4321. CancelOutDetailId: cancelInfo.ID,
  4322. ProductDate: it.ProductDate,
  4323. ExpireDate: it.ExpiryDate,
  4324. StorehouseId: houseConfig.StorehouseOutInfo,
  4325. OverCount: over_count_one,
  4326. }
  4327. service.CreateStockFlowOne(flow)
  4328. }
  4329. }
  4330. //查询已出库数量
  4331. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4332. if prescribingNumber < dialysisInfo.Count {
  4333. //改变数量
  4334. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4335. }
  4336. if prescribingNumber >= dialysisInfo.Count {
  4337. //删除出库表
  4338. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4339. }
  4340. //更新剩余库存
  4341. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4342. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4343. var total_count_one int64
  4344. for _, it := range stockList {
  4345. total_count_one += it.StockCount
  4346. }
  4347. //基础库插入数据
  4348. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4349. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4350. var flush_count int64
  4351. for _, it := range goodListOne {
  4352. flush_count += it.StockCount
  4353. }
  4354. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4355. if errs != nil {
  4356. goodErrcode := models.XtGoodErrcode{
  4357. UserOrgId: project.UserOrgId,
  4358. Errcode: "手动出库更新剩余出库失败",
  4359. GoodId: project.ProjectId,
  4360. Status: 1,
  4361. Ctime: time.Now().Unix(),
  4362. Mtime: 0,
  4363. Count: 0,
  4364. StockCount: 0,
  4365. Creater: creater,
  4366. BatchNumberId: 0,
  4367. WarehouseOutId: 0,
  4368. }
  4369. service.CreateGoodErrcode(goodErrcode)
  4370. }
  4371. }
  4372. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4373. fmt.Println(err)
  4374. } else {
  4375. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4376. fmt.Println(err)
  4377. }
  4378. }
  4379. c.ServeSuccessJSON(map[string]interface{}{
  4380. "msg": "删除成功",
  4381. })
  4382. return
  4383. }
  4384. func (c *HisApiController) CreateHisAdditionalCharge() {
  4385. his_patient_id, _ := c.GetInt64("his_patient_id")
  4386. patient_id, _ := c.GetInt64("patient_id")
  4387. record_date := c.GetString("record_date")
  4388. timeLayout := "2006-01-02"
  4389. loc, _ := time.LoadLocation("Local")
  4390. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4391. if err != nil {
  4392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4393. return
  4394. }
  4395. adminInfo := c.GetAdminUserInfo()
  4396. recordDateTime := theTime.Unix()
  4397. dataBody := make(map[string]interface{}, 0)
  4398. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4399. if err != nil {
  4400. utils.ErrorLog(err.Error())
  4401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4402. return
  4403. }
  4404. var additions []*models.HisAdditionalCharge
  4405. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4406. additions, _ := dataBody["addition"].([]interface{})
  4407. if len(additions) > 0 {
  4408. for _, item := range additions {
  4409. items := item.(map[string]interface{})
  4410. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4411. utils.ErrorLog("item_id")
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. return
  4414. }
  4415. item_id := int64(items["item_id"].(float64))
  4416. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4417. utils.ErrorLog("item_name")
  4418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4419. return
  4420. }
  4421. item_name := items["item_name"].(string)
  4422. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4423. utils.ErrorLog("price")
  4424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4425. return
  4426. }
  4427. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4428. ctime := time.Now().Unix()
  4429. additional := &models.HisAdditionalCharge{
  4430. PatientId: patient_id,
  4431. HisPatientId: his_patient_id,
  4432. UserOrgId: adminInfo.CurrentOrgId,
  4433. RecordDate: recordDateTime,
  4434. CreatedTime: ctime,
  4435. UpdatedTime: ctime,
  4436. Modifier: adminInfo.AdminUser.Id,
  4437. Creator: adminInfo.AdminUser.Id,
  4438. Price: price,
  4439. ItemName: item_name,
  4440. ItemId: item_id,
  4441. Status: 1,
  4442. }
  4443. additions = append(additions, additional)
  4444. }
  4445. }
  4446. }
  4447. for _, item := range additions {
  4448. service.CreateAddtionalCharge(item)
  4449. }
  4450. c.ServeSuccessJSON(map[string]interface{}{
  4451. "msg": "创建成功",
  4452. })
  4453. }
  4454. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4455. blood_fat := c.GetString("blood_fat")
  4456. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4457. blood_sugar := c.GetString("blood_sugar")
  4458. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4459. chief_conplaint := c.GetString("chief_conplaint")
  4460. dbp := c.GetString("dbp")
  4461. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4462. delivery_way, _ := c.GetInt64("delivery_way")
  4463. diagnostic := c.GetString("diagnostic")
  4464. family_history := c.GetString("family_history")
  4465. height := c.GetString("height")
  4466. history_of_present_illness := c.GetString("history_of_present_illness")
  4467. is_infect, _ := c.GetInt64("is_infect")
  4468. past_history := c.GetString("past_history")
  4469. patient_id, _ := c.GetInt64("patient_id")
  4470. his_patient_id, _ := c.GetInt64("his_patient_id")
  4471. personal_history := c.GetString("personal_history")
  4472. pulse := c.GetString("pulse")
  4473. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4474. sbp := c.GetString("sbp")
  4475. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4476. heightfloat, _ := strconv.ParseFloat(height, 64)
  4477. sicktype := c.GetString("sick_type")
  4478. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4479. symptom := c.GetString("symptom")
  4480. sick_date := c.GetString("sick_date")
  4481. temperatures := c.GetString("temperature")
  4482. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4483. record_date := c.GetString("record_date")
  4484. breathing := c.GetString("breathing")
  4485. doctor_advice := c.GetString("doctor_advice")
  4486. remark := c.GetString("remark")
  4487. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4488. sick, _ := c.GetInt64("sick")
  4489. diagnose, _ := c.GetInt64("diagnose")
  4490. //id, _ := c.GetInt64("id")
  4491. timeLayout := "2006-01-02"
  4492. loc, _ := time.LoadLocation("Local")
  4493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4494. allergic_history := c.GetString("allergic_history")
  4495. if err != nil {
  4496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4497. return
  4498. }
  4499. recordDateTime := theTime.Unix()
  4500. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4501. if err != nil {
  4502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4503. return
  4504. }
  4505. sickTimes := sickTime.Unix()
  4506. ctime := time.Now().Unix()
  4507. primary_disease := c.GetString("primary_disease")
  4508. confirm_failure_date := c.GetString("confirm_failure_date")
  4509. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4510. drug_allergy_history := c.GetString("drug_allergy_history")
  4511. physical_examination := c.GetString("physical_examination")
  4512. special_inspection := c.GetString("special_inspection")
  4513. lab_apparatus := c.GetString("lab_apparatus")
  4514. caseHistory := models.HisPatientCaseHistory{
  4515. HisPatientId: his_patient_id,
  4516. PatientId: patient_id,
  4517. Temperature: temperature,
  4518. BloodSugar: bloodsugarfloat,
  4519. Pulse: pulsefloat,
  4520. Sbp: sbpfloat,
  4521. Dbp: dbpfloat,
  4522. Height: heightfloat,
  4523. BloodFat: bloodfatfloat,
  4524. SickType: sick_type,
  4525. Symptom: symptom,
  4526. SickDate: sickTimes,
  4527. IsInfect: is_infect,
  4528. HistoryOfPresentIllness: history_of_present_illness,
  4529. PastHistory: past_history,
  4530. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4531. ChiefConplaint: chief_conplaint,
  4532. PersonalHistory: personal_history,
  4533. FamilyHistory: family_history,
  4534. Diagnostic: diagnostic,
  4535. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4536. Status: 1,
  4537. Ctime: ctime,
  4538. Mtime: ctime,
  4539. RecordDate: recordDateTime,
  4540. DeliveryWay: delivery_way,
  4541. Breathing: breathingfloat,
  4542. DoctorAdvice: doctor_advice,
  4543. Remark: remark,
  4544. Sick: sick,
  4545. Diagnose: diagnose,
  4546. AllergicHistory: allergic_history,
  4547. PrimaryDisease: primary_disease,
  4548. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4549. DrugAllergyHistory: drug_allergy_history,
  4550. PhysicalExamination: physical_examination,
  4551. SpecialInspection: special_inspection,
  4552. LabApparatus: lab_apparatus,
  4553. }
  4554. //查询该患者是否有病历
  4555. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4556. if errcodes == gorm.ErrRecordNotFound {
  4557. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4558. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4559. if err != nil {
  4560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4561. return
  4562. }
  4563. c.ServeSuccessJSON(map[string]interface{}{
  4564. "caseHistory": caseHistory,
  4565. "historyInfo": historyInfo,
  4566. })
  4567. return
  4568. } else if errcodes == nil {
  4569. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4570. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4571. if err != nil {
  4572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4573. return
  4574. }
  4575. c.ServeSuccessJSON(map[string]interface{}{
  4576. "caseHistory": caseHistory,
  4577. "historyInfo": historyInfo,
  4578. })
  4579. }
  4580. //查询该患者是否有病历
  4581. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4582. //if errcode == gorm.ErrRecordNotFound {
  4583. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4584. // if err != nil {
  4585. // c.ServeSuccessJSON(map[string]interface{}{
  4586. // "msg": "保存成功",
  4587. // })
  4588. // }
  4589. //} else if errcode == nil {
  4590. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4591. // return
  4592. //}
  4593. }
  4594. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4595. patient_id, _ := c.GetInt64("patient_id", 0)
  4596. adminUser := c.GetAdminUserInfo()
  4597. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4598. c.ServeSuccessJSON(map[string]interface{}{
  4599. "list": caseHistorys,
  4600. })
  4601. }
  4602. func (c *HisApiController) GetHisPatientCaseHistory() {
  4603. record_date, _ := c.GetInt64("record_date", 0)
  4604. patient_id, _ := c.GetInt64("patient_id", 0)
  4605. admin := c.GetAdminUserInfo()
  4606. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4607. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4608. c.ServeSuccessJSON(map[string]interface{}{
  4609. "info": info,
  4610. "case_history": case_history,
  4611. })
  4612. }
  4613. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4614. template_name := c.GetString("template_name")
  4615. template_remark := c.GetString("template_remark")
  4616. doctor := c.GetAdminUserInfo().AdminUser.Id
  4617. diagnostic := c.GetString("diagnostic")
  4618. chief_conplaint := c.GetString("chief_conplain")
  4619. history_of_present_illness := c.GetString("history_of_present_illness")
  4620. past_history := c.GetString("past_history")
  4621. personal_history := c.GetString("personal_history")
  4622. family_history := c.GetString("family_history")
  4623. user_name := c.GetString("user_name")
  4624. doctor_advice := c.GetString("doctor_advice")
  4625. remark := c.GetString("remark")
  4626. //record_date := c.GetString("record_date")
  4627. //fmt.Println("record_date--------",record_date)
  4628. //timeLayout := "2006-01-02"
  4629. //loc, _ := time.LoadLocation("Local")
  4630. //
  4631. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4632. //if err != nil {
  4633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4634. // return
  4635. //}
  4636. //recordDateTime := theTime.Unix()
  4637. ctime := time.Now().Unix()
  4638. template := models.HisCaseHistoryTemplate{
  4639. HistoryOfPresentIllness: history_of_present_illness,
  4640. PastHistory: past_history,
  4641. ChiefConplaint: chief_conplaint,
  4642. PersonalHistory: personal_history,
  4643. FamilyHistory: family_history,
  4644. Diagnostic: diagnostic,
  4645. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4646. Status: 1,
  4647. Ctime: ctime,
  4648. Mtime: ctime,
  4649. RecordDate: time.Now().Unix(),
  4650. TemplateName: template_name,
  4651. TemplateRemark: template_remark,
  4652. Creator: doctor,
  4653. Modifier: doctor,
  4654. UserName: user_name,
  4655. DoctorAdvice: doctor_advice,
  4656. Remark: remark,
  4657. }
  4658. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4659. if err == nil {
  4660. c.ServeSuccessJSON(map[string]interface{}{
  4661. "msg": "保存成功",
  4662. })
  4663. } else {
  4664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4665. return
  4666. }
  4667. }
  4668. func (c *HisApiController) GetCaseHistoryTemplate() {
  4669. timeLayout := "2006-01-02"
  4670. loc, _ := time.LoadLocation("Local")
  4671. keyword := c.GetString("keyword")
  4672. start_time := c.GetString("start_time")
  4673. end_time := c.GetString("end_time")
  4674. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4675. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4676. admin := c.GetAdminUserInfo()
  4677. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4678. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4679. c.ServeSuccessJSON(map[string]interface{}{
  4680. "template": template,
  4681. //"history": history,
  4682. })
  4683. }
  4684. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4685. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4686. utils.ErrorLog("drug_name")
  4687. return enums.ErrorCodeParamWrong
  4688. }
  4689. adviceName, _ := json["drug_name"].(string)
  4690. if len(adviceName) == 0 {
  4691. utils.ErrorLog("len(advice_name) == 0")
  4692. return enums.ErrorCodeParamWrong
  4693. }
  4694. advice.AdviceName = adviceName
  4695. adviceDesc, _ := json["advice_desc"].(string)
  4696. advice.AdviceDesc = adviceDesc
  4697. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4698. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4699. advice.DrugSpec = drugSpec
  4700. }
  4701. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4702. remark, _ := json["remark"].(string)
  4703. advice.Remark = remark
  4704. }
  4705. if json["id"] == nil {
  4706. advice.DrugId = 0
  4707. } else {
  4708. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4709. drug_id := int64(json["id"].(float64))
  4710. advice.DrugId = drug_id
  4711. }
  4712. }
  4713. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4714. advice_id := int64(json["advice_id"].(float64))
  4715. advice.ID = advice_id
  4716. if advice.ID > 0 {
  4717. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4718. if err == nil {
  4719. if hisAdvice.ID > 0 {
  4720. advice.ExecutionTime = hisAdvice.ExecutionTime
  4721. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4722. advice.ExecutionState = hisAdvice.ExecutionState
  4723. advice.CheckTime = hisAdvice.CheckTime
  4724. advice.Checker = hisAdvice.Checker
  4725. advice.CheckState = hisAdvice.CheckState
  4726. advice.StartTime = hisAdvice.StartTime
  4727. advice.FeedetlSn = hisAdvice.FeedetlSn
  4728. }
  4729. }
  4730. }
  4731. }
  4732. //
  4733. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4734. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4735. // advice.ExecutionTime = execution_time
  4736. //}
  4737. //
  4738. //
  4739. //
  4740. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4741. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4742. // advice.ExecutionStaff = execution_staff
  4743. //}
  4744. //
  4745. //
  4746. //
  4747. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4748. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4749. // advice.ExecutionState = execution_state
  4750. //}
  4751. //
  4752. //
  4753. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4754. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4755. // advice.CheckTime = check_time
  4756. //}
  4757. //
  4758. //
  4759. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4760. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4761. // advice.CheckState = check_state
  4762. //}
  4763. //
  4764. //
  4765. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4766. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4767. // advice.Checker = checker
  4768. //}
  4769. //
  4770. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4771. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4772. // advice.StartTime = start_time
  4773. //}
  4774. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4775. drugSpecUnit, _ := json["min_unit"].(string)
  4776. advice.DrugSpecUnit = drugSpecUnit
  4777. }
  4778. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4779. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4780. advice.SingleDose = singleDose
  4781. }
  4782. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4783. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4784. advice.SingleDoseUnit = singleDoseUnit
  4785. }
  4786. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4787. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4788. advice.PrescribingNumber = prescribingNumber
  4789. }
  4790. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4791. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4792. advice.PrescribingNumberUnit = prescribingNumberUnit
  4793. }
  4794. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4795. deliveryWay, _ := json["delivery_way"].(string)
  4796. advice.DeliveryWay = deliveryWay
  4797. }
  4798. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4799. executionFrequency, _ := json["execution_frequency"].(string)
  4800. advice.ExecutionFrequency = executionFrequency
  4801. }
  4802. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4803. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4804. advice.Price = price
  4805. }
  4806. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4807. med_list_codg, _ := json["medical_insurance_number"].(string)
  4808. advice.MedListCodg = med_list_codg
  4809. }
  4810. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4811. day := int64(json["day"].(float64))
  4812. advice.Day = day
  4813. }
  4814. return 0
  4815. }
  4816. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4817. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4818. id := int64(json["id"].(float64))
  4819. project.ID = id
  4820. historyProject, _ := service.GetHisProjectByID(id)
  4821. project.FeedetlSn = historyProject.FeedetlSn
  4822. }
  4823. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4824. project_id := int64(json["project_id"].(float64))
  4825. project.ProjectId = project_id
  4826. }
  4827. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4828. // price := int64(json["price"].(float64))
  4829. // formatInt_price := strconv.FormatInt(price, 10)
  4830. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4831. // project.Price = float_price
  4832. // }
  4833. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4834. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4835. project.Price = price
  4836. }
  4837. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4838. total, _ := json["total"].(string)
  4839. project.Count = total
  4840. }
  4841. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4842. medical_code, _ := json["medical_code"].(string)
  4843. project.MedListCodg = medical_code
  4844. }
  4845. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4846. single_dose, _ := json["single_dose"].(string)
  4847. project.SingleDose = single_dose
  4848. }
  4849. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4850. delivery_way, _ := json["delivery_way"].(string)
  4851. project.DeliveryWay = delivery_way
  4852. }
  4853. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4854. execution_frequency, _ := json["execution_frequency"].(string)
  4855. project.ExecutionFrequency = execution_frequency
  4856. }
  4857. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4858. remark, _ := json["remark"].(string)
  4859. project.Remark = remark
  4860. }
  4861. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4862. day, _ := json["number_days"].(string)
  4863. project.Day = day
  4864. }
  4865. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4866. unit, _ := json["unit"].(string)
  4867. project.Unit = unit
  4868. }
  4869. return 0
  4870. }
  4871. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4872. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4873. id := int64(json["id"].(float64))
  4874. historyAddtions, _ := service.GetHisAdditionByID(id)
  4875. additionalCharge.ID = id
  4876. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4877. }
  4878. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4879. item_id := int64(json["item_id"].(float64))
  4880. additionalCharge.ItemId = item_id
  4881. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4882. if config.ID > 0 {
  4883. if len(config.Code) > 0 {
  4884. additionalCharge.MedListCodg = config.Code
  4885. }
  4886. }
  4887. }
  4888. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4889. // price := int64(json["price"].(float64))
  4890. // formatInt_price := strconv.FormatInt(price, 10)
  4891. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4892. // additionalCharge.Price = float_price
  4893. // }
  4894. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4895. // price := int64(json["price"].(float64))
  4896. // formatInt_price := strconv.FormatInt(price, 10)
  4897. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4898. // additionalCharge.Price = float_price
  4899. //}
  4900. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4901. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4902. additionalCharge.Price = price
  4903. }
  4904. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4905. count, _ := json["count"].(string)
  4906. counts, _ := strconv.ParseInt(count, 10, 64)
  4907. additionalCharge.Count = counts
  4908. }
  4909. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4910. item_name, _ := json["item_name"].(string)
  4911. additionalCharge.ItemName = item_name
  4912. }
  4913. return 0
  4914. }
  4915. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4916. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4917. utils.ErrorLog("drug_name")
  4918. return enums.ErrorCodeParamWrong
  4919. }
  4920. adviceName, _ := json["drug_name"].(string)
  4921. if len(adviceName) == 0 {
  4922. utils.ErrorLog("len(advice_name) == 0")
  4923. return enums.ErrorCodeParamWrong
  4924. }
  4925. advice.AdviceName = adviceName
  4926. adviceDesc, _ := json["advice_desc"].(string)
  4927. advice.AdviceDesc = adviceDesc
  4928. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4929. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4930. advice.DrugSpec = drugSpec
  4931. }
  4932. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4933. remark, _ := json["remark"].(string)
  4934. advice.Remark = remark
  4935. }
  4936. if json["id"] == nil {
  4937. advice.DrugId = 0
  4938. } else {
  4939. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4940. drug_id := int64(json["id"].(float64))
  4941. advice.DrugId = drug_id
  4942. }
  4943. }
  4944. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4945. groupno := int64(json["groupno"].(float64))
  4946. advice.Groupno = groupno
  4947. }
  4948. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4949. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4950. advice.HospApprFlag = hosp_appr_flag
  4951. }
  4952. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4953. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4954. advice.PrescribingNumber = prescribingNumber
  4955. }
  4956. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4957. // frequency_type := int64(json["frequency_type"].(float64))
  4958. // advice.FrequencyType = frequency_type
  4959. //}
  4960. //
  4961. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4962. // day_count := int64(json["day_count"].(float64))
  4963. // advice.DayCount = day_count
  4964. //}
  4965. //
  4966. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4967. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4968. // week_day, _ := json["week_day"].(string)
  4969. // advice.WeekDay = week_day
  4970. //}
  4971. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4972. drugSpecUnit, _ := json["min_unit"].(string)
  4973. advice.DrugSpecUnit = drugSpecUnit
  4974. }
  4975. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4976. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4977. advice.SingleDose = singleDose
  4978. }
  4979. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4980. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4981. advice.SingleDoseUnit = singleDoseUnit
  4982. }
  4983. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4984. deliveryWay, _ := json["delivery_way"].(string)
  4985. advice.DeliveryWay = deliveryWay
  4986. }
  4987. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4988. executionFrequency, _ := json["execution_frequency"].(string)
  4989. advice.ExecutionFrequency = executionFrequency
  4990. }
  4991. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4992. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4993. advice.Price = price
  4994. }
  4995. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4996. med_list_codg, _ := json["medical_insurance_number"].(string)
  4997. advice.MedListCodg = med_list_codg
  4998. }
  4999. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5000. day := int64(json["day"].(float64))
  5001. advice.Day = day
  5002. }
  5003. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5004. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5005. advice.PrescribingNumberUnit = prescribingNumberUnit
  5006. }
  5007. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5008. advice_id := int64(json["advice_id"].(float64))
  5009. advice.ID = advice_id
  5010. if advice.ID > 0 {
  5011. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5012. if err == nil {
  5013. if hisAdvice.ID > 0 {
  5014. advice.ExecutionTime = hisAdvice.ExecutionTime
  5015. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5016. advice.ExecutionState = hisAdvice.ExecutionState
  5017. advice.CheckTime = hisAdvice.CheckTime
  5018. advice.Checker = hisAdvice.Checker
  5019. advice.CheckState = hisAdvice.CheckState
  5020. advice.StartTime = hisAdvice.StartTime
  5021. advice.HospApprFlag = hisAdvice.HospApprFlag
  5022. advice.IsMedicine = hisAdvice.IsMedicine
  5023. if hisAdvice.UserOrgId == 10028 {
  5024. 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 {
  5025. advice.ExecutionTime = 0
  5026. advice.ExecutionStaff = 0
  5027. advice.ExecutionState = 2
  5028. advice.CheckTime = 0
  5029. advice.Checker = 0
  5030. advice.CheckState = 2
  5031. }
  5032. } else {
  5033. 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 {
  5034. advice.ExecutionTime = 0
  5035. advice.ExecutionStaff = 0
  5036. advice.ExecutionState = 2
  5037. advice.CheckTime = 0
  5038. advice.Checker = 0
  5039. advice.CheckState = 2
  5040. }
  5041. }
  5042. //advice.Groupno = hisAdvice.Groupno
  5043. }
  5044. }
  5045. }
  5046. }
  5047. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5048. //
  5049. //if drugStockConfig.IsOpen == 1 {
  5050. //
  5051. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5052. // if advice.ID == 0 { //医嘱不存在
  5053. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5054. // drug.Total = drug.Total - advice.PrescribingNumber
  5055. // service.UpdateBaseDrugLib(&drug)
  5056. //
  5057. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5058. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5059. // drug.Total = drug.Total - num
  5060. // service.UpdateBaseDrugLib(&drug)
  5061. // }
  5062. //
  5063. // } else if advice.ID > 0 { //医嘱存在
  5064. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5065. // var num float64
  5066. //
  5067. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5068. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5069. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5070. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5071. // drug.Total = drug.Total + num
  5072. // service.UpdateBaseDrugLib(&drug)
  5073. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5074. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5075. // drug.Total = drug.Total - num
  5076. // service.UpdateBaseDrugLib(&drug)
  5077. // }
  5078. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5079. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5080. // if num2 > advice.PrescribingNumber {
  5081. // num = num2 - advice.PrescribingNumber
  5082. // drug.Total = drug.Total + num
  5083. // service.UpdateBaseDrugLib(&drug)
  5084. // } else if num2 < advice.PrescribingNumber {
  5085. // num = advice.PrescribingNumber - num2
  5086. // drug.Total = drug.Total - num
  5087. // service.UpdateBaseDrugLib(&drug)
  5088. // }
  5089. //
  5090. // }
  5091. //
  5092. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5093. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5094. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5095. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5096. // if num1 > num2 {
  5097. // num = num1 - num2
  5098. // drug.Total = drug.Total + num
  5099. // service.UpdateBaseDrugLib(&drug)
  5100. // } else if num1 < num2 {
  5101. // num = num2 - num1
  5102. // drug.Total = drug.Total - num
  5103. // service.UpdateBaseDrugLib(&drug)
  5104. // }
  5105. //
  5106. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5107. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5108. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5109. // if hisAdvice.PrescribingNumber > num2 {
  5110. // num = hisAdvice.PrescribingNumber - num2
  5111. // drug.Total = drug.Total + num
  5112. // service.UpdateBaseDrugLib(&drug)
  5113. // } else if num2 < advice.PrescribingNumber {
  5114. // num = num2 - hisAdvice.PrescribingNumber
  5115. // drug.Total = drug.Total - num
  5116. // service.UpdateBaseDrugLib(&drug)
  5117. // }
  5118. //
  5119. // }
  5120. // }
  5121. // }
  5122. //}
  5123. //
  5124. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5125. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5126. // advice.ExecutionTime = execution_time
  5127. //}
  5128. //
  5129. //
  5130. //
  5131. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5132. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5133. // advice.ExecutionStaff = execution_staff
  5134. //}
  5135. //
  5136. //
  5137. //
  5138. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5139. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5140. // advice.ExecutionState = execution_state
  5141. //}
  5142. //
  5143. //
  5144. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5145. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5146. // advice.CheckTime = check_time
  5147. //}
  5148. //
  5149. //
  5150. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5151. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5152. // advice.CheckState = check_state
  5153. //}
  5154. //
  5155. //
  5156. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5157. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5158. // advice.Checker = checker
  5159. //}
  5160. //
  5161. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5162. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5163. // advice.StartTime = start_time
  5164. //}
  5165. return 0
  5166. }
  5167. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5168. project.ExecutionStaff = 0
  5169. project.ExecutionState = 2
  5170. project.ExecutionTime = 0
  5171. project.Checker = 0
  5172. project.CheckState = 2
  5173. project.CheckTime = 0
  5174. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5175. id := int64(json["id"].(float64))
  5176. project.ID = id
  5177. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5178. project.ExecutionStaff = temp_project.ExecutionStaff
  5179. project.ExecutionState = temp_project.ExecutionState
  5180. project.ExecutionTime = temp_project.ExecutionTime
  5181. project.Checker = temp_project.Checker
  5182. project.CheckState = temp_project.CheckState
  5183. project.CheckTime = temp_project.CheckTime
  5184. project.TeamId = temp_project.TeamId
  5185. }
  5186. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5187. types := int64(json["type"].(float64))
  5188. project.Type = types
  5189. }
  5190. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5191. project_id := int64(json["project_id"].(float64))
  5192. project.ProjectId = project_id
  5193. }
  5194. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5195. team_id := int64(json["team_id"].(float64))
  5196. project.TeamId = team_id
  5197. }
  5198. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5199. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5200. project.Price = price
  5201. }
  5202. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5203. total, _ := json["total"].(string)
  5204. //totals, _ := strconv.ParseInt(total, 10, 64)
  5205. project.Count = total
  5206. }
  5207. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5208. medical_code, _ := json["medical_code"].(string)
  5209. project.MedListCodg = medical_code
  5210. }
  5211. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5212. single_dose, _ := json["single_dose"].(string)
  5213. project.SingleDose = single_dose
  5214. }
  5215. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5216. delivery_way, _ := json["delivery_way"].(string)
  5217. project.DeliveryWay = delivery_way
  5218. }
  5219. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5220. execution_frequency, _ := json["execution_frequency"].(string)
  5221. project.ExecutionFrequency = execution_frequency
  5222. }
  5223. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5224. remark, _ := json["remark"].(string)
  5225. project.Remark = remark
  5226. }
  5227. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5228. day, _ := json["number_days"].(string)
  5229. project.Day = day
  5230. }
  5231. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5232. unit, _ := json["unit"].(string)
  5233. project.Unit = unit
  5234. }
  5235. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5236. // frequency_type := int64(json["frequency_type"].(float64))
  5237. // project.FrequencyType = frequency_type
  5238. //}
  5239. //
  5240. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5241. // day_count := int64(json["day_count"].(float64))
  5242. // project.DayCount = day_count
  5243. //}
  5244. //
  5245. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5246. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5247. // week_day, _ := json["week_day"].(string)
  5248. // project.WeekDay = week_day
  5249. //}
  5250. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5251. //
  5252. //if project.ID == 0 {
  5253. // if stockConfig.IsOpen == 1 {
  5254. // if project.Type == 3 {
  5255. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5256. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5257. // good.Total = good.Total - f_count
  5258. // service.UpdateGoodInfo(&good)
  5259. // }
  5260. // }
  5261. //
  5262. //} else {
  5263. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5264. //
  5265. // if stockConfig.IsOpen == 1 {
  5266. // if project.Type == 3 {
  5267. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5268. // if project.Count < temp_project.Count {
  5269. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5270. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5271. //
  5272. // other_count := f_count_two - f_count_one
  5273. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5274. // good.Total = good.Total + other_count_two
  5275. // service.UpdateGoodInfo(&good)
  5276. // } else if project.Count > temp_project.Count {
  5277. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5278. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5279. //
  5280. // other_count := f_count_one - f_count_two
  5281. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5282. // good.Total = good.Total - other_count_two
  5283. // service.UpdateGoodInfo(&good)
  5284. // }
  5285. //
  5286. // }
  5287. // }
  5288. //
  5289. //}
  5290. return 0
  5291. }
  5292. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5293. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5294. id := int64(json["id"].(float64))
  5295. additionalCharge.ID = id
  5296. }
  5297. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5298. item_id := int64(json["item_id"].(float64))
  5299. additionalCharge.ItemId = item_id
  5300. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5301. if config.ID > 0 {
  5302. if len(config.Code) > 0 {
  5303. additionalCharge.MedListCodg = config.Code
  5304. }
  5305. }
  5306. }
  5307. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5308. // price := int64(json["price"].(float64))
  5309. // formatInt_price := strconv.FormatInt(price, 10)
  5310. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5311. // additionalCharge.Price = float_price
  5312. // }
  5313. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5314. // price := int64(json["price"].(float64))
  5315. // formatInt_price := strconv.FormatInt(price, 10)
  5316. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5317. // additionalCharge.Price = float_price
  5318. //}
  5319. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5320. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5321. additionalCharge.Price = price
  5322. }
  5323. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5324. count, _ := json["count"].(string)
  5325. counts, _ := strconv.ParseInt(count, 10, 64)
  5326. additionalCharge.Count = counts
  5327. }
  5328. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5329. item_name, _ := json["item_name"].(string)
  5330. additionalCharge.ItemName = item_name
  5331. }
  5332. return 0
  5333. }
  5334. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5335. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5336. utils.ErrorLog("drug_name")
  5337. return enums.ErrorCodeParamWrong
  5338. }
  5339. adviceName, _ := json["drug_name"].(string)
  5340. if len(adviceName) == 0 {
  5341. utils.ErrorLog("len(advice_name) == 0")
  5342. return enums.ErrorCodeParamWrong
  5343. }
  5344. advice.AdviceName = adviceName
  5345. adviceDesc, _ := json["advice_desc"].(string)
  5346. advice.AdviceDesc = adviceDesc
  5347. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5348. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5349. advice.DrugSpec = drugSpec
  5350. }
  5351. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5352. remark, _ := json["remark"].(string)
  5353. advice.Remark = remark
  5354. }
  5355. if json["id"] == nil {
  5356. advice.DrugId = 0
  5357. } else {
  5358. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5359. drug_id := int64(json["id"].(float64))
  5360. advice.DrugId = drug_id
  5361. }
  5362. }
  5363. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5364. drugSpecUnit, _ := json["min_unit"].(string)
  5365. advice.DrugSpecUnit = drugSpecUnit
  5366. }
  5367. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5368. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5369. advice.SingleDose = singleDose
  5370. }
  5371. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5372. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5373. advice.SingleDoseUnit = singleDoseUnit
  5374. }
  5375. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5376. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5377. advice.PrescribingNumber = prescribingNumber
  5378. }
  5379. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5380. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5381. advice.PrescribingNumberUnit = prescribingNumberUnit
  5382. }
  5383. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5384. deliveryWay, _ := json["delivery_way"].(string)
  5385. advice.DeliveryWay = deliveryWay
  5386. }
  5387. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5388. executionFrequency, _ := json["execution_frequency"].(string)
  5389. advice.ExecutionFrequency = executionFrequency
  5390. }
  5391. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5392. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5393. advice.Price = price
  5394. }
  5395. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5396. med_list_codg, _ := json["medical_insurance_number"].(string)
  5397. advice.MedListCodg = med_list_codg
  5398. }
  5399. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5400. day := int64(json["day"].(float64))
  5401. advice.Day = day
  5402. }
  5403. advice.FrequencyType = 1
  5404. return 0
  5405. }
  5406. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5407. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5408. types := int64(json["type"].(float64))
  5409. project.Type = types
  5410. }
  5411. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5412. project_id := int64(json["project_id"].(float64))
  5413. project.ProjectId = project_id
  5414. }
  5415. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5416. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5417. project.Price = price
  5418. }
  5419. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5420. total, _ := json["total"].(string)
  5421. //totals, _ := strconv.ParseInt(total, 10, 64)
  5422. project.Count = total
  5423. }
  5424. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5425. medical_code, _ := json["medical_code"].(string)
  5426. project.MedListCodg = medical_code
  5427. }
  5428. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5429. single_dose, _ := json["single_dose"].(string)
  5430. project.SingleDose = single_dose
  5431. }
  5432. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5433. delivery_way, _ := json["delivery_way"].(string)
  5434. project.DeliveryWay = delivery_way
  5435. }
  5436. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5437. execution_frequency, _ := json["execution_frequency"].(string)
  5438. project.ExecutionFrequency = execution_frequency
  5439. }
  5440. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5441. remark, _ := json["remark"].(string)
  5442. project.Remark = remark
  5443. }
  5444. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5445. day, _ := json["number_days"].(string)
  5446. project.Day = day
  5447. }
  5448. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5449. unit, _ := json["unit"].(string)
  5450. project.Unit = unit
  5451. }
  5452. project.FrequencyType = 1
  5453. return 0
  5454. }
  5455. func (c *HisApiController) GetHisOrderList() {
  5456. page, _ := c.GetInt64("page", -1)
  5457. limit, _ := c.GetInt64("limit", -1)
  5458. start_time := c.GetString("start_time")
  5459. end_time := c.GetString("end_time")
  5460. types, _ := c.GetInt64("type", 0)
  5461. keywords := c.GetString("keywords")
  5462. p_type, _ := c.GetInt64("p_type", 0)
  5463. sort_type, _ := c.GetInt64("sort_type", 0)
  5464. charge_type, _ := c.GetInt64("charge_type", 0)
  5465. sch_type, _ := c.GetInt64("sch_type", 0)
  5466. zone_type, _ := c.GetInt64("zone_type", 0)
  5467. timeLayout := "2006-01-02"
  5468. loc, _ := time.LoadLocation("Local")
  5469. var startTime int64
  5470. if len(start_time) > 0 {
  5471. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5472. if err != nil {
  5473. //fmt.Println(err)
  5474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5475. return
  5476. }
  5477. startTime = theTime.Unix()
  5478. }
  5479. var endTime int64
  5480. if len(end_time) > 0 {
  5481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5482. if err != nil {
  5483. utils.ErrorLog(err.Error())
  5484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5485. return
  5486. }
  5487. endTime = theTime.Unix()
  5488. }
  5489. adminUser := c.GetAdminUserInfo()
  5490. org_id := adminUser.CurrentOrgId
  5491. 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)
  5492. for _, item := range order {
  5493. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5494. item.DoctorName = info.Doctor
  5495. item.DepartmentName = info.XtHisDepartment.Name
  5496. }
  5497. if err == nil {
  5498. c.ServeSuccessJSON(map[string]interface{}{
  5499. "order": order,
  5500. "total": total,
  5501. })
  5502. } else {
  5503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5504. return
  5505. }
  5506. }
  5507. func (c *HisApiController) GetHisOrder() {
  5508. patient_id, _ := c.GetInt64("patient_id", 0)
  5509. number := c.GetString("number")
  5510. adminInfo := c.GetAdminUserInfo()
  5511. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5512. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5513. if err == nil {
  5514. c.ServeSuccessJSON(map[string]interface{}{
  5515. "order": order,
  5516. "prescription": prescriptions,
  5517. })
  5518. } else {
  5519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5520. return
  5521. }
  5522. }
  5523. func (c *HisApiController) GetHisPrescriptionList() {
  5524. record_date := c.GetString("record_date")
  5525. keywords := c.GetString("keywords")
  5526. page, _ := c.GetInt64("page")
  5527. limit, _ := c.GetInt64("limit")
  5528. sch_type, _ := c.GetInt64("sch_type")
  5529. timeLayout := "2006-01-02"
  5530. loc, _ := time.LoadLocation("Local")
  5531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5532. if err != nil {
  5533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5534. return
  5535. }
  5536. recordDateTime := theTime.Unix()
  5537. adminInfo := c.GetAdminUserInfo()
  5538. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5539. //adminInfo := c.GetAdminUserInfo()
  5540. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5541. //fmt.Println(prescriptionOrder)
  5542. if err == nil {
  5543. c.ServeSuccessJSON(map[string]interface{}{
  5544. "order": prescriptionOrder,
  5545. "total": total,
  5546. })
  5547. } else {
  5548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5549. return
  5550. }
  5551. }
  5552. func (c *HisApiController) GetHisPrescriptionInfo() {
  5553. id, _ := c.GetInt64("id")
  5554. adminInfo := c.GetAdminUserInfo()
  5555. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5556. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5557. if err == nil {
  5558. c.ServeSuccessJSON(map[string]interface{}{
  5559. "order": prescriptionOrder,
  5560. "prescription": prescription,
  5561. })
  5562. } else {
  5563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5564. return
  5565. }
  5566. }
  5567. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5568. adminUser := c.GetAdminUserInfo()
  5569. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5570. c.ServeSuccessJSON(map[string]interface{}{
  5571. "config": config,
  5572. })
  5573. }
  5574. type ResultTwo struct {
  5575. ErrMsg interface{} `json:"err_msg"`
  5576. InfRefmsgid string `json:"inf_refmsgid"`
  5577. Infcode int64 `json:"infcode"`
  5578. Output struct {
  5579. Baseinfo struct {
  5580. Age float64 `json:"age"`
  5581. Brdy string `json:"brdy"`
  5582. Certno string `json:"certno"`
  5583. Gend string `json:"gend"`
  5584. Naty string `json:"naty"`
  5585. PsnCertType string `json:"psn_cert_type"`
  5586. PsnName string `json:"psn_name"`
  5587. PsnNo string `json:"psn_no"`
  5588. } `json:"baseinfo"`
  5589. Idetinfo []interface{} `json:"idetinfo"`
  5590. Iinfo []struct {
  5591. Balc float64 `json:"balc"`
  5592. CvlservFlag string `json:"cvlserv_flag"`
  5593. EmpName string `json:"emp_name"`
  5594. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5595. Insutype string `json:"insutype"`
  5596. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5597. PausInsuDate interface{} `json:"paus_insu_date"`
  5598. PsnInsuDate string `json:"psn_insu_date"`
  5599. PsnInsuStas string `json:"psn_insu_stas"`
  5600. PsnType string `json:"psn_type"`
  5601. } `json:"insuinfo"`
  5602. } `json:"output"`
  5603. RefmsgTime string `json:"refmsg_time"`
  5604. RespondTime string `json:"respond_time"`
  5605. Signtype interface{} `json:"signtype"`
  5606. WarnInfo interface{} `json:"warn_info"`
  5607. }
  5608. type ResultThree struct {
  5609. Cainfo interface{} `json:"cainfo"`
  5610. ErrMsg interface{} `json:"err_msg"`
  5611. InfRefmsgid string `json:"inf_refmsgid"`
  5612. Infcode int64 `json:"infcode"`
  5613. Output struct {
  5614. Data struct {
  5615. IptOtpNo string `json:"ipt_otp_no"`
  5616. MdtrtID string `json:"mdtrt_id"`
  5617. PsnNo string `json:"psn_no"`
  5618. } `json:"data"`
  5619. } `json:"output"`
  5620. RefmsgTime string `json:"refmsg_time"`
  5621. RespondTime string `json:"respond_time"`
  5622. Signtype interface{} `json:"signtype"`
  5623. WarnMsg interface{} `json:"warn_msg"`
  5624. }
  5625. type ResultFour struct {
  5626. Cainfo string `json:"cainfo"`
  5627. ErrMsg string `json:"err_msg"`
  5628. InfRefmsgid string `json:"inf_refmsgid"`
  5629. Infcode int64 `json:"infcode"`
  5630. Output struct {
  5631. Result []struct {
  5632. BasMednFlag string `json:"bas_medn_flag"`
  5633. ChldMedcFlag string `json:"chld_medc_flag"`
  5634. ChrgitmLv string `json:"chrgitm_lv"`
  5635. Cnt float64 `json:"cnt"`
  5636. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5637. DrtReimFlag string `json:"drt_reim_flag"`
  5638. FeedetlSn string `json:"feedetl_sn"`
  5639. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5640. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5641. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5642. ListSpItemFlag string `json:"list_sp_item_flag"`
  5643. LmtUsedFlag string `json:"lmt_used_flag"`
  5644. MedChrgitmType string `json:"med_chrgitm_type"`
  5645. Memo string `json:"memo"`
  5646. OverlmtAmt float64 `json:"overlmt_amt"`
  5647. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5648. Pric float64 `json:"pric"`
  5649. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5650. SelfpayProp float64 `json:"selfpay_prop"`
  5651. } `json:"result"`
  5652. } `json:"output"`
  5653. RefmsgTime string `json:"refmsg_time"`
  5654. RespondTime string `json:"respond_time"`
  5655. Signtype string `json:"signtype"`
  5656. WarnMsg string `json:"warn_msg"`
  5657. }
  5658. type ResultFive struct {
  5659. Insutype string `json:"insutype"`
  5660. }
  5661. type ResultSix struct {
  5662. Cainfo interface{} `json:"cainfo"`
  5663. ErrMsg interface{} `json:"err_msg"`
  5664. InfRefmsgid string `json:"inf_refmsgid"`
  5665. Infcode int64 `json:"infcode"`
  5666. Output struct {
  5667. } `json:"output"`
  5668. RefmsgTime string `json:"refmsg_time"`
  5669. RespondTime string `json:"respond_time"`
  5670. Signtype interface{} `json:"signtype"`
  5671. WarnMsg interface{} `json:"warn_msg"`
  5672. }
  5673. type ResultSeven struct {
  5674. Cainfo string `json:"cainfo"`
  5675. ErrMsg string `json:"err_msg"`
  5676. InfRefmsgid string `json:"inf_refmsgid"`
  5677. Infcode int64 `json:"infcode"`
  5678. Output struct {
  5679. Setldetail []interface{} `json:"setldetail"`
  5680. Setlinfo struct {
  5681. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5682. AcctPay float64 `json:"acct_pay"`
  5683. ActPayDedc float64 `json:"act_pay_dedc"`
  5684. Age float64 `json:"age"`
  5685. Balc float64 `json:"balc"`
  5686. Brdy string `json:"brdy"`
  5687. Certno string `json:"certno"`
  5688. ClrOptins string `json:"clr_optins"`
  5689. ClrType string `json:"clr_type"`
  5690. ClrWay string `json:"clr_way"`
  5691. CvlservFlag string `json:"cvlserv_flag"`
  5692. CvlservPay float64 `json:"cvlserv_pay"`
  5693. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5694. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5695. Gend string `json:"gend"`
  5696. HifesPay float64 `json:"hifes_pay"`
  5697. HifmiPay float64 `json:"hifmi_pay"`
  5698. HifobPay float64 `json:"hifob_pay"`
  5699. HifpPay float64 `json:"hifp_pay"`
  5700. HospPartAmt float64 `json:"hosp_part_amt"`
  5701. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5702. Insutype string `json:"insutype"`
  5703. MafPay float64 `json:"maf_pay"`
  5704. MdtrtCertType string `json:"mdtrt_cert_type"`
  5705. MdtrtID string `json:"mdtrt_id"`
  5706. MedType string `json:"med_type"`
  5707. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5708. MedinsSetlID string `json:"medins_setl_id"`
  5709. Naty string `json:"naty"`
  5710. OthPay float64 `json:"oth_pay"`
  5711. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5712. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5713. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5714. PsnCashPay float64 `json:"psn_cash_pay"`
  5715. PsnCertType string `json:"psn_cert_type"`
  5716. PsnName string `json:"psn_name"`
  5717. PsnNo string `json:"psn_no"`
  5718. PsnPartAmt float64 `json:"psn_part_amt"`
  5719. PsnType string `json:"psn_type"`
  5720. SetlID string `json:"setl_id"`
  5721. SetlTime string `json:"setl_time"`
  5722. } `json:"setlinfo"`
  5723. } `json:"output"`
  5724. RefmsgTime string `json:"refmsg_time"`
  5725. RespondTime string `json:"respond_time"`
  5726. Signtype interface{} `json:"signtype"`
  5727. WarnMsg interface{} `json:"warn_msg"`
  5728. }
  5729. type ResultEight struct {
  5730. Cainfo string `json:"cainfo"`
  5731. ErrMsg string `json:"err_msg"`
  5732. InfRefmsgid string `json:"inf_refmsgid"`
  5733. Infcode int64 `json:"infcode"`
  5734. Output struct {
  5735. Stmtinfo struct {
  5736. SetlOptins string `json:"setl_optins"`
  5737. StmtRslt string `json:"stmt_rslt"`
  5738. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5739. } `json:"stmtinfo"`
  5740. } `json:"output"`
  5741. RefmsgTime string `json:"refmsg_time"`
  5742. RespondTime string `json:"respond_time"`
  5743. Signtype interface{} `json:"signtype"`
  5744. WarnMsg interface{} `json:"warn_msg"`
  5745. }
  5746. type ResultNine struct {
  5747. Cainfo string `json:"cainfo"`
  5748. ErrMsg string `json:"err_msg"`
  5749. InfRefmsgid string `json:"inf_refmsgid"`
  5750. Infcode int64 `json:"infcode"`
  5751. Output struct {
  5752. FileQuryNo string `json:"file_qury_no"`
  5753. } `json:"output"`
  5754. RefmsgTime string `json:"refmsg_time"`
  5755. RespondTime string `json:"respond_time"`
  5756. Signtype interface{} `json:"signtype"`
  5757. WarnMsg interface{} `json:"warn_msg"`
  5758. }
  5759. type ResultTen struct {
  5760. Cainfo string `json:"cainfo"`
  5761. ErrMsg string `json:"err_msg"`
  5762. InfRefmsgid string `json:"inf_refmsgid"`
  5763. Infcode int64 `json:"infcode"`
  5764. Output struct {
  5765. DldEndtime string `json:"dld_endtime"`
  5766. FileQuryNo string `json:"file_qury_no"`
  5767. Filename string `json:"filename"`
  5768. } `json:"output"`
  5769. RefmsgTime string `json:"refmsg_time"`
  5770. RespondTime string `json:"respond_time"`
  5771. Signtype interface{} `json:"signtype"`
  5772. WarnMsg interface{} `json:"warn_msg"`
  5773. }
  5774. type ResultEleven struct {
  5775. Cainfo string `json:"cainfo"`
  5776. ErrMsg string `json:"err_msg"`
  5777. InfRefmsgid string `json:"inf_refmsgid"`
  5778. Infcode int64 `json:"infcode"`
  5779. Output struct {
  5780. Setlinfo struct {
  5781. FixmedinsName string `json:"fixmedins_name"`
  5782. FixmedinsCode string `json:"fixmedins_code"`
  5783. PsnNo string `json:"psn_no"`
  5784. PsnName string `json:"psn_name"`
  5785. HifobPay float64 `json:"hifob_pay"`
  5786. Gend string `json:"gend"`
  5787. Brdy string `json:"brdy"`
  5788. PsnCertType string `json:"psn_cert_type"`
  5789. PsnType string `json:"psn_type"`
  5790. EmpName string `json:"emp_name"`
  5791. Certno string `json:"certno"`
  5792. Insutype string `json:"insutype"`
  5793. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5794. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5795. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5796. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5797. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5798. ActPayDedc float64 `json:"act_pay_dedc"`
  5799. HifpPay float64 `json:"hifp_pay"`
  5800. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5801. CvlservPay float64 `json:"cvlserv_pay"`
  5802. HifesPay float64 `json:"hifes_pay"`
  5803. HifmiPay float64 `json:"hifmi_pay"`
  5804. MafPay float64 `json:"maf_pay"`
  5805. OthPay float64 `json:"oth_pay"`
  5806. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5807. PsnPay float64 `json:"psn_pay"`
  5808. AcctPay float64 `json:"acct_pay"`
  5809. CashPayamt float64 `json:"cash_payamt"`
  5810. Balc float64 `json:"balc"`
  5811. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5812. MedinsSetlId string `json:"medins_setl_id"`
  5813. RefdSetlFlag string `json:"refd_setl_flag"`
  5814. SetlTime string `json:"setl_time"`
  5815. MedType string `json:"med_type"`
  5816. } `json:"setlinfo"`
  5817. } `json:"output"`
  5818. RefmsgTime string `json:"refmsg_time"`
  5819. RespondTime string `json:"respond_time"`
  5820. Signtype interface{} `json:"signtype"`
  5821. WarnMsg interface{} `json:"warn_msg"`
  5822. }
  5823. type Custom struct {
  5824. DetItemFeeSumamt string
  5825. Cut string
  5826. FeedetlSn string
  5827. Price string
  5828. MedListCodg string
  5829. Type int64
  5830. AdviceId int64
  5831. ProjectId int64
  5832. ItemId int64
  5833. }
  5834. // 获取个人信息----挂号-----上传就诊信息
  5835. func (c *HisApiController) GetRegisterInfo() {
  5836. id, _ := c.GetInt64("id")
  5837. record_time := c.GetString("record_time")
  5838. settlementValue, _ := c.GetInt64("settlement_value")
  5839. medical_insurance_card := c.GetString("medical_insurance_card")
  5840. name := c.GetString("name")
  5841. id_card_type, _ := c.GetInt64("id_card_type")
  5842. certificates, _ := c.GetInt64("certificates")
  5843. medical_care, _ := c.GetInt64("medical_care")
  5844. birthday := c.GetString("birthday")
  5845. age, _ := c.GetInt64("age")
  5846. id_card := c.GetString("id_card")
  5847. register_type, _ := c.GetInt64("register")
  5848. doctor, _ := c.GetInt64("doctor")
  5849. department, _ := c.GetInt64("department")
  5850. gender, _ := c.GetInt64("sex")
  5851. phone := c.GetString("phone")
  5852. registration_fee, _ := c.GetFloat("registration_fee")
  5853. medical_expenses, _ := c.GetFloat("medical_expenses")
  5854. social_type, _ := c.GetInt64("social_type")
  5855. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5856. diagnosis_ids := c.GetString("diagnosis")
  5857. sick_type, _ := c.GetInt64("sick_type")
  5858. reg_type := c.GetString("p_type")
  5859. timeLayout := "2006-01-02"
  5860. loc, _ := time.LoadLocation("Local")
  5861. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5862. birthUnix := birthdays.Unix()
  5863. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5864. if err != nil {
  5865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5866. return
  5867. }
  5868. recordDateTime := theTime.Unix()
  5869. adminInfo := c.GetAdminUserInfo()
  5870. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5871. if tempPatient.ID == 0 {
  5872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5873. return
  5874. }
  5875. var patient service.Patients
  5876. if id == 0 {
  5877. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5878. } else {
  5879. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5880. }
  5881. if patient.ID == 0 {
  5882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5883. return
  5884. }
  5885. if len(patient.IdCardNo) == 0 {
  5886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5887. return
  5888. }
  5889. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5890. if len(his) >= 1 {
  5891. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5892. if len(his) >= 1 && order.ID == 0 {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5894. return
  5895. }
  5896. }
  5897. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5898. fmt.Println(timeStr)
  5899. timeArr := strings.Split(timeStr, " ")
  5900. fmt.Println(timeArr)
  5901. timeArrTwo := strings.Split(timeArr[0], "-")
  5902. timeArrThree := strings.Split(timeArr[1], ":")
  5903. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5904. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5905. if len(lists) == 0 {
  5906. var hisPatient models.XtHisPatient
  5907. hisPatient = models.XtHisPatient{
  5908. Name: name,
  5909. Age: age,
  5910. Gender: gender,
  5911. Birthday: birthUnix,
  5912. Phone: phone,
  5913. MedicalTreatmentType: medical_care,
  5914. IdType: certificates,
  5915. IdCardNo: id_card,
  5916. BalanceAccountsType: settlementValue,
  5917. SocialType: social_type,
  5918. MedicalInsuranceNumber: medical_insurance_card,
  5919. RegisterType: register_type,
  5920. RegisterCost: registration_fee,
  5921. TreatmentCost: medical_expenses,
  5922. AdminUserId: adminInfo.AdminUser.Id,
  5923. UserOrgId: adminInfo.CurrentOrgId,
  5924. Status: 1,
  5925. RecordDate: recordDateTime,
  5926. IsReturn: 1,
  5927. PatientId: patient.ID,
  5928. Ctime: time.Now().Unix(),
  5929. Mtime: time.Now().Unix(),
  5930. Number: str,
  5931. IdCardType: id_card_type,
  5932. Departments: department,
  5933. Doctor: doctor,
  5934. PType: reg_type,
  5935. Diagnosis: diagnosis_ids,
  5936. SickType: sick_type,
  5937. }
  5938. service.CreateHisPatient(&hisPatient)
  5939. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5940. c.ServeSuccessJSON(map[string]interface{}{
  5941. "his_info": hisPatient,
  5942. })
  5943. } else {
  5944. //chrgBchno := rand.Intn(1000000) + 10000
  5945. var hisPatient models.XtHisPatient
  5946. hisPatient = models.XtHisPatient{
  5947. Name: name,
  5948. Age: age,
  5949. Gender: gender,
  5950. Birthday: birthUnix,
  5951. Phone: phone,
  5952. MedicalTreatmentType: medical_care,
  5953. IdType: certificates,
  5954. IdCardNo: id_card,
  5955. BalanceAccountsType: settlementValue,
  5956. SocialType: social_type,
  5957. MedicalInsuranceNumber: medical_insurance_card,
  5958. RegisterType: register_type,
  5959. RegisterCost: registration_fee,
  5960. TreatmentCost: medical_expenses,
  5961. AdminUserId: adminInfo.AdminUser.Id,
  5962. UserOrgId: adminInfo.CurrentOrgId,
  5963. Status: 1,
  5964. RecordDate: recordDateTime,
  5965. IsReturn: 1,
  5966. PatientId: patient.ID,
  5967. Ctime: time.Now().Unix(),
  5968. Mtime: time.Now().Unix(),
  5969. Number: str,
  5970. IdCardType: id_card_type,
  5971. Departments: department,
  5972. Doctor: doctor,
  5973. PType: reg_type,
  5974. Diagnosis: diagnosis_ids,
  5975. SickType: sick_type,
  5976. }
  5977. service.CreateHisPatient(&hisPatient)
  5978. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5979. c.ServeSuccessJSON(map[string]interface{}{
  5980. "his_info": hisPatient,
  5981. })
  5982. }
  5983. }
  5984. // 上传明细----结算
  5985. func (c *HisApiController) GetUploadInfo() {
  5986. id, _ := c.GetInt64("id")
  5987. record_time := c.GetString("record_time")
  5988. his_patient_id, _ := c.GetInt64("his_patient_id")
  5989. oth_desc := c.GetString("oth_desc")
  5990. pay_way, _ := c.GetInt64("pay_way")
  5991. pay_ways := c.GetString("pay_ways")
  5992. pay_price, _ := c.GetFloat("pay_price")
  5993. pay_card_no := c.GetString("pay_card_no")
  5994. discount_price, _ := c.GetFloat("discount_price")
  5995. preferential_price, _ := c.GetFloat("preferential_price")
  5996. reality_price, _ := c.GetFloat("reality_price")
  5997. found_price, _ := c.GetFloat("found_price")
  5998. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5999. private_price, _ := c.GetFloat("private_price")
  6000. timeLayout := "2006-01-02"
  6001. loc, _ := time.LoadLocation("Local")
  6002. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6003. fapiao_code := c.GetString("fapiao_code")
  6004. fapiao_number := c.GetString("fapiao_number")
  6005. diagnosis_id := c.GetString("diagnosis")
  6006. sick_type, _ := c.GetInt64("sick_type")
  6007. reg_type, _ := c.GetInt64("p_type")
  6008. order_id, _ := c.GetInt64("order_id")
  6009. cash_pay := c.GetString("cash_pay")
  6010. wechat_pay := c.GetString("wechat_pay")
  6011. ali_pay := c.GetString("ali_pay")
  6012. jifen_pay := c.GetString("jifen_pay")
  6013. band_card_pay := c.GetString("band_card_pay")
  6014. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6015. tmp_decimal := c.GetString("tmp_decimal")
  6016. var decimal float64 //本次使用的押金
  6017. var errmsg error
  6018. tx := service.XTWriteDB().Begin() //开了事务
  6019. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6020. defer func() {
  6021. if errmsg != nil {
  6022. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6023. tx.Rollback()
  6024. } else {
  6025. tx.Commit()
  6026. }
  6027. }()
  6028. fmt.Println("dec_way", dec_way)
  6029. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6030. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6031. return
  6032. }
  6033. if len(tmp_decimal) > 0 {
  6034. if tmp_decimal[0] == 45 {
  6035. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6036. return
  6037. }
  6038. }
  6039. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6040. fmt.Println(errs)
  6041. decimal = tt
  6042. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6043. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6045. if err != nil {
  6046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6047. return
  6048. }
  6049. recordDateTime := theTime.Unix()
  6050. adminUser := c.GetAdminUserInfo()
  6051. var prescriptions []*models.HisPrescription
  6052. var prescriptionsOne []*models.HisPrescription
  6053. var start_time int64
  6054. var end_time int64
  6055. ids_str := c.GetString("ids")
  6056. ids_arr := strings.Split(ids_str, ",")
  6057. if tempOrder.ID == 0 {
  6058. if settle_accounts_type == 1 { //日结
  6059. fmt.Println(reg_type)
  6060. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6061. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6062. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6063. } else {
  6064. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6065. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6066. }
  6067. } else { //月结
  6068. start_time_str := c.GetString("start_time")
  6069. end_time_str := c.GetString("end_time")
  6070. timeLayout := "2006-01-02"
  6071. loc, _ := time.LoadLocation("Local")
  6072. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6073. if err != nil {
  6074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6075. return
  6076. }
  6077. recordStartTime := theStartTime.Unix()
  6078. start_time = recordStartTime
  6079. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6080. if err != nil {
  6081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6082. return
  6083. }
  6084. recordEndTime := theEndTime.Unix()
  6085. end_time = recordEndTime
  6086. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6087. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6088. }
  6089. var goods []*models.DialysisBeforePrepareGoods
  6090. var newGoods []*models.NewDialysisBeforePrepareGoods
  6091. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6092. var infos []*models.HisDoctorAdviceInfo
  6093. var infoList []*models.HisDoctorAdviceInfo
  6094. var hisAdvice []*models.HisDoctorAdviceInfo
  6095. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6096. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6097. //判断库存不足
  6098. //结算出库开关
  6099. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6100. if settConfig.IsOpen == 1 {
  6101. //判断库存的地方
  6102. for _, info := range prescriptions {
  6103. if info.Type == 1 {
  6104. infos = append(infos, info.HisDoctorAdviceInfo...)
  6105. }
  6106. if info.Type == 2 {
  6107. for _, sumItem := range info.HisPrescriptionProject {
  6108. if sumItem.Type == 3 {
  6109. var good models.DialysisBeforePrepareGoods
  6110. var newGood models.NewDialysisBeforePrepareGoods
  6111. good.GoodId = sumItem.GoodInfo.ID
  6112. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6113. count, _ := strconv.Atoi(sumItem.Count)
  6114. good.Count = int64(count)
  6115. good.StorehouseId = houseConfig.StorehouseOutInfo
  6116. good.ProjectId = sumItem.ID
  6117. goods = append(goods, &good)
  6118. newGood.GoodId = sumItem.GoodInfo.ID
  6119. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6120. count2, _ := strconv.Atoi(sumItem.Count)
  6121. newGood.Count = int64(count2)
  6122. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6123. newGood.ProjectId = sumItem.ID
  6124. newGoods = append(newGoods, &newGood)
  6125. }
  6126. }
  6127. }
  6128. }
  6129. for _, info := range prescriptionsOne {
  6130. if info.Type == 1 {
  6131. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6132. }
  6133. if info.Type == 2 {
  6134. for _, sumItem := range info.HisPrescriptionProject {
  6135. if sumItem.Type == 3 {
  6136. var newGood models.NewDialysisBeforePrepareGoods
  6137. newGood.GoodId = sumItem.GoodInfo.ID
  6138. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6139. count2, _ := strconv.Atoi(sumItem.Count)
  6140. newGood.Count = int64(count2)
  6141. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6142. newGood.ProjectId = sumItem.ID
  6143. newGoodOne = append(newGoodOne, &newGood)
  6144. }
  6145. }
  6146. }
  6147. }
  6148. //判断
  6149. for _, itemOne := range infos {
  6150. for _, itemTwo := range hisAdvice {
  6151. if itemOne.DrugId == itemTwo.DrugId {
  6152. itemTwo.Child = append(itemTwo.Child, itemOne)
  6153. }
  6154. }
  6155. }
  6156. for _, itemTwo := range hisAdvice {
  6157. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6158. var sum_out_count int64
  6159. for _, itemThree := range itemTwo.Child {
  6160. var prescribing_number int64
  6161. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6162. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6163. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6164. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6165. }
  6166. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6167. prescribing_number = parseIntPrescribingNumber
  6168. }
  6169. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6170. prescribing_number = parseIntPrescribingNumber
  6171. }
  6172. sum_out_count += prescribing_number
  6173. }
  6174. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6175. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6176. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6177. if sum_out_count > drugStockOut.FlushCount {
  6178. c.ServeSuccessJSON(map[string]interface{}{
  6179. "msg": "2",
  6180. "drug": medical,
  6181. })
  6182. return
  6183. }
  6184. }
  6185. fmt.Println("newGoods99999988882os", newGoods)
  6186. for _, itemOne := range newGoods {
  6187. for _, item := range newGoodOne {
  6188. if itemOne.GoodId == item.GoodId {
  6189. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6190. }
  6191. }
  6192. }
  6193. for _, item := range newGoodOne {
  6194. var sum_out_count_one int64
  6195. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6196. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6197. sum_out_count_one += itemOne.Count
  6198. }
  6199. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6200. fmt.Println("sum_out_count_one", sum_out_count_one)
  6201. fmt.Println("list.FlushCount", list.FlushCount)
  6202. if sum_out_count_one > list.FlushCount {
  6203. c.ServeSuccessJSON(map[string]interface{}{
  6204. "msg": "3",
  6205. "good": good,
  6206. })
  6207. return
  6208. }
  6209. }
  6210. }
  6211. timestamp := time.Now().Unix()
  6212. tempTime := time.Unix(timestamp, 0)
  6213. timeFormat := tempTime.Format("20060102150405")
  6214. chrgBchno := rand.Intn(100000) + 10000
  6215. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6216. strconv.FormatInt(his.PatientId, 10)
  6217. var ids []int64
  6218. for _, item := range prescriptions {
  6219. ids = append(ids, item.ID)
  6220. }
  6221. var total float64
  6222. for _, item := range prescriptions {
  6223. fmt.Println(item)
  6224. if item.Type == 1 { //药品
  6225. for _, subItem := range item.HisDoctorAdviceInfo {
  6226. total = total + (subItem.Price * subItem.PrescribingNumber)
  6227. }
  6228. }
  6229. if item.Type == 2 { //项目
  6230. for _, subItem := range item.HisPrescriptionProject {
  6231. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6232. total = total + (subItem.Price * cnt)
  6233. }
  6234. }
  6235. for _, subItem := range item.HisAdditionalCharge {
  6236. total = total + (subItem.Price * float64(subItem.Count))
  6237. }
  6238. }
  6239. if reg_type == 1111 || reg_type == 1112 {
  6240. reg_type = 11
  6241. }
  6242. tm := time.Unix(time.Now().Unix(), 0)
  6243. allTotal := fmt.Sprintf("%.4f", total)
  6244. totals, _ := strconv.ParseFloat(allTotal, 64)
  6245. order := &models.HisOrder{
  6246. UserOrgId: adminUser.CurrentOrgId,
  6247. HisPatientId: his.ID,
  6248. PatientId: id,
  6249. SettleAccountsDate: recordDateTime,
  6250. Ctime: time.Now().Unix(),
  6251. Mtime: time.Now().Unix(),
  6252. Status: 1,
  6253. OrderStatus: 2,
  6254. MdtrtId: his.Number,
  6255. Number: chrg_bchno,
  6256. MedfeeSumamt: totals,
  6257. PayWay: pay_way,
  6258. PayWays: pay_ways,
  6259. PayPrice: pay_price,
  6260. MedType: strconv.Itoa(int(reg_type)),
  6261. PayCardNo: pay_card_no,
  6262. DiscountPrice: discount_price,
  6263. PreferentialPrice: preferential_price,
  6264. RealityPrice: reality_price,
  6265. FoundPrice: found_price,
  6266. MedicalInsurancePrice: medical_insurance_price,
  6267. PrivatePrice: private_price,
  6268. SettleEndTime: end_time,
  6269. SettleStartTime: start_time,
  6270. PsnPartAmt: totals,
  6271. PsnCashPay: totals,
  6272. SettleType: settle_accounts_type,
  6273. FaPiaoCode: fapiao_code,
  6274. FaPiaoNumber: fapiao_number,
  6275. Diagnosis: diagnosis_id,
  6276. PType: 2,
  6277. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6278. Decimal: decimal,
  6279. OthDesc: oth_desc,
  6280. CashPay: cash_pay,
  6281. WechatPay: wechat_pay,
  6282. AliPay: ali_pay,
  6283. JifenPay: jifen_pay,
  6284. BandCardPay: band_card_pay,
  6285. }
  6286. err = service.CreateOrderTX(order, tx)
  6287. if err != nil {
  6288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6289. return
  6290. }
  6291. var customs []*Custom
  6292. for _, item := range prescriptions {
  6293. if item.Type == 1 { //药品a
  6294. for _, subItem := range item.HisDoctorAdviceInfo {
  6295. cus := &Custom{
  6296. AdviceId: subItem.ID,
  6297. ProjectId: 0,
  6298. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6299. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6300. FeedetlSn: subItem.FeedetlSn,
  6301. Price: fmt.Sprintf("%.4f", subItem.Price),
  6302. MedListCodg: subItem.MedListCodg,
  6303. Type: 1,
  6304. }
  6305. customs = append(customs, cus)
  6306. }
  6307. }
  6308. if item.Type == 2 { //项目
  6309. for _, subItem := range item.HisPrescriptionProject {
  6310. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6311. cus := &Custom{
  6312. AdviceId: 0,
  6313. ProjectId: subItem.ID,
  6314. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6315. Cut: fmt.Sprintf("%.4f", cnt),
  6316. FeedetlSn: subItem.FeedetlSn,
  6317. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6318. MedListCodg: subItem.MedListCodg,
  6319. Type: 2,
  6320. }
  6321. customs = append(customs, cus)
  6322. }
  6323. }
  6324. for _, item := range item.HisAdditionalCharge {
  6325. cus := &Custom{
  6326. ItemId: item.ID,
  6327. AdviceId: 0,
  6328. ProjectId: 0,
  6329. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6330. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6331. FeedetlSn: item.FeedetlSn,
  6332. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6333. MedListCodg: item.XtHisAddtionConfig.Code,
  6334. Type: 3,
  6335. }
  6336. customs = append(customs, cus)
  6337. }
  6338. }
  6339. for _, item := range customs {
  6340. var advice_id int64 = 0
  6341. var project_id int64 = 0
  6342. var item_id int64 = 0
  6343. var types int64 = 0
  6344. if item.Type == 1 {
  6345. advice_id = item.AdviceId
  6346. project_id = 0
  6347. item_id = 0
  6348. } else if item.Type == 2 {
  6349. advice_id = 0
  6350. item_id = 0
  6351. project_id = item.ProjectId
  6352. } else if item.Type == 3 {
  6353. advice_id = 0
  6354. item_id = item.ItemId
  6355. project_id = 0
  6356. }
  6357. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6358. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6359. pric, _ := strconv.ParseFloat(item.Price, 32)
  6360. info := &models.HisOrderInfo{
  6361. OrderNumber: order.Number,
  6362. UploadDate: time.Now().Unix(),
  6363. AdviceId: advice_id,
  6364. DetItemFeeSumamt: detItemFeeSumamt,
  6365. Cnt: cut,
  6366. Pric: pric,
  6367. PatientId: id,
  6368. Status: 1,
  6369. Mtime: time.Now().Unix(),
  6370. Ctime: time.Now().Unix(),
  6371. UserOrgId: adminUser.CurrentOrgId,
  6372. HisPatientId: his.ID,
  6373. OrderId: order.ID,
  6374. ProjectId: project_id,
  6375. Type: types,
  6376. ItemId: item_id,
  6377. }
  6378. service.CreateOrderInfoTX(info, tx)
  6379. }
  6380. his.Diagnosis = diagnosis_id
  6381. his.SickType = sick_type
  6382. his.RegisterType = reg_type
  6383. his.MedicalTreatmentType = reg_type
  6384. service.UpdataHisPateintTX(&his, tx)
  6385. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6386. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6387. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6388. //判断是否使用了押金
  6389. if dec_way == "true" {
  6390. tmpstring := strconv.FormatInt(order.ID, 10)
  6391. //扣押金
  6392. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6393. order.Decimal = decimal
  6394. service.UpDateOrderTwo(order, tx)
  6395. if errmsg != nil {
  6396. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6397. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6398. return
  6399. }
  6400. }
  6401. if err == nil {
  6402. for _, info := range prescriptions {
  6403. if info.Type == 1 {
  6404. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6405. }
  6406. if info.Type == 2 {
  6407. for _, sumItem := range info.HisPrescriptionProject {
  6408. if sumItem.Type == 3 {
  6409. var good models.DialysisBeforePrepareGoods
  6410. var newGood models.NewDialysisBeforePrepareGoods
  6411. var oldGood models.OldDialysisBeforePrepareGoods
  6412. good.GoodId = sumItem.GoodInfo.ID
  6413. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6414. count, _ := strconv.Atoi(sumItem.Count)
  6415. good.Count = int64(count)
  6416. good.StorehouseId = houseConfig.StorehouseOutInfo
  6417. good.ProjectId = sumItem.ID
  6418. good.PatientId = sumItem.PatientId
  6419. goods = append(goods, &good)
  6420. newGood.GoodId = sumItem.GoodInfo.ID
  6421. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6422. count2, _ := strconv.Atoi(sumItem.Count)
  6423. newGood.Count = int64(count2)
  6424. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6425. newGood.ProjectId = sumItem.ID
  6426. newGood.PatientId = sumItem.HisPatientId
  6427. newGoods = append(newGoods, &newGood)
  6428. oldGood.GoodId = sumItem.GoodInfo.ID
  6429. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6430. count3, _ := strconv.Atoi(sumItem.Count)
  6431. oldGood.Count = int64(count3)
  6432. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6433. oldGood.ProjectId = sumItem.ID
  6434. oldGood.RecordDate = sumItem.RecordDate
  6435. oldGood.PatientId = sumItem.HisPatientId
  6436. oldGoods = append(oldGoods, &oldGood)
  6437. }
  6438. }
  6439. }
  6440. }
  6441. if settConfig.IsOpen == 1 {
  6442. for _, item := range infoList {
  6443. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6444. if medical.IsUse == 2 {
  6445. //药品出库
  6446. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6447. //查询默认仓库
  6448. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6449. //查询默认仓库剩余多少库存
  6450. var sum_count int64
  6451. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6452. for _, its := range stockInfo {
  6453. if its.MaxUnit == medical.MaxUnit {
  6454. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6455. }
  6456. sum_count += its.StockMaxNumber + its.StockMinNumber
  6457. }
  6458. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6459. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6460. }
  6461. }
  6462. orgId := c.GetAdminUserInfo().CurrentOrgId
  6463. if len(oldGoods) > 0 {
  6464. timeStr := time.Now().Format("2006-01-02")
  6465. timeArr := strings.Split(timeStr, "-")
  6466. total, _ := service.FindAllWarehouseOut(orgId)
  6467. total = total + 1
  6468. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6469. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6470. number = number + total
  6471. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6472. operation_time := time.Now().Unix()
  6473. creater := c.GetAdminUserInfo().AdminUser.Id
  6474. //查询默认出库仓库库存
  6475. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6476. recordDateStr := time.Now().Format("2006-01-02")
  6477. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6478. nowtime := recordDate.Unix()
  6479. warehouseOut := models.WarehouseOut{
  6480. WarehouseOutOrderNumber: warehousing_out_order,
  6481. OperationTime: operation_time,
  6482. OrgId: orgId,
  6483. Creater: creater,
  6484. Ctime: time.Now().Unix(),
  6485. Status: 1,
  6486. WarehouseOutTime: nowtime,
  6487. Type: 1,
  6488. StorehouseId: storeConfig.StorehouseOutInfo,
  6489. IsCheck: 1,
  6490. OrderId: order.ID,
  6491. IsSys: 5,
  6492. }
  6493. //查询是否生成出库单
  6494. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6495. if out.ID == 0 {
  6496. service.AddSigleWarehouseOut(&warehouseOut)
  6497. }
  6498. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6499. for _, item := range oldGoods {
  6500. dialyPrepareOne := models.DialysisBeforePrepare{
  6501. GoodTypeId: item.GoodTypeId,
  6502. GoodId: item.GoodId,
  6503. PatientId: his.PatientId,
  6504. RecordDate: item.RecordDate,
  6505. UserOrgId: adminUser.CurrentOrgId,
  6506. Count: item.Count,
  6507. Ctime: time.Now().Unix(),
  6508. Creater: adminUser.AdminUser.Id,
  6509. CommdityCode: item.CommdityCode,
  6510. Status: 1,
  6511. StorehouseId: houseConfig.StorehouseOutInfo,
  6512. }
  6513. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6514. //非零用
  6515. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6516. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6517. //查询剩余库存
  6518. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6519. var sum_count int64
  6520. for _, item := range goodList {
  6521. sum_count += item.StockCount
  6522. }
  6523. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6524. //耗材
  6525. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6526. }
  6527. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6528. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6529. //查询剩余库存
  6530. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6531. var sum_count int64
  6532. for _, item := range goodList {
  6533. sum_count += item.StockCount
  6534. }
  6535. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6536. //耗材
  6537. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6538. }
  6539. }
  6540. }
  6541. }
  6542. c.ServeSuccessJSON(map[string]interface{}{
  6543. "msg": "结算成功",
  6544. })
  6545. }
  6546. }
  6547. }
  6548. // 退款
  6549. func (c *HisApiController) Refund() {
  6550. order_id, _ := c.GetInt64("order_id")
  6551. order, _ := service.GetHisOrderByID(order_id)
  6552. adminUser := c.GetAdminUserInfo()
  6553. orgid := c.GetAdminUserInfo().CurrentOrgId
  6554. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6555. if err != nil {
  6556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6557. return
  6558. }
  6559. tmp := strconv.FormatInt(order.ID, 10)
  6560. //当押金不为零时产生退费记录
  6561. if order.Decimal != 0 {
  6562. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6563. if err != nil {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6565. return
  6566. }
  6567. }
  6568. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6569. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6570. var goods []*models.DialysisBeforePrepareGoods
  6571. var newGoods []*models.NewDialysisBeforePrepareGoods
  6572. var infos []*models.HisDoctorAdviceInfo
  6573. for _, info := range orders {
  6574. if info.AdviceId > 0 && info.ProjectId == 0 {
  6575. infos = append(infos, &info.HisDoctorAdviceInfo)
  6576. }
  6577. if info.ProjectId > 0 && info.AdviceId == 0 {
  6578. if info.HisPrescriptionProject.Type == 3 {
  6579. var good models.DialysisBeforePrepareGoods
  6580. var newGood models.NewDialysisBeforePrepareGoods
  6581. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6582. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6583. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6584. good.Count = int64(count)
  6585. good.StorehouseId = houseConfig.StorehouseOutInfo
  6586. good.ProjectId = info.HisPrescriptionProject.ID
  6587. good.PatientId = info.PatientId
  6588. good.OrderId = order_id
  6589. goods = append(goods, &good)
  6590. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6591. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6592. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6593. newGood.Count = int64(count2)
  6594. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6595. newGood.ProjectId = info.HisPrescriptionProject.ID
  6596. newGood.RecordDate = order.SettleAccountsDate
  6597. newGood.UserOrgId = order.UserOrgId
  6598. newGood.PatientId = info.PatientId
  6599. newGood.OrderId = order_id
  6600. newGoods = append(newGoods, &newGood)
  6601. }
  6602. }
  6603. }
  6604. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6605. if settConfig.IsOpen == 1 {
  6606. for _, item := range infos {
  6607. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6608. }
  6609. for _, item := range newGoods {
  6610. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6611. }
  6612. }
  6613. c.ServeSuccessJSON(map[string]interface{}{
  6614. "msg": "退费成功",
  6615. })
  6616. }
  6617. func (c *HisApiController) RefundNumber() {
  6618. his_patient_id, _ := c.GetInt64("id")
  6619. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6620. info.Status = 0
  6621. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6622. if count > 0 {
  6623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6624. return
  6625. }
  6626. err := service.SaveHisPatient(info)
  6627. if err == nil {
  6628. c.ServeSuccessJSON(map[string]interface{}{
  6629. "msg": "退号成功",
  6630. })
  6631. } else {
  6632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6633. return
  6634. }
  6635. }
  6636. func (this *HisApiController) AdditionalCharge() {
  6637. dataBody := make(map[string]interface{}, 0)
  6638. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6639. fmt.Println(err)
  6640. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6641. patient_id := int64(dataBody["patient_id"].(float64))
  6642. medicineData, _ := dataBody["medicineData"].([]interface{})
  6643. adminUserInfo := this.GetAdminUserInfo()
  6644. orgId := adminUserInfo.CurrentOrgId
  6645. admin_user_id := adminUserInfo.AdminUser.Id
  6646. timeStr := time.Now().Format("2006-01-02")
  6647. timeLayout := "2006-01-02 15:04:05"
  6648. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6649. timenow := timeStringToTime.Unix()
  6650. var additionalCharges []*models.HisAdditionalCharge
  6651. for _, item := range medicineData {
  6652. var randNum int
  6653. randNum = rand.Intn(10000) + 1000
  6654. timestamp := time.Now().Unix()
  6655. tempTime := time.Unix(timestamp, 0)
  6656. timeFormat := tempTime.Format("20060102150405")
  6657. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6658. items := item.(map[string]interface{})
  6659. money := items["price"].(string)
  6660. item_id_str := items["item_id"].(string)
  6661. name := items["name"].(string)
  6662. id_str := items["id"].(string)
  6663. moneys, _ := strconv.ParseInt(money, 10, 64)
  6664. monStr := strconv.FormatInt(moneys, 10)
  6665. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6666. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6667. id, _ := strconv.ParseInt(id_str, 10, 64)
  6668. additionalCharge := &models.HisAdditionalCharge{
  6669. ID: id,
  6670. HisPatientId: his_patient_id,
  6671. UserOrgId: orgId,
  6672. PatientId: patient_id,
  6673. RecordDate: timenow,
  6674. Price: monneyStr,
  6675. Status: 1,
  6676. ItemName: name,
  6677. ItemId: item_id,
  6678. AdminUserId: admin_user_id,
  6679. CreatedTime: time.Now().Unix(),
  6680. OrderStatus: 0,
  6681. PrescriptionNumber: "",
  6682. BatchNumber: "",
  6683. FeedetlSn: p_number,
  6684. }
  6685. service.CreateAdditionalCharge(additionalCharge)
  6686. additionalCharges = append(additionalCharges, additionalCharge)
  6687. }
  6688. this.ServeSuccessJSON(map[string]interface{}{
  6689. "msg": "添加成功",
  6690. "additional_charges": additionalCharges,
  6691. })
  6692. }
  6693. func (this *HisApiController) DeleteAddition() {
  6694. id, _ := this.GetInt64("id")
  6695. //TODO 需要判断是否已经结算
  6696. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6697. if err == nil {
  6698. this.ServeSuccessJSON(map[string]interface{}{
  6699. "msg": "删除成功",
  6700. })
  6701. return
  6702. } else {
  6703. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6704. return
  6705. }
  6706. }
  6707. func (this *HisApiController) GetAdminUsers() {
  6708. adminUser := this.GetAdminUserInfo()
  6709. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6710. this.ServeSuccessJSON(map[string]interface{}{
  6711. "doctors": doctors,
  6712. })
  6713. }
  6714. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6715. change_type, _ := this.GetInt64("type", 0)
  6716. record_date := this.GetString("record_time")
  6717. patient_id, _ := this.GetInt64("patient_id", 0)
  6718. p_type, _ := this.GetInt64("p_type", 0)
  6719. timeLayout := "2006-01-02"
  6720. loc, _ := time.LoadLocation("Local")
  6721. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6722. record_time := theAdviceRecordTime.Unix()
  6723. adminUserInfo := this.GetAdminUserInfo()
  6724. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6725. if err == nil {
  6726. if len(prescriptions) == 0 {
  6727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6728. return
  6729. } else {
  6730. this.ServeSuccessJSON(map[string]interface{}{
  6731. "prescriptions": prescriptions,
  6732. })
  6733. return
  6734. }
  6735. } else {
  6736. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6737. return
  6738. }
  6739. }
  6740. func (this *HisApiController) GetCallHisPrescription() {
  6741. patient_id, _ := this.GetInt64("patient_id", 0)
  6742. timeLayout := "2006-01-02"
  6743. loc, _ := time.LoadLocation("Local")
  6744. start_time := this.GetString("start_time")
  6745. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6746. end_time := this.GetString("end_time")
  6747. p_type, _ := this.GetInt64("p_type")
  6748. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6749. adminUserInfo := this.GetAdminUserInfo()
  6750. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6751. if err == nil {
  6752. this.ServeSuccessJSON(map[string]interface{}{
  6753. "prescriptions": prescriptions,
  6754. })
  6755. return
  6756. } else {
  6757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6758. return
  6759. }
  6760. }
  6761. func (this *HisApiController) GetHisDayPrescription() {
  6762. timeLayout := "2006-01-02"
  6763. loc, _ := time.LoadLocation("Local")
  6764. start_time := this.GetString("start_time")
  6765. patient_id, _ := this.GetInt64("patient_id", 0)
  6766. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6767. end_time := this.GetString("end_time")
  6768. p_type, _ := this.GetInt64("p_type")
  6769. order_status, _ := this.GetInt64("type")
  6770. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6771. adminUserInfo := this.GetAdminUserInfo()
  6772. var dayHisPrescription []*models.HisPrescription
  6773. var err error
  6774. if order_status == 1 || order_status == 0 {
  6775. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6776. } else if order_status == 2 {
  6777. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6778. }
  6779. var settle_total float64
  6780. for _, item := range dayHisPrescription {
  6781. if len(item.HisPrescriptionProject) > 0 {
  6782. for _, subItem := range item.HisPrescriptionProject {
  6783. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6784. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6785. settle_total = settle_total + total
  6786. }
  6787. }
  6788. if len(item.HisDoctorAdviceInfo) > 0 {
  6789. for _, subItem := range item.HisDoctorAdviceInfo {
  6790. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6791. settle_total = settle_total + total
  6792. }
  6793. }
  6794. }
  6795. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6796. if err == nil {
  6797. this.ServeSuccessJSON(map[string]interface{}{
  6798. "day_prescription": dayHisPrescription,
  6799. "settle_total": settle_total,
  6800. })
  6801. return
  6802. } else {
  6803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6804. return
  6805. }
  6806. }
  6807. func (c *HisApiController) GetHisChargePatientList() {
  6808. record_date := c.GetString("record_date")
  6809. order_status, _ := c.GetInt64("type")
  6810. timeLayout := "2006-01-02"
  6811. loc, _ := time.LoadLocation("Local")
  6812. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6813. if err != nil {
  6814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6815. return
  6816. }
  6817. recordDateTime := theTime.Unix()
  6818. adminInfo := c.GetAdminUserInfo()
  6819. var tempPatients []*service.NewTempPatients
  6820. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6821. if order_status != 2 {
  6822. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6823. } else {
  6824. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6825. }
  6826. var patients []*service.NewTempPatients
  6827. var patients_two []*service.NewTempPatients
  6828. for _, item := range tempPatients {
  6829. //过滤掉没挂号的和没开处方的
  6830. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6831. patients = append(patients, item)
  6832. }
  6833. //过滤掉没挂号的
  6834. if len(item.HisPatient) > 0 {
  6835. patients_two = append(patients_two, item)
  6836. }
  6837. }
  6838. c.ServeSuccessJSON(map[string]interface{}{
  6839. "list": patients,
  6840. "list_two": patients_two,
  6841. })
  6842. }
  6843. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6844. record_date := c.GetString("record_date")
  6845. timeLayout := "2006-01-02"
  6846. loc, _ := time.LoadLocation("Local")
  6847. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6848. if err != nil {
  6849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6850. return
  6851. }
  6852. recordDateTime := theTime.Unix()
  6853. adminUser := c.GetAdminUserInfo()
  6854. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6855. var patients []*service.Patients
  6856. for _, item := range tempPatients {
  6857. if item.HisPatient.ID == 0 {
  6858. patients = append(patients, item)
  6859. }
  6860. }
  6861. c.ServeSuccessJSON(map[string]interface{}{
  6862. "list": patients,
  6863. //"list_two": patients_two,
  6864. })
  6865. }
  6866. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6867. newArr = make([]*service.Patients, 0)
  6868. for i := 0; i < len(patient); i++ {
  6869. repeat := false
  6870. for j := i + 1; j < len(patient); j++ {
  6871. if patient[i].ID == patient[j].ID {
  6872. repeat = true
  6873. break
  6874. }
  6875. }
  6876. if !repeat {
  6877. newArr = append(newArr, patient[i])
  6878. }
  6879. }
  6880. return
  6881. }
  6882. func (c *HisApiController) GetHisChargePatientInfo() {
  6883. patient_id, _ := c.GetInt64("patient_id")
  6884. his_patient_id, _ := c.GetInt64("his_patient_id")
  6885. record_date := c.GetString("record_date")
  6886. //start_time := c.GetString("start_time")
  6887. //end_time := c.GetString("end_time")
  6888. order_status, _ := c.GetInt64("type", 0)
  6889. p_type, _ := c.GetInt64("p_type", 0)
  6890. order_id, _ := c.GetInt64("order_id", 0)
  6891. timeLayout := "2006-01-02"
  6892. loc, _ := time.LoadLocation("Local")
  6893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6894. if err != nil {
  6895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6896. return
  6897. }
  6898. recordDateTime := theTime.Unix()
  6899. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6900. //if err != nil {
  6901. //
  6902. //}
  6903. //startRecordDateTime := startTime.Unix()
  6904. //
  6905. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6906. //if err != nil {
  6907. //
  6908. //}
  6909. //endRecordDateTime := endTime.Unix()
  6910. admin := c.GetAdminUserInfo()
  6911. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6912. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6913. var prescriptions []*models.HisPrescription
  6914. //var unChargeMonthPrescriptions []*models.HisPrescription
  6915. order, _ := service.GetHisOrderByID(order_id)
  6916. if order_status == 1 || order_status == 0 {
  6917. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6918. } else if order_status == 2 {
  6919. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6920. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6921. }
  6922. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6923. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6924. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6925. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6926. //获取所有科室信息
  6927. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6928. c.ServeSuccessJSON(map[string]interface{}{
  6929. "his_info": his_patient_info,
  6930. "xt_info": xt_patient_info,
  6931. "prescription": prescriptions,
  6932. "case_history": case_history,
  6933. "info": patientPrescriptionInfo,
  6934. "last_info": lastPatientPrescriptionInfo,
  6935. "order": order,
  6936. "doctors": doctors,
  6937. "department": department,
  6938. })
  6939. return
  6940. }
  6941. func (c *HisApiController) GetAllOrderDetail() {
  6942. order_id, _ := c.GetInt64("id", 0)
  6943. order, _ := service.GetHisOrderByID(order_id)
  6944. if order.ID == 0 {
  6945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6946. return
  6947. }
  6948. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6949. org_id := c.GetAdminUserInfo().CurrentOrgId
  6950. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6951. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6952. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6953. c.ServeSuccessJSON(map[string]interface{}{
  6954. "order": order,
  6955. "order_info": order_info,
  6956. "patient": patient,
  6957. "admin_info": adminInfo,
  6958. "hospital_record": record,
  6959. })
  6960. return
  6961. }
  6962. func (c *HisApiController) GetAllOrderDetailCollect() {
  6963. order_id, _ := c.GetInt64("id", 0)
  6964. order, _ := service.GetHisOrderByID(order_id)
  6965. if order.ID == 0 {
  6966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6967. return
  6968. }
  6969. org_id := c.GetAdminUserInfo().CurrentOrgId
  6970. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6971. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6972. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6973. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6974. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6975. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6976. var bedCostTotal float64 = 0 //床位总费
  6977. //var bedCostSelfTotal float64 = 0 //床位自费
  6978. var operationCostTotal float64 = 0 //手术费
  6979. //var operationCostSelfTotal float64 = 0 //手术费
  6980. var otherCostTotal float64 = 0 //其他费用
  6981. //var otherCostSelfTotal float64 = 0 //其他费用
  6982. var materialCostTotal float64 = 0 //材料费
  6983. //var materialCostSelfTotal float64 = 0 //材料费
  6984. var westernMedicineCostTotal float64 = 0 //西药费
  6985. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6986. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6987. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6988. var checkCostTotal float64 = 0 //检查费
  6989. //var checkCostSelfTotal float64 = 0 //检查费
  6990. var laboratoryCostTotal float64 = 0 //化验费
  6991. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6992. var treatCostTotal float64 = 0 //治疗费用
  6993. //var treatCostSelfTotal float64 = 0 //治疗费用
  6994. var zhenChaCostTotal float64 = 0 //其他费用
  6995. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6996. decimal.DivisionPrecision = 2
  6997. var BalanceAccountsType int64
  6998. if his.ID > 0 {
  6999. BalanceAccountsType = his.BalanceAccountsType
  7000. } else {
  7001. BalanceAccountsType = record.BalanceAccountsType
  7002. }
  7003. if BalanceAccountsType != 2 {
  7004. for _, item := range order_info {
  7005. if org_id == 10215 {
  7006. if item.MedChrgitmType == "01" { //床位费
  7007. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7008. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7009. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7010. }
  7011. if item.MedChrgitmType == "02" { //诊察费
  7012. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7013. //zhenChaCostSelfTotal = zhenChaCostTotal
  7014. }
  7015. if item.MedChrgitmType == "03" { //检查费
  7016. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7017. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7018. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7019. }
  7020. //if item.MedChrgitmType == "02" { //检查费
  7021. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7022. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7023. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7024. //}
  7025. if item.MedChrgitmType == "04" { //化验费
  7026. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7027. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7028. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7029. }
  7030. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7031. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7032. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7033. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7034. }
  7035. if item.MedChrgitmType == "06" { //手术费
  7036. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7037. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7038. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7039. }
  7040. if item.MedChrgitmType == "08" { //材料费
  7041. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7042. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7043. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7044. }
  7045. if item.MedChrgitmType == "09" { //西药费
  7046. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7047. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7048. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7049. }
  7050. if item.MedChrgitmType == "11" { //中成费
  7051. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7052. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7053. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7054. }
  7055. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7056. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7057. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7058. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7059. }
  7060. } else if org_id == 10188 || org_id == 10217 {
  7061. if item.MedChrgitmType == "01" { //床位费
  7062. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7063. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7064. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7065. }
  7066. if item.MedChrgitmType == "02" { //诊察费
  7067. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7068. //zhenChaCostSelfTotal = zhenChaCostTotal
  7069. }
  7070. if item.MedChrgitmType == "03" { //检查费
  7071. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7072. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7073. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7074. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7075. }
  7076. //if item.MedChrgitmType == "02" { //检查费
  7077. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7078. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7079. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7080. //}
  7081. if item.MedChrgitmType == "04" { //化验费
  7082. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7083. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7084. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7085. }
  7086. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7088. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7089. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7090. }
  7091. if item.MedChrgitmType == "06" { //手术费
  7092. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7093. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7094. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7095. }
  7096. if item.MedChrgitmType == "08" { //材料费
  7097. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7098. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7099. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7100. }
  7101. if item.MedChrgitmType == "09" { //西药费
  7102. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7103. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7104. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7105. }
  7106. if item.MedChrgitmType == "11" { //中成费
  7107. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7108. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7109. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7110. }
  7111. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7112. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7113. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7114. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7115. }
  7116. } else {
  7117. if item.MedChrgitmType == "01" { //床位费
  7118. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7119. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7120. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7121. }
  7122. //if item.MedChrgitmType == "02" { //诊察费
  7123. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7124. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7125. //}
  7126. if item.MedChrgitmType == "03" { //检查费
  7127. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7128. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7129. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7130. }
  7131. //if item.MedChrgitmType == "02" { //检查费
  7132. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7133. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7134. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7135. //}
  7136. if item.MedChrgitmType == "04" { //化验费
  7137. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7138. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7139. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7140. }
  7141. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7142. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7143. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7144. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7145. }
  7146. if item.MedChrgitmType == "06" { //手术费
  7147. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7148. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7149. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7150. }
  7151. if item.MedChrgitmType == "08" { //材料费
  7152. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7153. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7154. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7155. }
  7156. if item.MedChrgitmType == "09" { //西药费
  7157. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7158. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7159. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7160. }
  7161. if item.MedChrgitmType == "11" { //中成费
  7162. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7163. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7164. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7165. }
  7166. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7167. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7168. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7169. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7170. }
  7171. }
  7172. }
  7173. c.ServeSuccessJSON(map[string]interface{}{
  7174. "order": order,
  7175. "order_info": order_info,
  7176. "patient": patient,
  7177. "admin_info": adminInfo,
  7178. "his_hospital": record,
  7179. "bedCostTotal": bedCostTotal,
  7180. "operationCostTotal": operationCostTotal,
  7181. "otherCostTotal": otherCostTotal,
  7182. "materialCostTotal": materialCostTotal,
  7183. "westernMedicineCostTotal": westernMedicineCostTotal,
  7184. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7185. "checkCostTotal": checkCostTotal,
  7186. "zhenChaCostTotal": zhenChaCostTotal,
  7187. "laboratoryCostTotal": laboratoryCostTotal,
  7188. "treatCostTotal": treatCostTotal,
  7189. })
  7190. } else {
  7191. for _, item := range order_info {
  7192. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7193. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7194. item.MedChrgitmType = "09"
  7195. }
  7196. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7197. if item.HisPrescriptionProject.Type == 2 {
  7198. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7199. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7200. case 0:
  7201. item.MedChrgitmType = "0"
  7202. break
  7203. case 1:
  7204. item.MedChrgitmType = "14"
  7205. break
  7206. case 2:
  7207. item.MedChrgitmType = "05"
  7208. break
  7209. case 3:
  7210. item.MedChrgitmType = "03"
  7211. break
  7212. case 4:
  7213. item.MedChrgitmType = "03"
  7214. break
  7215. case 5:
  7216. item.MedChrgitmType = "08"
  7217. break
  7218. case 6:
  7219. item.MedChrgitmType = "14"
  7220. break
  7221. case 7:
  7222. item.MedChrgitmType = "14"
  7223. break
  7224. case 8:
  7225. item.MedChrgitmType = "03"
  7226. break
  7227. case 9:
  7228. item.MedChrgitmType = "14"
  7229. break
  7230. case 10:
  7231. item.MedChrgitmType = "14"
  7232. break
  7233. case 11:
  7234. item.MedChrgitmType = "06"
  7235. break
  7236. case 12:
  7237. item.MedChrgitmType = "12"
  7238. break
  7239. case 13:
  7240. item.MedChrgitmType = "01"
  7241. break
  7242. case 14:
  7243. item.MedChrgitmType = "04"
  7244. break
  7245. case 15:
  7246. item.MedChrgitmType = "14"
  7247. break
  7248. }
  7249. } else {
  7250. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7251. case 1:
  7252. item.MedChrgitmType = "14"
  7253. break
  7254. case 2:
  7255. item.MedChrgitmType = "05"
  7256. break
  7257. case 3:
  7258. item.MedChrgitmType = "04"
  7259. break
  7260. case 4:
  7261. item.MedChrgitmType = "14"
  7262. break
  7263. case 5:
  7264. item.MedChrgitmType = "08"
  7265. break
  7266. case 6:
  7267. item.MedChrgitmType = "14"
  7268. break
  7269. case 7:
  7270. item.MedChrgitmType = "14"
  7271. break
  7272. case 8:
  7273. item.MedChrgitmType = "03"
  7274. break
  7275. case 9:
  7276. item.MedChrgitmType = "14"
  7277. break
  7278. }
  7279. }
  7280. } else if item.HisPrescriptionProject.Type == 3 {
  7281. item.MedChrgitmType = "08"
  7282. }
  7283. }
  7284. }
  7285. for _, item := range order_info {
  7286. if org_id == 10215 {
  7287. if item.MedChrgitmType == "01" { //床位费
  7288. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7289. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7290. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7291. }
  7292. if item.MedChrgitmType == "02" { //诊察费
  7293. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7294. //zhenChaCostSelfTotal = zhenChaCostTotal
  7295. }
  7296. if item.MedChrgitmType == "03" { //检查费
  7297. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7298. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7299. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7300. }
  7301. //if item.MedChrgitmType == "02" { //检查费
  7302. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7303. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7304. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7305. //}
  7306. if item.MedChrgitmType == "04" { //化验费
  7307. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7308. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7309. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7310. }
  7311. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7312. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7313. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7314. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7315. }
  7316. if item.MedChrgitmType == "06" { //手术费
  7317. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7318. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7319. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7320. }
  7321. if item.MedChrgitmType == "08" { //材料费
  7322. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7323. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7324. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7325. }
  7326. if item.MedChrgitmType == "09" { //西药费
  7327. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7328. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7329. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7330. }
  7331. if item.MedChrgitmType == "11" { //中成费
  7332. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7333. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7334. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7335. }
  7336. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7337. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7338. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7339. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7340. }
  7341. } else {
  7342. if item.MedChrgitmType == "01" { //床位费
  7343. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7344. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7345. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7346. }
  7347. //if item.MedChrgitmType == "02" { //诊察费
  7348. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7349. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7350. //}
  7351. if item.MedChrgitmType == "03" { //检查费
  7352. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7353. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7354. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7355. }
  7356. //if item.MedChrgitmType == "02" { //检查费
  7357. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7358. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7359. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7360. //}
  7361. if item.MedChrgitmType == "04" { //化验费
  7362. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7363. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7364. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7365. }
  7366. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7367. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7368. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7369. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7370. }
  7371. if item.MedChrgitmType == "06" { //手术费
  7372. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7373. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7374. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7375. }
  7376. if item.MedChrgitmType == "08" { //材料费
  7377. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7378. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7379. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7380. }
  7381. if item.MedChrgitmType == "09" { //西药费
  7382. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7383. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7384. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7385. }
  7386. if item.MedChrgitmType == "11" { //中成费
  7387. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7388. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7389. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7390. }
  7391. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7392. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7393. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7394. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7395. }
  7396. }
  7397. }
  7398. c.ServeSuccessJSON(map[string]interface{}{
  7399. "order": order,
  7400. "order_info": order_info,
  7401. "patient": patient,
  7402. "admin_info": adminInfo,
  7403. "his_hospital": record,
  7404. "bedCostTotal": bedCostTotal,
  7405. "operationCostTotal": operationCostTotal,
  7406. "otherCostTotal": otherCostTotal,
  7407. "materialCostTotal": materialCostTotal,
  7408. "westernMedicineCostTotal": westernMedicineCostTotal,
  7409. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7410. "checkCostTotal": checkCostTotal,
  7411. "zhenChaCostTotal": zhenChaCostTotal,
  7412. "laboratoryCostTotal": laboratoryCostTotal,
  7413. "treatCostTotal": treatCostTotal,
  7414. })
  7415. }
  7416. }
  7417. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7418. page, _ := c.GetInt64("page")
  7419. limit, _ := c.GetInt64("limit")
  7420. keywords := c.GetString("keywords")
  7421. start_time := c.GetString("start_time")
  7422. end_time := c.GetString("end_time")
  7423. //clr_type := c.GetString("clr_type")
  7424. insutype := c.GetString("insutype")
  7425. timeLayout := "2006-01-02"
  7426. loc, _ := time.LoadLocation("Local")
  7427. var theStartTIme int64
  7428. if len(start_time) > 0 {
  7429. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7430. theStartTIme = theTime.Unix()
  7431. }
  7432. var theEndtTIme int64
  7433. if len(end_time) > 0 {
  7434. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7435. theEndtTIme = theTime.Unix()
  7436. }
  7437. if page <= 0 {
  7438. page = 1
  7439. }
  7440. if limit <= 0 {
  7441. limit = 10
  7442. }
  7443. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7444. c.ServeSuccessJSON(map[string]interface{}{
  7445. "total": total,
  7446. "list": list,
  7447. })
  7448. return
  7449. }
  7450. func (c *HisApiController) GetPutOnRecordList() {
  7451. page, _ := c.GetInt64("page")
  7452. limit, _ := c.GetInt64("limit")
  7453. keywords := c.GetString("keywords")
  7454. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7455. if page <= 0 {
  7456. page = 1
  7457. }
  7458. if limit <= 0 {
  7459. limit = 10
  7460. }
  7461. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7462. c.ServeSuccessJSON(map[string]interface{}{
  7463. "total": total,
  7464. "list": list,
  7465. })
  7466. return
  7467. }
  7468. func (c *HisApiController) GetCompareData() {
  7469. start_time := c.GetString("start_time")
  7470. end_time := c.GetString("end_time")
  7471. insutype := c.GetString("insutype")
  7472. clr_type := c.GetString("clr_type")
  7473. timeLayout := "2006-01-02"
  7474. loc, _ := time.LoadLocation("Local")
  7475. var theStartTIme int64
  7476. if len(start_time) > 0 {
  7477. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7478. if err != nil {
  7479. theStartTIme = 0
  7480. }
  7481. theStartTIme = theTime.Unix()
  7482. }
  7483. var theEndtTIme int64
  7484. if len(end_time) > 0 {
  7485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7486. if err != nil {
  7487. theEndtTIme = 0
  7488. }
  7489. theEndtTIme = theTime.Unix()
  7490. }
  7491. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7492. fmt.Println(err)
  7493. if err == nil {
  7494. c.ServeSuccessJSON(map[string]interface{}{
  7495. "list": formData,
  7496. })
  7497. } else {
  7498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7499. return
  7500. }
  7501. }
  7502. func (c *HisApiController) GetFaPiaoData() {
  7503. order_id, _ := c.GetInt64("order_id")
  7504. patient_id, _ := c.GetInt64("patient_id")
  7505. //number := c.GetString("number")
  7506. adminUser := c.GetAdminUserInfo()
  7507. order, _ := service.GetHisOrderByID(order_id)
  7508. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7509. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7510. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7511. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7512. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7513. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7514. var bedCostTotal float64 = 0 //床位总费
  7515. var bedCostSelfTotal float64 = 0 //床位自费
  7516. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7517. var operationCostTotal float64 = 0 //手术费
  7518. var operationCostSelfTotal float64 = 0 //手术费
  7519. var operationCostPartSelfTotal float64 = 0 //手术费
  7520. var otherCostTotal float64 = 0 //其他费用
  7521. var otherCostSelfTotal float64 = 0 //其他费用
  7522. var otherCostPartSelfTotal float64 = 0 //其他费用
  7523. var materialCostTotal float64 = 0 //材料费
  7524. var materialCostSelfTotal float64 = 0 //材料费
  7525. var materialCostPartSelfTotal float64 = 0 //材料费
  7526. var westernMedicineCostTotal float64 = 0 //西药费
  7527. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7528. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7529. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7530. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7531. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7532. var checkCostTotal float64 = 0 //检查费
  7533. var checkCostSelfTotal float64 = 0 //检查费
  7534. var checkCostPartSelfTotal float64 = 0 //检查费
  7535. var laboratoryCostTotal float64 = 0 //化验费
  7536. var laboratoryCostSelfTotal float64 = 0 //化验费
  7537. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7538. var treatCostTotal float64 = 0 //治疗费用
  7539. var treatCostSelfTotal float64 = 0 //治疗费用
  7540. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7541. var zhenChaCostTotal float64 = 0 //其他费用
  7542. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7543. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7544. decimal.DivisionPrecision = 2
  7545. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7546. var balanceAccountsType int64
  7547. if his.ID > 0 {
  7548. balanceAccountsType = his.BalanceAccountsType
  7549. } else {
  7550. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7551. }
  7552. if balanceAccountsType == 2 {
  7553. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7554. for _, item := range orderInfos_two {
  7555. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7556. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7557. item.MedChrgitmType = "09"
  7558. }
  7559. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7560. if item.HisPrescriptionProject.Type == 2 {
  7561. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7562. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7563. case 0:
  7564. item.MedChrgitmType = "0"
  7565. break
  7566. case 1:
  7567. item.MedChrgitmType = "14"
  7568. break
  7569. case 2:
  7570. item.MedChrgitmType = "05"
  7571. break
  7572. case 3:
  7573. item.MedChrgitmType = "03"
  7574. break
  7575. case 4:
  7576. item.MedChrgitmType = "03"
  7577. break
  7578. case 5:
  7579. item.MedChrgitmType = "08"
  7580. break
  7581. case 6:
  7582. item.MedChrgitmType = "14"
  7583. break
  7584. case 7:
  7585. item.MedChrgitmType = "14"
  7586. break
  7587. case 8:
  7588. item.MedChrgitmType = "03"
  7589. break
  7590. case 9:
  7591. item.MedChrgitmType = "14"
  7592. break
  7593. case 10:
  7594. item.MedChrgitmType = "14"
  7595. break
  7596. case 11:
  7597. item.MedChrgitmType = "06"
  7598. break
  7599. case 12:
  7600. item.MedChrgitmType = "12"
  7601. break
  7602. case 13:
  7603. item.MedChrgitmType = "01"
  7604. break
  7605. case 14:
  7606. item.MedChrgitmType = "04"
  7607. break
  7608. case 15:
  7609. item.MedChrgitmType = "02"
  7610. break
  7611. }
  7612. } else {
  7613. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7614. case 1:
  7615. item.MedChrgitmType = "14"
  7616. break
  7617. case 2:
  7618. item.MedChrgitmType = "05"
  7619. break
  7620. case 3:
  7621. item.MedChrgitmType = "03"
  7622. break
  7623. case 4:
  7624. item.MedChrgitmType = "03"
  7625. break
  7626. case 5:
  7627. item.MedChrgitmType = "08"
  7628. break
  7629. case 6:
  7630. item.MedChrgitmType = "14"
  7631. break
  7632. case 7:
  7633. item.MedChrgitmType = "14"
  7634. break
  7635. case 8:
  7636. item.MedChrgitmType = "03"
  7637. break
  7638. case 9:
  7639. item.MedChrgitmType = "14"
  7640. break
  7641. }
  7642. }
  7643. } else if item.HisPrescriptionProject.Type == 3 {
  7644. item.MedChrgitmType = "08"
  7645. }
  7646. }
  7647. }
  7648. for _, item := range orderInfos_two {
  7649. fmt.Println(item.MedChrgitmType)
  7650. if item.MedChrgitmType == "01" { //床位费
  7651. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7652. bedCostSelfTotal = bedCostTotal
  7653. }
  7654. if item.MedChrgitmType == "02" { //诊察费
  7655. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. zhenChaCostSelfTotal = zhenChaCostTotal
  7657. }
  7658. if item.MedChrgitmType == "03" { //检查费
  7659. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7660. checkCostSelfTotal = checkCostTotal
  7661. }
  7662. if item.MedChrgitmType == "04" { //化验费
  7663. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7664. laboratoryCostSelfTotal = laboratoryCostTotal
  7665. }
  7666. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7667. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7668. treatCostSelfTotal = treatCostTotal
  7669. }
  7670. if item.MedChrgitmType == "06" { //手术费
  7671. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7672. operationCostSelfTotal = treatCostTotal
  7673. }
  7674. if item.MedChrgitmType == "08" { //材料费
  7675. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. materialCostSelfTotal = materialCostTotal
  7677. }
  7678. if item.MedChrgitmType == "09" { //西药费
  7679. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7680. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7681. }
  7682. if item.MedChrgitmType == "11" { //中成费
  7683. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7684. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7685. }
  7686. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7687. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7689. otherCostSelfTotal = otherCostTotal
  7690. }
  7691. } else {
  7692. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7693. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7694. otherCostSelfTotal = otherCostTotal
  7695. }
  7696. }
  7697. }
  7698. } else {
  7699. for _, item := range orderInfos {
  7700. if item.MedChrgitmType == "01" { //床位费
  7701. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7702. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7703. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7704. }
  7705. if item.MedChrgitmType == "02" { //诊察费
  7706. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7707. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7708. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7709. }
  7710. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7711. if item.MedChrgitmType == "03" { //检查费
  7712. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7713. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7714. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7715. }
  7716. } else {
  7717. if item.MedChrgitmType == "03" { //检查费
  7718. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7719. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7720. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7721. }
  7722. }
  7723. if item.MedChrgitmType == "04" { //化验费
  7724. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7725. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7726. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7727. }
  7728. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7729. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7730. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7731. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7732. }
  7733. if item.MedChrgitmType == "06" { //手术费
  7734. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7735. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7736. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7737. }
  7738. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7739. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7740. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7741. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7742. }
  7743. if item.MedChrgitmType == "09" { //西药费
  7744. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7745. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7746. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7747. }
  7748. if item.MedChrgitmType == "11" { //中成费
  7749. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7750. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7751. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7752. }
  7753. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7754. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7755. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7756. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7757. }
  7758. }
  7759. }
  7760. timeLayout := "2006-01-02"
  7761. loc, _ := time.LoadLocation("Local")
  7762. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7763. if err != nil {
  7764. }
  7765. startRecordDateTime := startTime.Unix()
  7766. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7767. if err != nil {
  7768. }
  7769. endRecordDateTime := endTime.Unix()
  7770. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7771. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7772. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7773. c.ServeSuccessJSON(map[string]interface{}{
  7774. "order_number": order.Number, //业务流水号
  7775. "id_card_no": his.IdCardNo, //社会保障号
  7776. "department_name": department.Name, //科室
  7777. "number": his.Number, //门诊号
  7778. "date": order.SettleAccountsDate, //结算日期
  7779. "name": order.PsnName, //姓名
  7780. "gender": patient.Gender, //性别
  7781. "psn_cash_money": order.PsnCashPay, //个人支付
  7782. "pay_way": "门诊", //结算方式
  7783. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7784. "admin_user_name": admin.UserName, //收款员
  7785. "order": order,
  7786. "order_info": orderInfos_two,
  7787. "his": his,
  7788. "bedCostTotal": bedCostTotal,
  7789. "bedCostSelfTotal": bedCostSelfTotal,
  7790. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7791. "operationCostTotal": operationCostTotal,
  7792. "operationCostSelfTotal": operationCostSelfTotal,
  7793. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7794. "otherCostTotal": otherCostTotal,
  7795. "otherCostSelfTotal": otherCostSelfTotal,
  7796. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7797. "materialCostTotal": materialCostTotal,
  7798. "materialCostSelfTotal": materialCostSelfTotal,
  7799. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7800. "westernMedicineCostTotal": westernMedicineCostTotal,
  7801. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7802. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7803. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7804. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7805. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7806. "checkCostTotal": checkCostTotal,
  7807. "checkCostSelfTotal": checkCostSelfTotal,
  7808. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7809. "laboratoryCostTotal": laboratoryCostTotal,
  7810. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7811. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7812. "treatCostTotal": treatCostTotal,
  7813. "treatCostSelfTotal": treatCostSelfTotal,
  7814. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7815. "zhenChaCostTotal": zhenChaCostTotal,
  7816. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7817. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7818. "his_hospital_record": his_hospital_record,
  7819. "pre_pay_money": pre_pay_money,
  7820. "refund_sum": sum,
  7821. })
  7822. }
  7823. func (this *HisApiController) GetIncomeStatisticsData() {
  7824. start_time := this.GetString("start_time")
  7825. end_time := this.GetString("end_time")
  7826. key_words := this.GetString("key_words")
  7827. limit, _ := this.GetInt64("limit")
  7828. page, _ := this.GetInt64("page")
  7829. if page <= 0 {
  7830. page = 1
  7831. }
  7832. if limit <= 0 {
  7833. limit = 10
  7834. }
  7835. statistics_type, _ := this.GetInt64("statistics_type")
  7836. admin := this.GetAdminUserInfo()
  7837. timeLayout := "2006-01-02"
  7838. loc, _ := time.LoadLocation("Local")
  7839. var theStartTIme int64
  7840. if len(start_time) > 0 {
  7841. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7842. if err != nil {
  7843. theStartTIme = 0
  7844. }
  7845. theStartTIme = theTime.Unix()
  7846. }
  7847. var theEndtTIme int64
  7848. if len(end_time) > 0 {
  7849. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7850. if err != nil {
  7851. theEndtTIme = 0
  7852. }
  7853. theEndtTIme = theTime.Unix()
  7854. }
  7855. if statistics_type == 1 {
  7856. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7857. this.ServeSuccessJSON(map[string]interface{}{
  7858. "list": list,
  7859. "total": total,
  7860. })
  7861. } else {
  7862. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7863. this.ServeSuccessJSON(map[string]interface{}{
  7864. "list": list,
  7865. "total": total,
  7866. })
  7867. }
  7868. }
  7869. func (c *HisApiController) PostProjectInformation() {
  7870. adminUser := c.GetAdminUserInfo()
  7871. orgId := adminUser.CurrentOrgId
  7872. dataBody := make(map[string]interface{}, 0)
  7873. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7874. if err != nil {
  7875. utils.ErrorLog(err.Error())
  7876. return
  7877. }
  7878. utils.ErrorLog("%v", dataBody)
  7879. var projectList []*models.HisProject
  7880. var total_goods []interface{}
  7881. tempProjects := dataBody["projects"].([]interface{})
  7882. total_goods = tempProjects
  7883. for index, projectMap := range tempProjects {
  7884. projectM := projectMap.(map[string]interface{})
  7885. var project models.HisProject
  7886. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7887. utils.ErrorLog("project_name")
  7888. return
  7889. }
  7890. project_name, _ := projectM["project_name"].(string)
  7891. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7892. err_log := models.ExportErrLog{
  7893. LogType: 6,
  7894. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7895. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7896. Status: 1,
  7897. CreateTime: time.Now().Unix(),
  7898. UpdateTime: time.Now().Unix(),
  7899. ExportTime: time.Now().Unix(),
  7900. }
  7901. service.CreateExportErrLog(&err_log)
  7902. continue
  7903. }
  7904. project.ProjectName = project_name
  7905. prices := projectM["price"].(string)
  7906. price, _ := strconv.ParseFloat(prices, 64)
  7907. if price <= 0 { //名字为空则生成一条导入错误日志
  7908. err_log := models.ExportErrLog{
  7909. LogType: 6,
  7910. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7911. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7912. Status: 1,
  7913. CreateTime: time.Now().Unix(),
  7914. UpdateTime: time.Now().Unix(),
  7915. ExportTime: time.Now().Unix(),
  7916. }
  7917. service.CreateExportErrLog(&err_log)
  7918. continue
  7919. }
  7920. project.Price = price
  7921. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7922. utils.ErrorLog("unit_id")
  7923. return
  7924. }
  7925. unit := projectM["unit"].(string)
  7926. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7927. err_log := models.ExportErrLog{
  7928. LogType: 6,
  7929. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7930. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7931. Status: 1,
  7932. CreateTime: time.Now().Unix(),
  7933. UpdateTime: time.Now().Unix(),
  7934. ExportTime: time.Now().Unix(),
  7935. }
  7936. service.CreateExportErrLog(&err_log)
  7937. continue
  7938. }
  7939. project.Unit = unit
  7940. cost_classify := projectM["cost_classify"].(string)
  7941. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7942. err_log := models.ExportErrLog{
  7943. LogType: 6,
  7944. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7945. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7946. Status: 1,
  7947. CreateTime: time.Now().Unix(),
  7948. UpdateTime: time.Now().Unix(),
  7949. ExportTime: time.Now().Unix(),
  7950. }
  7951. service.CreateExportErrLog(&err_log)
  7952. continue
  7953. }
  7954. var costClassify = "费用类别"
  7955. var cost_classify_id int64
  7956. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7957. if len(cost_classify) != 0 {
  7958. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7959. if errcode == gorm.ErrRecordNotFound {
  7960. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7961. dataconfig := models.DictDataconfig{
  7962. ParentId: costClassifyConfig.ID,
  7963. Module: "system",
  7964. OrgId: orgId,
  7965. Name: cost_classify,
  7966. FieldName: "",
  7967. Value: costConfig.Value + 1,
  7968. CreatedTime: "",
  7969. UpdatedTime: "",
  7970. CreateUserId: adminUser.AdminUser.Id,
  7971. Status: 1,
  7972. Remark: "",
  7973. DeleteIdSystem: 0,
  7974. Title: "",
  7975. Content: "",
  7976. Order: 0,
  7977. Code: "",
  7978. }
  7979. service.CreatedDicConfig(&dataconfig)
  7980. }
  7981. }
  7982. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7983. for _, it := range costClassList {
  7984. if cost_classify == it.Name {
  7985. cost_classify_id = int64(it.Value)
  7986. }
  7987. }
  7988. project.CostClassify = cost_classify_id
  7989. executive_section := projectM["executive_section"].(string)
  7990. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7991. err_log := models.ExportErrLog{
  7992. LogType: 6,
  7993. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7994. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7995. Status: 1,
  7996. CreateTime: time.Now().Unix(),
  7997. UpdateTime: time.Now().Unix(),
  7998. ExportTime: time.Now().Unix(),
  7999. }
  8000. service.CreateExportErrLog(&err_log)
  8001. continue
  8002. }
  8003. if len(executive_section) != 0 {
  8004. //查找科室是否有内容
  8005. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8006. if errcodedepart == gorm.ErrRecordNotFound {
  8007. department := models.XtHisDepartment{
  8008. Name: executive_section,
  8009. Status: 1,
  8010. UserOrgId: adminUser.CurrentOrgId,
  8011. CreatedTime: time.Now().Unix(),
  8012. }
  8013. service.CreateDePartment(&department)
  8014. }
  8015. }
  8016. var executive_section_id int64
  8017. departMentList, _ := service.GetAllDepartMent(orgId)
  8018. for _, it := range departMentList {
  8019. if executive_section == it.Name {
  8020. executive_section_id = it.ID
  8021. }
  8022. }
  8023. project.ExecutiveSection = executive_section_id
  8024. medical_coverage := projectM["medical_coverage"].(string)
  8025. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8026. err_log := models.ExportErrLog{
  8027. LogType: 6,
  8028. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8029. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8030. Status: 1,
  8031. CreateTime: time.Now().Unix(),
  8032. UpdateTime: time.Now().Unix(),
  8033. ExportTime: time.Now().Unix(),
  8034. }
  8035. service.CreateExportErrLog(&err_log)
  8036. continue
  8037. }
  8038. var medicalCoverage = "医保等级"
  8039. var medical_coverage_id int64
  8040. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8041. if len(medical_coverage) != 0 {
  8042. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8043. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8044. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8045. dataconfig := models.DictDataconfig{
  8046. ParentId: medicalCoverageConfig.ID,
  8047. Module: "system",
  8048. OrgId: orgId,
  8049. Name: medical_coverage,
  8050. FieldName: "",
  8051. Value: medicalCoverageConfig.Value + 1,
  8052. CreatedTime: "",
  8053. UpdatedTime: "",
  8054. CreateUserId: adminUser.AdminUser.Id,
  8055. Status: 1,
  8056. Remark: "",
  8057. DeleteIdSystem: 0,
  8058. Title: "",
  8059. Content: "",
  8060. Order: 0,
  8061. Code: "",
  8062. }
  8063. service.CreatedDicConfig(&dataconfig)
  8064. }
  8065. }
  8066. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8067. for _, it := range medicalCoverageList {
  8068. if medical_coverage == it.Name {
  8069. medical_coverage_id = int64(it.Value)
  8070. }
  8071. }
  8072. project.MedicalCoverage = medical_coverage_id
  8073. pinyin := projectM["pinyin"].(string)
  8074. project.Pinyin = pinyin
  8075. wubi := projectM["wubi"].(string)
  8076. project.Wubi = wubi
  8077. statistical_classification := projectM["statistical_classification"].(string)
  8078. var statisticalClassification = "统计分类"
  8079. var statistical_classification_id int64
  8080. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8081. if len(statistical_classification) != 0 {
  8082. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8083. if classificationerrcodes == gorm.ErrRecordNotFound {
  8084. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8085. dataconfig := models.DictDataconfig{
  8086. ParentId: classiFication.ID,
  8087. Module: "system",
  8088. OrgId: orgId,
  8089. Name: statistical_classification,
  8090. FieldName: "",
  8091. Value: classiFicationConfig.Value + 1,
  8092. CreatedTime: "",
  8093. UpdatedTime: "",
  8094. CreateUserId: adminUser.AdminUser.Id,
  8095. Status: 1,
  8096. Remark: "",
  8097. DeleteIdSystem: 0,
  8098. Title: "",
  8099. Content: "",
  8100. Order: 0,
  8101. Code: "",
  8102. }
  8103. service.CreatedDicConfig(&dataconfig)
  8104. }
  8105. }
  8106. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8107. for _, it := range classiFicationList {
  8108. if statistical_classification == it.Name {
  8109. statistical_classification_id = int64(it.Value)
  8110. }
  8111. }
  8112. project.StatisticalClassification = statistical_classification_id
  8113. disease_directory := int64(projectM["disease_directory"].(float64))
  8114. project.DiseaseDirectory = disease_directory
  8115. is_record := int64(projectM["is_record"].(float64))
  8116. project.IsRecord = is_record
  8117. medical_code := projectM["medical_code"].(string)
  8118. project.MedicalCode = medical_code
  8119. tube_color := projectM["tube_color"].(string)
  8120. var tubeColor = "试管颜色"
  8121. var tube_color_id int64
  8122. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8123. if len(tube_color) != 0 {
  8124. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8125. if errcodetube == gorm.ErrRecordNotFound {
  8126. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8127. dataconfig := models.DictDataconfig{
  8128. ParentId: tubeColorConfig.ID,
  8129. Module: "system",
  8130. OrgId: orgId,
  8131. Name: tube_color,
  8132. FieldName: "",
  8133. Value: tubeConfig.Value + 1,
  8134. CreatedTime: "",
  8135. UpdatedTime: "",
  8136. CreateUserId: adminUser.AdminUser.Id,
  8137. Status: 1,
  8138. Remark: "",
  8139. DeleteIdSystem: 0,
  8140. Title: "",
  8141. Content: "",
  8142. Order: 0,
  8143. Code: "",
  8144. }
  8145. service.CreatedDicConfig(&dataconfig)
  8146. }
  8147. }
  8148. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8149. for _, it := range tubeColorList {
  8150. if tube_color == it.Name {
  8151. tube_color_id = int64(it.Value)
  8152. }
  8153. }
  8154. project.TubeColor = tube_color_id
  8155. single_dose := projectM["single_dose"].(string)
  8156. project.SingleDose = single_dose
  8157. execution_frequency := projectM["execution_frequency"].(string)
  8158. project.ExecutionFrequency = execution_frequency
  8159. delivery_way := projectM["delivery_way"].(string)
  8160. project.DeliveryWay = delivery_way
  8161. number_days := projectM["number_days"].(string)
  8162. project.NumberDays = number_days
  8163. total := projectM["total"].(string)
  8164. project.Total = total
  8165. medical_status := int64(projectM["medical_status"].(float64))
  8166. project.MedicalStatus = medical_status
  8167. category := int64(projectM["category"].(float64))
  8168. project.Category = category
  8169. specail_project := int64(projectM["specail_project"].(float64))
  8170. project.SpecailProject = specail_project
  8171. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8172. project.SocialSecurityDirectoryCode = social_security_directory_code
  8173. remark := projectM["remark"].(string)
  8174. project.Remark = remark
  8175. record_date := projectM["record_date"].(string)
  8176. timeLayout := "2006-01-02"
  8177. loc, _ := time.LoadLocation("Local")
  8178. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8179. project.RecordDate = theTime.Unix()
  8180. projectList = append(projectList, &project)
  8181. }
  8182. export_time := time.Now().Unix()
  8183. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8184. if len(projectList) > 0 {
  8185. for _, item := range projectList {
  8186. project := models.HisProject{
  8187. ProjectName: item.ProjectName,
  8188. Price: item.Price,
  8189. Unit: item.Unit,
  8190. CostClassify: item.CostClassify,
  8191. ExecutiveSection: item.ExecutiveSection,
  8192. MedicalCoverage: item.MedicalCoverage,
  8193. UserOrgId: orgId,
  8194. Status: 1,
  8195. CreatedTime: time.Now().Unix(),
  8196. Pinyin: item.Pinyin,
  8197. Wubi: item.Wubi,
  8198. StatisticalClassification: item.StatisticalClassification,
  8199. DiseaseDirectory: item.DiseaseDirectory,
  8200. IsRecord: item.IsRecord,
  8201. MedicalCode: item.MedicalCode,
  8202. TubeColor: item.TubeColor,
  8203. SingleDose: item.SingleDose,
  8204. DeliveryWay: item.DeliveryWay,
  8205. NumberDays: item.NumberDays,
  8206. Total: item.Total,
  8207. Category: item.Category,
  8208. MedicalStatus: item.MedicalStatus,
  8209. SpecailProject: item.SpecailProject,
  8210. RecordDate: item.RecordDate,
  8211. Remark: item.Remark,
  8212. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8213. ExecutionFrequency: item.ExecutionFrequency,
  8214. }
  8215. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8216. if errcodeproject == gorm.ErrRecordNotFound {
  8217. service.CreateProjectInfomation(&project)
  8218. } else if errcodeproject == nil {
  8219. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8220. }
  8221. log := models.ExportLog{
  8222. LogType: 6,
  8223. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8224. TotalNum: int64(len(total_goods)),
  8225. FailNum: int64(len(errLogs)),
  8226. SuccessNum: int64(len(projectList)),
  8227. CreateTime: time.Now().Unix(),
  8228. UpdateTime: time.Now().Unix(),
  8229. ExportTime: export_time,
  8230. Status: 1,
  8231. }
  8232. service.CreateExportLog(&log)
  8233. c.ServeSuccessJSON(map[string]interface{}{
  8234. "msg": "导入成功",
  8235. "total_num": len(total_goods),
  8236. "success_num": len(projectList),
  8237. "fail_num": int64(len(errLogs)),
  8238. })
  8239. }
  8240. } else {
  8241. log := models.ExportLog{
  8242. LogType: 6,
  8243. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8244. TotalNum: int64(len(total_goods)),
  8245. FailNum: int64(len(errLogs)),
  8246. SuccessNum: int64(len(projectList)),
  8247. CreateTime: time.Now().Unix(),
  8248. UpdateTime: time.Now().Unix(),
  8249. ExportTime: export_time,
  8250. Status: 1,
  8251. }
  8252. service.CreateExportLog(&log)
  8253. c.ServeSuccessJSON(map[string]interface{}{
  8254. "msg": "导入成功",
  8255. "total_num": len(total_goods),
  8256. "success_num": len(projectList),
  8257. "fail_num": int64(len(errLogs)),
  8258. })
  8259. }
  8260. }
  8261. //func (this *HisApiController) EditProjectInformation(){
  8262. //
  8263. // id, _ := this.GetInt64("id")
  8264. // project_team := this.GetString("project_team")
  8265. // price := this.GetString("price")
  8266. // price_float, _ := strconv.ParseFloat(price, 64)
  8267. // pinyin := this.GetString("pinyin")
  8268. // wubi := this.GetString("wubi")
  8269. // tube_color, _ := this.GetInt64("tube_color")
  8270. // team_type, _ := this.GetInt64("team_type")
  8271. // remark := this.GetString("remark")
  8272. // ids := this.GetString("ids")
  8273. // item_id := this.GetString("item_id")
  8274. // projectTeam := models.XtHisProjectTeam{
  8275. // ProjectTeam: project_team,
  8276. // Price: price_float,
  8277. // Pinyin: pinyin,
  8278. // Wubi: wubi,
  8279. // TubeColor: tube_color,
  8280. // TeamType: team_type,
  8281. // Remark: remark,
  8282. // ProjectId: ids,
  8283. // ItemId: item_id,
  8284. // }
  8285. //
  8286. //
  8287. // dataBody := make(map[string]interface{}, 0)
  8288. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8289. // if err != nil {
  8290. // utils.ErrorLog(err.Error())
  8291. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8292. // return
  8293. // }
  8294. //
  8295. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8296. //
  8297. //
  8298. // if err != nil {
  8299. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8300. // return
  8301. // }
  8302. //
  8303. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8304. // infos, _ := dataBody["info"].([]interface{})
  8305. // if len(infos) > 0 {
  8306. // var ids []string
  8307. //
  8308. // for _, item := range infos {
  8309. // items := item.(map[string]interface{})
  8310. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8311. // utils.ErrorLog("id")
  8312. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8313. // return
  8314. // }
  8315. // id := int64(items["id"].(float64))
  8316. //
  8317. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8318. // utils.ErrorLog("type")
  8319. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8320. // return
  8321. // }
  8322. // types := int64(items["type"].(float64))
  8323. //
  8324. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8325. // utils.ErrorLog("number")
  8326. // }
  8327. //
  8328. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8329. //
  8330. // projectList := models.XtHisProjectList{
  8331. // Number: number,
  8332. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8333. // ProjectId: id,
  8334. // Status: 1,
  8335. // CreatedTime: time.Now().Unix(),
  8336. // UpdatedTime: time.Now().Unix(),
  8337. // TeamId: projectTeam.ID,
  8338. // Type: types,
  8339. // }
  8340. // list := projectList
  8341. //
  8342. // service.CreateProjectList(&list)
  8343. //
  8344. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8345. //
  8346. // }
  8347. // ids_str := strings.Join(ids, ",")
  8348. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8349. // service.SaveProjectTeam(&projectTeam)
  8350. // this.ServeSuccessJSON(map[string]interface{}{
  8351. // "projectTeam": projectTeam,
  8352. // })
  8353. // }
  8354. // }
  8355. //}
  8356. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8357. name := c.GetString("name")
  8358. mode_id, _ := c.GetInt64("mode", 0)
  8359. types, _ := c.GetInt64("type", 0)
  8360. patient_id, _ := c.GetInt64("patient_id", 0)
  8361. types = 1
  8362. adminInfo := c.GetAdminUserInfo()
  8363. template := &models.HisPrescriptionTemplate{
  8364. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8365. PatientId: patient_id,
  8366. Type: types,
  8367. Status: 1,
  8368. Ctime: time.Now().Unix(),
  8369. Mtime: time.Now().Unix(),
  8370. Name: name,
  8371. Mode: mode_id,
  8372. }
  8373. dataBody := make(map[string]interface{}, 0)
  8374. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8375. if err != nil {
  8376. utils.ErrorLog(err.Error())
  8377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8378. return
  8379. }
  8380. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8381. //如果已经存在记录则删除处方
  8382. if template_one.ID > 0 {
  8383. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8384. for _, item := range ps {
  8385. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8386. }
  8387. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8388. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8389. if len(prescriptions) > 0 {
  8390. for _, item := range prescriptions {
  8391. items := item.(map[string]interface{})
  8392. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8393. utils.ErrorLog("type")
  8394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8395. return
  8396. }
  8397. types := int64(items["type"].(float64))
  8398. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8399. utils.ErrorLog("med_type")
  8400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8401. return
  8402. }
  8403. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8404. ctime := time.Now().Unix()
  8405. prescription := &models.HisPrescriptionInfoTemplate{
  8406. PatientId: patient_id,
  8407. UserOrgId: adminInfo.CurrentOrgId,
  8408. Ctime: ctime,
  8409. Mtime: ctime,
  8410. Type: types,
  8411. Modifier: adminInfo.AdminUser.Id,
  8412. Creator: adminInfo.AdminUser.Id,
  8413. Status: 1,
  8414. PTemplateId: template_one.ID,
  8415. MedType: med_type,
  8416. }
  8417. service.CreateHisPrescriptionInfoTemplate(prescription)
  8418. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8419. advices := items["advices"].([]interface{})
  8420. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8421. ctime := time.Now().Unix()
  8422. mtime := ctime
  8423. if len(advices) > 0 {
  8424. for _, advice := range advices {
  8425. var s models.HisPrescriptionAdviceTemplate
  8426. s.PrescriptionId = prescription.ID
  8427. s.AdviceType = 2
  8428. s.StopState = 2
  8429. s.ExecutionState = 2
  8430. s.Status = 1
  8431. s.UserOrgId = adminInfo.CurrentOrgId
  8432. s.CreatedTime = ctime
  8433. s.UpdatedTime = mtime
  8434. s.PatientId = patient_id
  8435. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8436. if errcode > 0 {
  8437. c.ServeFailJSONWithSGJErrorCode(errcode)
  8438. return
  8439. }
  8440. service.CreateHisPrescriptionAdviceTemplate(&s)
  8441. }
  8442. }
  8443. }
  8444. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8445. projects := items["project"].([]interface{})
  8446. if len(projects) > 0 {
  8447. for _, project := range projects {
  8448. var p models.HisPrescriptionProjectTemplate
  8449. p.PrescriptionId = prescription.ID
  8450. p.Ctime = time.Now().Unix()
  8451. p.Mtime = time.Now().Unix()
  8452. p.PatientId = patient_id
  8453. p.UserOrgId = adminInfo.CurrentOrgId
  8454. p.Status = 1
  8455. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8456. if errcode > 0 {
  8457. c.ServeFailJSONWithSGJErrorCode(errcode)
  8458. return
  8459. }
  8460. service.CreateHisPrescriptionProjectTemplate(&p)
  8461. }
  8462. }
  8463. }
  8464. }
  8465. c.ServeSuccessJSON(map[string]interface{}{
  8466. "msg": "创建成功",
  8467. })
  8468. }
  8469. }
  8470. } else {
  8471. err = service.CreateHisPrescriptionTemplate(template)
  8472. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8473. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8474. if len(prescriptions) > 0 {
  8475. for _, item := range prescriptions {
  8476. items := item.(map[string]interface{})
  8477. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8478. utils.ErrorLog("type")
  8479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8480. return
  8481. }
  8482. types := int64(items["type"].(float64))
  8483. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8484. utils.ErrorLog("med_type")
  8485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8486. return
  8487. }
  8488. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8489. ctime := time.Now().Unix()
  8490. prescription := &models.HisPrescriptionInfoTemplate{
  8491. PatientId: patient_id,
  8492. UserOrgId: adminInfo.CurrentOrgId,
  8493. Ctime: ctime,
  8494. Mtime: ctime,
  8495. Type: types,
  8496. Modifier: adminInfo.AdminUser.Id,
  8497. Creator: adminInfo.AdminUser.Id,
  8498. Status: 1,
  8499. PTemplateId: template.ID,
  8500. MedType: med_type,
  8501. }
  8502. service.CreateHisPrescriptionInfoTemplate(prescription)
  8503. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8504. advices := items["advices"].([]interface{})
  8505. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8506. ctime := time.Now().Unix()
  8507. mtime := ctime
  8508. if len(advices) > 0 {
  8509. for _, advice := range advices {
  8510. var s models.HisPrescriptionAdviceTemplate
  8511. s.PrescriptionId = prescription.ID
  8512. s.AdviceType = 2
  8513. s.StopState = 2
  8514. s.ExecutionState = 2
  8515. s.Status = 1
  8516. s.UserOrgId = adminInfo.CurrentOrgId
  8517. s.CreatedTime = ctime
  8518. s.UpdatedTime = mtime
  8519. s.PatientId = patient_id
  8520. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8521. if errcode > 0 {
  8522. c.ServeFailJSONWithSGJErrorCode(errcode)
  8523. return
  8524. }
  8525. service.CreateHisPrescriptionAdviceTemplate(&s)
  8526. }
  8527. }
  8528. }
  8529. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8530. projects := items["project"].([]interface{})
  8531. if len(projects) > 0 {
  8532. for _, project := range projects {
  8533. var p models.HisPrescriptionProjectTemplate
  8534. p.PrescriptionId = prescription.ID
  8535. p.Ctime = time.Now().Unix()
  8536. p.Mtime = time.Now().Unix()
  8537. p.PatientId = patient_id
  8538. p.UserOrgId = adminInfo.CurrentOrgId
  8539. p.Status = 1
  8540. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8541. if errcode > 0 {
  8542. c.ServeFailJSONWithSGJErrorCode(errcode)
  8543. return
  8544. }
  8545. service.CreateHisPrescriptionProjectTemplate(&p)
  8546. }
  8547. }
  8548. }
  8549. }
  8550. c.ServeSuccessJSON(map[string]interface{}{
  8551. "msg": "创建成功",
  8552. })
  8553. }
  8554. }
  8555. }
  8556. }
  8557. func (c *HisApiController) PreSettle() {
  8558. id, _ := c.GetInt64("id")
  8559. record_time := c.GetString("record_time")
  8560. his_patient_id, _ := c.GetInt64("his_patient_id")
  8561. timeLayout := "2006-01-02"
  8562. loc, _ := time.LoadLocation("Local")
  8563. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8564. diagnosis_id := c.GetString("diagnosis")
  8565. sick_type, _ := c.GetInt64("sick_type")
  8566. reg_type, _ := c.GetInt64("p_type")
  8567. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8569. if err != nil {
  8570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8571. return
  8572. }
  8573. recordDateTime := theTime.Unix()
  8574. adminUser := c.GetAdminUserInfo()
  8575. var prescriptions []*models.HisPrescription
  8576. var start_time int64
  8577. var end_time int64
  8578. ids_str := c.GetString("ids")
  8579. ids_arr := strings.Split(ids_str, ",")
  8580. fmt.Println(reg_type)
  8581. if settle_accounts_type == 1 { //日结
  8582. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8583. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8584. } else {
  8585. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8586. }
  8587. fmt.Println(prescriptions)
  8588. } else { //月结
  8589. start_time_str := c.GetString("start_time")
  8590. end_time_str := c.GetString("end_time")
  8591. timeLayout := "2006-01-02"
  8592. loc, _ := time.LoadLocation("Local")
  8593. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8594. if err != nil {
  8595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8596. return
  8597. }
  8598. recordStartTime := theStartTime.Unix()
  8599. start_time = recordStartTime
  8600. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8601. if err != nil {
  8602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8603. return
  8604. }
  8605. recordEndTime := theEndTime.Unix()
  8606. end_time = recordEndTime
  8607. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8608. }
  8609. if reg_type == 1111 || reg_type == 1112 {
  8610. reg_type = 11
  8611. }
  8612. timestamp := time.Now().Unix()
  8613. tempTime := time.Unix(timestamp, 0)
  8614. timeFormat := tempTime.Format("20060102150405")
  8615. chrgBchno := rand.Intn(100000) + 10000
  8616. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8617. strconv.FormatInt(his.PatientId, 10)
  8618. var ids []int64
  8619. for _, item := range prescriptions {
  8620. ids = append(ids, item.ID)
  8621. }
  8622. fmt.Println(ids)
  8623. var total float64
  8624. for _, item := range prescriptions {
  8625. fmt.Println(item)
  8626. if item.Type == 1 { //药品
  8627. for _, subItem := range item.HisDoctorAdviceInfo {
  8628. total = total + (subItem.Price * subItem.PrescribingNumber)
  8629. }
  8630. }
  8631. if item.Type == 2 { //项目
  8632. for _, subItem := range item.HisPrescriptionProject {
  8633. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8634. total = total + (subItem.Price * cnt)
  8635. }
  8636. }
  8637. for _, subItem := range item.HisAdditionalCharge {
  8638. total = total + (subItem.Price * float64(subItem.Count))
  8639. }
  8640. }
  8641. allTotal := fmt.Sprintf("%.2f", total)
  8642. totals, _ := strconv.ParseFloat(allTotal, 64)
  8643. order := &models.HisOrder{
  8644. UserOrgId: adminUser.CurrentOrgId,
  8645. HisPatientId: his.ID,
  8646. PatientId: id,
  8647. SettleAccountsDate: recordDateTime,
  8648. Ctime: time.Now().Unix(),
  8649. Mtime: time.Now().Unix(),
  8650. Status: 1,
  8651. OrderStatus: 1,
  8652. MdtrtId: his.Number,
  8653. Number: chrg_bchno,
  8654. MedfeeSumamt: totals,
  8655. SettleEndTime: end_time,
  8656. SettleStartTime: start_time,
  8657. SettleType: settle_accounts_type,
  8658. PsnPartAmt: totals,
  8659. PsnCashPay: totals,
  8660. PType: 2,
  8661. IsPre: 1,
  8662. MedType: strconv.Itoa(int(reg_type)),
  8663. Diagnosis: diagnosis_id,
  8664. }
  8665. err = service.CreateOrder(order)
  8666. if err != nil {
  8667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8668. return
  8669. }
  8670. var customs []*Custom
  8671. for _, item := range prescriptions {
  8672. fmt.Println(item.Type)
  8673. if item.Type == 1 { //药品
  8674. for _, subItem := range item.HisDoctorAdviceInfo {
  8675. cus := &Custom{
  8676. AdviceId: subItem.ID,
  8677. ProjectId: 0,
  8678. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8679. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8680. FeedetlSn: subItem.FeedetlSn,
  8681. Price: fmt.Sprintf("%.2f", subItem.Price),
  8682. MedListCodg: subItem.MedListCodg,
  8683. Type: 1,
  8684. }
  8685. customs = append(customs, cus)
  8686. }
  8687. }
  8688. if item.Type == 2 { //项目
  8689. for _, subItem := range item.HisPrescriptionProject {
  8690. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8691. cus := &Custom{
  8692. AdviceId: 0,
  8693. ProjectId: subItem.ID,
  8694. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8695. Cut: fmt.Sprintf("%.2f", cnt),
  8696. FeedetlSn: subItem.FeedetlSn,
  8697. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8698. MedListCodg: subItem.MedListCodg,
  8699. Type: 2,
  8700. }
  8701. customs = append(customs, cus)
  8702. }
  8703. }
  8704. for _, item := range item.HisAdditionalCharge {
  8705. cus := &Custom{
  8706. ItemId: item.ID,
  8707. AdviceId: 0,
  8708. ProjectId: 0,
  8709. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8710. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8711. FeedetlSn: item.FeedetlSn,
  8712. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8713. MedListCodg: item.XtHisAddtionConfig.Code,
  8714. Type: 3,
  8715. }
  8716. customs = append(customs, cus)
  8717. }
  8718. }
  8719. fmt.Println(customs)
  8720. for _, item := range customs {
  8721. var advice_id int64 = 0
  8722. var project_id int64 = 0
  8723. var item_id int64 = 0
  8724. var types int64 = 0
  8725. if item.Type == 1 {
  8726. advice_id = item.AdviceId
  8727. project_id = 0
  8728. item_id = 0
  8729. } else if item.Type == 2 {
  8730. advice_id = 0
  8731. item_id = 0
  8732. project_id = item.ProjectId
  8733. } else if item.Type == 3 {
  8734. advice_id = 0
  8735. item_id = item.ItemId
  8736. project_id = 0
  8737. }
  8738. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8739. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8740. pric, _ := strconv.ParseFloat(item.Price, 32)
  8741. info := &models.HisOrderInfo{
  8742. OrderNumber: order.Number,
  8743. UploadDate: time.Now().Unix(),
  8744. AdviceId: advice_id,
  8745. DetItemFeeSumamt: detItemFeeSumamt,
  8746. Cnt: cut,
  8747. Pric: pric,
  8748. PatientId: id,
  8749. Status: 1,
  8750. Mtime: time.Now().Unix(),
  8751. Ctime: time.Now().Unix(),
  8752. UserOrgId: adminUser.CurrentOrgId,
  8753. HisPatientId: his.ID,
  8754. OrderId: order.ID,
  8755. ProjectId: project_id,
  8756. Type: types,
  8757. ItemId: item_id,
  8758. }
  8759. service.CreateOrderInfo(info)
  8760. }
  8761. his.SickType = sick_type
  8762. service.UpdataHisPateint(&his)
  8763. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8764. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8765. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8766. if err == nil {
  8767. c.ServeSuccessJSON(map[string]interface{}{
  8768. "msg": "结算成功",
  8769. })
  8770. }
  8771. }
  8772. type CustomOrderInfo struct {
  8773. Name string
  8774. Spec string
  8775. Unit string
  8776. Count float64
  8777. Price float64
  8778. Total float64
  8779. }
  8780. func (c *HisApiController) GetPrivateExpensesInfo() {
  8781. order_id, _ := c.GetInt64("id", 0)
  8782. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8783. order, _ := service.GetHisOrderByID(order_id)
  8784. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8785. if order.ID == 0 {
  8786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8787. return
  8788. }
  8789. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8790. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8791. org_id := c.GetAdminUserInfo().CurrentOrgId
  8792. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8793. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8794. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8795. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8796. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8797. //var orderInfos_four []*models.HisOrderInfoTwo
  8798. //for _, item := range orderInfos_three {
  8799. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8800. // item.HisPrescriptionProject.IsCheckTeam = 1
  8801. // orderInfos_four = append(orderInfos_four, item)
  8802. //
  8803. // }
  8804. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8805. // item.HisPrescriptionProject.IsCheckTeam = 2
  8806. // orderInfos_two = append(orderInfos_two, item)
  8807. // }
  8808. //}
  8809. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8810. //var cus_slice []CustomOrderInfo
  8811. //for _, item := range new_order_info {
  8812. // var cus CustomOrderInfo
  8813. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8814. // cus.Unit = ""
  8815. // cus.Spec = ""
  8816. // var total float64
  8817. // for _, subItem := range orderInfos_four {
  8818. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8819. // total = total + subItem.DetItemFeeSumamt
  8820. // fmt.Println(subItem.DetItemFeeSumamt)
  8821. // }
  8822. // }
  8823. // cus.Count = 1
  8824. // cus.Total = total
  8825. // cus_slice = append(cus_slice, cus)
  8826. //}
  8827. orderInfos = append(orderInfos, orderInfos_two...)
  8828. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8829. //orderInfos = append(orderInfos, orderInfos_three...)
  8830. //}/**/
  8831. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8832. c.ServeSuccessJSON(map[string]interface{}{
  8833. "order": order,
  8834. "order_info": orderInfos,
  8835. "patient": patient,
  8836. "admin_info": adminInfo,
  8837. "his": his,
  8838. "current_admin": role,
  8839. "org_config": miConfig,
  8840. //"new_order_info": cus_slice,
  8841. })
  8842. }
  8843. func (this *HisApiController) ChangeMedType() {
  8844. med_type := this.GetString("med_type")
  8845. old_med_type := this.GetString("old_med_type")
  8846. ids := this.GetString("ids")
  8847. settle_type, _ := this.GetInt64("settle_type")
  8848. start_time := this.GetString("start_time")
  8849. end_time := this.GetString("end_time")
  8850. ids_arr := strings.Split(ids, ",")
  8851. if settle_type == 1 { //日结
  8852. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8853. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8854. prescription.MedType = med_type
  8855. err := service.SaveHisPrescription(&prescription)
  8856. if err == nil {
  8857. this.ServeSuccessJSON(map[string]interface{}{
  8858. "msg": "修改成功",
  8859. })
  8860. } else {
  8861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8862. return
  8863. }
  8864. } else if settle_type == 2 {
  8865. timeLayout := "2006-01-02"
  8866. loc, _ := time.LoadLocation("Local")
  8867. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8868. if err != nil {
  8869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8870. return
  8871. }
  8872. recordStartTime := theStartTime.Unix()
  8873. start_time_timestamp := recordStartTime
  8874. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8875. if err != nil {
  8876. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8877. return
  8878. }
  8879. recordEndTime := theEndTime.Unix()
  8880. end_time_timestamp := recordEndTime
  8881. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8882. if updateErr == nil {
  8883. this.ServeSuccessJSON(map[string]interface{}{
  8884. "msg": "修改成功",
  8885. })
  8886. } else {
  8887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8888. return
  8889. }
  8890. }
  8891. }
  8892. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8893. patient_id, _ := c.GetInt64("patient_id")
  8894. his_patient_id, _ := c.GetInt64("his_patient_id")
  8895. record_date := c.GetString("record_date")
  8896. start_time := c.GetString("start_time")
  8897. end_time := c.GetString("end_time")
  8898. order_status, _ := c.GetInt64("type", 0)
  8899. p_type, _ := c.GetInt64("p_type", 0)
  8900. order_id, _ := c.GetInt64("order_id", 0)
  8901. timeLayout := "2006-01-02"
  8902. loc, _ := time.LoadLocation("Local")
  8903. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8904. if err != nil {
  8905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8906. return
  8907. }
  8908. recordDateTime := theTime.Unix()
  8909. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8910. if err != nil {
  8911. }
  8912. startRecordDateTime := startTime.Unix()
  8913. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8914. if err != nil {
  8915. }
  8916. endRecordDateTime := endTime.Unix()
  8917. admin := c.GetAdminUserInfo()
  8918. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8919. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8920. order, _ := service.GetHisOrderByID(order_id)
  8921. var monthPrescriptions []*models.HisPrescription
  8922. if order_status == 1 || order_status == 0 {
  8923. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8924. } else if order_status == 2 {
  8925. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8926. }
  8927. var settle_total float64
  8928. for _, item := range monthPrescriptions {
  8929. if len(item.HisPrescriptionProject) > 0 {
  8930. for _, subItem := range item.HisPrescriptionProject {
  8931. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8932. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8933. settle_total = settle_total + total
  8934. }
  8935. }
  8936. if len(item.HisDoctorAdviceInfo) > 0 {
  8937. for _, subItem := range item.HisDoctorAdviceInfo {
  8938. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8939. settle_total = settle_total + total
  8940. }
  8941. }
  8942. }
  8943. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8944. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8945. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8946. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8947. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8948. //获取所有科室信息
  8949. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8950. c.ServeSuccessJSON(map[string]interface{}{
  8951. "his_info": his_patient_info,
  8952. "xt_info": xt_patient_info,
  8953. "case_history": case_history,
  8954. "info": patientPrescriptionInfo,
  8955. "last_info": lastPatientPrescriptionInfo,
  8956. "month_prescriptions": monthPrescriptions,
  8957. "order": order,
  8958. "doctors": doctors,
  8959. "department": department,
  8960. "settle_total": settle_total,
  8961. })
  8962. return
  8963. }
  8964. func (c *HisApiController) GetHisMonthPatientInfo() {
  8965. patient_id, _ := c.GetInt64("patient_id")
  8966. his_patient_id, _ := c.GetInt64("his_patient_id")
  8967. record_date := c.GetString("record_date")
  8968. number := c.GetString("number")
  8969. start_time := c.GetString("start_time")
  8970. end_time := c.GetString("end_time")
  8971. p_type, _ := c.GetInt64("p_type")
  8972. timeLayout := "2006-01-02"
  8973. loc, _ := time.LoadLocation("Local")
  8974. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8975. if err != nil {
  8976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8977. return
  8978. }
  8979. recordDateTime := theTime.Unix()
  8980. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8981. if err != nil {
  8982. }
  8983. startRecordDateTime := startTime.Unix()
  8984. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8985. if err != nil {
  8986. }
  8987. endRecordDateTime := endTime.Unix()
  8988. admin := c.GetAdminUserInfo()
  8989. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8990. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8991. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8992. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8993. var settle_total float64
  8994. for _, item := range monthPrescriptions {
  8995. if len(item.HisPrescriptionProject) > 0 {
  8996. for _, subItem := range item.HisPrescriptionProject {
  8997. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8998. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8999. settle_total = settle_total + total
  9000. }
  9001. }
  9002. if len(item.HisDoctorAdviceInfo) > 0 {
  9003. for _, subItem := range item.HisDoctorAdviceInfo {
  9004. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9005. settle_total = settle_total + total
  9006. }
  9007. }
  9008. }
  9009. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9010. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9011. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9012. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9013. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9014. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9015. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9016. //获取所有科室信息
  9017. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9018. c.ServeSuccessJSON(map[string]interface{}{
  9019. "his_info": his_patient_info,
  9020. "xt_info": xt_patient_info,
  9021. "case_history": case_history,
  9022. "info": patientPrescriptionInfo,
  9023. "month_prescriptions": monthPrescriptions,
  9024. "order": order,
  9025. "doctors": doctors,
  9026. "department": department,
  9027. "count": count,
  9028. "drugStockConfig": drugStockConfig,
  9029. "last_info": lastPatientPrescriptionInfo,
  9030. "settle_total": settle_total,
  9031. })
  9032. return
  9033. }
  9034. func (c *HisApiController) GetAllOrder() {
  9035. org_id := c.GetAdminUserInfo().CurrentOrgId
  9036. orders, _ := service.GetNewHisOrderList(org_id)
  9037. c.ServeSuccessJSON(map[string]interface{}{
  9038. "order": orders,
  9039. })
  9040. return
  9041. }
  9042. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9043. newArr = make([]*models.HisOrderInfoTwo, 0)
  9044. for i := 0; i < len(arr); i++ {
  9045. repeat := false
  9046. for j := i + 1; j < len(arr); j++ {
  9047. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9048. repeat = true
  9049. break
  9050. }
  9051. }
  9052. if !repeat {
  9053. newArr = append(newArr, arr[i])
  9054. }
  9055. }
  9056. return
  9057. }
  9058. // 修改处方退库操作 参数传修改之前的处方数据
  9059. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9060. if advice.ExecutionState == 1 {
  9061. //查询该病人该药品是否有库存记录
  9062. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9063. if errcode == gorm.ErrRecordNotFound {
  9064. } else {
  9065. //退库
  9066. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9067. if advice.PrescribingNumberUnit == drug.MinUnit {
  9068. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9069. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9070. //退库
  9071. warehouseInfo := models.DrugWarehouseInfo{
  9072. StockMinNumber: prescribingNumber,
  9073. }
  9074. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9075. operation_time := time.Now().Unix()
  9076. creater := advice.AdviceDoctor
  9077. ctime := time.Now().Unix()
  9078. timeStr := time.Now().Format("2006-01-02")
  9079. timeArr := strings.Split(timeStr, "-")
  9080. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9081. total = total + 1
  9082. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9083. cancelStock := models.DrugCancelStock{
  9084. OrderNumber: orderNumber,
  9085. OperaTime: operation_time,
  9086. OrgId: advice.UserOrgId,
  9087. Creater: creater,
  9088. Ctime: ctime,
  9089. Status: 1,
  9090. ReturnTime: advice.AdviceDate,
  9091. Dealer: info.Dealer,
  9092. Manufacturer: info.Manufacturer,
  9093. Type: 1,
  9094. }
  9095. service.AddSigleDrugCancelStock(&cancelStock)
  9096. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9097. dealer, _ := service.GetDealerById(info.Dealer)
  9098. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9099. cancelStockInfo := models.DrugCancelStockInfo{
  9100. OrderNumber: cancelInfo.OrderNumber,
  9101. CancelStockId: cancelInfo.ID,
  9102. DrugId: info.DrugId,
  9103. Count: info.Count,
  9104. Status: 1,
  9105. Ctime: ctime,
  9106. OrgId: advice.UserOrgId,
  9107. Type: 1,
  9108. Manufacturer: manufactureName.ManufacturerName,
  9109. Dealer: dealer.DealerName,
  9110. Total: 0,
  9111. RetailPrice: info.RetailPrice,
  9112. RetailTotalPrice: info.RetailTotalPrice,
  9113. Price: info.Price,
  9114. RegisterAccount: "",
  9115. Remark: info.Remark,
  9116. BatchNumber: info.BatchNumber,
  9117. MaxUnit: info.CountUnit,
  9118. ProductDate: info.ProductDate,
  9119. ExpiryDate: info.ExpiryDate,
  9120. BatchNumberId: info.WarehouseInfoId,
  9121. }
  9122. flow := models.DrugFlow{
  9123. WarehousingId: 0,
  9124. DrugId: info.DrugId,
  9125. Number: "",
  9126. BatchNumber: info.BatchNumber,
  9127. Count: info.Count,
  9128. UserOrgId: advice.UserOrgId,
  9129. PatientId: 0,
  9130. SystemTime: ctime,
  9131. ConsumableType: 4,
  9132. IsSys: 0,
  9133. WarehousingOrder: "",
  9134. WarehouseOutId: 0,
  9135. WarehouseOutOrderNumber: "",
  9136. IsEdit: 0,
  9137. CancelStockId: cancelStock.ID,
  9138. CancelOrderNumber: cancelStock.OrderNumber,
  9139. Manufacturer: info.Manufacturer,
  9140. Dealer: info.Dealer,
  9141. Creator: advice.UserOrgId,
  9142. UpdateCreator: 0,
  9143. Status: 1,
  9144. Ctime: time.Now().Unix(),
  9145. Mtime: 0,
  9146. Price: info.Price,
  9147. WarehousingDetailId: 0,
  9148. WarehouseOutDetailId: 0,
  9149. CancelOutDetailId: 0,
  9150. ExpireDate: info.ExpiryDate,
  9151. ProductDate: info.ProductDate,
  9152. MaxUnit: info.CountUnit,
  9153. MinUnit: "",
  9154. }
  9155. service.CreatedCancelStock(cancelStockInfo)
  9156. service.CreateDrugFlowOne(flow)
  9157. } else {
  9158. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9159. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9160. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9161. warehouseInfo := models.DrugWarehouseInfo{
  9162. StockMinNumber: prescribingNumber,
  9163. }
  9164. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9165. }
  9166. operation_time := time.Now().Unix()
  9167. creater := advice.AdviceDoctor
  9168. ctime := time.Now().Unix()
  9169. timeStr := time.Now().Format("2006-01-02")
  9170. timeArr := strings.Split(timeStr, "-")
  9171. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9172. total = total + 1
  9173. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9174. cancelStock := models.DrugCancelStock{
  9175. OrderNumber: orderNumber,
  9176. OperaTime: operation_time,
  9177. OrgId: advice.UserOrgId,
  9178. Creater: creater,
  9179. Ctime: ctime,
  9180. Status: 1,
  9181. ReturnTime: advice.AdviceDate,
  9182. Dealer: info.Dealer,
  9183. Manufacturer: info.Manufacturer,
  9184. Type: 1,
  9185. }
  9186. service.AddSigleDrugCancelStock(&cancelStock)
  9187. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9188. dealer, _ := service.GetDealerById(info.Dealer)
  9189. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9190. cancelStockInfo := models.DrugCancelStockInfo{
  9191. OrderNumber: cancelInfo.OrderNumber,
  9192. CancelStockId: cancelInfo.ID,
  9193. DrugId: info.DrugId,
  9194. Count: info.Count,
  9195. Status: 1,
  9196. Ctime: ctime,
  9197. OrgId: advice.UserOrgId,
  9198. Type: 1,
  9199. Manufacturer: manufactureName.ManufacturerName,
  9200. Dealer: dealer.DealerName,
  9201. Total: 0,
  9202. RetailPrice: info.RetailPrice,
  9203. RetailTotalPrice: info.RetailTotalPrice,
  9204. Price: info.Price,
  9205. RegisterAccount: "",
  9206. Remark: info.Remark,
  9207. BatchNumber: info.BatchNumber,
  9208. MaxUnit: info.CountUnit,
  9209. ProductDate: info.ProductDate,
  9210. ExpiryDate: info.ExpiryDate,
  9211. BatchNumberId: info.WarehouseInfoId,
  9212. }
  9213. flow := models.DrugFlow{
  9214. WarehousingId: 0,
  9215. DrugId: info.DrugId,
  9216. Number: "",
  9217. BatchNumber: info.BatchNumber,
  9218. Count: info.Count,
  9219. UserOrgId: advice.UserOrgId,
  9220. PatientId: 0,
  9221. SystemTime: ctime,
  9222. ConsumableType: 4,
  9223. IsSys: 0,
  9224. WarehousingOrder: "",
  9225. WarehouseOutId: 0,
  9226. WarehouseOutOrderNumber: "",
  9227. IsEdit: 0,
  9228. CancelStockId: cancelStock.ID,
  9229. CancelOrderNumber: cancelStock.OrderNumber,
  9230. Manufacturer: info.Manufacturer,
  9231. Dealer: info.Dealer,
  9232. Creator: advice.AdviceDoctor,
  9233. UpdateCreator: 0,
  9234. Status: 1,
  9235. Ctime: time.Now().Unix(),
  9236. Mtime: 0,
  9237. Price: info.Price,
  9238. WarehousingDetailId: 0,
  9239. WarehouseOutDetailId: 0,
  9240. CancelOutDetailId: 0,
  9241. ExpireDate: info.ExpiryDate,
  9242. ProductDate: info.ProductDate,
  9243. MaxUnit: info.CountUnit,
  9244. MinUnit: "",
  9245. }
  9246. service.CreatedCancelStock(cancelStockInfo)
  9247. service.CreateDrugFlowOne(flow)
  9248. }
  9249. }
  9250. }
  9251. return err
  9252. }
  9253. func (this *HisApiController) DeleteNCDS() {
  9254. id, _ := this.GetInt64("id", 0)
  9255. if id > 0 {
  9256. service.DeletePsnNCDSRecordById(id)
  9257. this.ServeSuccessJSON(map[string]interface{}{
  9258. "msg": "删除成功",
  9259. })
  9260. } else {
  9261. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9262. return
  9263. }
  9264. }
  9265. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9266. id, _ := c.GetInt64("id")
  9267. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9268. c.ServeSuccessJSON(map[string]interface{}{
  9269. "advice": advice,
  9270. })
  9271. return
  9272. }
  9273. func (c *HisApiController) GetHisMonthChargePatientList() {
  9274. record_date := c.GetString("record_date")
  9275. start_time := c.GetString("start_time")
  9276. end_time := c.GetString("end_time")
  9277. timeLayout := "2006-01-02"
  9278. loc, _ := time.LoadLocation("Local")
  9279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9280. if err != nil {
  9281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9282. return
  9283. }
  9284. if err != nil {
  9285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9286. return
  9287. }
  9288. recordDateTime := theTime.Unix()
  9289. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9290. if err != nil {
  9291. }
  9292. startRecordDateTime := startTime.Unix()
  9293. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9294. if err != nil {
  9295. }
  9296. endRecordDateTime := endTime.Unix()
  9297. adminInfo := c.GetAdminUserInfo()
  9298. var tempMonthChargePatients []*service.MonthChargePatients
  9299. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9300. for _, item := range tempPatients {
  9301. //过滤没有处方的
  9302. if len(item.HisPrescription) == 0 {
  9303. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9304. }
  9305. }
  9306. c.ServeSuccessJSON(map[string]interface{}{
  9307. "list": tempMonthChargePatients,
  9308. })
  9309. }