his_api_controller.go 243KB

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