his_api_controller.go 192KB

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