his_api_controller.go 190KB

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