his_api_controller.go 292KB

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