his_api_controller.go 308KB

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