his_api_controller.go 212KB

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