his_api_controller.go 320KB

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