his_api_controller.go 289KB

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