his_api_controller.go 297KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  540. } else { //门诊
  541. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  542. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  543. }
  544. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  545. if sch.ID > 0 {
  546. var week string
  547. t := time.Now()
  548. switch t.Weekday().String() {
  549. case "Monday":
  550. week = "周一"
  551. break
  552. case "Tuesday":
  553. week = "周二"
  554. break
  555. case "Wednesday":
  556. week = "周三"
  557. break
  558. case "Thursday":
  559. week = "周四"
  560. break
  561. case "Friday":
  562. week = "周五"
  563. break
  564. case "Saturday":
  565. week = "周六"
  566. break
  567. case "Sunday":
  568. week = "周日"
  569. break
  570. }
  571. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  572. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  573. //根据推送频率组装新的数组
  574. for _, item := range temp_sch_prescriptions {
  575. var cus CustomTemplate
  576. cus.ID = item.ID
  577. cus.UserOrgId = item.UserOrgId
  578. cus.PatientId = item.PatientId
  579. cus.MedType = item.MedType
  580. cus.RecordDate = item.RecordDate
  581. cus.Type = item.Type
  582. cus.PType = item.PType
  583. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  584. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  585. if subItem.FrequencyType == 1 { //每次必推
  586. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  587. }
  588. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  589. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  590. }
  591. if subItem.FrequencyType == 2 { //按照天数频率
  592. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  593. now := p.Unix()
  594. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  595. dayStr2 := "-" + dayStr
  596. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  597. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  598. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  599. if len(advices) == 0 {
  600. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  601. }
  602. }
  603. }
  604. }
  605. for _, subItem := range item.HisPrescriptionProjectTemplate {
  606. if subItem.Type == 2 {
  607. if subItem.XtHisProject.MedicalStatus != 1 {
  608. if subItem.FrequencyType == 1 {
  609. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  610. }
  611. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  612. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  613. }
  614. if subItem.FrequencyType == 2 {
  615. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  616. now := p.Unix()
  617. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  618. dayStr2 := "-" + dayStr
  619. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  620. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  621. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  622. if len(projects) == 0 {
  623. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  624. }
  625. }
  626. }
  627. } else if subItem.Type == 3 {
  628. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  629. if subItem.FrequencyType == 1 {
  630. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  631. }
  632. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  633. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  634. }
  635. if subItem.FrequencyType == 2 {
  636. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  637. now := p.Unix()
  638. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  639. dayStr2 := "-" + dayStr
  640. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  641. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  642. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  643. if len(projects) == 0 {
  644. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  645. }
  646. }
  647. }
  648. }
  649. }
  650. sch_prescriptions = append(sch_prescriptions, cus)
  651. }
  652. for _, item := range sch_prescriptions {
  653. if len(item.HisPrescriptionProjectTemplate) == 0 {
  654. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  655. }
  656. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  657. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  658. }
  659. }
  660. }
  661. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  662. if config.ID > 0 && config.IsOpen == 1 {
  663. for _, item := range sch_prescriptions {
  664. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  665. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  666. if info.RetailPrice > 0 {
  667. subItem.Drug.MinPrice = info.RetailPrice
  668. }
  669. }
  670. }
  671. }
  672. if config.ID > 0 && config.IsOpen == 1 {
  673. for _, item := range sch_prescriptions {
  674. for _, subItem := range item.HisPrescriptionProjectTemplate {
  675. if subItem.Type == 3 {
  676. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  677. if info.Price > 0 {
  678. subItem.GoodInfo.PackingPrice = info.Price
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  685. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  689. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  692. //获取所有科室信息
  693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "his_info": his_patient_info,
  696. "xt_info": xt_patient_info,
  697. "prescription": prescriptions,
  698. "case_history": case_history,
  699. "info": patientPrescriptionInfo,
  700. //"month_prescriptions": monthPrescriptions,
  701. "order": order,
  702. "doctors": doctors,
  703. "department": department,
  704. "sch_prescriptions": sch_prescriptions,
  705. "last_prescriptions": last_prescriptions,
  706. "schedule": sch,
  707. "count": count,
  708. "drugStockConfig": drugStockConfig,
  709. "last_info": lastPatientPrescriptionInfo,
  710. })
  711. return
  712. }
  713. func (c *HisApiController) GetHisPrescriptionConfig() {
  714. adminInfo := c.GetAdminUserInfo()
  715. //获取医嘱模版
  716. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  717. //获取所有基础药
  718. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  719. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  720. if config.ID > 0 && config.IsOpen == 1 {
  721. for _, item := range drugs {
  722. var index = 0
  723. for _, subItem := range item.OtherDrugWarehouseInfo {
  724. if index == 0 {
  725. index = index + 1
  726. if subItem.RetailPrice > 0 {
  727. item.MinPrice = subItem.RetailPrice
  728. }
  729. }
  730. }
  731. }
  732. }
  733. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  734. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  735. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  736. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  737. //获取所有科室信息
  738. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  739. //获取诊断信息
  740. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  741. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  742. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "drugs": drugs,
  745. "advices_template": advices,
  746. "drugways": drugways,
  747. "efs": efs,
  748. "doctors": doctors,
  749. "department": department,
  750. "sick": sick,
  751. "additions": additions,
  752. "diagnose": diagnose,
  753. "manufacturers": manufacturers,
  754. })
  755. }
  756. func (c *HisApiController) CreateHisPrescription() {
  757. record_date := c.GetString("record_date")
  758. patient_id, _ := c.GetInt64("patient_id")
  759. reg_type, _ := c.GetInt64("reg_type")
  760. diagnose := c.GetString("diagnose")
  761. sick_type, _ := c.GetInt64("sick_type")
  762. sick_history := c.GetString("sick_history")
  763. doctor_id, _ := c.GetInt64("doctor", 0)
  764. department, _ := c.GetInt64("department", 0)
  765. his_patient_id, _ := c.GetInt64("his_patient_id")
  766. p_type, _ := c.GetInt64("p_type")
  767. dataBody := make(map[string]interface{}, 0)
  768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  769. if err != nil {
  770. utils.ErrorLog(err.Error())
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminInfo := c.GetAdminUserInfo()
  782. recordDateTime := theTime.Unix()
  783. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  784. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  785. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  786. if len(lists) == 1 {
  787. his_patient_id = lists[0].ID
  788. }
  789. }
  790. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  791. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  792. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  793. if drugStockConfig.IsOpen == 1 {
  794. //校验库存总量
  795. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  796. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  797. if len(prescriptions) > 0 {
  798. for _, item := range prescriptions {
  799. items := item.(map[string]interface{})
  800. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  801. advices := items["advices"].([]interface{})
  802. if len(advices) > 0 {
  803. for _, advice := range advices {
  804. var drug_id int64
  805. var prescribing_number float64
  806. var prescribingNumberUnit string
  807. var prescribingNumber string
  808. var adviceId int64
  809. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  810. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  811. }
  812. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  813. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  814. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  815. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  816. }
  817. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  818. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  819. }
  820. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  821. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  822. }
  823. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  824. if drug.ID == 0 {
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. //查询药品的所有库存
  829. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  830. var total_count int64
  831. for _, it := range list {
  832. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  833. }
  834. totals := strconv.FormatInt(total_count, 10)
  835. //查询该药品是否存在开药记录
  836. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  837. //新增处方
  838. if advicelist.ID == 0 {
  839. all_count, _ := strconv.ParseFloat(totals, 64)
  840. if prescribingNumberUnit == drug.MinUnit {
  841. if prescribing_number > all_count {
  842. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  843. return
  844. }
  845. } else {
  846. if prescribingNumberUnit == drug.MaxUnit {
  847. num := prescribing_number * float64(drug.MinNumber)
  848. if num > all_count {
  849. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  850. return
  851. }
  852. }
  853. }
  854. }
  855. //修改处方
  856. if advicelist.ID > 0 {
  857. var device_number int64
  858. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  859. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  860. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  861. device_number = prescribingNumberInt * drug.MinNumber
  862. }
  863. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  864. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  865. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  866. device_number = prescribingNumberInt
  867. }
  868. var number_count int64
  869. if prescribingNumberUnit == drug.MaxUnit {
  870. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  871. number_count = prescribingNumberInt * drug.MinNumber
  872. }
  873. if prescribingNumberUnit == drug.MinUnit {
  874. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  875. number_count = prescribingNumberInt
  876. }
  877. //如果修改的数量大于之前修改的数量
  878. if (number_count - device_number) > 0 {
  879. //如果修改的差数量 大于库存数量
  880. if (number_count - device_number) > total_count {
  881. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  882. return
  883. }
  884. }
  885. if device_number != number_count {
  886. // 查询该药品最后一次出库记录
  887. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  888. //回退库存
  889. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  890. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  891. }
  892. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  893. var stock_max_number int64
  894. var stock_min_number int64
  895. if number_count >= drug.MinNumber {
  896. stock_max_number = device_number / drug.MinNumber
  897. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  898. stock_min_number = device_number % drug.MinNumber
  899. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  900. } else {
  901. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  902. }
  903. }
  904. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  905. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  906. }
  907. //删除记录
  908. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }
  916. }
  917. }
  918. if stockConfig.IsOpen == 1 {
  919. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  920. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  921. if len(prescriptions) > 0 {
  922. for _, item := range prescriptions {
  923. items := item.(map[string]interface{})
  924. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  925. projects := items["project"].([]interface{})
  926. if len(projects) > 0 {
  927. for _, project := range projects {
  928. var project_id int64
  929. var project_type int64
  930. var totals float64
  931. var project_name string
  932. var parsetotal int64
  933. var id int64
  934. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  935. id = int64(project.(map[string]interface{})["id"].(float64))
  936. }
  937. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  938. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  939. }
  940. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  941. project_type = int64(project.(map[string]interface{})["type"].(float64))
  942. }
  943. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  944. total, _ := project.(map[string]interface{})["total"].(string)
  945. totals, _ = strconv.ParseFloat(total, 64)
  946. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  947. }
  948. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  949. project_name = project.(map[string]interface{})["project_name"].(string)
  950. }
  951. if project_type == 3 {
  952. //查找该耗材的出库记录
  953. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  954. //var total_count int64
  955. //for _, it := range goodWarehouseInfo {
  956. // total_count += it.Count
  957. //}
  958. if len(goodWarehouseInfo) == 0 {
  959. //查询耗材库存
  960. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  961. var stock_count int64
  962. for _, it := range list {
  963. stock_count += it.StockCount
  964. }
  965. stock_counts := strconv.FormatInt(stock_count, 10)
  966. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  967. if totals > stock_total_count {
  968. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  969. return
  970. }
  971. //查找今日该患者已经出库的所有耗材
  972. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  973. for _, item := range goodList {
  974. //回退库存
  975. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  976. }
  977. //删除记录
  978. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  979. }
  980. if len(goodWarehouseInfo) > 0 {
  981. //查询该患者耗材的历史数据
  982. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  983. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  984. //数量发生改变
  985. if parsetotal != count {
  986. //查找今日该患者已经出库的所有耗材
  987. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  988. for _, item := range goodList {
  989. //回退库存
  990. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  991. }
  992. //删除记录
  993. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1005. var hpInfo models.HisPrescriptionInfo
  1006. if info.ID == 0 {
  1007. var randNum int
  1008. randNum = rand.Intn(10000) + 1000
  1009. timestamp := time.Now().Unix()
  1010. tempTime := time.Unix(timestamp, 0)
  1011. timeFormat := tempTime.Format("20060102150405")
  1012. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1013. hpInfo = models.HisPrescriptionInfo{
  1014. HisPatientId: his_patient_id,
  1015. UserOrgId: adminInfo.CurrentOrgId,
  1016. RecordDate: theTime.Unix(),
  1017. PatientId: patient_id,
  1018. Status: 1,
  1019. Ctime: time.Now().Unix(),
  1020. Mtime: time.Now().Unix(),
  1021. Creator: adminInfo.AdminUser.Id,
  1022. Modifier: adminInfo.AdminUser.Id,
  1023. Diagnosis: diagnose,
  1024. SickHistory: sick_history,
  1025. Departments: department,
  1026. RegisterType: reg_type,
  1027. PrescriptionNumber: p_number,
  1028. PrescriptionStatus: 1,
  1029. Doctor: role.UserName,
  1030. DoctorId: doctor_id,
  1031. SickType: sick_type,
  1032. PType: p_type,
  1033. }
  1034. service.SavePatientPrescriptionInfo(hpInfo)
  1035. redis := service.RedisClient()
  1036. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1037. redis.Set(key, "", time.Second)
  1038. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1039. redis.Set(keyOne, "", time.Second)
  1040. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1041. redis.Set(keySeven, "", time.Second)
  1042. defer redis.Close()
  1043. } else {
  1044. hpInfo = models.HisPrescriptionInfo{
  1045. ID: info.ID,
  1046. UserOrgId: adminInfo.CurrentOrgId,
  1047. RecordDate: info.RecordDate,
  1048. PatientId: info.PatientId,
  1049. Status: 1,
  1050. Ctime: info.Ctime,
  1051. Mtime: time.Now().Unix(),
  1052. Creator: info.Creator,
  1053. Modifier: adminInfo.AdminUser.Id,
  1054. Diagnosis: diagnose,
  1055. SickHistory: sick_history,
  1056. Departments: department,
  1057. RegisterType: reg_type,
  1058. PrescriptionNumber: info.PrescriptionNumber,
  1059. Doctor: role.UserName,
  1060. PrescriptionStatus: info.PrescriptionStatus,
  1061. DoctorId: doctor_id,
  1062. SickType: sick_type,
  1063. PType: info.PType,
  1064. HisPatientId: info.HisPatientId,
  1065. }
  1066. service.SavePatientPrescriptionInfo(hpInfo)
  1067. redis := service.RedisClient()
  1068. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1069. redis.Set(key, "", time.Second)
  1070. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1071. redis.Set(keyOne, "", time.Second)
  1072. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1073. redis.Set(keySeven, "", time.Second)
  1074. defer redis.Close()
  1075. }
  1076. //定义切片
  1077. var adviceList []models.HisDoctorAdviceInfo
  1078. var projectList []models.HisPrescriptionProject
  1079. //var hisLis []models.HisList
  1080. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1081. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1082. var tempPrescription *models.HisPrescription
  1083. if len(prescriptions) > 0 {
  1084. for _, item := range prescriptions {
  1085. items := item.(map[string]interface{})
  1086. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1087. utils.ErrorLog("id")
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. id := int64(items["id"].(float64))
  1092. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1093. tempPrescription = &new_prescription
  1094. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1095. utils.ErrorLog("type")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. types := int64(items["type"].(float64))
  1100. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1101. utils.ErrorLog("med_type")
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1106. if med_type == "0" {
  1107. med_type = "14"
  1108. }
  1109. //if order_status == 0 {
  1110. // order_status = 1
  1111. //}
  1112. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1113. utils.ErrorLog("pre_time")
  1114. }
  1115. preTime, _ := items["pre_time"].(string)
  1116. timeLayout := "2006-01-02"
  1117. loc, _ := time.LoadLocation("Local")
  1118. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1119. if err != nil {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. pTime := theTime2.Unix()
  1124. ctime := time.Now().Unix()
  1125. if tempPrescription.ID == 0 {
  1126. prescription := &models.HisPrescription{
  1127. ID: 0,
  1128. PatientId: patient_id,
  1129. UserOrgId: adminInfo.CurrentOrgId,
  1130. RecordDate: recordDateTime,
  1131. Ctime: ctime,
  1132. Mtime: ctime,
  1133. Type: types,
  1134. Modifier: adminInfo.AdminUser.Id,
  1135. Creator: adminInfo.AdminUser.Id,
  1136. Status: 1,
  1137. Doctor: role.UserName,
  1138. HisPatientId: his_patient_id,
  1139. OrderStatus: 1,
  1140. BatchNumber: "",
  1141. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1142. PreTime: pTime,
  1143. PType: p_type,
  1144. MedType: med_type,
  1145. }
  1146. tempPrescription = prescription
  1147. service.SaveHisPrescription(tempPrescription)
  1148. redis := service.RedisClient()
  1149. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1150. redis.Set(key, "", time.Second)
  1151. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1152. redis.Set(keyOne, "", time.Second)
  1153. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1154. redis.Set(keySeven, "", time.Second)
  1155. defer redis.Close()
  1156. } else {
  1157. tempPrescription.ID = id
  1158. tempPrescription.Type = types
  1159. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1160. tempPrescription.Mtime = time.Now().Unix()
  1161. tempPrescription.Doctor = role.UserName
  1162. //tempPrescription.OrderStatus = order_status
  1163. tempPrescription.PreTime = pTime
  1164. tempPrescription.MedType = med_type
  1165. service.SaveHisPrescription(tempPrescription)
  1166. redis := service.RedisClient()
  1167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1168. redis.Set(key, "", time.Second)
  1169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1170. redis.Set(keyOne, "", time.Second)
  1171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1172. redis.Set(keySeven, "", time.Second)
  1173. defer redis.Close()
  1174. }
  1175. //service.SaveHisPrescription(prescription)
  1176. //更改患者挂号状态
  1177. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1178. fmt.Println("更改失败", err2)
  1179. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1180. advices := items["advices"].([]interface{})
  1181. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1182. groupNo := int64(0)
  1183. ctime := time.Now().Unix()
  1184. mtime := ctime
  1185. if len(advices) > 0 {
  1186. for _, advice := range advices {
  1187. var s models.HisDoctorAdviceInfo
  1188. s.PrescriptionId = tempPrescription.ID
  1189. s.AdviceType = 2
  1190. s.AdviceDoctor = doctor_id
  1191. s.StopState = 2
  1192. s.ExecutionState = 2
  1193. s.AdviceDate = recordDateTime
  1194. s.Status = 1
  1195. s.UserOrgId = adminInfo.CurrentOrgId
  1196. s.RecordDate = recordDateTime
  1197. s.StartTime = tempPrescription.PreTime
  1198. s.Groupno = groupNo
  1199. s.CreatedTime = ctime
  1200. s.UpdatedTime = mtime
  1201. s.PatientId = patient_id
  1202. s.HisPatientId = his_patient_id
  1203. s.StartTime = pTime
  1204. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1205. if errcode > 0 {
  1206. c.ServeFailJSONWithSGJErrorCode(errcode)
  1207. return
  1208. }
  1209. s.StartTime = pTime
  1210. service.CreateHisDoctorAdvice(&s)
  1211. //存储切片中
  1212. adviceList = append(adviceList, s)
  1213. redis := service.RedisClient()
  1214. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1215. redis.Set(key, "", time.Second)
  1216. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1217. redis.Set(keyOne, "", time.Second)
  1218. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1219. redis.Set(keySeven, "", time.Second)
  1220. var randNum int
  1221. randNum = rand.Intn(10000) + 1000
  1222. timestamp := time.Now().Unix()
  1223. tempTime := time.Unix(timestamp, 0)
  1224. timeFormat := tempTime.Format("20060102150405")
  1225. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1226. service.CreateHisDoctorAdvice(&s)
  1227. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1228. redis.Set(keySix, "", time.Second)
  1229. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1230. redis.Set(keyFive, "", time.Second)
  1231. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1232. redis.Set(keyEight, "", time.Second)
  1233. defer redis.Close()
  1234. }
  1235. }
  1236. }
  1237. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1238. projects := items["project"].([]interface{})
  1239. if len(projects) > 0 {
  1240. for _, project := range projects {
  1241. var p models.HisPrescriptionProject
  1242. p.PrescriptionId = tempPrescription.ID
  1243. p.Ctime = time.Now().Unix()
  1244. p.Mtime = time.Now().Unix()
  1245. p.PatientId = patient_id
  1246. p.RecordDate = recordDateTime
  1247. p.Doctor = doctor_id
  1248. p.UserOrgId = adminInfo.CurrentOrgId
  1249. p.HisPatientId = his_patient_id
  1250. p.Status = 1
  1251. p.StartTime = pTime
  1252. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1253. if errcode > 0 {
  1254. c.ServeFailJSONWithSGJErrorCode(errcode)
  1255. return
  1256. }
  1257. service.CreateHisProjectTwo(&p)
  1258. projectList = append(projectList, p)
  1259. var randNum int
  1260. randNum = rand.Intn(10000) + 1000
  1261. timestamp := time.Now().Unix()
  1262. tempTime := time.Unix(timestamp, 0)
  1263. timeFormat := tempTime.Format("20060102150405")
  1264. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1265. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1266. //新增或者编辑项目,修改对应的标签数据
  1267. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1268. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1269. var label models.HisLabelPrintInfo
  1270. project, _ := service.GetProjectDetail(p.ProjectId)
  1271. if project.CostClassify == 3 { //类别为检验检查
  1272. if p.TeamId > 0 { //检验检查组套
  1273. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1274. if tempLabel.ID == 0 {
  1275. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1276. label.Number = tempPrescription.PrescriptionNumber
  1277. label.ProjectId = project.ID
  1278. label.Status = 1
  1279. label.IsPrint = 2
  1280. label.DoctorId = info.DoctorId
  1281. label.UserOrgId = p.UserOrgId
  1282. label.PatientId = patient_id
  1283. label.RecordDate = recordDateTime
  1284. label.Ctime = time.Now().Unix()
  1285. label.Mtime = time.Now().Unix()
  1286. label.ItemId = p.TeamId
  1287. label.FeedetlSn = p.FeedetlSn
  1288. label.PProjectId = p.ID
  1289. label.ProjectName = team.ProjectTeam
  1290. label.PatientName = patient.Name
  1291. service.CreateHisLabelRecord(&label)
  1292. }
  1293. } else { //单条检验检查项目
  1294. label.Number = tempPrescription.PrescriptionNumber
  1295. label.ProjectId = project.ID
  1296. label.Status = 1
  1297. label.DoctorId = info.DoctorId
  1298. label.UserOrgId = p.UserOrgId
  1299. label.PatientId = patient_id
  1300. label.RecordDate = recordDateTime
  1301. label.IsPrint = 2
  1302. label.Ctime = time.Now().Unix()
  1303. label.Mtime = time.Now().Unix()
  1304. label.FeedetlSn = p.FeedetlSn
  1305. label.PProjectId = p.ID
  1306. label.ItemId = p.TeamId
  1307. label.ProjectName = project.ProjectName
  1308. label.PatientName = patient.Name
  1309. service.CreateHisLabelRecord(&label)
  1310. }
  1311. }
  1312. }
  1313. }
  1314. service.SaveHisProjectTwo(&p)
  1315. //if p.Type == 3 { //处理透前准备耗材数量数据
  1316. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1317. // if consumables.ID > 0 {
  1318. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1319. // consumables.Count = cnt
  1320. // service.UpdateConsumables(&consumables)
  1321. // }
  1322. //}
  1323. }
  1324. }
  1325. }
  1326. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1327. // addition := items["addition"].([]interface{})
  1328. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1329. // ctime := time.Now().Unix()
  1330. // mtime := ctime
  1331. // if len(addition) > 0 {
  1332. // for _, item := range addition {
  1333. // var s models.HisAdditionalCharge
  1334. // s.PrescriptionId = tempPrescription.ID
  1335. // s.Status = 1
  1336. // s.UserOrgId = adminInfo.CurrentOrgId
  1337. // s.RecordDate = recordDateTime
  1338. // s.CreatedTime = ctime
  1339. // s.UpdatedTime = mtime
  1340. // s.PatientId = patient_id
  1341. // s.HisPatientId = his_patient_id
  1342. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1343. // if errcode > 0 {
  1344. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1345. // return
  1346. // }
  1347. // service.CreateAdditionalCharge(&s)
  1348. // var randNum int
  1349. // randNum = rand.Intn(10000) + 1000
  1350. // timestamp := time.Now().Unix()
  1351. // tempTime := time.Unix(timestamp, 0)
  1352. // timeFormat := tempTime.Format("20060102150405")
  1353. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1354. // service.CreateAdditionalCharge(&s)
  1355. //
  1356. // }
  1357. // }
  1358. //}
  1359. }
  1360. }
  1361. }
  1362. //redisClient := service.RedisClient()
  1363. //defer redisClient.Close()
  1364. //
  1365. //list := models.HisList{
  1366. // Patient_id: patient_id,
  1367. // Advice_id:0,
  1368. // Record_date: 0,
  1369. // Advice: adviceList,
  1370. // Project: nil,
  1371. //}
  1372. //hisLis = append(hisLis, list)
  1373. //
  1374. //advice_json, _ := json.Marshal(&hisLis)
  1375. //redisClient.RPush("111", advice_json).Result()
  1376. //result, _ := redisClient.RPop("111").Result()
  1377. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1378. //
  1379. //var dat []map[string]interface{}
  1380. //json.Unmarshal([]byte(result), &dat)
  1381. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1382. //
  1383. //for k,v:=range dat{
  1384. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1385. //}
  1386. //project_json, _ := json.Marshal(&projectList)
  1387. //redisClient.LPush("222", project_json).Result()
  1388. if err == nil {
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "保存成功",
  1391. })
  1392. return
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. return
  1396. }
  1397. }
  1398. func (c *HisApiController) EditHisPrescription() {
  1399. record_date := c.GetString("record_date")
  1400. patient_id, _ := c.GetInt64("patient_id")
  1401. reg_type, _ := c.GetInt64("reg_type")
  1402. //diagnose, _ := c.GetInt64("diagnose", 0)
  1403. diagnose := c.GetString("diagnose")
  1404. sick_type, _ := c.GetInt64("sick_type")
  1405. sick_history := c.GetString("sick_history")
  1406. doctor_id, _ := c.GetInt64("doctor", 0)
  1407. department, _ := c.GetInt64("department", 0)
  1408. his_patient_id, _ := c.GetInt64("his_patient_id")
  1409. p_type, _ := c.GetInt64("p_type")
  1410. dataBody := make(map[string]interface{}, 0)
  1411. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1412. if err != nil {
  1413. utils.ErrorLog(err.Error())
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. timeLayout := "2006-01-02"
  1418. loc, _ := time.LoadLocation("Local")
  1419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1420. if err != nil {
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. adminInfo := c.GetAdminUserInfo()
  1425. recordDateTime := theTime.Unix()
  1426. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1427. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1428. var hpInfo models.HisPrescriptionInfo
  1429. if info.ID == 0 {
  1430. var randNum int
  1431. randNum = rand.Intn(10000) + 1000
  1432. timestamp := time.Now().Unix()
  1433. tempTime := time.Unix(timestamp, 0)
  1434. timeFormat := tempTime.Format("20060102150405")
  1435. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1436. hpInfo = models.HisPrescriptionInfo{
  1437. UserOrgId: adminInfo.CurrentOrgId,
  1438. RecordDate: theTime.Unix(),
  1439. PatientId: patient_id,
  1440. Status: 1,
  1441. Ctime: time.Now().Unix(),
  1442. Mtime: time.Now().Unix(),
  1443. Creator: adminInfo.AdminUser.Id,
  1444. Modifier: adminInfo.AdminUser.Id,
  1445. Diagnosis: diagnose,
  1446. SickHistory: sick_history,
  1447. Departments: department,
  1448. RegisterType: reg_type,
  1449. PrescriptionNumber: p_number,
  1450. PrescriptionStatus: 1,
  1451. Doctor: role.UserName,
  1452. DoctorId: doctor_id,
  1453. SickType: sick_type,
  1454. PType: p_type,
  1455. }
  1456. service.SavePatientPrescriptionInfo(hpInfo)
  1457. } else {
  1458. hpInfo = models.HisPrescriptionInfo{
  1459. ID: info.ID,
  1460. UserOrgId: adminInfo.CurrentOrgId,
  1461. RecordDate: info.RecordDate,
  1462. PatientId: info.PatientId,
  1463. Status: 1,
  1464. Ctime: info.Ctime,
  1465. Mtime: time.Now().Unix(),
  1466. Creator: info.Creator,
  1467. Modifier: adminInfo.AdminUser.Id,
  1468. Diagnosis: diagnose,
  1469. SickHistory: sick_history,
  1470. Departments: department,
  1471. RegisterType: reg_type,
  1472. PrescriptionNumber: info.PrescriptionNumber,
  1473. Doctor: role.UserName,
  1474. PrescriptionStatus: info.PrescriptionStatus,
  1475. DoctorId: doctor_id,
  1476. SickType: sick_type,
  1477. PType: info.PType,
  1478. }
  1479. service.SavePatientPrescriptionInfo(hpInfo)
  1480. }
  1481. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1482. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1483. if len(prescriptions) > 0 {
  1484. for _, item := range prescriptions {
  1485. items := item.(map[string]interface{})
  1486. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1487. utils.ErrorLog("id")
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1489. return
  1490. }
  1491. id := int64(items["id"].(float64))
  1492. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1493. utils.ErrorLog("type")
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. types := int64(items["type"].(float64))
  1498. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1499. utils.ErrorLog("med_type")
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1504. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1505. ctime := time.Now().Unix()
  1506. prescription := &models.HisPrescription{
  1507. ID: id,
  1508. PatientId: patient_id,
  1509. UserOrgId: adminInfo.CurrentOrgId,
  1510. RecordDate: recordDateTime,
  1511. Ctime: ctime,
  1512. Mtime: ctime,
  1513. Type: types,
  1514. Modifier: adminInfo.AdminUser.Id,
  1515. Creator: adminInfo.AdminUser.Id,
  1516. Status: 1,
  1517. Doctor: role.UserName,
  1518. HisPatientId: his_patient_id,
  1519. OrderStatus: 1,
  1520. BatchNumber: "",
  1521. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1522. PType: hpInfo.PType,
  1523. MedType: med_type,
  1524. }
  1525. if historyPrescription.ID > 0 {
  1526. prescription.PreTime = historyPrescription.PreTime
  1527. }
  1528. service.SaveHisPrescription(prescription)
  1529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1530. advices := items["advices"].([]interface{})
  1531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1532. groupNo := int64(0)
  1533. ctime := time.Now().Unix()
  1534. mtime := ctime
  1535. if len(advices) > 0 {
  1536. for _, advice := range advices {
  1537. var s models.HisDoctorAdviceInfo
  1538. s.PrescriptionId = prescription.ID
  1539. s.AdviceType = 2
  1540. s.AdviceDoctor = adminInfo.AdminUser.Id
  1541. s.StopState = 2
  1542. s.ExecutionState = 2
  1543. s.AdviceDate = recordDateTime
  1544. s.Status = 1
  1545. s.UserOrgId = adminInfo.CurrentOrgId
  1546. s.RecordDate = recordDateTime
  1547. s.StartTime = prescription.PreTime
  1548. s.Groupno = groupNo
  1549. s.CreatedTime = ctime
  1550. s.UpdatedTime = mtime
  1551. s.PatientId = patient_id
  1552. s.HisPatientId = his_patient_id
  1553. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1554. if errcode > 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(errcode)
  1556. return
  1557. }
  1558. service.CreateHisDoctorAdvice(&s)
  1559. redis := service.RedisClient()
  1560. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1561. redis.Set(key, "", time.Second)
  1562. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1563. fmt.Println("keyOne", keyOne)
  1564. redis.Set(keyOne, "", time.Second)
  1565. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1566. redis.Set(keySeven, "", time.Second)
  1567. redis.Close()
  1568. }
  1569. }
  1570. }
  1571. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1572. projects := items["project"].([]interface{})
  1573. if len(projects) > 0 {
  1574. for _, project := range projects {
  1575. var p models.HisPrescriptionProject
  1576. p.PrescriptionId = prescription.ID
  1577. p.Ctime = time.Now().Unix()
  1578. p.Mtime = time.Now().Unix()
  1579. p.PatientId = patient_id
  1580. p.RecordDate = recordDateTime
  1581. p.UserOrgId = adminInfo.CurrentOrgId
  1582. p.HisPatientId = his_patient_id
  1583. p.Status = 1
  1584. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1585. if errcode > 0 {
  1586. c.ServeFailJSONWithSGJErrorCode(errcode)
  1587. return
  1588. }
  1589. service.CreateHisProjectTwo(&p)
  1590. }
  1591. }
  1592. }
  1593. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1594. addition := items["addition"].([]interface{})
  1595. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1596. ctime := time.Now().Unix()
  1597. mtime := ctime
  1598. if len(addition) > 0 {
  1599. for _, item := range addition {
  1600. var s models.HisAdditionalCharge
  1601. s.PrescriptionId = prescription.ID
  1602. s.Status = 1
  1603. s.UserOrgId = adminInfo.CurrentOrgId
  1604. s.RecordDate = recordDateTime
  1605. s.CreatedTime = ctime
  1606. s.UpdatedTime = mtime
  1607. s.PatientId = patient_id
  1608. s.HisPatientId = his_patient_id
  1609. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1610. if errcode > 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(errcode)
  1612. return
  1613. }
  1614. service.CreateAdditionalCharge(&s)
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. if err == nil {
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "msg": "保存成功",
  1624. })
  1625. return
  1626. } else {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1628. return
  1629. }
  1630. }
  1631. func (c *HisApiController) DeletePrescription() {
  1632. prescription_id, _ := c.GetInt64("id")
  1633. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1634. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1636. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1637. if len(projects) > 0 {
  1638. for _, item := range projects {
  1639. service.DeletePrintInfo(item.ID) //删除打印信息
  1640. if stockConfig.IsOpen == 1 {
  1641. if item.Type == 3 {
  1642. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1643. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1644. good.Total = good.Total + f_count
  1645. service.UpdateGoodInfo(&good)
  1646. operation_time := time.Now().Unix()
  1647. creater := c.GetAdminUserInfo().AdminUser.Id
  1648. //创建退库单
  1649. timeStr := time.Now().Format("2006-01-02")
  1650. timeArr := strings.Split(timeStr, "-")
  1651. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1652. total = total + 1
  1653. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1654. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1655. cancelStock := models.CancelStock{
  1656. OrderNumber: orderNumber,
  1657. OperaTime: operation_time,
  1658. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1659. Creater: creater,
  1660. Ctime: time.Now().Unix(),
  1661. Status: 1,
  1662. ReturnTime: item.RecordDate,
  1663. Type: 1,
  1664. StorehouseId: houseConfig.StorehouseOutInfo,
  1665. }
  1666. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1667. if msgerrkonde == gorm.ErrRecordNotFound {
  1668. service.AddSigleCancelStock(&cancelStock)
  1669. }
  1670. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1671. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1672. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1673. //查询该耗材是否出库
  1674. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1675. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1676. deaerler, _ := service.GetDealerById(info.Dealer)
  1677. if info.ID > 0 {
  1678. cancelStockInfo := models.CancelStockInfo{
  1679. GoodId: item.ProjectId,
  1680. CancelStockId: cancel.ID,
  1681. GoodTypeId: good.GoodTypeId,
  1682. Count: prescribingNumber,
  1683. Price: info.Price,
  1684. Total: 0,
  1685. ProductDate: info.ProductDate,
  1686. ExpiryDate: info.ExpiryDate,
  1687. Ctime: time.Now().Unix(),
  1688. Status: 1,
  1689. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1690. OrderNumber: cancel.OrderNumber,
  1691. Type: 0,
  1692. Dealer: deaerler.DealerName,
  1693. Manufacturer: manufacturer.ManufacturerName,
  1694. Number: info.Number,
  1695. RegisterAccount: "",
  1696. Remark: "",
  1697. WarehouseInfoId: info.WarehouseInfotId,
  1698. PatientId: info.PatientId,
  1699. RecordDate: info.SysRecordTime,
  1700. StorehouseId: houseConfig.StorehouseOutInfo,
  1701. }
  1702. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1703. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1704. flow := models.VmStockFlow{
  1705. WarehousingId: 0,
  1706. GoodId: item.ProjectId,
  1707. Number: info.Number,
  1708. LicenseNumber: info.LicenseNumber,
  1709. Count: prescribingNumber,
  1710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1711. PatientId: item.PatientId,
  1712. SystemTime: info.SysRecordTime,
  1713. ConsumableType: 7,
  1714. IsSys: 0,
  1715. WarehousingOrder: "",
  1716. WarehouseOutId: 0,
  1717. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1718. IsEdit: 0,
  1719. CancelStockId: cancel.ID,
  1720. CancelOrderNumber: cancel.OrderNumber,
  1721. Manufacturer: manufacturer.ID,
  1722. Dealer: 0,
  1723. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1724. UpdateCreator: 0,
  1725. Status: 1,
  1726. Ctime: time.Now().Unix(),
  1727. Mtime: 0,
  1728. Price: info.Price,
  1729. WarehousingDetailId: info.WarehouseInfotId,
  1730. WarehouseOutDetailId: 0,
  1731. CancelOutDetailId: cancelInfo.ID,
  1732. ProductDate: info.ProductDate,
  1733. ExpireDate: info.ExpiryDate,
  1734. StorehouseId: houseConfig.StorehouseOutInfo,
  1735. }
  1736. service.CreateStockFlowOne(flow)
  1737. //删除出库表
  1738. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1739. //查询今日该患者开了多少耗材
  1740. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1741. var total_count int64
  1742. var cha_count int64
  1743. for _, item := range projectList {
  1744. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1745. total_count += count
  1746. }
  1747. //回退库存
  1748. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1749. //查询今日该耗材退库数量
  1750. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1751. var cancel_Count int64
  1752. for _, items := range cancelInfoOne {
  1753. cancel_Count += items.Count
  1754. }
  1755. cha_count = total_count - cancel_Count
  1756. if total_count > cancel_Count {
  1757. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1758. if err == gorm.ErrRecordNotFound {
  1759. //没有记录,则创建出库单
  1760. timeStr := time.Now().Format("2006-01-02")
  1761. timeArr := strings.Split(timeStr, "-")
  1762. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1763. total = total + 1
  1764. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1765. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1766. number = number + total
  1767. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1768. warehouseOut := models.WarehouseOut{
  1769. WarehouseOutOrderNumber: warehousing_out_order,
  1770. OperationTime: time.Now().Unix(),
  1771. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1772. Creater: creater,
  1773. Ctime: time.Now().Unix(),
  1774. Status: 1,
  1775. WarehouseOutTime: info.SysRecordTime,
  1776. Dealer: 0,
  1777. Manufacturer: 0,
  1778. Type: 1,
  1779. IsSys: 1,
  1780. StorehouseId: houseConfig.StorehouseOutInfo,
  1781. }
  1782. err := service.AddSigleWarehouseOut(&warehouseOut)
  1783. if err != nil {
  1784. utils.TraceLog("创建出库单失败 err = %v", err)
  1785. return
  1786. }
  1787. prepare := &models.DialysisBeforePrepare{
  1788. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1789. PatientId: info.PatientId,
  1790. RecordDate: info.SysRecordTime,
  1791. GoodId: item.ProjectId,
  1792. GoodTypeId: info.GoodTypeId,
  1793. Count: cha_count,
  1794. StorehouseId: houseConfig.StorehouseOutInfo,
  1795. }
  1796. //出库
  1797. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1798. } else if err == nil {
  1799. prepare := &models.DialysisBeforePrepare{
  1800. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1801. PatientId: info.PatientId,
  1802. RecordDate: info.SysRecordTime,
  1803. GoodId: item.ProjectId,
  1804. GoodTypeId: info.GoodTypeId,
  1805. Count: cha_count,
  1806. StorehouseId: houseConfig.StorehouseOutInfo,
  1807. }
  1808. //出库
  1809. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1817. fmt.Println(err)
  1818. }
  1819. if drugStockConfig.IsOpen == 1 {
  1820. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1821. fmt.Println(err)
  1822. if len(advices) > 0 {
  1823. for _, item := range advices {
  1824. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1825. redis := service.RedisClient()
  1826. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1827. redis.Set(keyFive, "", time.Second)
  1828. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1829. redis.Set(keyOne, "", time.Second)
  1830. redis.Close()
  1831. //查询该药品是否存在出库记录
  1832. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1833. if errcode == gorm.ErrRecordNotFound {
  1834. } else if errcode == nil {
  1835. if item.PrescribingNumberUnit == drug.MinUnit {
  1836. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1837. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1838. //退库
  1839. warehouseInfo := models.DrugWarehouseInfo{
  1840. StockMinNumber: prescribingNumber,
  1841. }
  1842. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1843. adminUserInfo := c.GetAdminUserInfo()
  1844. operation_time := time.Now().Unix()
  1845. creater := adminUserInfo.AdminUser.Id
  1846. ctime := time.Now().Unix()
  1847. timeStr := time.Now().Format("2006-01-02")
  1848. timeArr := strings.Split(timeStr, "-")
  1849. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1850. total = total + 1
  1851. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1852. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1853. cancelStock := models.DrugCancelStock{
  1854. OrderNumber: orderNumber,
  1855. OperaTime: operation_time,
  1856. OrgId: adminUserInfo.CurrentOrgId,
  1857. Creater: creater,
  1858. Ctime: ctime,
  1859. Status: 1,
  1860. ReturnTime: item.AdviceDate,
  1861. Dealer: info.Dealer,
  1862. Manufacturer: info.Manufacturer,
  1863. Type: 1,
  1864. StorehouseId: houseConfig.DrugStorehouseOut,
  1865. }
  1866. service.AddSigleDrugCancelStock(&cancelStock)
  1867. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1868. dealer, _ := service.GetDealerById(info.Dealer)
  1869. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1870. cancelStockInfo := models.DrugCancelStockInfo{
  1871. OrderNumber: cancelInfo.OrderNumber,
  1872. CancelStockId: cancelInfo.ID,
  1873. DrugId: info.DrugId,
  1874. Count: prescribingNumber,
  1875. Status: 1,
  1876. Ctime: ctime,
  1877. OrgId: adminUserInfo.CurrentOrgId,
  1878. Type: 1,
  1879. Manufacturer: manufactureName.ManufacturerName,
  1880. Dealer: dealer.DealerName,
  1881. Total: 0,
  1882. RetailPrice: info.RetailPrice,
  1883. RetailTotalPrice: info.RetailTotalPrice,
  1884. Price: info.Price,
  1885. RegisterAccount: "",
  1886. Remark: info.Remark,
  1887. BatchNumber: info.BatchNumber,
  1888. MaxUnit: info.CountUnit,
  1889. ProductDate: info.ProductDate,
  1890. ExpiryDate: info.ExpiryDate,
  1891. BatchNumberId: info.WarehouseInfoId,
  1892. StorehouseId: houseConfig.DrugStorehouseOut,
  1893. }
  1894. flow := models.DrugFlow{
  1895. WarehousingId: 0,
  1896. DrugId: info.DrugId,
  1897. Number: "",
  1898. BatchNumber: info.BatchNumber,
  1899. Count: prescribingNumber,
  1900. UserOrgId: adminUserInfo.CurrentOrgId,
  1901. PatientId: 0,
  1902. SystemTime: info.SysRecordTime,
  1903. ConsumableType: 7,
  1904. IsSys: 0,
  1905. WarehousingOrder: "",
  1906. WarehouseOutId: 0,
  1907. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1908. IsEdit: 0,
  1909. CancelStockId: cancelStock.ID,
  1910. CancelOrderNumber: cancelStock.OrderNumber,
  1911. Manufacturer: info.Manufacturer,
  1912. Dealer: info.Dealer,
  1913. Creator: adminUserInfo.AdminUser.Id,
  1914. UpdateCreator: 0,
  1915. Status: 1,
  1916. Ctime: time.Now().Unix(),
  1917. Mtime: 0,
  1918. Price: info.Price,
  1919. WarehousingDetailId: 0,
  1920. WarehouseOutDetailId: 0,
  1921. CancelOutDetailId: 0,
  1922. ExpireDate: info.ExpiryDate,
  1923. ProductDate: info.ProductDate,
  1924. MaxUnit: info.CountUnit,
  1925. MinUnit: "",
  1926. AdviceId: info.AdviceId,
  1927. StorehouseId: houseConfig.DrugStorehouseOut,
  1928. }
  1929. service.CreatedCancelStock(cancelStockInfo)
  1930. service.CreateDrugFlowOne(flow)
  1931. //删除出库记录
  1932. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1933. //删除流水
  1934. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1935. } else {
  1936. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1937. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1938. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1939. if item.PrescribingNumberUnit == drug.MaxUnit {
  1940. warehouseInfo := models.DrugWarehouseInfo{
  1941. StockMaxNumber: prescribingNumber,
  1942. }
  1943. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1944. }
  1945. adminUserInfo := c.GetAdminUserInfo()
  1946. operation_time := time.Now().Unix()
  1947. creater := adminUserInfo.AdminUser.Id
  1948. ctime := time.Now().Unix()
  1949. timeStr := time.Now().Format("2006-01-02")
  1950. timeArr := strings.Split(timeStr, "-")
  1951. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1952. total = total + 1
  1953. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1954. cancelStock := models.DrugCancelStock{
  1955. OrderNumber: orderNumber,
  1956. OperaTime: operation_time,
  1957. OrgId: adminUserInfo.CurrentOrgId,
  1958. Creater: creater,
  1959. Ctime: ctime,
  1960. Status: 1,
  1961. ReturnTime: item.AdviceDate,
  1962. Dealer: info.Dealer,
  1963. Manufacturer: info.Manufacturer,
  1964. Type: 1,
  1965. StorehouseId: houseConfig.DrugStorehouseOut,
  1966. }
  1967. service.AddSigleDrugCancelStock(&cancelStock)
  1968. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1969. dealer, _ := service.GetDealerById(info.Dealer)
  1970. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1971. cancelStockInfo := models.DrugCancelStockInfo{
  1972. OrderNumber: cancelInfo.OrderNumber,
  1973. CancelStockId: cancelInfo.ID,
  1974. DrugId: info.DrugId,
  1975. // Count: info.Count,
  1976. Count: prescribingNumber,
  1977. Status: 1,
  1978. Ctime: ctime,
  1979. OrgId: adminUserInfo.CurrentOrgId,
  1980. Type: 1,
  1981. Manufacturer: manufactureName.ManufacturerName,
  1982. Dealer: dealer.DealerName,
  1983. Total: 0,
  1984. RetailPrice: info.RetailPrice,
  1985. RetailTotalPrice: info.RetailTotalPrice,
  1986. Price: info.Price,
  1987. RegisterAccount: "",
  1988. Remark: info.Remark,
  1989. BatchNumber: info.BatchNumber,
  1990. MaxUnit: info.CountUnit,
  1991. ProductDate: info.ProductDate,
  1992. ExpiryDate: info.ExpiryDate,
  1993. BatchNumberId: info.WarehouseInfoId,
  1994. StorehouseId: houseConfig.DrugStorehouseOut,
  1995. }
  1996. flow := models.DrugFlow{
  1997. WarehousingId: 0,
  1998. DrugId: info.DrugId,
  1999. Number: "",
  2000. BatchNumber: info.BatchNumber,
  2001. //Count: info.Count,
  2002. Count: prescribingNumber,
  2003. UserOrgId: adminUserInfo.CurrentOrgId,
  2004. PatientId: 0,
  2005. SystemTime: info.SysRecordTime,
  2006. ConsumableType: 7,
  2007. IsSys: 0,
  2008. WarehousingOrder: "",
  2009. WarehouseOutId: 0,
  2010. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2011. IsEdit: 0,
  2012. CancelStockId: cancelStock.ID,
  2013. CancelOrderNumber: cancelStock.OrderNumber,
  2014. Manufacturer: info.Manufacturer,
  2015. Dealer: info.Dealer,
  2016. Creator: adminUserInfo.AdminUser.Id,
  2017. UpdateCreator: 0,
  2018. Status: 1,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. Price: info.Price,
  2022. WarehousingDetailId: 0,
  2023. WarehouseOutDetailId: 0,
  2024. CancelOutDetailId: 0,
  2025. ExpireDate: info.ExpiryDate,
  2026. ProductDate: info.ProductDate,
  2027. MaxUnit: info.CountUnit,
  2028. MinUnit: "",
  2029. AdviceId: info.AdviceId,
  2030. StorehouseId: houseConfig.DrugStorehouseOut,
  2031. }
  2032. service.CreatedCancelStock(cancelStockInfo)
  2033. service.CreateDrugFlowOne(flow)
  2034. //删除出库记录
  2035. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2036. //删除流水
  2037. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2038. }
  2039. }
  2040. if item.PrescribingNumberUnit == drug.MinUnit {
  2041. drug.Total = drug.Total + item.PrescribingNumber
  2042. service.UpdateBaseDrugLib(&drug)
  2043. } else {
  2044. if item.PrescribingNumberUnit == drug.MaxUnit {
  2045. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2046. drug.Total = drug.Total + item.PrescribingNumber
  2047. service.UpdateBaseDrugLib(&drug)
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. c.ServeSuccessJSON(map[string]interface{}{
  2054. "msg": "删除成功",
  2055. })
  2056. return
  2057. }
  2058. func (c *HisApiController) DeleteDoctorAdvice() {
  2059. id, _ := c.GetInt64("id")
  2060. advice, _ := service.GetHisDoctorAdvicesById(id)
  2061. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2062. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2063. redis := service.RedisClient()
  2064. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2065. redis.Set(keyFive, "", time.Second)
  2066. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2067. redis.Set(keyOne, "", time.Second)
  2068. defer redis.Close()
  2069. if err == nil {
  2070. if drugStockConfig.IsOpen == 1 {
  2071. //判断该医嘱是否执行了
  2072. if advice.ExecutionState == 1 {
  2073. //查询该病人该药品是否有库存记录
  2074. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2075. if errcode == gorm.ErrRecordNotFound {
  2076. } else {
  2077. //退库
  2078. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2079. if advice.PrescribingNumberUnit == drug.MinUnit {
  2080. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2081. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2082. //退库
  2083. warehouseInfo := models.DrugWarehouseInfo{
  2084. StockMinNumber: prescribingNumber,
  2085. }
  2086. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2087. adminUserInfo := c.GetAdminUserInfo()
  2088. operation_time := time.Now().Unix()
  2089. creater := adminUserInfo.AdminUser.Id
  2090. ctime := time.Now().Unix()
  2091. timeStr := time.Now().Format("2006-01-02")
  2092. timeArr := strings.Split(timeStr, "-")
  2093. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2094. total = total + 1
  2095. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2096. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2097. cancelStock := models.DrugCancelStock{
  2098. OrderNumber: orderNumber,
  2099. OperaTime: operation_time,
  2100. OrgId: adminUserInfo.CurrentOrgId,
  2101. Creater: creater,
  2102. Ctime: ctime,
  2103. Status: 1,
  2104. ReturnTime: advice.AdviceDate,
  2105. Dealer: info.Dealer,
  2106. Manufacturer: info.Manufacturer,
  2107. Type: 1,
  2108. StorehouseId: houseConfig.DrugStorehouseOut,
  2109. }
  2110. service.AddSigleDrugCancelStock(&cancelStock)
  2111. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2112. dealer, _ := service.GetDealerById(info.Dealer)
  2113. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2114. cancelStockInfo := models.DrugCancelStockInfo{
  2115. OrderNumber: cancelInfo.OrderNumber,
  2116. CancelStockId: cancelInfo.ID,
  2117. DrugId: info.DrugId,
  2118. Count: info.Count,
  2119. Status: 1,
  2120. Ctime: ctime,
  2121. OrgId: adminUserInfo.CurrentOrgId,
  2122. Type: 1,
  2123. Manufacturer: manufactureName.ManufacturerName,
  2124. Dealer: dealer.DealerName,
  2125. Total: 0,
  2126. RetailPrice: info.RetailPrice,
  2127. RetailTotalPrice: info.RetailTotalPrice,
  2128. Price: info.Price,
  2129. RegisterAccount: "",
  2130. Remark: info.Remark,
  2131. BatchNumber: info.BatchNumber,
  2132. MaxUnit: info.CountUnit,
  2133. ProductDate: info.ProductDate,
  2134. ExpiryDate: info.ExpiryDate,
  2135. BatchNumberId: info.WarehouseInfoId,
  2136. StorehouseId: houseConfig.DrugStorehouseOut,
  2137. }
  2138. flow := models.DrugFlow{
  2139. WarehousingId: 0,
  2140. DrugId: info.DrugId,
  2141. Number: "",
  2142. BatchNumber: info.BatchNumber,
  2143. Count: info.Count,
  2144. UserOrgId: adminUserInfo.CurrentOrgId,
  2145. PatientId: 0,
  2146. SystemTime: info.SysRecordTime,
  2147. ConsumableType: 7,
  2148. IsSys: 0,
  2149. WarehousingOrder: "",
  2150. WarehouseOutId: 0,
  2151. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2152. IsEdit: 0,
  2153. CancelStockId: cancelStock.ID,
  2154. CancelOrderNumber: cancelStock.OrderNumber,
  2155. Manufacturer: info.Manufacturer,
  2156. Dealer: info.Dealer,
  2157. Creator: adminUserInfo.AdminUser.Id,
  2158. UpdateCreator: 0,
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Price: info.Price,
  2163. WarehousingDetailId: 0,
  2164. WarehouseOutDetailId: 0,
  2165. CancelOutDetailId: 0,
  2166. ExpireDate: info.ExpiryDate,
  2167. ProductDate: info.ProductDate,
  2168. MaxUnit: info.CountUnit,
  2169. MinUnit: "",
  2170. AdviceId: info.AdviceId,
  2171. StorehouseId: houseConfig.DrugStorehouseOut,
  2172. }
  2173. service.CreatedCancelStock(cancelStockInfo)
  2174. service.CreateDrugFlowOne(flow)
  2175. //删除出库记录
  2176. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2177. //删除流水
  2178. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2179. } else {
  2180. adminUserInfo := c.GetAdminUserInfo()
  2181. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2182. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2183. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2184. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2185. warehouseInfo := models.DrugWarehouseInfo{
  2186. StockMaxNumber: prescribingNumber,
  2187. }
  2188. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2189. }
  2190. operation_time := time.Now().Unix()
  2191. creater := adminUserInfo.AdminUser.Id
  2192. ctime := time.Now().Unix()
  2193. timeStr := time.Now().Format("2006-01-02")
  2194. timeArr := strings.Split(timeStr, "-")
  2195. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2196. total = total + 1
  2197. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2198. cancelStock := models.DrugCancelStock{
  2199. OrderNumber: orderNumber,
  2200. OperaTime: operation_time,
  2201. OrgId: adminUserInfo.CurrentOrgId,
  2202. Creater: creater,
  2203. Ctime: ctime,
  2204. Status: 1,
  2205. ReturnTime: advice.AdviceDate,
  2206. Dealer: info.Dealer,
  2207. Manufacturer: info.Manufacturer,
  2208. Type: 1,
  2209. StorehouseId: houseConfig.DrugStorehouseOut,
  2210. }
  2211. service.AddSigleDrugCancelStock(&cancelStock)
  2212. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2213. dealer, _ := service.GetDealerById(info.Dealer)
  2214. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2215. cancelStockInfo := models.DrugCancelStockInfo{
  2216. OrderNumber: cancelInfo.OrderNumber,
  2217. CancelStockId: cancelInfo.ID,
  2218. DrugId: info.DrugId,
  2219. Count: info.Count,
  2220. Status: 1,
  2221. Ctime: ctime,
  2222. OrgId: adminUserInfo.CurrentOrgId,
  2223. Type: 1,
  2224. Manufacturer: manufactureName.ManufacturerName,
  2225. Dealer: dealer.DealerName,
  2226. Total: 0,
  2227. RetailPrice: info.RetailPrice,
  2228. RetailTotalPrice: info.RetailTotalPrice,
  2229. Price: info.Price,
  2230. RegisterAccount: "",
  2231. Remark: info.Remark,
  2232. BatchNumber: info.BatchNumber,
  2233. MaxUnit: info.CountUnit,
  2234. ProductDate: info.ProductDate,
  2235. ExpiryDate: info.ExpiryDate,
  2236. BatchNumberId: info.WarehouseInfoId,
  2237. StorehouseId: houseConfig.DrugStorehouseOut,
  2238. }
  2239. flow := models.DrugFlow{
  2240. WarehousingId: 0,
  2241. DrugId: info.DrugId,
  2242. Number: "",
  2243. BatchNumber: info.BatchNumber,
  2244. Count: info.Count,
  2245. UserOrgId: adminUserInfo.CurrentOrgId,
  2246. PatientId: 0,
  2247. SystemTime: info.SysRecordTime,
  2248. ConsumableType: 7,
  2249. IsSys: 0,
  2250. WarehousingOrder: "",
  2251. WarehouseOutId: 0,
  2252. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2253. IsEdit: 0,
  2254. CancelStockId: cancelStock.ID,
  2255. CancelOrderNumber: cancelStock.OrderNumber,
  2256. Manufacturer: info.Manufacturer,
  2257. Dealer: info.Dealer,
  2258. Creator: adminUserInfo.AdminUser.Id,
  2259. UpdateCreator: 0,
  2260. Status: 1,
  2261. Ctime: time.Now().Unix(),
  2262. Mtime: 0,
  2263. Price: info.Price,
  2264. WarehousingDetailId: 0,
  2265. WarehouseOutDetailId: 0,
  2266. CancelOutDetailId: 0,
  2267. ExpireDate: info.ExpiryDate,
  2268. ProductDate: info.ProductDate,
  2269. MaxUnit: info.CountUnit,
  2270. MinUnit: "",
  2271. AdviceId: info.AdviceId,
  2272. StorehouseId: houseConfig.DrugStorehouseOut,
  2273. }
  2274. service.CreatedCancelStock(cancelStockInfo)
  2275. service.CreateDrugFlowOne(flow)
  2276. //删除出库记录
  2277. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2278. //删除流水
  2279. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2280. }
  2281. }
  2282. }
  2283. }
  2284. c.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "删除成功",
  2286. })
  2287. return
  2288. } else {
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2290. return
  2291. }
  2292. }
  2293. func (c *HisApiController) DeleteProject() {
  2294. id, _ := c.GetInt64("id")
  2295. adminInfo := c.GetAdminUserInfo()
  2296. project, _ := service.GetHisProjectByID(id)
  2297. // var consumable models.DialysisBeforePrepare
  2298. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2299. service.DeletePrintInfo(id)
  2300. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2301. label.Status = 0
  2302. service.CreateHisLabelRecord(&label)
  2303. if stockConfig.IsOpen == 1 {
  2304. if project.Type == 2 {
  2305. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2306. fmt.Println(err)
  2307. }
  2308. if project.Type == 3 {
  2309. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2310. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2311. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2312. good.Total = good.Total + f_count
  2313. service.UpdateGoodInfo(&good)
  2314. operation_time := time.Now().Unix()
  2315. creater := adminInfo.AdminUser.Id
  2316. //创建退库单
  2317. timeStr := time.Now().Format("2006-01-02")
  2318. timeArr := strings.Split(timeStr, "-")
  2319. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2320. total = total + 1
  2321. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2322. cancelStock := models.CancelStock{
  2323. OrderNumber: orderNumber,
  2324. OperaTime: operation_time,
  2325. OrgId: adminInfo.CurrentOrgId,
  2326. Creater: creater,
  2327. Ctime: time.Now().Unix(),
  2328. Status: 1,
  2329. ReturnTime: project.RecordDate,
  2330. Type: 1,
  2331. StorehouseId: houseConfig.StorehouseOutInfo,
  2332. }
  2333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2334. if msgerrkonde == gorm.ErrRecordNotFound {
  2335. service.AddSigleCancelStock(&cancelStock)
  2336. }
  2337. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2340. //获取该耗材有库存的第一条数据
  2341. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2343. deaerler, _ := service.GetDealerById(info.Dealer)
  2344. if info.ID > 0 {
  2345. cancelStockInfo := models.CancelStockInfo{
  2346. GoodId: project.ProjectId,
  2347. CancelStockId: cancel.ID,
  2348. GoodTypeId: good.GoodTypeId,
  2349. Count: prescribingNumber,
  2350. Price: info.Price,
  2351. Total: 0,
  2352. ProductDate: info.ProductDate,
  2353. ExpiryDate: info.ExpiryDate,
  2354. Ctime: time.Now().Unix(),
  2355. Status: 1,
  2356. OrgId: adminInfo.CurrentOrgId,
  2357. OrderNumber: cancel.OrderNumber,
  2358. Type: 0,
  2359. Dealer: deaerler.DealerName,
  2360. Manufacturer: manufacturer.ManufacturerName,
  2361. Number: info.Number,
  2362. RegisterAccount: "",
  2363. Remark: "",
  2364. WarehouseInfoId: info.WarehouseInfotId,
  2365. PatientId: info.PatientId,
  2366. RecordDate: info.SysRecordTime,
  2367. StorehouseId: houseConfig.StorehouseOutInfo,
  2368. }
  2369. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2370. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2371. flow := models.VmStockFlow{
  2372. WarehousingId: 0,
  2373. GoodId: project.ProjectId,
  2374. Number: info.Number,
  2375. LicenseNumber: info.LicenseNumber,
  2376. Count: prescribingNumber,
  2377. UserOrgId: adminInfo.CurrentOrgId,
  2378. PatientId: project.PatientId,
  2379. SystemTime: time.Now().Unix(),
  2380. ConsumableType: 7,
  2381. IsSys: 0,
  2382. WarehousingOrder: "",
  2383. WarehouseOutId: 0,
  2384. WarehouseOutOrderNumber: "",
  2385. IsEdit: 0,
  2386. CancelStockId: cancel.ID,
  2387. CancelOrderNumber: cancel.OrderNumber,
  2388. Manufacturer: manufacturer.ID,
  2389. Dealer: 0,
  2390. Creator: adminInfo.AdminUser.Id,
  2391. UpdateCreator: 0,
  2392. Status: 1,
  2393. Ctime: time.Now().Unix(),
  2394. Mtime: 0,
  2395. Price: info.Price,
  2396. WarehousingDetailId: info.WarehouseInfotId,
  2397. WarehouseOutDetailId: 0,
  2398. CancelOutDetailId: cancelInfo.ID,
  2399. ProductDate: info.ProductDate,
  2400. ExpireDate: info.ExpiryDate,
  2401. StorehouseId: houseConfig.StorehouseOutInfo,
  2402. }
  2403. service.CreateStockFlowOne(flow)
  2404. //删除出库表
  2405. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2406. //查询今日该患者开了多少耗材
  2407. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2408. var total_count int64
  2409. var cha_count int64
  2410. for _, item := range projectList {
  2411. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2412. total_count += count
  2413. }
  2414. //回退库存
  2415. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2416. //查询今日该耗材退库数量
  2417. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2418. var cancel_count int64
  2419. for _, items := range cancelInfoOne {
  2420. cancel_count += items.Count
  2421. }
  2422. cha_count = total_count - cancel_count
  2423. if total_count > cancel_count {
  2424. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2425. if err == gorm.ErrRecordNotFound {
  2426. //没有记录,则创建出库单
  2427. timeStr := time.Now().Format("2006-01-02")
  2428. timeArr := strings.Split(timeStr, "-")
  2429. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2430. total = total + 1
  2431. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2432. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2433. number = number + total
  2434. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2435. warehouseOut := models.WarehouseOut{
  2436. WarehouseOutOrderNumber: warehousing_out_order,
  2437. OperationTime: time.Now().Unix(),
  2438. OrgId: adminInfo.CurrentOrgId,
  2439. Creater: creater,
  2440. Ctime: time.Now().Unix(),
  2441. Status: 1,
  2442. WarehouseOutTime: info.SysRecordTime,
  2443. Dealer: 0,
  2444. Manufacturer: 0,
  2445. Type: 1,
  2446. IsSys: 1,
  2447. StorehouseId: houseConfig.StorehouseOutInfo,
  2448. }
  2449. err := service.AddSigleWarehouseOut(&warehouseOut)
  2450. if err != nil {
  2451. utils.TraceLog("创建出库单失败 err = %v", err)
  2452. return
  2453. }
  2454. prepare := &models.DialysisBeforePrepare{
  2455. UserOrgId: adminInfo.CurrentOrgId,
  2456. PatientId: info.PatientId,
  2457. RecordDate: info.SysRecordTime,
  2458. GoodId: project.ProjectId,
  2459. GoodTypeId: info.GoodTypeId,
  2460. Count: cha_count,
  2461. StorehouseId: houseConfig.StorehouseOutInfo,
  2462. }
  2463. //出库
  2464. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2465. } else if err == nil {
  2466. prepare := &models.DialysisBeforePrepare{
  2467. UserOrgId: adminInfo.CurrentOrgId,
  2468. PatientId: info.PatientId,
  2469. RecordDate: info.SysRecordTime,
  2470. GoodId: project.ProjectId,
  2471. GoodTypeId: info.GoodTypeId,
  2472. Count: cha_count,
  2473. StorehouseId: houseConfig.StorehouseOutInfo,
  2474. }
  2475. //出库
  2476. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2477. }
  2478. }
  2479. }
  2480. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2481. fmt.Println(err)
  2482. }
  2483. }
  2484. c.ServeSuccessJSON(map[string]interface{}{
  2485. "msg": "删除成功",
  2486. })
  2487. return
  2488. }
  2489. func (c *HisApiController) CreateHisAdditionalCharge() {
  2490. his_patient_id, _ := c.GetInt64("his_patient_id")
  2491. patient_id, _ := c.GetInt64("patient_id")
  2492. record_date := c.GetString("record_date")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2496. if err != nil {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. }
  2500. adminInfo := c.GetAdminUserInfo()
  2501. recordDateTime := theTime.Unix()
  2502. dataBody := make(map[string]interface{}, 0)
  2503. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2504. if err != nil {
  2505. utils.ErrorLog(err.Error())
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. var additions []*models.HisAdditionalCharge
  2510. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2511. additions, _ := dataBody["addition"].([]interface{})
  2512. if len(additions) > 0 {
  2513. for _, item := range additions {
  2514. items := item.(map[string]interface{})
  2515. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2516. utils.ErrorLog("item_id")
  2517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2518. return
  2519. }
  2520. item_id := int64(items["item_id"].(float64))
  2521. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2522. utils.ErrorLog("item_name")
  2523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2524. return
  2525. }
  2526. item_name := items["item_name"].(string)
  2527. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2528. utils.ErrorLog("price")
  2529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2530. return
  2531. }
  2532. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2533. ctime := time.Now().Unix()
  2534. additional := &models.HisAdditionalCharge{
  2535. PatientId: patient_id,
  2536. HisPatientId: his_patient_id,
  2537. UserOrgId: adminInfo.CurrentOrgId,
  2538. RecordDate: recordDateTime,
  2539. CreatedTime: ctime,
  2540. UpdatedTime: ctime,
  2541. Modifier: adminInfo.AdminUser.Id,
  2542. Creator: adminInfo.AdminUser.Id,
  2543. Price: price,
  2544. ItemName: item_name,
  2545. ItemId: item_id,
  2546. Status: 1,
  2547. }
  2548. additions = append(additions, additional)
  2549. }
  2550. }
  2551. }
  2552. for _, item := range additions {
  2553. service.CreateAddtionalCharge(item)
  2554. }
  2555. c.ServeSuccessJSON(map[string]interface{}{
  2556. "msg": "创建成功",
  2557. })
  2558. }
  2559. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2560. blood_fat := c.GetString("blood_fat")
  2561. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2562. blood_sugar := c.GetString("blood_sugar")
  2563. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2564. chief_conplaint := c.GetString("chief_conplaint")
  2565. dbp := c.GetString("dbp")
  2566. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2567. delivery_way, _ := c.GetInt64("delivery_way")
  2568. diagnostic := c.GetString("diagnostic")
  2569. family_history := c.GetString("family_history")
  2570. height := c.GetString("height")
  2571. history_of_present_illness := c.GetString("history_of_present_illness")
  2572. is_infect, _ := c.GetInt64("is_infect")
  2573. past_history := c.GetString("past_history")
  2574. patient_id, _ := c.GetInt64("patient_id")
  2575. his_patient_id, _ := c.GetInt64("his_patient_id")
  2576. personal_history := c.GetString("personal_history")
  2577. pulse := c.GetString("pulse")
  2578. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2579. sbp := c.GetString("sbp")
  2580. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2581. heightfloat, _ := strconv.ParseFloat(height, 64)
  2582. sicktype := c.GetString("sick_type")
  2583. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2584. symptom := c.GetString("symptom")
  2585. sick_date := c.GetString("sick_date")
  2586. temperatures := c.GetString("temperature")
  2587. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2588. record_date := c.GetString("record_date")
  2589. breathing := c.GetString("breathing")
  2590. doctor_advice := c.GetString("doctor_advice")
  2591. remark := c.GetString("remark")
  2592. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2593. sick, _ := c.GetInt64("sick")
  2594. diagnose, _ := c.GetInt64("diagnose")
  2595. //id, _ := c.GetInt64("id")
  2596. timeLayout := "2006-01-02"
  2597. loc, _ := time.LoadLocation("Local")
  2598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2599. allergic_history := c.GetString("allergic_history")
  2600. if err != nil {
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. recordDateTime := theTime.Unix()
  2605. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2606. if err != nil {
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. sickTimes := sickTime.Unix()
  2611. ctime := time.Now().Unix()
  2612. primary_disease := c.GetString("primary_disease")
  2613. confirm_failure_date := c.GetString("confirm_failure_date")
  2614. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2615. drug_allergy_history := c.GetString("drug_allergy_history")
  2616. physical_examination := c.GetString("physical_examination")
  2617. special_inspection := c.GetString("special_inspection")
  2618. lab_apparatus := c.GetString("lab_apparatus")
  2619. caseHistory := models.HisPatientCaseHistory{
  2620. HisPatientId: his_patient_id,
  2621. PatientId: patient_id,
  2622. Temperature: temperature,
  2623. BloodSugar: bloodsugarfloat,
  2624. Pulse: pulsefloat,
  2625. Sbp: sbpfloat,
  2626. Dbp: dbpfloat,
  2627. Height: heightfloat,
  2628. BloodFat: bloodfatfloat,
  2629. SickType: sick_type,
  2630. Symptom: symptom,
  2631. SickDate: sickTimes,
  2632. IsInfect: is_infect,
  2633. HistoryOfPresentIllness: history_of_present_illness,
  2634. PastHistory: past_history,
  2635. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2636. ChiefConplaint: chief_conplaint,
  2637. PersonalHistory: personal_history,
  2638. FamilyHistory: family_history,
  2639. Diagnostic: diagnostic,
  2640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2641. Status: 1,
  2642. Ctime: ctime,
  2643. Mtime: ctime,
  2644. RecordDate: recordDateTime,
  2645. DeliveryWay: delivery_way,
  2646. Breathing: breathingfloat,
  2647. DoctorAdvice: doctor_advice,
  2648. Remark: remark,
  2649. Sick: sick,
  2650. Diagnose: diagnose,
  2651. AllergicHistory: allergic_history,
  2652. PrimaryDisease: primary_disease,
  2653. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2654. DrugAllergyHistory: drug_allergy_history,
  2655. PhysicalExamination: physical_examination,
  2656. SpecialInspection: special_inspection,
  2657. LabApparatus: lab_apparatus,
  2658. }
  2659. //查询该患者是否有病历
  2660. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2661. if errcodes == gorm.ErrRecordNotFound {
  2662. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2663. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2664. if err != nil {
  2665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2666. return
  2667. }
  2668. c.ServeSuccessJSON(map[string]interface{}{
  2669. "caseHistory": caseHistory,
  2670. "historyInfo": historyInfo,
  2671. })
  2672. return
  2673. } else if errcodes == nil {
  2674. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2675. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2676. if err != nil {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2678. return
  2679. }
  2680. c.ServeSuccessJSON(map[string]interface{}{
  2681. "caseHistory": caseHistory,
  2682. "historyInfo": historyInfo,
  2683. })
  2684. }
  2685. //查询该患者是否有病历
  2686. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2687. //if errcode == gorm.ErrRecordNotFound {
  2688. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2689. // if err != nil {
  2690. // c.ServeSuccessJSON(map[string]interface{}{
  2691. // "msg": "保存成功",
  2692. // })
  2693. // }
  2694. //} else if errcode == nil {
  2695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2696. // return
  2697. //}
  2698. }
  2699. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2700. patient_id, _ := c.GetInt64("patient_id", 0)
  2701. adminUser := c.GetAdminUserInfo()
  2702. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2703. c.ServeSuccessJSON(map[string]interface{}{
  2704. "list": caseHistorys,
  2705. })
  2706. }
  2707. func (c *HisApiController) GetHisPatientCaseHistory() {
  2708. record_date, _ := c.GetInt64("record_date", 0)
  2709. patient_id, _ := c.GetInt64("patient_id", 0)
  2710. admin := c.GetAdminUserInfo()
  2711. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2712. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2713. c.ServeSuccessJSON(map[string]interface{}{
  2714. "info": info,
  2715. "case_history": case_history,
  2716. })
  2717. }
  2718. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2719. template_name := c.GetString("template_name")
  2720. template_remark := c.GetString("template_remark")
  2721. doctor := c.GetAdminUserInfo().AdminUser.Id
  2722. diagnostic := c.GetString("diagnostic")
  2723. chief_conplaint := c.GetString("chief_conplain")
  2724. history_of_present_illness := c.GetString("history_of_present_illness")
  2725. past_history := c.GetString("past_history")
  2726. personal_history := c.GetString("personal_history")
  2727. family_history := c.GetString("family_history")
  2728. user_name := c.GetString("user_name")
  2729. doctor_advice := c.GetString("doctor_advice")
  2730. remark := c.GetString("remark")
  2731. //record_date := c.GetString("record_date")
  2732. //fmt.Println("record_date--------",record_date)
  2733. //timeLayout := "2006-01-02"
  2734. //loc, _ := time.LoadLocation("Local")
  2735. //
  2736. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2737. //if err != nil {
  2738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. // return
  2740. //}
  2741. //recordDateTime := theTime.Unix()
  2742. ctime := time.Now().Unix()
  2743. template := models.HisCaseHistoryTemplate{
  2744. HistoryOfPresentIllness: history_of_present_illness,
  2745. PastHistory: past_history,
  2746. ChiefConplaint: chief_conplaint,
  2747. PersonalHistory: personal_history,
  2748. FamilyHistory: family_history,
  2749. Diagnostic: diagnostic,
  2750. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: ctime,
  2753. Mtime: ctime,
  2754. RecordDate: time.Now().Unix(),
  2755. TemplateName: template_name,
  2756. TemplateRemark: template_remark,
  2757. Creator: doctor,
  2758. Modifier: doctor,
  2759. UserName: user_name,
  2760. DoctorAdvice: doctor_advice,
  2761. Remark: remark,
  2762. }
  2763. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2764. if err == nil {
  2765. c.ServeSuccessJSON(map[string]interface{}{
  2766. "msg": "保存成功",
  2767. })
  2768. } else {
  2769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2770. return
  2771. }
  2772. }
  2773. func (c *HisApiController) GetCaseHistoryTemplate() {
  2774. timeLayout := "2006-01-02"
  2775. loc, _ := time.LoadLocation("Local")
  2776. keyword := c.GetString("keyword")
  2777. start_time := c.GetString("start_time")
  2778. end_time := c.GetString("end_time")
  2779. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2780. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2781. admin := c.GetAdminUserInfo()
  2782. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2783. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2784. c.ServeSuccessJSON(map[string]interface{}{
  2785. "template": template,
  2786. //"history": history,
  2787. })
  2788. }
  2789. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2790. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2791. utils.ErrorLog("drug_name")
  2792. return enums.ErrorCodeParamWrong
  2793. }
  2794. adviceName, _ := json["drug_name"].(string)
  2795. if len(adviceName) == 0 {
  2796. utils.ErrorLog("len(advice_name) == 0")
  2797. return enums.ErrorCodeParamWrong
  2798. }
  2799. advice.AdviceName = adviceName
  2800. adviceDesc, _ := json["advice_desc"].(string)
  2801. advice.AdviceDesc = adviceDesc
  2802. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2803. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2804. advice.DrugSpec = drugSpec
  2805. }
  2806. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2807. remark, _ := json["remark"].(string)
  2808. advice.Remark = remark
  2809. }
  2810. if json["id"] == nil {
  2811. advice.DrugId = 0
  2812. } else {
  2813. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2814. drug_id := int64(json["id"].(float64))
  2815. advice.DrugId = drug_id
  2816. }
  2817. }
  2818. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2819. advice_id := int64(json["advice_id"].(float64))
  2820. advice.ID = advice_id
  2821. if advice.ID > 0 {
  2822. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2823. if err == nil {
  2824. if hisAdvice.ID > 0 {
  2825. advice.ExecutionTime = hisAdvice.ExecutionTime
  2826. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2827. advice.ExecutionState = hisAdvice.ExecutionState
  2828. advice.CheckTime = hisAdvice.CheckTime
  2829. advice.Checker = hisAdvice.Checker
  2830. advice.CheckState = hisAdvice.CheckState
  2831. advice.StartTime = hisAdvice.StartTime
  2832. advice.FeedetlSn = hisAdvice.FeedetlSn
  2833. }
  2834. }
  2835. }
  2836. }
  2837. //
  2838. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2839. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2840. // advice.ExecutionTime = execution_time
  2841. //}
  2842. //
  2843. //
  2844. //
  2845. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2846. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2847. // advice.ExecutionStaff = execution_staff
  2848. //}
  2849. //
  2850. //
  2851. //
  2852. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2853. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2854. // advice.ExecutionState = execution_state
  2855. //}
  2856. //
  2857. //
  2858. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2859. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2860. // advice.CheckTime = check_time
  2861. //}
  2862. //
  2863. //
  2864. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2865. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2866. // advice.CheckState = check_state
  2867. //}
  2868. //
  2869. //
  2870. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2871. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2872. // advice.Checker = checker
  2873. //}
  2874. //
  2875. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2876. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2877. // advice.StartTime = start_time
  2878. //}
  2879. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2880. drugSpecUnit, _ := json["min_unit"].(string)
  2881. advice.DrugSpecUnit = drugSpecUnit
  2882. }
  2883. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2884. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2885. advice.SingleDose = singleDose
  2886. }
  2887. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2888. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2889. advice.SingleDoseUnit = singleDoseUnit
  2890. }
  2891. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2892. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2893. advice.PrescribingNumber = prescribingNumber
  2894. }
  2895. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2896. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2897. advice.PrescribingNumberUnit = prescribingNumberUnit
  2898. }
  2899. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2900. deliveryWay, _ := json["delivery_way"].(string)
  2901. advice.DeliveryWay = deliveryWay
  2902. }
  2903. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2904. executionFrequency, _ := json["execution_frequency"].(string)
  2905. advice.ExecutionFrequency = executionFrequency
  2906. }
  2907. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2908. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2909. advice.Price = price
  2910. }
  2911. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2912. med_list_codg, _ := json["medical_insurance_number"].(string)
  2913. advice.MedListCodg = med_list_codg
  2914. }
  2915. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2916. day := int64(json["day"].(float64))
  2917. advice.Day = day
  2918. }
  2919. return 0
  2920. }
  2921. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2922. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2923. id := int64(json["id"].(float64))
  2924. project.ID = id
  2925. historyProject, _ := service.GetHisProjectByID(id)
  2926. project.FeedetlSn = historyProject.FeedetlSn
  2927. }
  2928. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2929. project_id := int64(json["project_id"].(float64))
  2930. project.ProjectId = project_id
  2931. }
  2932. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2933. // price := int64(json["price"].(float64))
  2934. // formatInt_price := strconv.FormatInt(price, 10)
  2935. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2936. // project.Price = float_price
  2937. // }
  2938. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2939. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2940. project.Price = price
  2941. }
  2942. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2943. total, _ := json["total"].(string)
  2944. project.Count = total
  2945. }
  2946. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2947. medical_code, _ := json["medical_code"].(string)
  2948. project.MedListCodg = medical_code
  2949. }
  2950. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2951. single_dose, _ := json["single_dose"].(string)
  2952. project.SingleDose = single_dose
  2953. }
  2954. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2955. delivery_way, _ := json["delivery_way"].(string)
  2956. project.DeliveryWay = delivery_way
  2957. }
  2958. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2959. execution_frequency, _ := json["execution_frequency"].(string)
  2960. project.ExecutionFrequency = execution_frequency
  2961. }
  2962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2963. remark, _ := json["remark"].(string)
  2964. project.Remark = remark
  2965. }
  2966. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2967. day, _ := json["number_days"].(string)
  2968. project.Day = day
  2969. }
  2970. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2971. unit, _ := json["unit"].(string)
  2972. project.Unit = unit
  2973. }
  2974. return 0
  2975. }
  2976. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2977. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2978. id := int64(json["id"].(float64))
  2979. historyAddtions, _ := service.GetHisAdditionByID(id)
  2980. additionalCharge.ID = id
  2981. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2982. }
  2983. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2984. item_id := int64(json["item_id"].(float64))
  2985. additionalCharge.ItemId = item_id
  2986. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2987. if config.ID > 0 {
  2988. if len(config.Code) > 0 {
  2989. additionalCharge.MedListCodg = config.Code
  2990. }
  2991. }
  2992. }
  2993. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2994. // price := int64(json["price"].(float64))
  2995. // formatInt_price := strconv.FormatInt(price, 10)
  2996. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2997. // additionalCharge.Price = float_price
  2998. // }
  2999. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3000. // price := int64(json["price"].(float64))
  3001. // formatInt_price := strconv.FormatInt(price, 10)
  3002. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3003. // additionalCharge.Price = float_price
  3004. //}
  3005. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3006. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3007. additionalCharge.Price = price
  3008. }
  3009. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3010. count, _ := json["count"].(string)
  3011. counts, _ := strconv.ParseInt(count, 10, 64)
  3012. additionalCharge.Count = counts
  3013. }
  3014. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3015. item_name, _ := json["item_name"].(string)
  3016. additionalCharge.ItemName = item_name
  3017. }
  3018. return 0
  3019. }
  3020. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3021. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3022. utils.ErrorLog("drug_name")
  3023. return enums.ErrorCodeParamWrong
  3024. }
  3025. adviceName, _ := json["drug_name"].(string)
  3026. if len(adviceName) == 0 {
  3027. utils.ErrorLog("len(advice_name) == 0")
  3028. return enums.ErrorCodeParamWrong
  3029. }
  3030. advice.AdviceName = adviceName
  3031. adviceDesc, _ := json["advice_desc"].(string)
  3032. advice.AdviceDesc = adviceDesc
  3033. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3034. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3035. advice.DrugSpec = drugSpec
  3036. }
  3037. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3038. remark, _ := json["remark"].(string)
  3039. advice.Remark = remark
  3040. }
  3041. if json["id"] == nil {
  3042. advice.DrugId = 0
  3043. } else {
  3044. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3045. drug_id := int64(json["id"].(float64))
  3046. advice.DrugId = drug_id
  3047. }
  3048. }
  3049. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3050. groupno := int64(json["groupno"].(float64))
  3051. advice.Groupno = groupno
  3052. }
  3053. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3054. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3055. advice.HospApprFlag = hosp_appr_flag
  3056. }
  3057. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3058. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3059. advice.PrescribingNumber = prescribingNumber
  3060. }
  3061. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3062. // frequency_type := int64(json["frequency_type"].(float64))
  3063. // advice.FrequencyType = frequency_type
  3064. //}
  3065. //
  3066. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3067. // day_count := int64(json["day_count"].(float64))
  3068. // advice.DayCount = day_count
  3069. //}
  3070. //
  3071. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3072. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3073. // week_day, _ := json["week_day"].(string)
  3074. // advice.WeekDay = week_day
  3075. //}
  3076. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3077. drugSpecUnit, _ := json["min_unit"].(string)
  3078. advice.DrugSpecUnit = drugSpecUnit
  3079. }
  3080. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3081. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3082. advice.SingleDose = singleDose
  3083. }
  3084. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3085. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3086. advice.SingleDoseUnit = singleDoseUnit
  3087. }
  3088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3089. deliveryWay, _ := json["delivery_way"].(string)
  3090. advice.DeliveryWay = deliveryWay
  3091. }
  3092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3093. executionFrequency, _ := json["execution_frequency"].(string)
  3094. advice.ExecutionFrequency = executionFrequency
  3095. }
  3096. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3097. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3098. advice.Price = price
  3099. }
  3100. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3101. med_list_codg, _ := json["medical_insurance_number"].(string)
  3102. advice.MedListCodg = med_list_codg
  3103. }
  3104. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3105. day := int64(json["day"].(float64))
  3106. advice.Day = day
  3107. }
  3108. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3109. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3110. advice.PrescribingNumberUnit = prescribingNumberUnit
  3111. }
  3112. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3113. advice_id := int64(json["advice_id"].(float64))
  3114. advice.ID = advice_id
  3115. if advice.ID > 0 {
  3116. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3117. if err == nil {
  3118. if hisAdvice.ID > 0 {
  3119. advice.ExecutionTime = hisAdvice.ExecutionTime
  3120. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3121. advice.ExecutionState = hisAdvice.ExecutionState
  3122. advice.CheckTime = hisAdvice.CheckTime
  3123. advice.Checker = hisAdvice.Checker
  3124. advice.CheckState = hisAdvice.CheckState
  3125. advice.StartTime = hisAdvice.StartTime
  3126. advice.HospApprFlag = hisAdvice.HospApprFlag
  3127. if hisAdvice.UserOrgId == 10028 {
  3128. 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 {
  3129. advice.ExecutionTime = 0
  3130. advice.ExecutionStaff = 0
  3131. advice.ExecutionState = 2
  3132. advice.CheckTime = 0
  3133. advice.Checker = 0
  3134. advice.CheckState = 2
  3135. }
  3136. } else {
  3137. 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 {
  3138. advice.ExecutionTime = 0
  3139. advice.ExecutionStaff = 0
  3140. advice.ExecutionState = 2
  3141. advice.CheckTime = 0
  3142. advice.Checker = 0
  3143. advice.CheckState = 2
  3144. }
  3145. }
  3146. //advice.Groupno = hisAdvice.Groupno
  3147. }
  3148. }
  3149. }
  3150. }
  3151. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3152. //
  3153. //if drugStockConfig.IsOpen == 1 {
  3154. //
  3155. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3156. // if advice.ID == 0 { //医嘱不存在
  3157. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3158. // drug.Total = drug.Total - advice.PrescribingNumber
  3159. // service.UpdateBaseDrugLib(&drug)
  3160. //
  3161. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3162. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3163. // drug.Total = drug.Total - num
  3164. // service.UpdateBaseDrugLib(&drug)
  3165. // }
  3166. //
  3167. // } else if advice.ID > 0 { //医嘱存在
  3168. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3169. // var num float64
  3170. //
  3171. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3172. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3173. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3174. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3175. // drug.Total = drug.Total + num
  3176. // service.UpdateBaseDrugLib(&drug)
  3177. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3178. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3179. // drug.Total = drug.Total - num
  3180. // service.UpdateBaseDrugLib(&drug)
  3181. // }
  3182. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3183. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3184. // if num2 > advice.PrescribingNumber {
  3185. // num = num2 - advice.PrescribingNumber
  3186. // drug.Total = drug.Total + num
  3187. // service.UpdateBaseDrugLib(&drug)
  3188. // } else if num2 < advice.PrescribingNumber {
  3189. // num = advice.PrescribingNumber - num2
  3190. // drug.Total = drug.Total - num
  3191. // service.UpdateBaseDrugLib(&drug)
  3192. // }
  3193. //
  3194. // }
  3195. //
  3196. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3197. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3198. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3199. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3200. // if num1 > num2 {
  3201. // num = num1 - num2
  3202. // drug.Total = drug.Total + num
  3203. // service.UpdateBaseDrugLib(&drug)
  3204. // } else if num1 < num2 {
  3205. // num = num2 - num1
  3206. // drug.Total = drug.Total - num
  3207. // service.UpdateBaseDrugLib(&drug)
  3208. // }
  3209. //
  3210. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3211. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3212. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3213. // if hisAdvice.PrescribingNumber > num2 {
  3214. // num = hisAdvice.PrescribingNumber - num2
  3215. // drug.Total = drug.Total + num
  3216. // service.UpdateBaseDrugLib(&drug)
  3217. // } else if num2 < advice.PrescribingNumber {
  3218. // num = num2 - hisAdvice.PrescribingNumber
  3219. // drug.Total = drug.Total - num
  3220. // service.UpdateBaseDrugLib(&drug)
  3221. // }
  3222. //
  3223. // }
  3224. // }
  3225. // }
  3226. //}
  3227. //
  3228. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3229. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3230. // advice.ExecutionTime = execution_time
  3231. //}
  3232. //
  3233. //
  3234. //
  3235. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3236. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3237. // advice.ExecutionStaff = execution_staff
  3238. //}
  3239. //
  3240. //
  3241. //
  3242. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3243. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3244. // advice.ExecutionState = execution_state
  3245. //}
  3246. //
  3247. //
  3248. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3249. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3250. // advice.CheckTime = check_time
  3251. //}
  3252. //
  3253. //
  3254. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3255. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3256. // advice.CheckState = check_state
  3257. //}
  3258. //
  3259. //
  3260. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3261. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3262. // advice.Checker = checker
  3263. //}
  3264. //
  3265. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3266. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3267. // advice.StartTime = start_time
  3268. //}
  3269. return 0
  3270. }
  3271. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3272. project.ExecutionStaff = 0
  3273. project.ExecutionState = 2
  3274. project.ExecutionTime = 0
  3275. project.Checker = 0
  3276. project.CheckState = 2
  3277. project.CheckTime = 0
  3278. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3279. id := int64(json["id"].(float64))
  3280. project.ID = id
  3281. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3282. project.ExecutionStaff = temp_project.ExecutionStaff
  3283. project.ExecutionState = temp_project.ExecutionState
  3284. project.ExecutionTime = temp_project.ExecutionTime
  3285. project.Checker = temp_project.Checker
  3286. project.CheckState = temp_project.CheckState
  3287. project.CheckTime = temp_project.CheckTime
  3288. project.TeamId = temp_project.TeamId
  3289. }
  3290. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3291. types := int64(json["type"].(float64))
  3292. project.Type = types
  3293. }
  3294. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3295. project_id := int64(json["project_id"].(float64))
  3296. project.ProjectId = project_id
  3297. }
  3298. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3299. team_id := int64(json["team_id"].(float64))
  3300. project.TeamId = team_id
  3301. }
  3302. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3303. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3304. project.Price = price
  3305. }
  3306. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3307. total, _ := json["total"].(string)
  3308. //totals, _ := strconv.ParseInt(total, 10, 64)
  3309. project.Count = total
  3310. }
  3311. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3312. medical_code, _ := json["medical_code"].(string)
  3313. project.MedListCodg = medical_code
  3314. }
  3315. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3316. single_dose, _ := json["single_dose"].(string)
  3317. project.SingleDose = single_dose
  3318. }
  3319. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3320. delivery_way, _ := json["delivery_way"].(string)
  3321. project.DeliveryWay = delivery_way
  3322. }
  3323. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3324. execution_frequency, _ := json["execution_frequency"].(string)
  3325. project.ExecutionFrequency = execution_frequency
  3326. }
  3327. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3328. remark, _ := json["remark"].(string)
  3329. project.Remark = remark
  3330. }
  3331. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3332. day, _ := json["number_days"].(string)
  3333. project.Day = day
  3334. }
  3335. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3336. unit, _ := json["unit"].(string)
  3337. project.Unit = unit
  3338. }
  3339. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3340. // frequency_type := int64(json["frequency_type"].(float64))
  3341. // project.FrequencyType = frequency_type
  3342. //}
  3343. //
  3344. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3345. // day_count := int64(json["day_count"].(float64))
  3346. // project.DayCount = day_count
  3347. //}
  3348. //
  3349. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3350. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3351. // week_day, _ := json["week_day"].(string)
  3352. // project.WeekDay = week_day
  3353. //}
  3354. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3355. //
  3356. //if project.ID == 0 {
  3357. // if stockConfig.IsOpen == 1 {
  3358. // if project.Type == 3 {
  3359. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3360. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3361. // good.Total = good.Total - f_count
  3362. // service.UpdateGoodInfo(&good)
  3363. // }
  3364. // }
  3365. //
  3366. //} else {
  3367. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3368. //
  3369. // if stockConfig.IsOpen == 1 {
  3370. // if project.Type == 3 {
  3371. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3372. // if project.Count < temp_project.Count {
  3373. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3374. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3375. //
  3376. // other_count := f_count_two - f_count_one
  3377. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3378. // good.Total = good.Total + other_count_two
  3379. // service.UpdateGoodInfo(&good)
  3380. // } else if project.Count > temp_project.Count {
  3381. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3382. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3383. //
  3384. // other_count := f_count_one - f_count_two
  3385. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3386. // good.Total = good.Total - other_count_two
  3387. // service.UpdateGoodInfo(&good)
  3388. // }
  3389. //
  3390. // }
  3391. // }
  3392. //
  3393. //}
  3394. return 0
  3395. }
  3396. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3397. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3398. id := int64(json["id"].(float64))
  3399. additionalCharge.ID = id
  3400. }
  3401. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3402. item_id := int64(json["item_id"].(float64))
  3403. additionalCharge.ItemId = item_id
  3404. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3405. if config.ID > 0 {
  3406. if len(config.Code) > 0 {
  3407. additionalCharge.MedListCodg = config.Code
  3408. }
  3409. }
  3410. }
  3411. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3412. // price := int64(json["price"].(float64))
  3413. // formatInt_price := strconv.FormatInt(price, 10)
  3414. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3415. // additionalCharge.Price = float_price
  3416. // }
  3417. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3418. // price := int64(json["price"].(float64))
  3419. // formatInt_price := strconv.FormatInt(price, 10)
  3420. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3421. // additionalCharge.Price = float_price
  3422. //}
  3423. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3424. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3425. additionalCharge.Price = price
  3426. }
  3427. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3428. count, _ := json["count"].(string)
  3429. counts, _ := strconv.ParseInt(count, 10, 64)
  3430. additionalCharge.Count = counts
  3431. }
  3432. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3433. item_name, _ := json["item_name"].(string)
  3434. additionalCharge.ItemName = item_name
  3435. }
  3436. return 0
  3437. }
  3438. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3439. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3440. utils.ErrorLog("drug_name")
  3441. return enums.ErrorCodeParamWrong
  3442. }
  3443. adviceName, _ := json["drug_name"].(string)
  3444. if len(adviceName) == 0 {
  3445. utils.ErrorLog("len(advice_name) == 0")
  3446. return enums.ErrorCodeParamWrong
  3447. }
  3448. advice.AdviceName = adviceName
  3449. adviceDesc, _ := json["advice_desc"].(string)
  3450. advice.AdviceDesc = adviceDesc
  3451. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3452. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3453. advice.DrugSpec = drugSpec
  3454. }
  3455. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3456. remark, _ := json["remark"].(string)
  3457. advice.Remark = remark
  3458. }
  3459. if json["id"] == nil {
  3460. advice.DrugId = 0
  3461. } else {
  3462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3463. drug_id := int64(json["id"].(float64))
  3464. advice.DrugId = drug_id
  3465. }
  3466. }
  3467. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3468. drugSpecUnit, _ := json["min_unit"].(string)
  3469. advice.DrugSpecUnit = drugSpecUnit
  3470. }
  3471. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3472. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3473. advice.SingleDose = singleDose
  3474. }
  3475. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3476. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3477. advice.SingleDoseUnit = singleDoseUnit
  3478. }
  3479. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3480. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3481. advice.PrescribingNumber = prescribingNumber
  3482. }
  3483. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3484. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3485. advice.PrescribingNumberUnit = prescribingNumberUnit
  3486. }
  3487. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3488. deliveryWay, _ := json["delivery_way"].(string)
  3489. advice.DeliveryWay = deliveryWay
  3490. }
  3491. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3492. executionFrequency, _ := json["execution_frequency"].(string)
  3493. advice.ExecutionFrequency = executionFrequency
  3494. }
  3495. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3496. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3497. advice.Price = price
  3498. }
  3499. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3500. med_list_codg, _ := json["medical_insurance_number"].(string)
  3501. advice.MedListCodg = med_list_codg
  3502. }
  3503. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3504. day := int64(json["day"].(float64))
  3505. advice.Day = day
  3506. }
  3507. return 0
  3508. }
  3509. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3510. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3511. types := int64(json["type"].(float64))
  3512. project.Type = types
  3513. }
  3514. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3515. project_id := int64(json["project_id"].(float64))
  3516. project.ProjectId = project_id
  3517. }
  3518. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3519. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3520. project.Price = price
  3521. }
  3522. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3523. total, _ := json["total"].(string)
  3524. //totals, _ := strconv.ParseInt(total, 10, 64)
  3525. project.Count = total
  3526. }
  3527. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3528. medical_code, _ := json["medical_code"].(string)
  3529. project.MedListCodg = medical_code
  3530. }
  3531. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3532. single_dose, _ := json["single_dose"].(string)
  3533. project.SingleDose = single_dose
  3534. }
  3535. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3536. delivery_way, _ := json["delivery_way"].(string)
  3537. project.DeliveryWay = delivery_way
  3538. }
  3539. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3540. execution_frequency, _ := json["execution_frequency"].(string)
  3541. project.ExecutionFrequency = execution_frequency
  3542. }
  3543. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3544. remark, _ := json["remark"].(string)
  3545. project.Remark = remark
  3546. }
  3547. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3548. day, _ := json["number_days"].(string)
  3549. project.Day = day
  3550. }
  3551. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3552. unit, _ := json["unit"].(string)
  3553. project.Unit = unit
  3554. }
  3555. return 0
  3556. }
  3557. func (c *HisApiController) GetHisOrderList() {
  3558. page, _ := c.GetInt64("page", -1)
  3559. limit, _ := c.GetInt64("limit", -1)
  3560. start_time := c.GetString("start_time")
  3561. end_time := c.GetString("end_time")
  3562. types, _ := c.GetInt64("type", 0)
  3563. keywords := c.GetString("keywords")
  3564. p_type, _ := c.GetInt64("p_type", 0)
  3565. sort_type, _ := c.GetInt64("sort_type", 0)
  3566. charge_type, _ := c.GetInt64("charge_type", 0)
  3567. timeLayout := "2006-01-02"
  3568. loc, _ := time.LoadLocation("Local")
  3569. var startTime int64
  3570. if len(start_time) > 0 {
  3571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3572. if err != nil {
  3573. //fmt.Println(err)
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3575. return
  3576. }
  3577. startTime = theTime.Unix()
  3578. }
  3579. var endTime int64
  3580. if len(end_time) > 0 {
  3581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3582. if err != nil {
  3583. utils.ErrorLog(err.Error())
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3585. return
  3586. }
  3587. endTime = theTime.Unix()
  3588. }
  3589. adminUser := c.GetAdminUserInfo()
  3590. org_id := adminUser.CurrentOrgId
  3591. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  3592. for _, item := range order {
  3593. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3594. item.DoctorName = info.Doctor
  3595. item.DepartmentName = info.XtHisDepartment.Name
  3596. }
  3597. if err == nil {
  3598. c.ServeSuccessJSON(map[string]interface{}{
  3599. "order": order,
  3600. "total": total,
  3601. })
  3602. } else {
  3603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3604. return
  3605. }
  3606. }
  3607. func (c *HisApiController) GetHisOrder() {
  3608. patient_id, _ := c.GetInt64("patient_id", 0)
  3609. number := c.GetString("number")
  3610. adminInfo := c.GetAdminUserInfo()
  3611. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3612. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3613. if err == nil {
  3614. c.ServeSuccessJSON(map[string]interface{}{
  3615. "order": order,
  3616. "prescription": prescriptions,
  3617. })
  3618. } else {
  3619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3620. return
  3621. }
  3622. }
  3623. func (c *HisApiController) GetHisPrescriptionList() {
  3624. record_date := c.GetString("record_date")
  3625. keywords := c.GetString("keywords")
  3626. page, _ := c.GetInt64("page")
  3627. limit, _ := c.GetInt64("limit")
  3628. timeLayout := "2006-01-02"
  3629. loc, _ := time.LoadLocation("Local")
  3630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3631. if err != nil {
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. return
  3634. }
  3635. recordDateTime := theTime.Unix()
  3636. adminInfo := c.GetAdminUserInfo()
  3637. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3638. //adminInfo := c.GetAdminUserInfo()
  3639. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3640. //fmt.Println(prescriptionOrder)
  3641. if err == nil {
  3642. c.ServeSuccessJSON(map[string]interface{}{
  3643. "order": prescriptionOrder,
  3644. "total": total,
  3645. })
  3646. } else {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3648. return
  3649. }
  3650. }
  3651. func (c *HisApiController) GetHisPrescriptionInfo() {
  3652. id, _ := c.GetInt64("id")
  3653. adminInfo := c.GetAdminUserInfo()
  3654. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3655. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3656. if err == nil {
  3657. c.ServeSuccessJSON(map[string]interface{}{
  3658. "order": prescriptionOrder,
  3659. "prescription": prescription,
  3660. })
  3661. } else {
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. }
  3666. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3667. adminUser := c.GetAdminUserInfo()
  3668. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3669. c.ServeSuccessJSON(map[string]interface{}{
  3670. "config": config,
  3671. })
  3672. }
  3673. type ResultTwo struct {
  3674. ErrMsg interface{} `json:"err_msg"`
  3675. InfRefmsgid string `json:"inf_refmsgid"`
  3676. Infcode int64 `json:"infcode"`
  3677. Output struct {
  3678. Baseinfo struct {
  3679. Age float64 `json:"age"`
  3680. Brdy string `json:"brdy"`
  3681. Certno string `json:"certno"`
  3682. Gend string `json:"gend"`
  3683. Naty string `json:"naty"`
  3684. PsnCertType string `json:"psn_cert_type"`
  3685. PsnName string `json:"psn_name"`
  3686. PsnNo string `json:"psn_no"`
  3687. } `json:"baseinfo"`
  3688. Idetinfo []interface{} `json:"idetinfo"`
  3689. Iinfo []struct {
  3690. Balc float64 `json:"balc"`
  3691. CvlservFlag string `json:"cvlserv_flag"`
  3692. EmpName string `json:"emp_name"`
  3693. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3694. Insutype string `json:"insutype"`
  3695. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3696. PausInsuDate interface{} `json:"paus_insu_date"`
  3697. PsnInsuDate string `json:"psn_insu_date"`
  3698. PsnInsuStas string `json:"psn_insu_stas"`
  3699. PsnType string `json:"psn_type"`
  3700. } `json:"insuinfo"`
  3701. } `json:"output"`
  3702. RefmsgTime string `json:"refmsg_time"`
  3703. RespondTime string `json:"respond_time"`
  3704. Signtype interface{} `json:"signtype"`
  3705. WarnInfo interface{} `json:"warn_info"`
  3706. }
  3707. type ResultThree struct {
  3708. Cainfo interface{} `json:"cainfo"`
  3709. ErrMsg interface{} `json:"err_msg"`
  3710. InfRefmsgid string `json:"inf_refmsgid"`
  3711. Infcode int64 `json:"infcode"`
  3712. Output struct {
  3713. Data struct {
  3714. IptOtpNo string `json:"ipt_otp_no"`
  3715. MdtrtID string `json:"mdtrt_id"`
  3716. PsnNo string `json:"psn_no"`
  3717. } `json:"data"`
  3718. } `json:"output"`
  3719. RefmsgTime string `json:"refmsg_time"`
  3720. RespondTime string `json:"respond_time"`
  3721. Signtype interface{} `json:"signtype"`
  3722. WarnMsg interface{} `json:"warn_msg"`
  3723. }
  3724. type ResultFour struct {
  3725. Cainfo string `json:"cainfo"`
  3726. ErrMsg string `json:"err_msg"`
  3727. InfRefmsgid string `json:"inf_refmsgid"`
  3728. Infcode int64 `json:"infcode"`
  3729. Output struct {
  3730. Result []struct {
  3731. BasMednFlag string `json:"bas_medn_flag"`
  3732. ChldMedcFlag string `json:"chld_medc_flag"`
  3733. ChrgitmLv string `json:"chrgitm_lv"`
  3734. Cnt float64 `json:"cnt"`
  3735. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3736. DrtReimFlag string `json:"drt_reim_flag"`
  3737. FeedetlSn string `json:"feedetl_sn"`
  3738. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3739. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3740. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3741. ListSpItemFlag string `json:"list_sp_item_flag"`
  3742. LmtUsedFlag string `json:"lmt_used_flag"`
  3743. MedChrgitmType string `json:"med_chrgitm_type"`
  3744. Memo string `json:"memo"`
  3745. OverlmtAmt float64 `json:"overlmt_amt"`
  3746. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3747. Pric float64 `json:"pric"`
  3748. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3749. SelfpayProp float64 `json:"selfpay_prop"`
  3750. } `json:"result"`
  3751. } `json:"output"`
  3752. RefmsgTime string `json:"refmsg_time"`
  3753. RespondTime string `json:"respond_time"`
  3754. Signtype string `json:"signtype"`
  3755. WarnMsg string `json:"warn_msg"`
  3756. }
  3757. type ResultFive struct {
  3758. Insutype string `json:"insutype"`
  3759. }
  3760. type ResultSix struct {
  3761. Cainfo interface{} `json:"cainfo"`
  3762. ErrMsg interface{} `json:"err_msg"`
  3763. InfRefmsgid string `json:"inf_refmsgid"`
  3764. Infcode int64 `json:"infcode"`
  3765. Output struct {
  3766. } `json:"output"`
  3767. RefmsgTime string `json:"refmsg_time"`
  3768. RespondTime string `json:"respond_time"`
  3769. Signtype interface{} `json:"signtype"`
  3770. WarnMsg interface{} `json:"warn_msg"`
  3771. }
  3772. type ResultSeven struct {
  3773. Cainfo string `json:"cainfo"`
  3774. ErrMsg string `json:"err_msg"`
  3775. InfRefmsgid string `json:"inf_refmsgid"`
  3776. Infcode int64 `json:"infcode"`
  3777. Output struct {
  3778. Setldetail []interface{} `json:"setldetail"`
  3779. Setlinfo struct {
  3780. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3781. AcctPay float64 `json:"acct_pay"`
  3782. ActPayDedc float64 `json:"act_pay_dedc"`
  3783. Age float64 `json:"age"`
  3784. Balc float64 `json:"balc"`
  3785. Brdy string `json:"brdy"`
  3786. Certno string `json:"certno"`
  3787. ClrOptins string `json:"clr_optins"`
  3788. ClrType string `json:"clr_type"`
  3789. ClrWay string `json:"clr_way"`
  3790. CvlservFlag string `json:"cvlserv_flag"`
  3791. CvlservPay float64 `json:"cvlserv_pay"`
  3792. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3793. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3794. Gend string `json:"gend"`
  3795. HifesPay float64 `json:"hifes_pay"`
  3796. HifmiPay float64 `json:"hifmi_pay"`
  3797. HifobPay float64 `json:"hifob_pay"`
  3798. HifpPay float64 `json:"hifp_pay"`
  3799. HospPartAmt float64 `json:"hosp_part_amt"`
  3800. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3801. Insutype string `json:"insutype"`
  3802. MafPay float64 `json:"maf_pay"`
  3803. MdtrtCertType string `json:"mdtrt_cert_type"`
  3804. MdtrtID string `json:"mdtrt_id"`
  3805. MedType string `json:"med_type"`
  3806. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3807. MedinsSetlID string `json:"medins_setl_id"`
  3808. Naty string `json:"naty"`
  3809. OthPay float64 `json:"oth_pay"`
  3810. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3811. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3812. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3813. PsnCashPay float64 `json:"psn_cash_pay"`
  3814. PsnCertType string `json:"psn_cert_type"`
  3815. PsnName string `json:"psn_name"`
  3816. PsnNo string `json:"psn_no"`
  3817. PsnPartAmt float64 `json:"psn_part_amt"`
  3818. PsnType string `json:"psn_type"`
  3819. SetlID string `json:"setl_id"`
  3820. SetlTime string `json:"setl_time"`
  3821. } `json:"setlinfo"`
  3822. } `json:"output"`
  3823. RefmsgTime string `json:"refmsg_time"`
  3824. RespondTime string `json:"respond_time"`
  3825. Signtype interface{} `json:"signtype"`
  3826. WarnMsg interface{} `json:"warn_msg"`
  3827. }
  3828. type ResultEight struct {
  3829. Cainfo string `json:"cainfo"`
  3830. ErrMsg string `json:"err_msg"`
  3831. InfRefmsgid string `json:"inf_refmsgid"`
  3832. Infcode int64 `json:"infcode"`
  3833. Output struct {
  3834. Stmtinfo struct {
  3835. SetlOptins string `json:"setl_optins"`
  3836. StmtRslt string `json:"stmt_rslt"`
  3837. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3838. } `json:"stmtinfo"`
  3839. } `json:"output"`
  3840. RefmsgTime string `json:"refmsg_time"`
  3841. RespondTime string `json:"respond_time"`
  3842. Signtype interface{} `json:"signtype"`
  3843. WarnMsg interface{} `json:"warn_msg"`
  3844. }
  3845. type ResultNine struct {
  3846. Cainfo string `json:"cainfo"`
  3847. ErrMsg string `json:"err_msg"`
  3848. InfRefmsgid string `json:"inf_refmsgid"`
  3849. Infcode int64 `json:"infcode"`
  3850. Output struct {
  3851. FileQuryNo string `json:"file_qury_no"`
  3852. } `json:"output"`
  3853. RefmsgTime string `json:"refmsg_time"`
  3854. RespondTime string `json:"respond_time"`
  3855. Signtype interface{} `json:"signtype"`
  3856. WarnMsg interface{} `json:"warn_msg"`
  3857. }
  3858. type ResultTen struct {
  3859. Cainfo string `json:"cainfo"`
  3860. ErrMsg string `json:"err_msg"`
  3861. InfRefmsgid string `json:"inf_refmsgid"`
  3862. Infcode int64 `json:"infcode"`
  3863. Output struct {
  3864. DldEndtime string `json:"dld_endtime"`
  3865. FileQuryNo string `json:"file_qury_no"`
  3866. Filename string `json:"filename"`
  3867. } `json:"output"`
  3868. RefmsgTime string `json:"refmsg_time"`
  3869. RespondTime string `json:"respond_time"`
  3870. Signtype interface{} `json:"signtype"`
  3871. WarnMsg interface{} `json:"warn_msg"`
  3872. }
  3873. type ResultEleven struct {
  3874. Cainfo string `json:"cainfo"`
  3875. ErrMsg string `json:"err_msg"`
  3876. InfRefmsgid string `json:"inf_refmsgid"`
  3877. Infcode int64 `json:"infcode"`
  3878. Output struct {
  3879. Setlinfo struct {
  3880. FixmedinsName string `json:"fixmedins_name"`
  3881. FixmedinsCode string `json:"fixmedins_code"`
  3882. PsnNo string `json:"psn_no"`
  3883. PsnName string `json:"psn_name"`
  3884. HifobPay float64 `json:"hifob_pay"`
  3885. Gend string `json:"gend"`
  3886. Brdy string `json:"brdy"`
  3887. PsnCertType string `json:"psn_cert_type"`
  3888. PsnType string `json:"psn_type"`
  3889. EmpName string `json:"emp_name"`
  3890. Certno string `json:"certno"`
  3891. Insutype string `json:"insutype"`
  3892. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3893. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3894. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3895. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3896. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3897. ActPayDedc float64 `json:"act_pay_dedc"`
  3898. HifpPay float64 `json:"hifp_pay"`
  3899. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3900. CvlservPay float64 `json:"cvlserv_pay"`
  3901. HifesPay float64 `json:"hifes_pay"`
  3902. HifmiPay float64 `json:"hifmi_pay"`
  3903. MafPay float64 `json:"maf_pay"`
  3904. OthPay float64 `json:"oth_pay"`
  3905. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3906. PsnPay float64 `json:"psn_pay"`
  3907. AcctPay float64 `json:"acct_pay"`
  3908. CashPayamt float64 `json:"cash_payamt"`
  3909. Balc float64 `json:"balc"`
  3910. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3911. MedinsSetlId string `json:"medins_setl_id"`
  3912. RefdSetlFlag string `json:"refd_setl_flag"`
  3913. SetlTime string `json:"setl_time"`
  3914. MedType string `json:"med_type"`
  3915. } `json:"setlinfo"`
  3916. } `json:"output"`
  3917. RefmsgTime string `json:"refmsg_time"`
  3918. RespondTime string `json:"respond_time"`
  3919. Signtype interface{} `json:"signtype"`
  3920. WarnMsg interface{} `json:"warn_msg"`
  3921. }
  3922. type Custom struct {
  3923. DetItemFeeSumamt string
  3924. Cut string
  3925. FeedetlSn string
  3926. Price string
  3927. MedListCodg string
  3928. Type int64
  3929. AdviceId int64
  3930. ProjectId int64
  3931. ItemId int64
  3932. }
  3933. //获取个人信息----挂号-----上传就诊信息
  3934. func (c *HisApiController) GetRegisterInfo() {
  3935. id, _ := c.GetInt64("id")
  3936. record_time := c.GetString("record_time")
  3937. settlementValue, _ := c.GetInt64("settlement_value")
  3938. medical_insurance_card := c.GetString("medical_insurance_card")
  3939. name := c.GetString("name")
  3940. id_card_type, _ := c.GetInt64("id_card_type")
  3941. certificates, _ := c.GetInt64("certificates")
  3942. medical_care, _ := c.GetInt64("medical_care")
  3943. birthday := c.GetString("birthday")
  3944. age, _ := c.GetInt64("age")
  3945. id_card := c.GetString("id_card")
  3946. register_type, _ := c.GetInt64("register")
  3947. doctor, _ := c.GetInt64("doctor")
  3948. department, _ := c.GetInt64("department")
  3949. gender, _ := c.GetInt64("sex")
  3950. phone := c.GetString("phone")
  3951. registration_fee, _ := c.GetFloat("registration_fee")
  3952. medical_expenses, _ := c.GetFloat("medical_expenses")
  3953. social_type, _ := c.GetInt64("social_type")
  3954. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3955. diagnosis_ids := c.GetString("diagnosis")
  3956. sick_type, _ := c.GetInt64("sick_type")
  3957. reg_type := c.GetString("p_type")
  3958. timeLayout := "2006-01-02"
  3959. loc, _ := time.LoadLocation("Local")
  3960. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3961. birthUnix := birthdays.Unix()
  3962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3963. if err != nil {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. recordDateTime := theTime.Unix()
  3968. adminInfo := c.GetAdminUserInfo()
  3969. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3970. if tempPatient.ID == 0 {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3972. return
  3973. }
  3974. var patient service.Patients
  3975. if id == 0 {
  3976. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3977. } else {
  3978. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3979. }
  3980. if patient.ID == 0 {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3982. return
  3983. }
  3984. if len(patient.IdCardNo) == 0 {
  3985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3986. return
  3987. }
  3988. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3989. if len(his) >= 1 {
  3990. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3991. if len(his) >= 1 && order.ID == 0 {
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3993. return
  3994. }
  3995. }
  3996. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3997. fmt.Println(timeStr)
  3998. timeArr := strings.Split(timeStr, " ")
  3999. fmt.Println(timeArr)
  4000. timeArrTwo := strings.Split(timeArr[0], "-")
  4001. timeArrThree := strings.Split(timeArr[1], ":")
  4002. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4003. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4004. if len(lists) == 0 {
  4005. var hisPatient models.XtHisPatient
  4006. hisPatient = models.XtHisPatient{
  4007. Name: name,
  4008. Age: age,
  4009. Gender: gender,
  4010. Birthday: birthUnix,
  4011. Phone: phone,
  4012. MedicalTreatmentType: medical_care,
  4013. IdType: certificates,
  4014. IdCardNo: id_card,
  4015. BalanceAccountsType: settlementValue,
  4016. SocialType: social_type,
  4017. MedicalInsuranceNumber: medical_insurance_card,
  4018. RegisterType: register_type,
  4019. RegisterCost: registration_fee,
  4020. TreatmentCost: medical_expenses,
  4021. AdminUserId: adminInfo.AdminUser.Id,
  4022. UserOrgId: adminInfo.CurrentOrgId,
  4023. Status: 1,
  4024. RecordDate: recordDateTime,
  4025. IsReturn: 1,
  4026. PatientId: patient.ID,
  4027. Ctime: time.Now().Unix(),
  4028. Mtime: time.Now().Unix(),
  4029. Number: str,
  4030. IdCardType: id_card_type,
  4031. Departments: department,
  4032. Doctor: doctor,
  4033. PType: reg_type,
  4034. Diagnosis: diagnosis_ids,
  4035. SickType: sick_type,
  4036. }
  4037. service.CreateHisPatient(&hisPatient)
  4038. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4039. c.ServeSuccessJSON(map[string]interface{}{
  4040. "his_info": hisPatient,
  4041. })
  4042. } else {
  4043. //chrgBchno := rand.Intn(1000000) + 10000
  4044. var hisPatient models.XtHisPatient
  4045. hisPatient = models.XtHisPatient{
  4046. Name: name,
  4047. Age: age,
  4048. Gender: gender,
  4049. Birthday: birthUnix,
  4050. Phone: phone,
  4051. MedicalTreatmentType: medical_care,
  4052. IdType: certificates,
  4053. IdCardNo: id_card,
  4054. BalanceAccountsType: settlementValue,
  4055. SocialType: social_type,
  4056. MedicalInsuranceNumber: medical_insurance_card,
  4057. RegisterType: register_type,
  4058. RegisterCost: registration_fee,
  4059. TreatmentCost: medical_expenses,
  4060. AdminUserId: adminInfo.AdminUser.Id,
  4061. UserOrgId: adminInfo.CurrentOrgId,
  4062. Status: 1,
  4063. RecordDate: recordDateTime,
  4064. IsReturn: 1,
  4065. PatientId: patient.ID,
  4066. Ctime: time.Now().Unix(),
  4067. Mtime: time.Now().Unix(),
  4068. Number: str,
  4069. IdCardType: id_card_type,
  4070. Departments: department,
  4071. Doctor: doctor,
  4072. PType: reg_type,
  4073. Diagnosis: diagnosis_ids,
  4074. SickType: sick_type,
  4075. }
  4076. service.CreateHisPatient(&hisPatient)
  4077. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4078. c.ServeSuccessJSON(map[string]interface{}{
  4079. "his_info": hisPatient,
  4080. })
  4081. }
  4082. }
  4083. //上传明细----结算
  4084. func (c *HisApiController) GetUploadInfo() {
  4085. id, _ := c.GetInt64("id")
  4086. record_time := c.GetString("record_time")
  4087. his_patient_id, _ := c.GetInt64("his_patient_id")
  4088. pay_way, _ := c.GetInt64("pay_way")
  4089. pay_price, _ := c.GetFloat("pay_price")
  4090. pay_card_no := c.GetString("pay_card_no")
  4091. discount_price, _ := c.GetFloat("discount_price")
  4092. preferential_price, _ := c.GetFloat("preferential_price")
  4093. reality_price, _ := c.GetFloat("reality_price")
  4094. found_price, _ := c.GetFloat("found_price")
  4095. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4096. private_price, _ := c.GetFloat("private_price")
  4097. timeLayout := "2006-01-02"
  4098. loc, _ := time.LoadLocation("Local")
  4099. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4100. fapiao_code := c.GetString("fapiao_code")
  4101. fapiao_number := c.GetString("fapiao_number")
  4102. diagnosis_id := c.GetString("diagnosis")
  4103. sick_type, _ := c.GetInt64("sick_type")
  4104. reg_type, _ := c.GetInt64("p_type")
  4105. order_id, _ := c.GetInt64("order_id")
  4106. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4107. tmp_decimal := c.GetString("tmp_decimal")
  4108. var decimal float64 //本次使用的押金
  4109. var errmsg error
  4110. tx := service.XTWriteDB().Begin() //开了事务
  4111. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4112. defer func() {
  4113. if errmsg != nil {
  4114. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4115. tx.Rollback()
  4116. } else {
  4117. tx.Commit()
  4118. }
  4119. }()
  4120. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  4121. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4122. return
  4123. }
  4124. if len(tmp_decimal) > 0 {
  4125. if tmp_decimal[0] == 45 {
  4126. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4127. return
  4128. }
  4129. }
  4130. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4131. fmt.Println(errs)
  4132. //if errs != nil {
  4133. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4134. // return
  4135. //}
  4136. decimal = tt
  4137. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4138. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4140. if err != nil {
  4141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4142. return
  4143. }
  4144. recordDateTime := theTime.Unix()
  4145. adminUser := c.GetAdminUserInfo()
  4146. var prescriptions []*models.HisPrescription
  4147. var start_time int64
  4148. var end_time int64
  4149. ids_str := c.GetString("ids")
  4150. ids_arr := strings.Split(ids_str, ",")
  4151. if tempOrder.ID == 0 {
  4152. if settle_accounts_type == 1 { //日结
  4153. fmt.Println(reg_type)
  4154. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4155. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4156. } else {
  4157. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4158. }
  4159. } else { //月结
  4160. start_time_str := c.GetString("start_time")
  4161. end_time_str := c.GetString("end_time")
  4162. timeLayout := "2006-01-02"
  4163. loc, _ := time.LoadLocation("Local")
  4164. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4165. if err != nil {
  4166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4167. return
  4168. }
  4169. recordStartTime := theStartTime.Unix()
  4170. start_time = recordStartTime
  4171. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4172. if err != nil {
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. recordEndTime := theEndTime.Unix()
  4177. end_time = recordEndTime
  4178. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4179. }
  4180. timestamp := time.Now().Unix()
  4181. tempTime := time.Unix(timestamp, 0)
  4182. timeFormat := tempTime.Format("20060102150405")
  4183. chrgBchno := rand.Intn(100000) + 10000
  4184. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4185. strconv.FormatInt(his.PatientId, 10)
  4186. var ids []int64
  4187. for _, item := range prescriptions {
  4188. ids = append(ids, item.ID)
  4189. }
  4190. var total float64
  4191. for _, item := range prescriptions {
  4192. fmt.Println(item)
  4193. if item.Type == 1 { //药品
  4194. for _, subItem := range item.HisDoctorAdviceInfo {
  4195. total = total + (subItem.Price * subItem.PrescribingNumber)
  4196. }
  4197. }
  4198. if item.Type == 2 { //项目
  4199. for _, subItem := range item.HisPrescriptionProject {
  4200. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4201. total = total + (subItem.Price * cnt)
  4202. }
  4203. }
  4204. for _, subItem := range item.HisAdditionalCharge {
  4205. total = total + (subItem.Price * float64(subItem.Count))
  4206. }
  4207. }
  4208. if reg_type == 1111 || reg_type == 1112 {
  4209. reg_type = 11
  4210. }
  4211. tm := time.Unix(time.Now().Unix(), 0)
  4212. allTotal := fmt.Sprintf("%.4f", total)
  4213. totals, _ := strconv.ParseFloat(allTotal, 64)
  4214. order := &models.HisOrder{
  4215. UserOrgId: adminUser.CurrentOrgId,
  4216. HisPatientId: his.ID,
  4217. PatientId: id,
  4218. SettleAccountsDate: recordDateTime,
  4219. Ctime: time.Now().Unix(),
  4220. Mtime: time.Now().Unix(),
  4221. Status: 1,
  4222. OrderStatus: 2,
  4223. MdtrtId: his.Number,
  4224. Number: chrg_bchno,
  4225. MedfeeSumamt: totals,
  4226. PayWay: pay_way,
  4227. PayPrice: pay_price,
  4228. MedType: strconv.Itoa(int(reg_type)),
  4229. PayCardNo: pay_card_no,
  4230. DiscountPrice: discount_price,
  4231. PreferentialPrice: preferential_price,
  4232. RealityPrice: reality_price,
  4233. FoundPrice: found_price,
  4234. MedicalInsurancePrice: medical_insurance_price,
  4235. PrivatePrice: private_price,
  4236. SettleEndTime: end_time,
  4237. SettleStartTime: start_time,
  4238. SettleType: settle_accounts_type,
  4239. FaPiaoCode: fapiao_code,
  4240. FaPiaoNumber: fapiao_number,
  4241. Diagnosis: diagnosis_id,
  4242. PType: 2,
  4243. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4244. }
  4245. err = service.CreateOrder(order)
  4246. if err != nil {
  4247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4248. return
  4249. }
  4250. var customs []*Custom
  4251. for _, item := range prescriptions {
  4252. if item.Type == 1 { //药品
  4253. for _, subItem := range item.HisDoctorAdviceInfo {
  4254. cus := &Custom{
  4255. AdviceId: subItem.ID,
  4256. ProjectId: 0,
  4257. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4258. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4259. FeedetlSn: subItem.FeedetlSn,
  4260. Price: fmt.Sprintf("%.2f", subItem.Price),
  4261. MedListCodg: subItem.MedListCodg,
  4262. Type: 1,
  4263. }
  4264. customs = append(customs, cus)
  4265. }
  4266. }
  4267. if item.Type == 2 { //项目
  4268. for _, subItem := range item.HisPrescriptionProject {
  4269. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4270. cus := &Custom{
  4271. AdviceId: 0,
  4272. ProjectId: subItem.ID,
  4273. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4274. Cut: fmt.Sprintf("%.4f", cnt),
  4275. FeedetlSn: subItem.FeedetlSn,
  4276. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4277. MedListCodg: subItem.MedListCodg,
  4278. Type: 2,
  4279. }
  4280. customs = append(customs, cus)
  4281. }
  4282. }
  4283. for _, item := range item.HisAdditionalCharge {
  4284. cus := &Custom{
  4285. ItemId: item.ID,
  4286. AdviceId: 0,
  4287. ProjectId: 0,
  4288. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4289. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4290. FeedetlSn: item.FeedetlSn,
  4291. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4292. MedListCodg: item.XtHisAddtionConfig.Code,
  4293. Type: 3,
  4294. }
  4295. customs = append(customs, cus)
  4296. }
  4297. }
  4298. for _, item := range customs {
  4299. var advice_id int64 = 0
  4300. var project_id int64 = 0
  4301. var item_id int64 = 0
  4302. var types int64 = 0
  4303. if item.Type == 1 {
  4304. advice_id = item.AdviceId
  4305. project_id = 0
  4306. item_id = 0
  4307. } else if item.Type == 2 {
  4308. advice_id = 0
  4309. item_id = 0
  4310. project_id = item.ProjectId
  4311. } else if item.Type == 3 {
  4312. advice_id = 0
  4313. item_id = item.ItemId
  4314. project_id = 0
  4315. }
  4316. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4317. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4318. pric, _ := strconv.ParseFloat(item.Price, 32)
  4319. info := &models.HisOrderInfo{
  4320. OrderNumber: order.Number,
  4321. UploadDate: time.Now().Unix(),
  4322. AdviceId: advice_id,
  4323. DetItemFeeSumamt: detItemFeeSumamt,
  4324. Cnt: cut,
  4325. Pric: pric,
  4326. PatientId: id,
  4327. Status: 1,
  4328. Mtime: time.Now().Unix(),
  4329. Ctime: time.Now().Unix(),
  4330. UserOrgId: adminUser.CurrentOrgId,
  4331. HisPatientId: his.ID,
  4332. OrderId: order.ID,
  4333. ProjectId: project_id,
  4334. Type: types,
  4335. ItemId: item_id,
  4336. }
  4337. service.CreateOrderInfoTX(info, tx)
  4338. }
  4339. his.Diagnosis = diagnosis_id
  4340. his.SickType = sick_type
  4341. his.RegisterType = reg_type
  4342. his.MedicalTreatmentType = reg_type
  4343. service.UpdataHisPateintTX(&his, tx)
  4344. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4345. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4346. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4347. //判断是否使用了押金
  4348. if dec_way == "true" {
  4349. tmpstring := strconv.FormatInt(order.ID, 10)
  4350. //扣押金
  4351. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4352. if errmsg != nil {
  4353. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4354. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4355. return
  4356. }
  4357. }
  4358. if err == nil {
  4359. c.ServeSuccessJSON(map[string]interface{}{
  4360. "msg": "结算成功",
  4361. })
  4362. }
  4363. } else {
  4364. if tempOrder.IsPre > 0 {
  4365. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4366. totals, _ := strconv.ParseFloat(allTotal, 64)
  4367. tempOrder.OrderStatus = 2
  4368. tempOrder.PayWay = pay_way
  4369. tempOrder.PayPrice = pay_price
  4370. tempOrder.PayCardNo = pay_card_no
  4371. tempOrder.DiscountPrice = discount_price
  4372. tempOrder.PreferentialPrice = preferential_price
  4373. tempOrder.RealityPrice = reality_price
  4374. tempOrder.FoundPrice = found_price
  4375. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4376. tempOrder.PrivatePrice = private_price
  4377. tempOrder.FaPiaoCode = fapiao_code
  4378. tempOrder.FaPiaoNumber = fapiao_number
  4379. tempOrder.PType = 2
  4380. tempOrder.MedfeeSumamt = totals
  4381. tempOrder.Diagnosis = diagnosis_id
  4382. err = service.SaveHisOrder(&tempOrder)
  4383. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4384. if err != nil {
  4385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4386. return
  4387. }
  4388. if err == nil {
  4389. c.ServeSuccessJSON(map[string]interface{}{
  4390. "msg": "结算成功",
  4391. })
  4392. }
  4393. }
  4394. }
  4395. }
  4396. //退款
  4397. func (c *HisApiController) Refund() {
  4398. order_id, _ := c.GetInt64("order_id")
  4399. order, _ := service.GetHisOrderByID(order_id)
  4400. adminUser := c.GetAdminUserInfo()
  4401. orgid := c.GetAdminUserInfo().CurrentOrgId
  4402. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4403. if err != nil {
  4404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4405. return
  4406. }
  4407. tmp := strconv.FormatInt(order.ID, 10)
  4408. //当押金不为零时产生退费记录
  4409. if order.Decimal != 0 {
  4410. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  4411. if err != nil {
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4413. return
  4414. }
  4415. }
  4416. c.ServeSuccessJSON(map[string]interface{}{
  4417. "msg": "退费成功",
  4418. })
  4419. }
  4420. func (c *HisApiController) RefundNumber() {
  4421. his_patient_id, _ := c.GetInt64("id")
  4422. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4423. info.Status = 0
  4424. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4425. if count > 0 {
  4426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4427. return
  4428. }
  4429. err := service.SaveHisPatient(info)
  4430. if err == nil {
  4431. c.ServeSuccessJSON(map[string]interface{}{
  4432. "msg": "退号成功",
  4433. })
  4434. } else {
  4435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4436. return
  4437. }
  4438. }
  4439. func (this *HisApiController) AdditionalCharge() {
  4440. dataBody := make(map[string]interface{}, 0)
  4441. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4442. fmt.Println(err)
  4443. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4444. patient_id := int64(dataBody["patient_id"].(float64))
  4445. medicineData, _ := dataBody["medicineData"].([]interface{})
  4446. adminUserInfo := this.GetAdminUserInfo()
  4447. orgId := adminUserInfo.CurrentOrgId
  4448. admin_user_id := adminUserInfo.AdminUser.Id
  4449. timeStr := time.Now().Format("2006-01-02")
  4450. timeLayout := "2006-01-02 15:04:05"
  4451. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4452. timenow := timeStringToTime.Unix()
  4453. var additionalCharges []*models.HisAdditionalCharge
  4454. for _, item := range medicineData {
  4455. var randNum int
  4456. randNum = rand.Intn(10000) + 1000
  4457. timestamp := time.Now().Unix()
  4458. tempTime := time.Unix(timestamp, 0)
  4459. timeFormat := tempTime.Format("20060102150405")
  4460. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4461. items := item.(map[string]interface{})
  4462. money := items["price"].(string)
  4463. item_id_str := items["item_id"].(string)
  4464. name := items["name"].(string)
  4465. id_str := items["id"].(string)
  4466. moneys, _ := strconv.ParseInt(money, 10, 64)
  4467. monStr := strconv.FormatInt(moneys, 10)
  4468. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4469. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4470. id, _ := strconv.ParseInt(id_str, 10, 64)
  4471. additionalCharge := &models.HisAdditionalCharge{
  4472. ID: id,
  4473. HisPatientId: his_patient_id,
  4474. UserOrgId: orgId,
  4475. PatientId: patient_id,
  4476. RecordDate: timenow,
  4477. Price: monneyStr,
  4478. Status: 1,
  4479. ItemName: name,
  4480. ItemId: item_id,
  4481. AdminUserId: admin_user_id,
  4482. CreatedTime: time.Now().Unix(),
  4483. OrderStatus: 0,
  4484. PrescriptionNumber: "",
  4485. BatchNumber: "",
  4486. FeedetlSn: p_number,
  4487. }
  4488. service.CreateAdditionalCharge(additionalCharge)
  4489. additionalCharges = append(additionalCharges, additionalCharge)
  4490. }
  4491. this.ServeSuccessJSON(map[string]interface{}{
  4492. "msg": "添加成功",
  4493. "additional_charges": additionalCharges,
  4494. })
  4495. }
  4496. func (this *HisApiController) DeleteAddition() {
  4497. id, _ := this.GetInt64("id")
  4498. //TODO 需要判断是否已经结算
  4499. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4500. if err == nil {
  4501. this.ServeSuccessJSON(map[string]interface{}{
  4502. "msg": "删除成功",
  4503. })
  4504. return
  4505. } else {
  4506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4507. return
  4508. }
  4509. }
  4510. func (this *HisApiController) GetAdminUsers() {
  4511. adminUser := this.GetAdminUserInfo()
  4512. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4513. this.ServeSuccessJSON(map[string]interface{}{
  4514. "doctors": doctors,
  4515. })
  4516. }
  4517. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4518. change_type, _ := this.GetInt64("type", 0)
  4519. record_date := this.GetString("record_time")
  4520. patient_id, _ := this.GetInt64("patient_id", 0)
  4521. p_type, _ := this.GetInt64("p_type", 0)
  4522. timeLayout := "2006-01-02"
  4523. loc, _ := time.LoadLocation("Local")
  4524. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4525. record_time := theAdviceRecordTime.Unix()
  4526. adminUserInfo := this.GetAdminUserInfo()
  4527. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4528. if err == nil {
  4529. if len(prescriptions) == 0 {
  4530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4531. return
  4532. } else {
  4533. this.ServeSuccessJSON(map[string]interface{}{
  4534. "prescriptions": prescriptions,
  4535. })
  4536. return
  4537. }
  4538. } else {
  4539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4540. return
  4541. }
  4542. }
  4543. func (this *HisApiController) GetCallHisPrescription() {
  4544. patient_id, _ := this.GetInt64("patient_id", 0)
  4545. timeLayout := "2006-01-02"
  4546. loc, _ := time.LoadLocation("Local")
  4547. start_time := this.GetString("start_time")
  4548. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4549. end_time := this.GetString("end_time")
  4550. p_type, _ := this.GetInt64("p_type")
  4551. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4552. adminUserInfo := this.GetAdminUserInfo()
  4553. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4554. if err == nil {
  4555. this.ServeSuccessJSON(map[string]interface{}{
  4556. "prescriptions": prescriptions,
  4557. })
  4558. return
  4559. } else {
  4560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4561. return
  4562. }
  4563. }
  4564. func (this *HisApiController) GetHisDayPrescription() {
  4565. timeLayout := "2006-01-02"
  4566. loc, _ := time.LoadLocation("Local")
  4567. start_time := this.GetString("start_time")
  4568. patient_id, _ := this.GetInt64("patient_id", 0)
  4569. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4570. end_time := this.GetString("end_time")
  4571. p_type, _ := this.GetInt64("p_type")
  4572. order_status, _ := this.GetInt64("type")
  4573. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4574. adminUserInfo := this.GetAdminUserInfo()
  4575. var dayHisPrescription []*models.HisPrescription
  4576. var err error
  4577. if order_status == 1 || order_status == 0 {
  4578. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4579. } else if order_status == 2 {
  4580. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4581. }
  4582. var settle_total float64
  4583. for _, item := range dayHisPrescription {
  4584. if len(item.HisPrescriptionProject) > 0 {
  4585. for _, subItem := range item.HisPrescriptionProject {
  4586. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4587. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4588. settle_total = settle_total + total
  4589. }
  4590. }
  4591. if len(item.HisDoctorAdviceInfo) > 0 {
  4592. for _, subItem := range item.HisDoctorAdviceInfo {
  4593. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4594. settle_total = settle_total + total
  4595. }
  4596. }
  4597. }
  4598. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4599. if err == nil {
  4600. this.ServeSuccessJSON(map[string]interface{}{
  4601. "day_prescription": dayHisPrescription,
  4602. "settle_total": settle_total,
  4603. })
  4604. return
  4605. } else {
  4606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4607. return
  4608. }
  4609. }
  4610. func (c *HisApiController) GetHisChargePatientList() {
  4611. record_date := c.GetString("record_date")
  4612. order_status, _ := c.GetInt64("type")
  4613. timeLayout := "2006-01-02"
  4614. loc, _ := time.LoadLocation("Local")
  4615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4616. if err != nil {
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4618. return
  4619. }
  4620. recordDateTime := theTime.Unix()
  4621. adminInfo := c.GetAdminUserInfo()
  4622. var tempPatients []*service.NewTempPatients
  4623. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4624. if order_status != 2 {
  4625. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4626. } else {
  4627. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4628. }
  4629. var patients []*service.NewTempPatients
  4630. var patients_two []*service.NewTempPatients
  4631. for _, item := range tempPatients {
  4632. //过滤掉没挂号的和没开处方的
  4633. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4634. patients = append(patients, item)
  4635. }
  4636. //过滤掉没挂号的
  4637. if len(item.HisPatient) > 0 {
  4638. patients_two = append(patients_two, item)
  4639. }
  4640. }
  4641. c.ServeSuccessJSON(map[string]interface{}{
  4642. "list": patients,
  4643. "list_two": patients_two,
  4644. })
  4645. }
  4646. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4647. record_date := c.GetString("record_date")
  4648. timeLayout := "2006-01-02"
  4649. loc, _ := time.LoadLocation("Local")
  4650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4651. if err != nil {
  4652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4653. return
  4654. }
  4655. recordDateTime := theTime.Unix()
  4656. adminUser := c.GetAdminUserInfo()
  4657. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4658. var patients []*service.Patients
  4659. for _, item := range tempPatients {
  4660. if item.HisPatient.ID == 0 {
  4661. patients = append(patients, item)
  4662. }
  4663. }
  4664. c.ServeSuccessJSON(map[string]interface{}{
  4665. "list": patients,
  4666. //"list_two": patients_two,
  4667. })
  4668. }
  4669. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4670. newArr = make([]*service.Patients, 0)
  4671. for i := 0; i < len(patient); i++ {
  4672. repeat := false
  4673. for j := i + 1; j < len(patient); j++ {
  4674. if patient[i].ID == patient[j].ID {
  4675. repeat = true
  4676. break
  4677. }
  4678. }
  4679. if !repeat {
  4680. newArr = append(newArr, patient[i])
  4681. }
  4682. }
  4683. return
  4684. }
  4685. func (c *HisApiController) GetHisChargePatientInfo() {
  4686. patient_id, _ := c.GetInt64("patient_id")
  4687. his_patient_id, _ := c.GetInt64("his_patient_id")
  4688. record_date := c.GetString("record_date")
  4689. //start_time := c.GetString("start_time")
  4690. //end_time := c.GetString("end_time")
  4691. order_status, _ := c.GetInt64("type", 0)
  4692. p_type, _ := c.GetInt64("p_type", 0)
  4693. order_id, _ := c.GetInt64("order_id", 0)
  4694. timeLayout := "2006-01-02"
  4695. loc, _ := time.LoadLocation("Local")
  4696. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4697. if err != nil {
  4698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4699. return
  4700. }
  4701. recordDateTime := theTime.Unix()
  4702. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4703. //if err != nil {
  4704. //
  4705. //}
  4706. //startRecordDateTime := startTime.Unix()
  4707. //
  4708. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4709. //if err != nil {
  4710. //
  4711. //}
  4712. //endRecordDateTime := endTime.Unix()
  4713. admin := c.GetAdminUserInfo()
  4714. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4715. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4716. var prescriptions []*models.HisPrescription
  4717. //var unChargeMonthPrescriptions []*models.HisPrescription
  4718. order, _ := service.GetHisOrderByID(order_id)
  4719. if order_status == 1 || order_status == 0 {
  4720. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4721. } else if order_status == 2 {
  4722. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4723. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4724. }
  4725. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4726. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4727. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4728. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4729. //获取所有科室信息
  4730. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4731. c.ServeSuccessJSON(map[string]interface{}{
  4732. "his_info": his_patient_info,
  4733. "xt_info": xt_patient_info,
  4734. "prescription": prescriptions,
  4735. "case_history": case_history,
  4736. "info": patientPrescriptionInfo,
  4737. "last_info": lastPatientPrescriptionInfo,
  4738. "order": order,
  4739. "doctors": doctors,
  4740. "department": department,
  4741. })
  4742. return
  4743. }
  4744. func (c *HisApiController) GetAllOrderDetail() {
  4745. order_id, _ := c.GetInt64("id", 0)
  4746. order, _ := service.GetHisOrderByID(order_id)
  4747. if order.ID == 0 {
  4748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4749. return
  4750. }
  4751. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4752. org_id := c.GetAdminUserInfo().CurrentOrgId
  4753. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4754. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4755. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4756. c.ServeSuccessJSON(map[string]interface{}{
  4757. "order": order,
  4758. "order_info": order_info,
  4759. "patient": patient,
  4760. "admin_info": adminInfo,
  4761. "hospital_record": record,
  4762. })
  4763. return
  4764. }
  4765. func (c *HisApiController) GetAllOrderDetailCollect() {
  4766. order_id, _ := c.GetInt64("id", 0)
  4767. order, _ := service.GetHisOrderByID(order_id)
  4768. if order.ID == 0 {
  4769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4770. return
  4771. }
  4772. org_id := c.GetAdminUserInfo().CurrentOrgId
  4773. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4774. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4775. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4776. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4777. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4778. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4779. var bedCostTotal float64 = 0 //床位总费
  4780. //var bedCostSelfTotal float64 = 0 //床位自费
  4781. var operationCostTotal float64 = 0 //手术费
  4782. //var operationCostSelfTotal float64 = 0 //手术费
  4783. var otherCostTotal float64 = 0 //其他费用
  4784. //var otherCostSelfTotal float64 = 0 //其他费用
  4785. var materialCostTotal float64 = 0 //材料费
  4786. //var materialCostSelfTotal float64 = 0 //材料费
  4787. var westernMedicineCostTotal float64 = 0 //西药费
  4788. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4789. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4790. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4791. var checkCostTotal float64 = 0 //检查费
  4792. //var checkCostSelfTotal float64 = 0 //检查费
  4793. var laboratoryCostTotal float64 = 0 //化验费
  4794. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4795. var treatCostTotal float64 = 0 //治疗费用
  4796. //var treatCostSelfTotal float64 = 0 //治疗费用
  4797. var zhenChaCostTotal float64 = 0 //其他费用
  4798. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4799. decimal.DivisionPrecision = 2
  4800. var BalanceAccountsType int64
  4801. if his.ID > 0 {
  4802. BalanceAccountsType = his.BalanceAccountsType
  4803. } else {
  4804. BalanceAccountsType = record.BalanceAccountsType
  4805. }
  4806. if BalanceAccountsType != 2 {
  4807. for _, item := range order_info {
  4808. if org_id == 10215 {
  4809. if item.MedChrgitmType == "01" { //床位费
  4810. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4811. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4812. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4813. }
  4814. if item.MedChrgitmType == "02" { //诊察费
  4815. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4816. //zhenChaCostSelfTotal = zhenChaCostTotal
  4817. }
  4818. if item.MedChrgitmType == "03" { //检查费
  4819. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4820. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4821. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4822. }
  4823. //if item.MedChrgitmType == "02" { //检查费
  4824. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4825. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4826. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4827. //}
  4828. if item.MedChrgitmType == "04" { //化验费
  4829. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4830. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4831. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4832. }
  4833. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4834. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4835. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4836. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4837. }
  4838. if item.MedChrgitmType == "06" { //手术费
  4839. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4840. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4841. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4842. }
  4843. if item.MedChrgitmType == "08" { //材料费
  4844. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4845. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4846. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4847. }
  4848. if item.MedChrgitmType == "09" { //西药费
  4849. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4850. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4851. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4852. }
  4853. if item.MedChrgitmType == "11" { //中成费
  4854. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4855. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4856. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4857. }
  4858. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4859. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4860. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4861. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4862. }
  4863. } else if org_id == 10188 || org_id == 10217 {
  4864. if item.MedChrgitmType == "01" { //床位费
  4865. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4866. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4867. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4868. }
  4869. if item.MedChrgitmType == "02" { //诊察费
  4870. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4871. //zhenChaCostSelfTotal = zhenChaCostTotal
  4872. }
  4873. if item.MedChrgitmType == "03" { //检查费
  4874. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4875. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4876. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4877. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4878. }
  4879. //if item.MedChrgitmType == "02" { //检查费
  4880. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4881. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4882. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4883. //}
  4884. if item.MedChrgitmType == "04" { //化验费
  4885. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4886. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4887. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4888. }
  4889. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4890. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4891. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4892. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4893. }
  4894. if item.MedChrgitmType == "06" { //手术费
  4895. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4896. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4897. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4898. }
  4899. if item.MedChrgitmType == "08" { //材料费
  4900. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4901. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4902. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4903. }
  4904. if item.MedChrgitmType == "09" { //西药费
  4905. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4906. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4907. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4908. }
  4909. if item.MedChrgitmType == "11" { //中成费
  4910. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4911. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4912. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4913. }
  4914. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4915. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4916. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4917. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4918. }
  4919. } else {
  4920. if item.MedChrgitmType == "01" { //床位费
  4921. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4922. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4923. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4924. }
  4925. //if item.MedChrgitmType == "02" { //诊察费
  4926. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4927. // //zhenChaCostSelfTotal = zhenChaCostTotal
  4928. //}
  4929. if item.MedChrgitmType == "03" { //检查费
  4930. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4931. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4932. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4933. }
  4934. //if item.MedChrgitmType == "02" { //检查费
  4935. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4936. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4937. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4938. //}
  4939. if item.MedChrgitmType == "04" { //化验费
  4940. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4941. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4942. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4943. }
  4944. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4945. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4946. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4947. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4948. }
  4949. if item.MedChrgitmType == "06" { //手术费
  4950. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4951. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4952. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4953. }
  4954. if item.MedChrgitmType == "08" { //材料费
  4955. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4956. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4957. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4958. }
  4959. if item.MedChrgitmType == "09" { //西药费
  4960. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4961. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4962. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4963. }
  4964. if item.MedChrgitmType == "11" { //中成费
  4965. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4966. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4967. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4968. }
  4969. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4970. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4971. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4972. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4973. }
  4974. }
  4975. }
  4976. c.ServeSuccessJSON(map[string]interface{}{
  4977. "order": order,
  4978. "order_info": order_info,
  4979. "patient": patient,
  4980. "admin_info": adminInfo,
  4981. "his_hospital": record,
  4982. "bedCostTotal": bedCostTotal,
  4983. "operationCostTotal": operationCostTotal,
  4984. "otherCostTotal": otherCostTotal,
  4985. "materialCostTotal": materialCostTotal,
  4986. "westernMedicineCostTotal": westernMedicineCostTotal,
  4987. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4988. "checkCostTotal": checkCostTotal,
  4989. "zhenChaCostTotal": zhenChaCostTotal,
  4990. "laboratoryCostTotal": laboratoryCostTotal,
  4991. "treatCostTotal": treatCostTotal,
  4992. })
  4993. } else {
  4994. for _, item := range order_info {
  4995. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4996. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4997. item.MedChrgitmType = "09"
  4998. }
  4999. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5000. if item.HisPrescriptionProject.Type == 2 {
  5001. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5002. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5003. case 0:
  5004. item.MedChrgitmType = "0"
  5005. break
  5006. case 1:
  5007. item.MedChrgitmType = "14"
  5008. break
  5009. case 2:
  5010. item.MedChrgitmType = "05"
  5011. break
  5012. case 3:
  5013. item.MedChrgitmType = "03"
  5014. break
  5015. case 4:
  5016. item.MedChrgitmType = "03"
  5017. break
  5018. case 5:
  5019. item.MedChrgitmType = "08"
  5020. break
  5021. case 6:
  5022. item.MedChrgitmType = "14"
  5023. break
  5024. case 7:
  5025. item.MedChrgitmType = "14"
  5026. break
  5027. case 8:
  5028. item.MedChrgitmType = "03"
  5029. break
  5030. case 9:
  5031. item.MedChrgitmType = "14"
  5032. break
  5033. case 10:
  5034. item.MedChrgitmType = "14"
  5035. break
  5036. case 11:
  5037. item.MedChrgitmType = "06"
  5038. break
  5039. case 12:
  5040. item.MedChrgitmType = "12"
  5041. break
  5042. case 13:
  5043. item.MedChrgitmType = "01"
  5044. break
  5045. case 14:
  5046. item.MedChrgitmType = "04"
  5047. break
  5048. case 15:
  5049. item.MedChrgitmType = "14"
  5050. break
  5051. }
  5052. } else {
  5053. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5054. case 1:
  5055. item.MedChrgitmType = "14"
  5056. break
  5057. case 2:
  5058. item.MedChrgitmType = "05"
  5059. break
  5060. case 3:
  5061. item.MedChrgitmType = "04"
  5062. break
  5063. case 4:
  5064. item.MedChrgitmType = "14"
  5065. break
  5066. case 5:
  5067. item.MedChrgitmType = "08"
  5068. break
  5069. case 6:
  5070. item.MedChrgitmType = "14"
  5071. break
  5072. case 7:
  5073. item.MedChrgitmType = "14"
  5074. break
  5075. case 8:
  5076. item.MedChrgitmType = "03"
  5077. break
  5078. case 9:
  5079. item.MedChrgitmType = "14"
  5080. break
  5081. }
  5082. }
  5083. } else if item.HisPrescriptionProject.Type == 3 {
  5084. item.MedChrgitmType = "08"
  5085. }
  5086. }
  5087. }
  5088. for _, item := range order_info {
  5089. if org_id == 10215 {
  5090. if item.MedChrgitmType == "01" { //床位费
  5091. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5092. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5093. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5094. }
  5095. if item.MedChrgitmType == "02" { //诊察费
  5096. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5097. //zhenChaCostSelfTotal = zhenChaCostTotal
  5098. }
  5099. if item.MedChrgitmType == "03" { //检查费
  5100. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5101. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5102. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5103. }
  5104. //if item.MedChrgitmType == "02" { //检查费
  5105. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5106. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5107. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5108. //}
  5109. if item.MedChrgitmType == "04" { //化验费
  5110. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5111. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5112. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5113. }
  5114. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5115. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5116. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5117. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5118. }
  5119. if item.MedChrgitmType == "06" { //手术费
  5120. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5121. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5122. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5123. }
  5124. if item.MedChrgitmType == "08" { //材料费
  5125. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5126. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5127. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5128. }
  5129. if item.MedChrgitmType == "09" { //西药费
  5130. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5131. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5132. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5133. }
  5134. if item.MedChrgitmType == "11" { //中成费
  5135. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5136. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5137. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5138. }
  5139. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5140. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5141. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5142. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5143. }
  5144. } else {
  5145. if item.MedChrgitmType == "01" { //床位费
  5146. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5147. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5148. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5149. }
  5150. //if item.MedChrgitmType == "02" { //诊察费
  5151. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5152. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5153. //}
  5154. if item.MedChrgitmType == "03" { //检查费
  5155. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5156. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5157. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5158. }
  5159. //if item.MedChrgitmType == "02" { //检查费
  5160. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5161. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5162. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5163. //}
  5164. if item.MedChrgitmType == "04" { //化验费
  5165. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5166. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5167. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5168. }
  5169. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5170. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5171. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5172. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5173. }
  5174. if item.MedChrgitmType == "06" { //手术费
  5175. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5176. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5177. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5178. }
  5179. if item.MedChrgitmType == "08" { //材料费
  5180. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5181. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5182. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5183. }
  5184. if item.MedChrgitmType == "09" { //西药费
  5185. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5186. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5187. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5188. }
  5189. if item.MedChrgitmType == "11" { //中成费
  5190. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5191. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5192. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5193. }
  5194. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5195. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5196. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5197. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5198. }
  5199. }
  5200. }
  5201. c.ServeSuccessJSON(map[string]interface{}{
  5202. "order": order,
  5203. "order_info": order_info,
  5204. "patient": patient,
  5205. "admin_info": adminInfo,
  5206. "his_hospital": record,
  5207. "bedCostTotal": bedCostTotal,
  5208. "operationCostTotal": operationCostTotal,
  5209. "otherCostTotal": otherCostTotal,
  5210. "materialCostTotal": materialCostTotal,
  5211. "westernMedicineCostTotal": westernMedicineCostTotal,
  5212. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5213. "checkCostTotal": checkCostTotal,
  5214. "zhenChaCostTotal": zhenChaCostTotal,
  5215. "laboratoryCostTotal": laboratoryCostTotal,
  5216. "treatCostTotal": treatCostTotal,
  5217. })
  5218. }
  5219. }
  5220. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5221. page, _ := c.GetInt64("page")
  5222. limit, _ := c.GetInt64("limit")
  5223. keywords := c.GetString("keywords")
  5224. start_time := c.GetString("start_time")
  5225. end_time := c.GetString("end_time")
  5226. //clr_type := c.GetString("clr_type")
  5227. insutype := c.GetString("insutype")
  5228. timeLayout := "2006-01-02"
  5229. loc, _ := time.LoadLocation("Local")
  5230. var theStartTIme int64
  5231. if len(start_time) > 0 {
  5232. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5233. theStartTIme = theTime.Unix()
  5234. }
  5235. var theEndtTIme int64
  5236. if len(end_time) > 0 {
  5237. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5238. theEndtTIme = theTime.Unix()
  5239. }
  5240. if page <= 0 {
  5241. page = 1
  5242. }
  5243. if limit <= 0 {
  5244. limit = 10
  5245. }
  5246. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5247. c.ServeSuccessJSON(map[string]interface{}{
  5248. "total": total,
  5249. "list": list,
  5250. })
  5251. return
  5252. }
  5253. func (c *HisApiController) GetPutOnRecordList() {
  5254. page, _ := c.GetInt64("page")
  5255. limit, _ := c.GetInt64("limit")
  5256. keywords := c.GetString("keywords")
  5257. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5258. if page <= 0 {
  5259. page = 1
  5260. }
  5261. if limit <= 0 {
  5262. limit = 10
  5263. }
  5264. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5265. c.ServeSuccessJSON(map[string]interface{}{
  5266. "total": total,
  5267. "list": list,
  5268. })
  5269. return
  5270. }
  5271. func (c *HisApiController) GetCompareData() {
  5272. start_time := c.GetString("start_time")
  5273. end_time := c.GetString("end_time")
  5274. insutype := c.GetString("insutype")
  5275. clr_type := c.GetString("clr_type")
  5276. timeLayout := "2006-01-02"
  5277. loc, _ := time.LoadLocation("Local")
  5278. var theStartTIme int64
  5279. if len(start_time) > 0 {
  5280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5281. if err != nil {
  5282. theStartTIme = 0
  5283. }
  5284. theStartTIme = theTime.Unix()
  5285. }
  5286. var theEndtTIme int64
  5287. if len(end_time) > 0 {
  5288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5289. if err != nil {
  5290. theEndtTIme = 0
  5291. }
  5292. theEndtTIme = theTime.Unix()
  5293. }
  5294. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5295. fmt.Println(err)
  5296. if err == nil {
  5297. c.ServeSuccessJSON(map[string]interface{}{
  5298. "list": formData,
  5299. })
  5300. } else {
  5301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5302. return
  5303. }
  5304. }
  5305. func (c *HisApiController) GetFaPiaoData() {
  5306. order_id, _ := c.GetInt64("order_id")
  5307. patient_id, _ := c.GetInt64("patient_id")
  5308. number := c.GetString("number")
  5309. adminUser := c.GetAdminUserInfo()
  5310. order, _ := service.GetHisOrderByID(order_id)
  5311. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5312. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5313. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5314. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5315. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5316. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5317. var bedCostTotal float64 = 0 //床位总费
  5318. var bedCostSelfTotal float64 = 0 //床位自费
  5319. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5320. var operationCostTotal float64 = 0 //手术费
  5321. var operationCostSelfTotal float64 = 0 //手术费
  5322. var operationCostPartSelfTotal float64 = 0 //手术费
  5323. var otherCostTotal float64 = 0 //其他费用
  5324. var otherCostSelfTotal float64 = 0 //其他费用
  5325. var otherCostPartSelfTotal float64 = 0 //其他费用
  5326. var materialCostTotal float64 = 0 //材料费
  5327. var materialCostSelfTotal float64 = 0 //材料费
  5328. var materialCostPartSelfTotal float64 = 0 //材料费
  5329. var westernMedicineCostTotal float64 = 0 //西药费
  5330. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5331. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5332. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5333. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5334. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5335. var checkCostTotal float64 = 0 //检查费
  5336. var checkCostSelfTotal float64 = 0 //检查费
  5337. var checkCostPartSelfTotal float64 = 0 //检查费
  5338. var laboratoryCostTotal float64 = 0 //化验费
  5339. var laboratoryCostSelfTotal float64 = 0 //化验费
  5340. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5341. var treatCostTotal float64 = 0 //治疗费用
  5342. var treatCostSelfTotal float64 = 0 //治疗费用
  5343. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5344. var zhenChaCostTotal float64 = 0 //其他费用
  5345. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5346. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5347. decimal.DivisionPrecision = 2
  5348. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5349. var balanceAccountsType int64
  5350. if his.ID > 0 {
  5351. balanceAccountsType = his.BalanceAccountsType
  5352. } else {
  5353. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5354. }
  5355. if balanceAccountsType == 2 {
  5356. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5357. for _, item := range orderInfos_two {
  5358. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5359. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5360. item.MedChrgitmType = "09"
  5361. }
  5362. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5363. if item.HisPrescriptionProject.Type == 2 {
  5364. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5365. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5366. case 0:
  5367. item.MedChrgitmType = "0"
  5368. break
  5369. case 1:
  5370. item.MedChrgitmType = "14"
  5371. break
  5372. case 2:
  5373. item.MedChrgitmType = "05"
  5374. break
  5375. case 3:
  5376. item.MedChrgitmType = "03"
  5377. break
  5378. case 4:
  5379. item.MedChrgitmType = "03"
  5380. break
  5381. case 5:
  5382. item.MedChrgitmType = "08"
  5383. break
  5384. case 6:
  5385. item.MedChrgitmType = "14"
  5386. break
  5387. case 7:
  5388. item.MedChrgitmType = "14"
  5389. break
  5390. case 8:
  5391. item.MedChrgitmType = "03"
  5392. break
  5393. case 9:
  5394. item.MedChrgitmType = "14"
  5395. break
  5396. case 10:
  5397. item.MedChrgitmType = "14"
  5398. break
  5399. case 11:
  5400. item.MedChrgitmType = "06"
  5401. break
  5402. case 12:
  5403. item.MedChrgitmType = "12"
  5404. break
  5405. case 13:
  5406. item.MedChrgitmType = "01"
  5407. break
  5408. case 14:
  5409. item.MedChrgitmType = "04"
  5410. break
  5411. case 15:
  5412. item.MedChrgitmType = "02"
  5413. break
  5414. }
  5415. } else {
  5416. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5417. case 1:
  5418. item.MedChrgitmType = "14"
  5419. break
  5420. case 2:
  5421. item.MedChrgitmType = "05"
  5422. break
  5423. case 3:
  5424. item.MedChrgitmType = "03"
  5425. break
  5426. case 4:
  5427. item.MedChrgitmType = "03"
  5428. break
  5429. case 5:
  5430. item.MedChrgitmType = "08"
  5431. break
  5432. case 6:
  5433. item.MedChrgitmType = "14"
  5434. break
  5435. case 7:
  5436. item.MedChrgitmType = "14"
  5437. break
  5438. case 8:
  5439. item.MedChrgitmType = "03"
  5440. break
  5441. case 9:
  5442. item.MedChrgitmType = "14"
  5443. break
  5444. }
  5445. }
  5446. } else if item.HisPrescriptionProject.Type == 3 {
  5447. item.MedChrgitmType = "08"
  5448. }
  5449. }
  5450. }
  5451. for _, item := range orderInfos_two {
  5452. fmt.Println(item.MedChrgitmType)
  5453. if item.MedChrgitmType == "01" { //床位费
  5454. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5455. bedCostSelfTotal = bedCostTotal
  5456. }
  5457. if item.MedChrgitmType == "02" { //诊察费
  5458. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5459. zhenChaCostSelfTotal = zhenChaCostTotal
  5460. }
  5461. if item.MedChrgitmType == "03" { //检查费
  5462. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5463. checkCostSelfTotal = checkCostTotal
  5464. }
  5465. if item.MedChrgitmType == "04" { //化验费
  5466. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5467. laboratoryCostSelfTotal = laboratoryCostTotal
  5468. }
  5469. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5470. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5471. treatCostSelfTotal = treatCostTotal
  5472. }
  5473. if item.MedChrgitmType == "06" { //手术费
  5474. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5475. operationCostSelfTotal = treatCostTotal
  5476. }
  5477. if item.MedChrgitmType == "08" { //材料费
  5478. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5479. materialCostSelfTotal = materialCostTotal
  5480. }
  5481. if item.MedChrgitmType == "09" { //西药费
  5482. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5483. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5484. }
  5485. if item.MedChrgitmType == "11" { //中成费
  5486. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5487. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5488. }
  5489. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  5490. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5491. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5492. otherCostSelfTotal = otherCostTotal
  5493. }
  5494. } else {
  5495. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5496. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5497. otherCostSelfTotal = otherCostTotal
  5498. }
  5499. }
  5500. }
  5501. } else {
  5502. for _, item := range orderInfos {
  5503. if item.MedChrgitmType == "01" { //床位费
  5504. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5505. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5506. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5507. }
  5508. if item.MedChrgitmType == "02" { //诊察费
  5509. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5510. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5511. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5512. }
  5513. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  5514. if item.MedChrgitmType == "03" { //检查费
  5515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5516. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5517. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5518. }
  5519. } else {
  5520. if item.MedChrgitmType == "03" { //检查费
  5521. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5522. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5523. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5524. }
  5525. }
  5526. if item.MedChrgitmType == "04" { //化验费
  5527. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5528. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5529. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5530. }
  5531. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5532. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5533. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5534. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5535. }
  5536. if item.MedChrgitmType == "06" { //手术费
  5537. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5538. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5539. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5540. }
  5541. if item.MedChrgitmType == "08" { //材料费
  5542. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5543. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5544. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5545. }
  5546. if item.MedChrgitmType == "09" { //西药费
  5547. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5548. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5549. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5550. }
  5551. if item.MedChrgitmType == "11" { //中成费
  5552. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5553. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5554. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5555. }
  5556. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5557. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5558. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5559. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5560. }
  5561. }
  5562. }
  5563. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5564. c.ServeSuccessJSON(map[string]interface{}{
  5565. "order_number": order.Number, //业务流水号
  5566. "id_card_no": his.IdCardNo, //社会保障号
  5567. "department_name": department.Name, //科室
  5568. "number": his.Number, //门诊号
  5569. "date": order.SettleAccountsDate, //结算日期
  5570. "name": order.PsnName, //姓名
  5571. "gender": order.Gend, //性别
  5572. "psn_cash_money": order.PsnCashPay, //个人支付
  5573. "pay_way": "门诊", //结算方式
  5574. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5575. "admin_user_name": admin.UserName, //收款员
  5576. "order": order,
  5577. "order_info": orderInfos_two,
  5578. "his": his,
  5579. "bedCostTotal": bedCostTotal,
  5580. "bedCostSelfTotal": bedCostSelfTotal,
  5581. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5582. "operationCostTotal": operationCostTotal,
  5583. "operationCostSelfTotal": operationCostSelfTotal,
  5584. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5585. "otherCostTotal": otherCostTotal,
  5586. "otherCostSelfTotal": otherCostSelfTotal,
  5587. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5588. "materialCostTotal": materialCostTotal,
  5589. "materialCostSelfTotal": materialCostSelfTotal,
  5590. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5591. "westernMedicineCostTotal": westernMedicineCostTotal,
  5592. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5593. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5594. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5595. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5596. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5597. "checkCostTotal": checkCostTotal,
  5598. "checkCostSelfTotal": checkCostSelfTotal,
  5599. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5600. "laboratoryCostTotal": laboratoryCostTotal,
  5601. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5602. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5603. "treatCostTotal": treatCostTotal,
  5604. "treatCostSelfTotal": treatCostSelfTotal,
  5605. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5606. "zhenChaCostTotal": zhenChaCostTotal,
  5607. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5608. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5609. "his_hospital_record": his_hospital_record,
  5610. })
  5611. }
  5612. func (this *HisApiController) GetIncomeStatisticsData() {
  5613. start_time := this.GetString("start_time")
  5614. end_time := this.GetString("end_time")
  5615. key_words := this.GetString("key_words")
  5616. limit, _ := this.GetInt64("limit")
  5617. page, _ := this.GetInt64("page")
  5618. if page <= 0 {
  5619. page = 1
  5620. }
  5621. if limit <= 0 {
  5622. limit = 10
  5623. }
  5624. statistics_type, _ := this.GetInt64("statistics_type")
  5625. admin := this.GetAdminUserInfo()
  5626. timeLayout := "2006-01-02"
  5627. loc, _ := time.LoadLocation("Local")
  5628. var theStartTIme int64
  5629. if len(start_time) > 0 {
  5630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5631. if err != nil {
  5632. theStartTIme = 0
  5633. }
  5634. theStartTIme = theTime.Unix()
  5635. }
  5636. var theEndtTIme int64
  5637. if len(end_time) > 0 {
  5638. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5639. if err != nil {
  5640. theEndtTIme = 0
  5641. }
  5642. theEndtTIme = theTime.Unix()
  5643. }
  5644. if statistics_type == 1 {
  5645. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5646. this.ServeSuccessJSON(map[string]interface{}{
  5647. "list": list,
  5648. "total": total,
  5649. })
  5650. } else {
  5651. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5652. this.ServeSuccessJSON(map[string]interface{}{
  5653. "list": list,
  5654. "total": total,
  5655. })
  5656. }
  5657. }
  5658. func (c *HisApiController) PostProjectInformation() {
  5659. adminUser := c.GetAdminUserInfo()
  5660. orgId := adminUser.CurrentOrgId
  5661. dataBody := make(map[string]interface{}, 0)
  5662. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5663. if err != nil {
  5664. utils.ErrorLog(err.Error())
  5665. return
  5666. }
  5667. utils.ErrorLog("%v", dataBody)
  5668. var projectList []*models.HisProject
  5669. var total_goods []interface{}
  5670. tempProjects := dataBody["projects"].([]interface{})
  5671. total_goods = tempProjects
  5672. for index, projectMap := range tempProjects {
  5673. projectM := projectMap.(map[string]interface{})
  5674. var project models.HisProject
  5675. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5676. utils.ErrorLog("project_name")
  5677. return
  5678. }
  5679. project_name, _ := projectM["project_name"].(string)
  5680. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5681. err_log := models.ExportErrLog{
  5682. LogType: 6,
  5683. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5684. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5685. Status: 1,
  5686. CreateTime: time.Now().Unix(),
  5687. UpdateTime: time.Now().Unix(),
  5688. ExportTime: time.Now().Unix(),
  5689. }
  5690. service.CreateExportErrLog(&err_log)
  5691. continue
  5692. }
  5693. project.ProjectName = project_name
  5694. prices := projectM["price"].(string)
  5695. price, _ := strconv.ParseFloat(prices, 64)
  5696. if price <= 0 { //名字为空则生成一条导入错误日志
  5697. err_log := models.ExportErrLog{
  5698. LogType: 6,
  5699. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5700. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5701. Status: 1,
  5702. CreateTime: time.Now().Unix(),
  5703. UpdateTime: time.Now().Unix(),
  5704. ExportTime: time.Now().Unix(),
  5705. }
  5706. service.CreateExportErrLog(&err_log)
  5707. continue
  5708. }
  5709. project.Price = price
  5710. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5711. utils.ErrorLog("unit_id")
  5712. return
  5713. }
  5714. unit := projectM["unit"].(string)
  5715. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5716. err_log := models.ExportErrLog{
  5717. LogType: 6,
  5718. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5719. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5720. Status: 1,
  5721. CreateTime: time.Now().Unix(),
  5722. UpdateTime: time.Now().Unix(),
  5723. ExportTime: time.Now().Unix(),
  5724. }
  5725. service.CreateExportErrLog(&err_log)
  5726. continue
  5727. }
  5728. project.Unit = unit
  5729. cost_classify := projectM["cost_classify"].(string)
  5730. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5731. err_log := models.ExportErrLog{
  5732. LogType: 6,
  5733. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5734. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5735. Status: 1,
  5736. CreateTime: time.Now().Unix(),
  5737. UpdateTime: time.Now().Unix(),
  5738. ExportTime: time.Now().Unix(),
  5739. }
  5740. service.CreateExportErrLog(&err_log)
  5741. continue
  5742. }
  5743. var costClassify = "费用类别"
  5744. var cost_classify_id int64
  5745. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5746. if len(cost_classify) != 0 {
  5747. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5748. if errcode == gorm.ErrRecordNotFound {
  5749. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5750. dataconfig := models.DictDataconfig{
  5751. ParentId: costClassifyConfig.ID,
  5752. Module: "system",
  5753. OrgId: orgId,
  5754. Name: cost_classify,
  5755. FieldName: "",
  5756. Value: costConfig.Value + 1,
  5757. CreatedTime: "",
  5758. UpdatedTime: "",
  5759. CreateUserId: adminUser.AdminUser.Id,
  5760. Status: 1,
  5761. Remark: "",
  5762. DeleteIdSystem: 0,
  5763. Title: "",
  5764. Content: "",
  5765. Order: 0,
  5766. Code: "",
  5767. }
  5768. service.CreatedDicConfig(&dataconfig)
  5769. }
  5770. }
  5771. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5772. for _, it := range costClassList {
  5773. if cost_classify == it.Name {
  5774. cost_classify_id = int64(it.Value)
  5775. }
  5776. }
  5777. project.CostClassify = cost_classify_id
  5778. executive_section := projectM["executive_section"].(string)
  5779. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5780. err_log := models.ExportErrLog{
  5781. LogType: 6,
  5782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5783. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5784. Status: 1,
  5785. CreateTime: time.Now().Unix(),
  5786. UpdateTime: time.Now().Unix(),
  5787. ExportTime: time.Now().Unix(),
  5788. }
  5789. service.CreateExportErrLog(&err_log)
  5790. continue
  5791. }
  5792. if len(executive_section) != 0 {
  5793. //查找科室是否有内容
  5794. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5795. if errcodedepart == gorm.ErrRecordNotFound {
  5796. department := models.XtHisDepartment{
  5797. Name: executive_section,
  5798. Status: 1,
  5799. UserOrgId: adminUser.CurrentOrgId,
  5800. CreatedTime: time.Now().Unix(),
  5801. }
  5802. service.CreateDePartment(&department)
  5803. }
  5804. }
  5805. var executive_section_id int64
  5806. departMentList, _ := service.GetAllDepartMent(orgId)
  5807. for _, it := range departMentList {
  5808. if executive_section == it.Name {
  5809. executive_section_id = it.ID
  5810. }
  5811. }
  5812. project.ExecutiveSection = executive_section_id
  5813. medical_coverage := projectM["medical_coverage"].(string)
  5814. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5815. err_log := models.ExportErrLog{
  5816. LogType: 6,
  5817. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5818. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5819. Status: 1,
  5820. CreateTime: time.Now().Unix(),
  5821. UpdateTime: time.Now().Unix(),
  5822. ExportTime: time.Now().Unix(),
  5823. }
  5824. service.CreateExportErrLog(&err_log)
  5825. continue
  5826. }
  5827. var medicalCoverage = "医保等级"
  5828. var medical_coverage_id int64
  5829. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5830. if len(medical_coverage) != 0 {
  5831. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5832. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5833. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5834. dataconfig := models.DictDataconfig{
  5835. ParentId: medicalCoverageConfig.ID,
  5836. Module: "system",
  5837. OrgId: orgId,
  5838. Name: medical_coverage,
  5839. FieldName: "",
  5840. Value: medicalCoverageConfig.Value + 1,
  5841. CreatedTime: "",
  5842. UpdatedTime: "",
  5843. CreateUserId: adminUser.AdminUser.Id,
  5844. Status: 1,
  5845. Remark: "",
  5846. DeleteIdSystem: 0,
  5847. Title: "",
  5848. Content: "",
  5849. Order: 0,
  5850. Code: "",
  5851. }
  5852. service.CreatedDicConfig(&dataconfig)
  5853. }
  5854. }
  5855. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5856. for _, it := range medicalCoverageList {
  5857. if medical_coverage == it.Name {
  5858. medical_coverage_id = int64(it.Value)
  5859. }
  5860. }
  5861. project.MedicalCoverage = medical_coverage_id
  5862. pinyin := projectM["pinyin"].(string)
  5863. project.Pinyin = pinyin
  5864. wubi := projectM["wubi"].(string)
  5865. project.Wubi = wubi
  5866. statistical_classification := projectM["statistical_classification"].(string)
  5867. var statisticalClassification = "统计分类"
  5868. var statistical_classification_id int64
  5869. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5870. if len(statistical_classification) != 0 {
  5871. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5872. if classificationerrcodes == gorm.ErrRecordNotFound {
  5873. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5874. dataconfig := models.DictDataconfig{
  5875. ParentId: classiFication.ID,
  5876. Module: "system",
  5877. OrgId: orgId,
  5878. Name: statistical_classification,
  5879. FieldName: "",
  5880. Value: classiFicationConfig.Value + 1,
  5881. CreatedTime: "",
  5882. UpdatedTime: "",
  5883. CreateUserId: adminUser.AdminUser.Id,
  5884. Status: 1,
  5885. Remark: "",
  5886. DeleteIdSystem: 0,
  5887. Title: "",
  5888. Content: "",
  5889. Order: 0,
  5890. Code: "",
  5891. }
  5892. service.CreatedDicConfig(&dataconfig)
  5893. }
  5894. }
  5895. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5896. for _, it := range classiFicationList {
  5897. if statistical_classification == it.Name {
  5898. statistical_classification_id = int64(it.Value)
  5899. }
  5900. }
  5901. project.StatisticalClassification = statistical_classification_id
  5902. disease_directory := int64(projectM["disease_directory"].(float64))
  5903. project.DiseaseDirectory = disease_directory
  5904. is_record := int64(projectM["is_record"].(float64))
  5905. project.IsRecord = is_record
  5906. medical_code := projectM["medical_code"].(string)
  5907. project.MedicalCode = medical_code
  5908. tube_color := projectM["tube_color"].(string)
  5909. var tubeColor = "试管颜色"
  5910. var tube_color_id int64
  5911. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5912. if len(tube_color) != 0 {
  5913. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5914. if errcodetube == gorm.ErrRecordNotFound {
  5915. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5916. dataconfig := models.DictDataconfig{
  5917. ParentId: tubeColorConfig.ID,
  5918. Module: "system",
  5919. OrgId: orgId,
  5920. Name: tube_color,
  5921. FieldName: "",
  5922. Value: tubeConfig.Value + 1,
  5923. CreatedTime: "",
  5924. UpdatedTime: "",
  5925. CreateUserId: adminUser.AdminUser.Id,
  5926. Status: 1,
  5927. Remark: "",
  5928. DeleteIdSystem: 0,
  5929. Title: "",
  5930. Content: "",
  5931. Order: 0,
  5932. Code: "",
  5933. }
  5934. service.CreatedDicConfig(&dataconfig)
  5935. }
  5936. }
  5937. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5938. for _, it := range tubeColorList {
  5939. if tube_color == it.Name {
  5940. tube_color_id = int64(it.Value)
  5941. }
  5942. }
  5943. project.TubeColor = tube_color_id
  5944. single_dose := projectM["single_dose"].(string)
  5945. project.SingleDose = single_dose
  5946. execution_frequency := projectM["execution_frequency"].(string)
  5947. project.ExecutionFrequency = execution_frequency
  5948. delivery_way := projectM["delivery_way"].(string)
  5949. project.DeliveryWay = delivery_way
  5950. number_days := projectM["number_days"].(string)
  5951. project.NumberDays = number_days
  5952. total := projectM["total"].(string)
  5953. project.Total = total
  5954. medical_status := int64(projectM["medical_status"].(float64))
  5955. project.MedicalStatus = medical_status
  5956. category := int64(projectM["category"].(float64))
  5957. project.Category = category
  5958. specail_project := int64(projectM["specail_project"].(float64))
  5959. project.SpecailProject = specail_project
  5960. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5961. project.SocialSecurityDirectoryCode = social_security_directory_code
  5962. remark := projectM["remark"].(string)
  5963. project.Remark = remark
  5964. record_date := projectM["record_date"].(string)
  5965. timeLayout := "2006-01-02"
  5966. loc, _ := time.LoadLocation("Local")
  5967. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5968. project.RecordDate = theTime.Unix()
  5969. projectList = append(projectList, &project)
  5970. }
  5971. export_time := time.Now().Unix()
  5972. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5973. if len(projectList) > 0 {
  5974. for _, item := range projectList {
  5975. project := models.HisProject{
  5976. ProjectName: item.ProjectName,
  5977. Price: item.Price,
  5978. Unit: item.Unit,
  5979. CostClassify: item.CostClassify,
  5980. ExecutiveSection: item.ExecutiveSection,
  5981. MedicalCoverage: item.MedicalCoverage,
  5982. UserOrgId: orgId,
  5983. Status: 1,
  5984. CreatedTime: time.Now().Unix(),
  5985. Pinyin: item.Pinyin,
  5986. Wubi: item.Wubi,
  5987. StatisticalClassification: item.StatisticalClassification,
  5988. DiseaseDirectory: item.DiseaseDirectory,
  5989. IsRecord: item.IsRecord,
  5990. MedicalCode: item.MedicalCode,
  5991. TubeColor: item.TubeColor,
  5992. SingleDose: item.SingleDose,
  5993. DeliveryWay: item.DeliveryWay,
  5994. NumberDays: item.NumberDays,
  5995. Total: item.Total,
  5996. Category: item.Category,
  5997. MedicalStatus: item.MedicalStatus,
  5998. SpecailProject: item.SpecailProject,
  5999. RecordDate: item.RecordDate,
  6000. Remark: item.Remark,
  6001. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  6002. ExecutionFrequency: item.ExecutionFrequency,
  6003. }
  6004. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  6005. if errcodeproject == gorm.ErrRecordNotFound {
  6006. service.CreateProjectInfomation(&project)
  6007. } else if errcodeproject == nil {
  6008. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  6009. }
  6010. log := models.ExportLog{
  6011. LogType: 6,
  6012. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6013. TotalNum: int64(len(total_goods)),
  6014. FailNum: int64(len(errLogs)),
  6015. SuccessNum: int64(len(projectList)),
  6016. CreateTime: time.Now().Unix(),
  6017. UpdateTime: time.Now().Unix(),
  6018. ExportTime: export_time,
  6019. Status: 1,
  6020. }
  6021. service.CreateExportLog(&log)
  6022. c.ServeSuccessJSON(map[string]interface{}{
  6023. "msg": "导入成功",
  6024. "total_num": len(total_goods),
  6025. "success_num": len(projectList),
  6026. "fail_num": int64(len(errLogs)),
  6027. })
  6028. }
  6029. } else {
  6030. log := models.ExportLog{
  6031. LogType: 6,
  6032. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6033. TotalNum: int64(len(total_goods)),
  6034. FailNum: int64(len(errLogs)),
  6035. SuccessNum: int64(len(projectList)),
  6036. CreateTime: time.Now().Unix(),
  6037. UpdateTime: time.Now().Unix(),
  6038. ExportTime: export_time,
  6039. Status: 1,
  6040. }
  6041. service.CreateExportLog(&log)
  6042. c.ServeSuccessJSON(map[string]interface{}{
  6043. "msg": "导入成功",
  6044. "total_num": len(total_goods),
  6045. "success_num": len(projectList),
  6046. "fail_num": int64(len(errLogs)),
  6047. })
  6048. }
  6049. }
  6050. //func (this *HisApiController) EditProjectInformation(){
  6051. //
  6052. // id, _ := this.GetInt64("id")
  6053. // project_team := this.GetString("project_team")
  6054. // price := this.GetString("price")
  6055. // price_float, _ := strconv.ParseFloat(price, 64)
  6056. // pinyin := this.GetString("pinyin")
  6057. // wubi := this.GetString("wubi")
  6058. // tube_color, _ := this.GetInt64("tube_color")
  6059. // team_type, _ := this.GetInt64("team_type")
  6060. // remark := this.GetString("remark")
  6061. // ids := this.GetString("ids")
  6062. // item_id := this.GetString("item_id")
  6063. // projectTeam := models.XtHisProjectTeam{
  6064. // ProjectTeam: project_team,
  6065. // Price: price_float,
  6066. // Pinyin: pinyin,
  6067. // Wubi: wubi,
  6068. // TubeColor: tube_color,
  6069. // TeamType: team_type,
  6070. // Remark: remark,
  6071. // ProjectId: ids,
  6072. // ItemId: item_id,
  6073. // }
  6074. //
  6075. //
  6076. // dataBody := make(map[string]interface{}, 0)
  6077. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6078. // if err != nil {
  6079. // utils.ErrorLog(err.Error())
  6080. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6081. // return
  6082. // }
  6083. //
  6084. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6085. //
  6086. //
  6087. // if err != nil {
  6088. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6089. // return
  6090. // }
  6091. //
  6092. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6093. // infos, _ := dataBody["info"].([]interface{})
  6094. // if len(infos) > 0 {
  6095. // var ids []string
  6096. //
  6097. // for _, item := range infos {
  6098. // items := item.(map[string]interface{})
  6099. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6100. // utils.ErrorLog("id")
  6101. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6102. // return
  6103. // }
  6104. // id := int64(items["id"].(float64))
  6105. //
  6106. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6107. // utils.ErrorLog("type")
  6108. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6109. // return
  6110. // }
  6111. // types := int64(items["type"].(float64))
  6112. //
  6113. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6114. // utils.ErrorLog("number")
  6115. // }
  6116. //
  6117. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6118. //
  6119. // projectList := models.XtHisProjectList{
  6120. // Number: number,
  6121. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6122. // ProjectId: id,
  6123. // Status: 1,
  6124. // CreatedTime: time.Now().Unix(),
  6125. // UpdatedTime: time.Now().Unix(),
  6126. // TeamId: projectTeam.ID,
  6127. // Type: types,
  6128. // }
  6129. // list := projectList
  6130. //
  6131. // service.CreateProjectList(&list)
  6132. //
  6133. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6134. //
  6135. // }
  6136. // ids_str := strings.Join(ids, ",")
  6137. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6138. // service.SaveProjectTeam(&projectTeam)
  6139. // this.ServeSuccessJSON(map[string]interface{}{
  6140. // "projectTeam": projectTeam,
  6141. // })
  6142. // }
  6143. // }
  6144. //}
  6145. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6146. name := c.GetString("name")
  6147. mode_id, _ := c.GetInt64("mode", 0)
  6148. types, _ := c.GetInt64("type", 0)
  6149. patient_id, _ := c.GetInt64("patient_id", 0)
  6150. types = 1
  6151. adminInfo := c.GetAdminUserInfo()
  6152. template := &models.HisPrescriptionTemplate{
  6153. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6154. PatientId: patient_id,
  6155. Type: types,
  6156. Status: 1,
  6157. Ctime: time.Now().Unix(),
  6158. Mtime: time.Now().Unix(),
  6159. Name: name,
  6160. Mode: mode_id,
  6161. }
  6162. dataBody := make(map[string]interface{}, 0)
  6163. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6164. if err != nil {
  6165. utils.ErrorLog(err.Error())
  6166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6167. return
  6168. }
  6169. err = service.CreateHisPrescriptionTemplate(template)
  6170. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6171. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6172. if len(prescriptions) > 0 {
  6173. for _, item := range prescriptions {
  6174. items := item.(map[string]interface{})
  6175. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6176. utils.ErrorLog("type")
  6177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6178. return
  6179. }
  6180. types := int64(items["type"].(float64))
  6181. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6182. utils.ErrorLog("med_type")
  6183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6184. return
  6185. }
  6186. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6187. ctime := time.Now().Unix()
  6188. prescription := &models.HisPrescriptionInfoTemplate{
  6189. PatientId: patient_id,
  6190. UserOrgId: adminInfo.CurrentOrgId,
  6191. Ctime: ctime,
  6192. Mtime: ctime,
  6193. Type: types,
  6194. Modifier: adminInfo.AdminUser.Id,
  6195. Creator: adminInfo.AdminUser.Id,
  6196. Status: 1,
  6197. PTemplateId: template.ID,
  6198. MedType: med_type,
  6199. }
  6200. service.CreateHisPrescriptionInfoTemplate(prescription)
  6201. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6202. advices := items["advices"].([]interface{})
  6203. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6204. ctime := time.Now().Unix()
  6205. mtime := ctime
  6206. if len(advices) > 0 {
  6207. for _, advice := range advices {
  6208. var s models.HisPrescriptionAdviceTemplate
  6209. s.PrescriptionId = prescription.ID
  6210. s.AdviceType = 2
  6211. s.StopState = 2
  6212. s.ExecutionState = 2
  6213. s.Status = 1
  6214. s.UserOrgId = adminInfo.CurrentOrgId
  6215. s.CreatedTime = ctime
  6216. s.UpdatedTime = mtime
  6217. s.PatientId = patient_id
  6218. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6219. if errcode > 0 {
  6220. c.ServeFailJSONWithSGJErrorCode(errcode)
  6221. return
  6222. }
  6223. service.CreateHisPrescriptionAdviceTemplate(&s)
  6224. }
  6225. }
  6226. }
  6227. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6228. projects := items["project"].([]interface{})
  6229. if len(projects) > 0 {
  6230. for _, project := range projects {
  6231. var p models.HisPrescriptionProjectTemplate
  6232. p.PrescriptionId = prescription.ID
  6233. p.Ctime = time.Now().Unix()
  6234. p.Mtime = time.Now().Unix()
  6235. p.PatientId = patient_id
  6236. p.UserOrgId = adminInfo.CurrentOrgId
  6237. p.Status = 1
  6238. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6239. if errcode > 0 {
  6240. c.ServeFailJSONWithSGJErrorCode(errcode)
  6241. return
  6242. }
  6243. service.CreateHisPrescriptionProjectTemplate(&p)
  6244. }
  6245. }
  6246. }
  6247. }
  6248. c.ServeSuccessJSON(map[string]interface{}{
  6249. "msg": "创建成功",
  6250. })
  6251. }
  6252. }
  6253. }
  6254. func (c *HisApiController) PreSettle() {
  6255. id, _ := c.GetInt64("id")
  6256. record_time := c.GetString("record_time")
  6257. his_patient_id, _ := c.GetInt64("his_patient_id")
  6258. timeLayout := "2006-01-02"
  6259. loc, _ := time.LoadLocation("Local")
  6260. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6261. diagnosis_id := c.GetString("diagnosis")
  6262. sick_type, _ := c.GetInt64("sick_type")
  6263. reg_type, _ := c.GetInt64("p_type")
  6264. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6265. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6266. if err != nil {
  6267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6268. return
  6269. }
  6270. recordDateTime := theTime.Unix()
  6271. adminUser := c.GetAdminUserInfo()
  6272. var prescriptions []*models.HisPrescription
  6273. var start_time int64
  6274. var end_time int64
  6275. ids_str := c.GetString("ids")
  6276. ids_arr := strings.Split(ids_str, ",")
  6277. fmt.Println(reg_type)
  6278. if settle_accounts_type == 1 { //日结
  6279. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6280. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6281. } else {
  6282. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6283. }
  6284. fmt.Println(prescriptions)
  6285. } else { //月结
  6286. start_time_str := c.GetString("start_time")
  6287. end_time_str := c.GetString("end_time")
  6288. timeLayout := "2006-01-02"
  6289. loc, _ := time.LoadLocation("Local")
  6290. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6291. if err != nil {
  6292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6293. return
  6294. }
  6295. recordStartTime := theStartTime.Unix()
  6296. start_time = recordStartTime
  6297. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6298. if err != nil {
  6299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6300. return
  6301. }
  6302. recordEndTime := theEndTime.Unix()
  6303. end_time = recordEndTime
  6304. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6305. }
  6306. if reg_type == 1111 || reg_type == 1112 {
  6307. reg_type = 11
  6308. }
  6309. timestamp := time.Now().Unix()
  6310. tempTime := time.Unix(timestamp, 0)
  6311. timeFormat := tempTime.Format("20060102150405")
  6312. chrgBchno := rand.Intn(100000) + 10000
  6313. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6314. strconv.FormatInt(his.PatientId, 10)
  6315. var ids []int64
  6316. for _, item := range prescriptions {
  6317. ids = append(ids, item.ID)
  6318. }
  6319. fmt.Println(ids)
  6320. var total float64
  6321. for _, item := range prescriptions {
  6322. fmt.Println(item)
  6323. if item.Type == 1 { //药品
  6324. for _, subItem := range item.HisDoctorAdviceInfo {
  6325. total = total + (subItem.Price * subItem.PrescribingNumber)
  6326. }
  6327. }
  6328. if item.Type == 2 { //项目
  6329. for _, subItem := range item.HisPrescriptionProject {
  6330. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6331. total = total + (subItem.Price * cnt)
  6332. }
  6333. }
  6334. for _, subItem := range item.HisAdditionalCharge {
  6335. total = total + (subItem.Price * float64(subItem.Count))
  6336. }
  6337. }
  6338. allTotal := fmt.Sprintf("%.2f", total)
  6339. totals, _ := strconv.ParseFloat(allTotal, 64)
  6340. order := &models.HisOrder{
  6341. UserOrgId: adminUser.CurrentOrgId,
  6342. HisPatientId: his.ID,
  6343. PatientId: id,
  6344. SettleAccountsDate: recordDateTime,
  6345. Ctime: time.Now().Unix(),
  6346. Mtime: time.Now().Unix(),
  6347. Status: 1,
  6348. OrderStatus: 1,
  6349. MdtrtId: his.Number,
  6350. Number: chrg_bchno,
  6351. MedfeeSumamt: totals,
  6352. SettleEndTime: end_time,
  6353. SettleStartTime: start_time,
  6354. SettleType: settle_accounts_type,
  6355. PType: 2,
  6356. IsPre: 1,
  6357. MedType: strconv.Itoa(int(reg_type)),
  6358. Diagnosis: diagnosis_id,
  6359. }
  6360. err = service.CreateOrder(order)
  6361. if err != nil {
  6362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6363. return
  6364. }
  6365. var customs []*Custom
  6366. for _, item := range prescriptions {
  6367. fmt.Println(item.Type)
  6368. if item.Type == 1 { //药品
  6369. for _, subItem := range item.HisDoctorAdviceInfo {
  6370. cus := &Custom{
  6371. AdviceId: subItem.ID,
  6372. ProjectId: 0,
  6373. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6374. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6375. FeedetlSn: subItem.FeedetlSn,
  6376. Price: fmt.Sprintf("%.2f", subItem.Price),
  6377. MedListCodg: subItem.MedListCodg,
  6378. Type: 1,
  6379. }
  6380. customs = append(customs, cus)
  6381. }
  6382. }
  6383. if item.Type == 2 { //项目
  6384. for _, subItem := range item.HisPrescriptionProject {
  6385. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6386. cus := &Custom{
  6387. AdviceId: 0,
  6388. ProjectId: subItem.ID,
  6389. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6390. Cut: fmt.Sprintf("%.2f", cnt),
  6391. FeedetlSn: subItem.FeedetlSn,
  6392. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6393. MedListCodg: subItem.MedListCodg,
  6394. Type: 2,
  6395. }
  6396. customs = append(customs, cus)
  6397. }
  6398. }
  6399. for _, item := range item.HisAdditionalCharge {
  6400. cus := &Custom{
  6401. ItemId: item.ID,
  6402. AdviceId: 0,
  6403. ProjectId: 0,
  6404. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6405. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6406. FeedetlSn: item.FeedetlSn,
  6407. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6408. MedListCodg: item.XtHisAddtionConfig.Code,
  6409. Type: 3,
  6410. }
  6411. customs = append(customs, cus)
  6412. }
  6413. }
  6414. fmt.Println(customs)
  6415. for _, item := range customs {
  6416. var advice_id int64 = 0
  6417. var project_id int64 = 0
  6418. var item_id int64 = 0
  6419. var types int64 = 0
  6420. if item.Type == 1 {
  6421. advice_id = item.AdviceId
  6422. project_id = 0
  6423. item_id = 0
  6424. } else if item.Type == 2 {
  6425. advice_id = 0
  6426. item_id = 0
  6427. project_id = item.ProjectId
  6428. } else if item.Type == 3 {
  6429. advice_id = 0
  6430. item_id = item.ItemId
  6431. project_id = 0
  6432. }
  6433. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6434. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6435. pric, _ := strconv.ParseFloat(item.Price, 32)
  6436. info := &models.HisOrderInfo{
  6437. OrderNumber: order.Number,
  6438. UploadDate: time.Now().Unix(),
  6439. AdviceId: advice_id,
  6440. DetItemFeeSumamt: detItemFeeSumamt,
  6441. Cnt: cut,
  6442. Pric: pric,
  6443. PatientId: id,
  6444. Status: 1,
  6445. Mtime: time.Now().Unix(),
  6446. Ctime: time.Now().Unix(),
  6447. UserOrgId: adminUser.CurrentOrgId,
  6448. HisPatientId: his.ID,
  6449. OrderId: order.ID,
  6450. ProjectId: project_id,
  6451. Type: types,
  6452. ItemId: item_id,
  6453. }
  6454. service.CreateOrderInfo(info)
  6455. }
  6456. his.SickType = sick_type
  6457. service.UpdataHisPateint(&his)
  6458. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6459. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6460. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6461. if err == nil {
  6462. c.ServeSuccessJSON(map[string]interface{}{
  6463. "msg": "结算成功",
  6464. })
  6465. }
  6466. }
  6467. type CustomOrderInfo struct {
  6468. Name string
  6469. Spec string
  6470. Unit string
  6471. Count float64
  6472. Price float64
  6473. Total float64
  6474. }
  6475. func (c *HisApiController) GetPrivateExpensesInfo() {
  6476. order_id, _ := c.GetInt64("id", 0)
  6477. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6478. order, _ := service.GetHisOrderByID(order_id)
  6479. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6480. if order.ID == 0 {
  6481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6482. return
  6483. }
  6484. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6485. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6486. org_id := c.GetAdminUserInfo().CurrentOrgId
  6487. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6488. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6489. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6490. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6491. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6492. var orderInfos_four []*models.HisOrderInfoTwo
  6493. for _, item := range orderInfos_three {
  6494. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6495. item.HisPrescriptionProject.IsCheckTeam = 1
  6496. orderInfos_four = append(orderInfos_four, item)
  6497. }
  6498. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6499. item.HisPrescriptionProject.IsCheckTeam = 2
  6500. orderInfos_two = append(orderInfos_two, item)
  6501. }
  6502. }
  6503. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6504. var cus_slice []CustomOrderInfo
  6505. for _, item := range new_order_info {
  6506. var cus CustomOrderInfo
  6507. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6508. cus.Unit = ""
  6509. cus.Spec = ""
  6510. var total float64
  6511. for _, subItem := range orderInfos_four {
  6512. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6513. total = total + subItem.DetItemFeeSumamt
  6514. fmt.Println(subItem.DetItemFeeSumamt)
  6515. }
  6516. }
  6517. cus.Count = 1
  6518. cus.Total = total
  6519. cus_slice = append(cus_slice, cus)
  6520. }
  6521. orderInfos = append(orderInfos, orderInfos_two...)
  6522. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6523. orderInfos = append(orderInfos, orderInfos_three...)
  6524. }
  6525. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6526. c.ServeSuccessJSON(map[string]interface{}{
  6527. "order": order,
  6528. "order_info": orderInfos,
  6529. "patient": patient,
  6530. "admin_info": adminInfo,
  6531. "his": his,
  6532. "current_admin": role,
  6533. "org_config": miConfig,
  6534. "new_order_info": cus_slice,
  6535. })
  6536. }
  6537. func (this *HisApiController) ChangeMedType() {
  6538. med_type := this.GetString("med_type")
  6539. old_med_type := this.GetString("old_med_type")
  6540. ids := this.GetString("ids")
  6541. settle_type, _ := this.GetInt64("settle_type")
  6542. start_time := this.GetString("start_time")
  6543. end_time := this.GetString("end_time")
  6544. ids_arr := strings.Split(ids, ",")
  6545. if settle_type == 1 { //日结
  6546. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6547. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6548. prescription.MedType = med_type
  6549. err := service.SaveHisPrescription(&prescription)
  6550. if err == nil {
  6551. this.ServeSuccessJSON(map[string]interface{}{
  6552. "msg": "修改成功",
  6553. })
  6554. } else {
  6555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6556. return
  6557. }
  6558. } else if settle_type == 2 {
  6559. timeLayout := "2006-01-02"
  6560. loc, _ := time.LoadLocation("Local")
  6561. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6562. if err != nil {
  6563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6564. return
  6565. }
  6566. recordStartTime := theStartTime.Unix()
  6567. start_time_timestamp := recordStartTime
  6568. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6569. if err != nil {
  6570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6571. return
  6572. }
  6573. recordEndTime := theEndTime.Unix()
  6574. end_time_timestamp := recordEndTime
  6575. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6576. if updateErr == nil {
  6577. this.ServeSuccessJSON(map[string]interface{}{
  6578. "msg": "修改成功",
  6579. })
  6580. } else {
  6581. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6582. return
  6583. }
  6584. }
  6585. }
  6586. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6587. patient_id, _ := c.GetInt64("patient_id")
  6588. his_patient_id, _ := c.GetInt64("his_patient_id")
  6589. record_date := c.GetString("record_date")
  6590. start_time := c.GetString("start_time")
  6591. end_time := c.GetString("end_time")
  6592. order_status, _ := c.GetInt64("type", 0)
  6593. p_type, _ := c.GetInt64("p_type", 0)
  6594. order_id, _ := c.GetInt64("order_id", 0)
  6595. timeLayout := "2006-01-02"
  6596. loc, _ := time.LoadLocation("Local")
  6597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6598. if err != nil {
  6599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6600. return
  6601. }
  6602. recordDateTime := theTime.Unix()
  6603. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6604. if err != nil {
  6605. }
  6606. startRecordDateTime := startTime.Unix()
  6607. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6608. if err != nil {
  6609. }
  6610. endRecordDateTime := endTime.Unix()
  6611. admin := c.GetAdminUserInfo()
  6612. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6613. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6614. order, _ := service.GetHisOrderByID(order_id)
  6615. var monthPrescriptions []*models.HisPrescription
  6616. if order_status == 1 || order_status == 0 {
  6617. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6618. } else if order_status == 2 {
  6619. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6620. }
  6621. var settle_total float64
  6622. for _, item := range monthPrescriptions {
  6623. if len(item.HisPrescriptionProject) > 0 {
  6624. for _, subItem := range item.HisPrescriptionProject {
  6625. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6626. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6627. settle_total = settle_total + total
  6628. }
  6629. }
  6630. if len(item.HisDoctorAdviceInfo) > 0 {
  6631. for _, subItem := range item.HisDoctorAdviceInfo {
  6632. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6633. settle_total = settle_total + total
  6634. }
  6635. }
  6636. }
  6637. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6638. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6639. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6640. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6641. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6642. //获取所有科室信息
  6643. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6644. c.ServeSuccessJSON(map[string]interface{}{
  6645. "his_info": his_patient_info,
  6646. "xt_info": xt_patient_info,
  6647. "case_history": case_history,
  6648. "info": patientPrescriptionInfo,
  6649. "last_info": lastPatientPrescriptionInfo,
  6650. "month_prescriptions": monthPrescriptions,
  6651. "order": order,
  6652. "doctors": doctors,
  6653. "department": department,
  6654. "settle_total": settle_total,
  6655. })
  6656. return
  6657. }
  6658. func (c *HisApiController) GetHisMonthPatientInfo() {
  6659. patient_id, _ := c.GetInt64("patient_id")
  6660. his_patient_id, _ := c.GetInt64("his_patient_id")
  6661. record_date := c.GetString("record_date")
  6662. number := c.GetString("number")
  6663. start_time := c.GetString("start_time")
  6664. end_time := c.GetString("end_time")
  6665. p_type, _ := c.GetInt64("p_type")
  6666. timeLayout := "2006-01-02"
  6667. loc, _ := time.LoadLocation("Local")
  6668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6669. if err != nil {
  6670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6671. return
  6672. }
  6673. recordDateTime := theTime.Unix()
  6674. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6675. if err != nil {
  6676. }
  6677. startRecordDateTime := startTime.Unix()
  6678. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6679. if err != nil {
  6680. }
  6681. endRecordDateTime := endTime.Unix()
  6682. admin := c.GetAdminUserInfo()
  6683. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6684. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6685. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6686. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6687. var settle_total float64
  6688. for _, item := range monthPrescriptions {
  6689. if len(item.HisPrescriptionProject) > 0 {
  6690. for _, subItem := range item.HisPrescriptionProject {
  6691. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6692. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6693. settle_total = settle_total + total
  6694. }
  6695. }
  6696. if len(item.HisDoctorAdviceInfo) > 0 {
  6697. for _, subItem := range item.HisDoctorAdviceInfo {
  6698. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6699. settle_total = settle_total + total
  6700. }
  6701. }
  6702. }
  6703. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6704. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6705. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6706. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6707. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6708. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6709. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6710. //获取所有科室信息
  6711. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6712. c.ServeSuccessJSON(map[string]interface{}{
  6713. "his_info": his_patient_info,
  6714. "xt_info": xt_patient_info,
  6715. "case_history": case_history,
  6716. "info": patientPrescriptionInfo,
  6717. "month_prescriptions": monthPrescriptions,
  6718. "order": order,
  6719. "doctors": doctors,
  6720. "department": department,
  6721. "count": count,
  6722. "drugStockConfig": drugStockConfig,
  6723. "last_info": lastPatientPrescriptionInfo,
  6724. "settle_total": settle_total,
  6725. })
  6726. return
  6727. }
  6728. func (c *HisApiController) GetAllOrder() {
  6729. org_id := c.GetAdminUserInfo().CurrentOrgId
  6730. orders, _ := service.GetNewHisOrderList(org_id)
  6731. c.ServeSuccessJSON(map[string]interface{}{
  6732. "order": orders,
  6733. })
  6734. return
  6735. }
  6736. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6737. newArr = make([]*models.HisOrderInfoTwo, 0)
  6738. for i := 0; i < len(arr); i++ {
  6739. repeat := false
  6740. for j := i + 1; j < len(arr); j++ {
  6741. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6742. repeat = true
  6743. break
  6744. }
  6745. }
  6746. if !repeat {
  6747. newArr = append(newArr, arr[i])
  6748. }
  6749. }
  6750. return
  6751. }
  6752. //修改处方退库操作 参数传修改之前的处方数据
  6753. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6754. if advice.ExecutionState == 1 {
  6755. //查询该病人该药品是否有库存记录
  6756. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6757. if errcode == gorm.ErrRecordNotFound {
  6758. } else {
  6759. //退库
  6760. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6761. if advice.PrescribingNumberUnit == drug.MinUnit {
  6762. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6763. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6764. //退库
  6765. warehouseInfo := models.DrugWarehouseInfo{
  6766. StockMinNumber: prescribingNumber,
  6767. }
  6768. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6769. operation_time := time.Now().Unix()
  6770. creater := advice.AdviceDoctor
  6771. ctime := time.Now().Unix()
  6772. timeStr := time.Now().Format("2006-01-02")
  6773. timeArr := strings.Split(timeStr, "-")
  6774. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6775. total = total + 1
  6776. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6777. cancelStock := models.DrugCancelStock{
  6778. OrderNumber: orderNumber,
  6779. OperaTime: operation_time,
  6780. OrgId: advice.UserOrgId,
  6781. Creater: creater,
  6782. Ctime: ctime,
  6783. Status: 1,
  6784. ReturnTime: advice.AdviceDate,
  6785. Dealer: info.Dealer,
  6786. Manufacturer: info.Manufacturer,
  6787. Type: 1,
  6788. }
  6789. service.AddSigleDrugCancelStock(&cancelStock)
  6790. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6791. dealer, _ := service.GetDealerById(info.Dealer)
  6792. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6793. cancelStockInfo := models.DrugCancelStockInfo{
  6794. OrderNumber: cancelInfo.OrderNumber,
  6795. CancelStockId: cancelInfo.ID,
  6796. DrugId: info.DrugId,
  6797. Count: info.Count,
  6798. Status: 1,
  6799. Ctime: ctime,
  6800. OrgId: advice.UserOrgId,
  6801. Type: 1,
  6802. Manufacturer: manufactureName.ManufacturerName,
  6803. Dealer: dealer.DealerName,
  6804. Total: 0,
  6805. RetailPrice: info.RetailPrice,
  6806. RetailTotalPrice: info.RetailTotalPrice,
  6807. Price: info.Price,
  6808. RegisterAccount: "",
  6809. Remark: info.Remark,
  6810. BatchNumber: info.BatchNumber,
  6811. MaxUnit: info.CountUnit,
  6812. ProductDate: info.ProductDate,
  6813. ExpiryDate: info.ExpiryDate,
  6814. BatchNumberId: info.WarehouseInfoId,
  6815. }
  6816. flow := models.DrugFlow{
  6817. WarehousingId: 0,
  6818. DrugId: info.DrugId,
  6819. Number: "",
  6820. BatchNumber: info.BatchNumber,
  6821. Count: info.Count,
  6822. UserOrgId: advice.UserOrgId,
  6823. PatientId: 0,
  6824. SystemTime: ctime,
  6825. ConsumableType: 4,
  6826. IsSys: 0,
  6827. WarehousingOrder: "",
  6828. WarehouseOutId: 0,
  6829. WarehouseOutOrderNumber: "",
  6830. IsEdit: 0,
  6831. CancelStockId: cancelStock.ID,
  6832. CancelOrderNumber: cancelStock.OrderNumber,
  6833. Manufacturer: info.Manufacturer,
  6834. Dealer: info.Dealer,
  6835. Creator: advice.UserOrgId,
  6836. UpdateCreator: 0,
  6837. Status: 1,
  6838. Ctime: time.Now().Unix(),
  6839. Mtime: 0,
  6840. Price: info.Price,
  6841. WarehousingDetailId: 0,
  6842. WarehouseOutDetailId: 0,
  6843. CancelOutDetailId: 0,
  6844. ExpireDate: info.ExpiryDate,
  6845. ProductDate: info.ProductDate,
  6846. MaxUnit: info.CountUnit,
  6847. MinUnit: "",
  6848. }
  6849. service.CreatedCancelStock(cancelStockInfo)
  6850. service.CreateDrugFlowOne(flow)
  6851. } else {
  6852. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6853. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6854. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6855. warehouseInfo := models.DrugWarehouseInfo{
  6856. StockMinNumber: prescribingNumber,
  6857. }
  6858. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6859. }
  6860. operation_time := time.Now().Unix()
  6861. creater := advice.AdviceDoctor
  6862. ctime := time.Now().Unix()
  6863. timeStr := time.Now().Format("2006-01-02")
  6864. timeArr := strings.Split(timeStr, "-")
  6865. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6866. total = total + 1
  6867. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6868. cancelStock := models.DrugCancelStock{
  6869. OrderNumber: orderNumber,
  6870. OperaTime: operation_time,
  6871. OrgId: advice.UserOrgId,
  6872. Creater: creater,
  6873. Ctime: ctime,
  6874. Status: 1,
  6875. ReturnTime: advice.AdviceDate,
  6876. Dealer: info.Dealer,
  6877. Manufacturer: info.Manufacturer,
  6878. Type: 1,
  6879. }
  6880. service.AddSigleDrugCancelStock(&cancelStock)
  6881. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6882. dealer, _ := service.GetDealerById(info.Dealer)
  6883. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6884. cancelStockInfo := models.DrugCancelStockInfo{
  6885. OrderNumber: cancelInfo.OrderNumber,
  6886. CancelStockId: cancelInfo.ID,
  6887. DrugId: info.DrugId,
  6888. Count: info.Count,
  6889. Status: 1,
  6890. Ctime: ctime,
  6891. OrgId: advice.UserOrgId,
  6892. Type: 1,
  6893. Manufacturer: manufactureName.ManufacturerName,
  6894. Dealer: dealer.DealerName,
  6895. Total: 0,
  6896. RetailPrice: info.RetailPrice,
  6897. RetailTotalPrice: info.RetailTotalPrice,
  6898. Price: info.Price,
  6899. RegisterAccount: "",
  6900. Remark: info.Remark,
  6901. BatchNumber: info.BatchNumber,
  6902. MaxUnit: info.CountUnit,
  6903. ProductDate: info.ProductDate,
  6904. ExpiryDate: info.ExpiryDate,
  6905. BatchNumberId: info.WarehouseInfoId,
  6906. }
  6907. flow := models.DrugFlow{
  6908. WarehousingId: 0,
  6909. DrugId: info.DrugId,
  6910. Number: "",
  6911. BatchNumber: info.BatchNumber,
  6912. Count: info.Count,
  6913. UserOrgId: advice.UserOrgId,
  6914. PatientId: 0,
  6915. SystemTime: ctime,
  6916. ConsumableType: 4,
  6917. IsSys: 0,
  6918. WarehousingOrder: "",
  6919. WarehouseOutId: 0,
  6920. WarehouseOutOrderNumber: "",
  6921. IsEdit: 0,
  6922. CancelStockId: cancelStock.ID,
  6923. CancelOrderNumber: cancelStock.OrderNumber,
  6924. Manufacturer: info.Manufacturer,
  6925. Dealer: info.Dealer,
  6926. Creator: advice.AdviceDoctor,
  6927. UpdateCreator: 0,
  6928. Status: 1,
  6929. Ctime: time.Now().Unix(),
  6930. Mtime: 0,
  6931. Price: info.Price,
  6932. WarehousingDetailId: 0,
  6933. WarehouseOutDetailId: 0,
  6934. CancelOutDetailId: 0,
  6935. ExpireDate: info.ExpiryDate,
  6936. ProductDate: info.ProductDate,
  6937. MaxUnit: info.CountUnit,
  6938. MinUnit: "",
  6939. }
  6940. service.CreatedCancelStock(cancelStockInfo)
  6941. service.CreateDrugFlowOne(flow)
  6942. }
  6943. }
  6944. }
  6945. return err
  6946. }
  6947. func (this *HisApiController) DeleteNCDS() {
  6948. id, _ := this.GetInt64("id", 0)
  6949. if id > 0 {
  6950. service.DeletePsnNCDSRecordById(id)
  6951. this.ServeSuccessJSON(map[string]interface{}{
  6952. "msg": "删除成功",
  6953. })
  6954. } else {
  6955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6956. return
  6957. }
  6958. }
  6959. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6960. id, _ := c.GetInt64("id")
  6961. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6962. c.ServeSuccessJSON(map[string]interface{}{
  6963. "advice": advice,
  6964. })
  6965. return
  6966. }
  6967. func (c *HisApiController) GetHisMonthChargePatientList() {
  6968. record_date := c.GetString("record_date")
  6969. start_time := c.GetString("start_time")
  6970. end_time := c.GetString("end_time")
  6971. timeLayout := "2006-01-02"
  6972. loc, _ := time.LoadLocation("Local")
  6973. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6974. if err != nil {
  6975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6976. return
  6977. }
  6978. if err != nil {
  6979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6980. return
  6981. }
  6982. recordDateTime := theTime.Unix()
  6983. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6984. if err != nil {
  6985. }
  6986. startRecordDateTime := startTime.Unix()
  6987. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6988. if err != nil {
  6989. }
  6990. endRecordDateTime := endTime.Unix()
  6991. adminInfo := c.GetAdminUserInfo()
  6992. var tempMonthChargePatients []*service.MonthChargePatients
  6993. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6994. for _, item := range tempPatients {
  6995. //过滤没有处方的
  6996. if len(item.HisPrescription) == 0 {
  6997. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6998. }
  6999. }
  7000. c.ServeSuccessJSON(map[string]interface{}{
  7001. "list": tempMonthChargePatients,
  7002. })
  7003. }