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