dialysis_api_controller.go 222KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  41. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  42. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  43. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  44. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  45. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  46. }
  47. func (c *DialysisApiController) PostPrescription() {
  48. patient, _ := c.GetInt64("patient", 0)
  49. recordDateStr := c.GetString("record_date")
  50. if patient <= 0 {
  51. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  52. return
  53. }
  54. adminUserInfo := c.GetAdminUserInfo()
  55. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  56. if patientInfo.ID == 0 {
  57. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  58. return
  59. }
  60. if len(recordDateStr) == 0 {
  61. recordDateStr = time.Now().Format("2006-01-02")
  62. }
  63. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  64. if parseDateErr != nil {
  65. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  66. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  67. return
  68. }
  69. mode_id, _ := c.GetInt64("mode_id", 0)
  70. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  71. dialyzer, _ := c.GetInt64("dialyzer", 0)
  72. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  73. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  74. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  75. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  76. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  77. replacement_way, _ := c.GetInt64("replacement_way", 0)
  78. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  79. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  80. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  81. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  82. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  83. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  84. kalium, _ := c.GetFloat("kalium", 0)
  85. sodium, _ := c.GetFloat("sodium", 0)
  86. replacement_total, _ := c.GetFloat("replacement_total", 0)
  87. calcium, _ := c.GetFloat("calcium", 0)
  88. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  89. glucose, _ := c.GetFloat("glucose", 0)
  90. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  91. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  92. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  93. conductivity, _ := c.GetFloat("conductivity", 0)
  94. remark := c.GetString("remark")
  95. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  96. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  97. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  98. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  99. body_fluid, _ := c.GetInt64("body_fluid", 0)
  100. special_medicine, _ := c.GetInt64("special_medicine", 0)
  101. special_medicine_other := c.GetString("special_medicine_other")
  102. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  103. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  104. blood_access, _ := c.GetInt64("blood_access", 0)
  105. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  106. body_fluid_other := c.GetString("body_fluid_other")
  107. target_ktv, _ := c.GetFloat("target_ktv", 0)
  108. niprocart, _ := c.GetInt64("niprocart", 0)
  109. jms, _ := c.GetInt64("jms", 0)
  110. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  111. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  112. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  113. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  114. filtryzer, _ := c.GetInt64("filtryzer", 0)
  115. dialyzers, _ := c.GetInt64("dialyzers", 0)
  116. injector, _ := c.GetInt64("injector", 0)
  117. bloodlines, _ := c.GetInt64("bloodlines", 0)
  118. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  119. safe_package, _ := c.GetInt64("package", 0)
  120. a_liquid, _ := c.GetInt64("a_liquid", 0)
  121. var prescription_doctor int64
  122. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  123. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  124. //if template.TemplateId == 2 || template.TemplateId == 6 {
  125. // if appRole.UserType == 3 {
  126. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  127. // if getPermissionErr != nil {
  128. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  129. // return
  130. // } else if headNursePermission == nil {
  131. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  132. // return
  133. // }
  134. // }
  135. //}
  136. if appRole.UserType == 2 || appRole.UserType == 1 {
  137. prescription_doctor = appRole.AdminUserId
  138. } else {
  139. prescription_doctor = 0
  140. }
  141. prescription := models.DialysisPrescription{
  142. UserOrgId: adminUserInfo.CurrentOrgId,
  143. PatientId: patient,
  144. RecordDate: recordDate.Unix(),
  145. ModeId: mode_id,
  146. DialysisDuration: dialysis_duration,
  147. Dialyzer: dialyzer,
  148. ReplacementTotal: replacement_total,
  149. PerfusionApparatus: perfusion_apparatus,
  150. BloodFlowVolume: blood_flow_volume,
  151. DewaterAmount: dewater_amount,
  152. DisplaceLiqui: displace_liqui,
  153. ReplacementWay: replacement_way,
  154. Anticoagulant: anticoagulant,
  155. AnticoagulantShouji: anticoagulant_shouji,
  156. AnticoagulantWeichi: anticoagulant_weichi,
  157. AnticoagulantZongliang: anticoagulant_zongliang,
  158. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  159. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  160. Kalium: kalium,
  161. Sodium: sodium,
  162. Calcium: calcium,
  163. Bicarbonate: bicarbonate,
  164. Glucose: glucose,
  165. // DryWeight: dry_weight,
  166. DialysateFlow: dialysate_flow,
  167. DialysateTemperature: dialysate_temperature,
  168. Conductivity: conductivity,
  169. Remark: remark,
  170. PrescriptionDoctor: prescription_doctor,
  171. Status: 1,
  172. CreatedTime: time.Now().Unix(),
  173. UpdatedTime: time.Now().Unix(),
  174. DialysisDurationMinute: dialysisDurationMinute,
  175. DialysisDurationHour: dialysisDurationHour,
  176. TargetUltrafiltration: targetUltrafiltration,
  177. DialysateFormulation: dialysateFormulation,
  178. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  179. BodyFluid: body_fluid,
  180. SpecialMedicine: special_medicine,
  181. SpecialMedicineOther: special_medicine_other,
  182. DisplaceLiquiPart: displace_liqui_part,
  183. DisplaceLiquiValue: displace_liqui_value,
  184. BloodAccess: blood_access,
  185. Ultrafiltration: ultrafiltration,
  186. BodyFluidOther: body_fluid_other,
  187. TargetKtv: target_ktv,
  188. Niprocart: niprocart,
  189. Jms: jms,
  190. FistulaNeedleSet: fistula_needle_set,
  191. FistulaNeedleSet16: fistula_needle_set_16,
  192. Hemoperfusion: hemoperfusion,
  193. DialyserSterilised: dialyser_sterilised,
  194. Filtryzer: filtryzer,
  195. Dialyzers: dialyzers,
  196. Injector: injector,
  197. Bloodlines: bloodlines,
  198. TubingHemodialysis: tubing_hemodialysis,
  199. Package: safe_package,
  200. ALiquid: a_liquid,
  201. }
  202. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  203. if dialysisPrescription.ID == 0 { //新增
  204. if mode_id > 0 {
  205. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  206. }
  207. prescription.Creater = adminUserInfo.AdminUser.Id
  208. err := service.AddSigleRecord(&prescription)
  209. if err == nil {
  210. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  211. if updateErr != nil {
  212. utils.ErrorLog("%v", updateErr)
  213. }
  214. c.ServeSuccessJSON(map[string]interface{}{
  215. "prescription": &prescription,
  216. })
  217. } else {
  218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  219. }
  220. } else { //修改
  221. if mode_id > 0 {
  222. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  223. }
  224. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  225. //if template.TemplateId == 1 {
  226. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  227. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  228. // if getPermissionErr != nil {
  229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  230. // return
  231. // } else if headNursePermission == nil {
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  233. // return
  234. // }
  235. // }
  236. //}
  237. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  238. if record.IsOpen == 1 {
  239. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  240. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  241. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  242. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  243. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  244. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  245. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  246. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  247. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  248. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  249. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  250. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  251. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  252. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  253. if err == nil {
  254. if order.ID > 0 {
  255. if dialysisPrescription.Niprocart != niprocart {
  256. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  257. //1.用上机透析日期查出当天的订单
  258. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  259. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  260. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  261. //判断前端更改后的商品id的出库记录在数据库中是否存在
  262. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  263. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  264. warehouseOutInfo := &models.WarehouseOutInfo{
  265. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  266. WarehouseOutId: out.ID,
  267. Count: 1,
  268. Status: 1,
  269. Ctime: time.Now().Unix(),
  270. Remark: "",
  271. OrgId: adminUserInfo.CurrentOrgId,
  272. Type: 1,
  273. Manufacturer: 0,
  274. Dealer: 0,
  275. IsSys: 1,
  276. SysRecordTime: order.StartTime,
  277. }
  278. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  279. warehouseOutInfo.Price = stockInInfo.Price
  280. warehouseOutInfo.GoodId = niprocart
  281. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  282. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  283. if err == nil {
  284. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  285. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  286. if err == gorm.ErrRecordNotFound {
  287. details := &models.AutomaticReduceDetail{
  288. WarehouseOutId: warehouseOutInfo.ID,
  289. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  290. PatientId: patient,
  291. Ctime: time.Now().Unix(),
  292. Mtime: time.Now().Unix(),
  293. Status: 1,
  294. RecordTime: order.StartTime,
  295. OrgId: adminUserInfo.CurrentOrgId,
  296. GoodId: niprocart,
  297. GoodTypeId: niprocart_good_type_id,
  298. }
  299. service.AddSigleAutoReduceRecordInfo(details)
  300. } else if err == nil {
  301. if user.ID > 0 {
  302. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  303. }
  304. }
  305. }
  306. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  307. if newOut.ID > 0 {
  308. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  309. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  310. if err == gorm.ErrRecordNotFound {
  311. details := &models.AutomaticReduceDetail{
  312. WarehouseOutId: newOut.ID,
  313. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  314. PatientId: patient,
  315. Ctime: time.Now().Unix(),
  316. Mtime: time.Now().Unix(),
  317. Status: 1,
  318. RecordTime: order.StartTime,
  319. OrgId: adminUserInfo.CurrentOrgId,
  320. GoodId: niprocart,
  321. GoodTypeId: niprocart_good_type_id,
  322. }
  323. service.AddSigleAutoReduceRecordInfo(details)
  324. } else if err == nil {
  325. if user.ID > 0 {
  326. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  327. }
  328. }
  329. }
  330. }
  331. }
  332. if dialysisPrescription.Jms != jms {
  333. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  334. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  335. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  336. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  337. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  338. //判断前端更改后的商品id的出库记录在数据库中是否存在
  339. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  340. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  341. warehouseOutInfo := &models.WarehouseOutInfo{
  342. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  343. WarehouseOutId: out.ID,
  344. Count: 1,
  345. Status: 1,
  346. Ctime: time.Now().Unix(),
  347. Remark: "",
  348. OrgId: adminUserInfo.CurrentOrgId,
  349. Type: 1,
  350. Manufacturer: 0,
  351. Dealer: 0,
  352. IsSys: 1,
  353. SysRecordTime: order.StartTime,
  354. }
  355. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  356. warehouseOutInfo.Price = stockInInfo.Price
  357. warehouseOutInfo.GoodId = jms
  358. warehouseOutInfo.GoodTypeId = jms_good_type_id
  359. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  360. if err == nil {
  361. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  362. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  363. if err == gorm.ErrRecordNotFound {
  364. details := &models.AutomaticReduceDetail{
  365. WarehouseOutId: warehouseOutInfo.ID,
  366. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  367. PatientId: patient,
  368. Ctime: time.Now().Unix(),
  369. Mtime: time.Now().Unix(),
  370. Status: 1,
  371. RecordTime: order.StartTime,
  372. OrgId: adminUserInfo.CurrentOrgId,
  373. GoodId: jms,
  374. GoodTypeId: jms_good_type_id,
  375. }
  376. service.AddSigleAutoReduceRecordInfo(details)
  377. } else if err == nil {
  378. if user.ID > 0 {
  379. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  380. }
  381. }
  382. }
  383. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  384. if newOut.ID > 0 {
  385. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  386. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  387. if err == gorm.ErrRecordNotFound {
  388. details := &models.AutomaticReduceDetail{
  389. WarehouseOutId: newOut.ID,
  390. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  391. PatientId: patient,
  392. Ctime: time.Now().Unix(),
  393. Mtime: time.Now().Unix(),
  394. Status: 1,
  395. RecordTime: order.StartTime,
  396. OrgId: adminUserInfo.CurrentOrgId,
  397. GoodId: jms,
  398. GoodTypeId: jms_good_type_id,
  399. }
  400. service.AddSigleAutoReduceRecordInfo(details)
  401. } else if err == nil {
  402. if user.ID > 0 {
  403. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  404. }
  405. }
  406. }
  407. }
  408. }
  409. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  410. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  411. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  412. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  413. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  414. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  415. //判断前端更改后的商品id的出库记录在数据库中是否存在
  416. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  417. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  418. warehouseOutInfo := &models.WarehouseOutInfo{
  419. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  420. WarehouseOutId: out.ID,
  421. Count: 1,
  422. Status: 1,
  423. Ctime: time.Now().Unix(),
  424. Remark: "",
  425. OrgId: adminUserInfo.CurrentOrgId,
  426. Type: 1,
  427. Manufacturer: 0,
  428. Dealer: 0,
  429. IsSys: 1,
  430. SysRecordTime: order.StartTime,
  431. }
  432. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  433. warehouseOutInfo.Price = stockInInfo.Price
  434. warehouseOutInfo.GoodId = fistula_needle_set
  435. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  436. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  437. if err == nil {
  438. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  439. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  440. if err == gorm.ErrRecordNotFound {
  441. details := &models.AutomaticReduceDetail{
  442. WarehouseOutId: warehouseOutInfo.ID,
  443. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  444. PatientId: patient,
  445. Ctime: time.Now().Unix(),
  446. Mtime: time.Now().Unix(),
  447. Status: 1,
  448. RecordTime: order.StartTime,
  449. OrgId: adminUserInfo.CurrentOrgId,
  450. GoodId: fistula_needle_set,
  451. GoodTypeId: fistula_needle_set_good_type_id,
  452. }
  453. service.AddSigleAutoReduceRecordInfo(details)
  454. } else if err == nil {
  455. if user.ID > 0 {
  456. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  457. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  458. }
  459. }
  460. }
  461. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  462. if newOut.ID > 0 {
  463. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  464. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  465. if err == gorm.ErrRecordNotFound {
  466. details := &models.AutomaticReduceDetail{
  467. WarehouseOutId: newOut.ID,
  468. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  469. PatientId: patient,
  470. Ctime: time.Now().Unix(),
  471. Mtime: time.Now().Unix(),
  472. Status: 1,
  473. RecordTime: order.StartTime,
  474. OrgId: adminUserInfo.CurrentOrgId,
  475. GoodId: fistula_needle_set,
  476. GoodTypeId: fistula_needle_set_good_type_id,
  477. }
  478. service.AddSigleAutoReduceRecordInfo(details)
  479. } else if err == nil {
  480. if user.ID > 0 {
  481. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  482. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  483. }
  484. }
  485. }
  486. }
  487. }
  488. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  489. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  490. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  491. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  492. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  493. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  494. //判断前端更改后的商品id的出库记录在数据库中是否存在
  495. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  496. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  497. warehouseOutInfo := &models.WarehouseOutInfo{
  498. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  499. WarehouseOutId: out.ID,
  500. Count: 1,
  501. Status: 1,
  502. Ctime: time.Now().Unix(),
  503. Remark: "",
  504. OrgId: adminUserInfo.CurrentOrgId,
  505. Type: 1,
  506. Manufacturer: 0,
  507. Dealer: 0,
  508. IsSys: 1,
  509. SysRecordTime: order.StartTime,
  510. }
  511. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  512. warehouseOutInfo.Price = stockInInfo.Price
  513. warehouseOutInfo.GoodId = fistula_needle_set_16
  514. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  515. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  516. if err == nil {
  517. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  518. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  519. if err == gorm.ErrRecordNotFound {
  520. details := &models.AutomaticReduceDetail{
  521. WarehouseOutId: warehouseOutInfo.ID,
  522. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  523. PatientId: patient,
  524. Ctime: time.Now().Unix(),
  525. Mtime: time.Now().Unix(),
  526. Status: 1,
  527. RecordTime: order.StartTime,
  528. OrgId: adminUserInfo.CurrentOrgId,
  529. GoodId: fistula_needle_set_16,
  530. GoodTypeId: fistula_needle_set_16_good_type_id,
  531. }
  532. service.AddSigleAutoReduceRecordInfo(details)
  533. } else if err == nil {
  534. if user.ID > 0 {
  535. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  536. }
  537. }
  538. }
  539. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  540. if newOut.ID > 0 {
  541. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  542. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  543. if err == gorm.ErrRecordNotFound {
  544. details := &models.AutomaticReduceDetail{
  545. WarehouseOutId: newOut.ID,
  546. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  547. PatientId: patient,
  548. Ctime: time.Now().Unix(),
  549. Mtime: time.Now().Unix(),
  550. Status: 1,
  551. RecordTime: order.StartTime,
  552. OrgId: adminUserInfo.CurrentOrgId,
  553. GoodId: fistula_needle_set_16,
  554. GoodTypeId: fistula_needle_set_16_good_type_id,
  555. }
  556. service.AddSigleAutoReduceRecordInfo(details)
  557. } else if err == nil {
  558. if user.ID > 0 {
  559. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  560. }
  561. }
  562. }
  563. }
  564. }
  565. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  566. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  567. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  568. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  569. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  570. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  571. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  572. //判断前端更改后的商品id的出库记录在数据库中是否存在
  573. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  574. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  575. warehouseOutInfo := &models.WarehouseOutInfo{
  576. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  577. WarehouseOutId: out.ID,
  578. Count: 1,
  579. Status: 1,
  580. Ctime: time.Now().Unix(),
  581. Remark: "",
  582. OrgId: adminUserInfo.CurrentOrgId,
  583. Type: 1,
  584. Manufacturer: 0,
  585. Dealer: 0,
  586. IsSys: 1,
  587. SysRecordTime: order.StartTime,
  588. }
  589. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  590. warehouseOutInfo.Price = stockInInfo.Price
  591. warehouseOutInfo.GoodId = hemoperfusion
  592. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  593. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  594. if err == nil {
  595. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  596. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  597. if err == gorm.ErrRecordNotFound {
  598. details := &models.AutomaticReduceDetail{
  599. WarehouseOutId: warehouseOutInfo.ID,
  600. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  601. PatientId: patient,
  602. Ctime: time.Now().Unix(),
  603. Mtime: time.Now().Unix(),
  604. Status: 1,
  605. RecordTime: order.StartTime,
  606. OrgId: adminUserInfo.CurrentOrgId,
  607. GoodId: hemoperfusion,
  608. GoodTypeId: hemoperfusion_good_type_id,
  609. }
  610. service.AddSigleAutoReduceRecordInfo(details)
  611. } else if err == nil {
  612. if user.ID > 0 {
  613. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  614. }
  615. }
  616. }
  617. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  618. if newOut.ID > 0 {
  619. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  620. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  621. if err == gorm.ErrRecordNotFound {
  622. details := &models.AutomaticReduceDetail{
  623. WarehouseOutId: newOut.ID,
  624. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  625. PatientId: patient,
  626. Ctime: time.Now().Unix(),
  627. Mtime: time.Now().Unix(),
  628. Status: 1,
  629. RecordTime: order.StartTime,
  630. OrgId: adminUserInfo.CurrentOrgId,
  631. GoodId: hemoperfusion,
  632. GoodTypeId: hemoperfusion_good_type_id,
  633. }
  634. service.AddSigleAutoReduceRecordInfo(details)
  635. } else if err == nil {
  636. if user.ID > 0 {
  637. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  638. }
  639. }
  640. }
  641. }
  642. }
  643. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  644. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  645. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  646. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  647. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  648. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  649. //判断前端更改后的商品id的出库记录在数据库中是否存在
  650. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  651. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  652. warehouseOutInfo := &models.WarehouseOutInfo{
  653. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  654. WarehouseOutId: out.WarehouseOutId,
  655. Count: 1,
  656. Status: 1,
  657. Ctime: time.Now().Unix(),
  658. Remark: "",
  659. OrgId: adminUserInfo.CurrentOrgId,
  660. Type: 1,
  661. Manufacturer: 0,
  662. Dealer: 0,
  663. IsSys: 1,
  664. SysRecordTime: order.StartTime,
  665. }
  666. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  667. warehouseOutInfo.Price = stockInInfo.Price
  668. warehouseOutInfo.GoodId = dialyser_sterilised
  669. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  670. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  671. if err == nil {
  672. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  673. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  674. if err == gorm.ErrRecordNotFound {
  675. details := &models.AutomaticReduceDetail{
  676. WarehouseOutId: warehouseOutInfo.ID,
  677. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  678. PatientId: patient,
  679. Ctime: time.Now().Unix(),
  680. Mtime: time.Now().Unix(),
  681. Status: 1,
  682. RecordTime: order.StartTime,
  683. OrgId: adminUserInfo.CurrentOrgId,
  684. GoodId: dialyser_sterilised,
  685. GoodTypeId: dialyser_sterilised_good_type_id,
  686. }
  687. service.AddSigleAutoReduceRecordInfo(details)
  688. } else if err == nil {
  689. if user.ID > 0 {
  690. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  691. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  692. }
  693. }
  694. }
  695. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  696. if newOut.ID > 0 {
  697. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  698. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  699. if err == gorm.ErrRecordNotFound {
  700. details := &models.AutomaticReduceDetail{
  701. WarehouseOutId: newOut.ID,
  702. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  703. PatientId: patient,
  704. Ctime: time.Now().Unix(),
  705. Mtime: time.Now().Unix(),
  706. Status: 1,
  707. RecordTime: order.StartTime,
  708. OrgId: adminUserInfo.CurrentOrgId,
  709. GoodId: dialyser_sterilised,
  710. GoodTypeId: dialyser_sterilised_good_type_id,
  711. }
  712. service.AddSigleAutoReduceRecordInfo(details)
  713. } else if err == nil {
  714. if user.ID > 0 {
  715. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  716. }
  717. }
  718. }
  719. }
  720. }
  721. if dialysisPrescription.Filtryzer != filtryzer {
  722. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  723. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  724. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  725. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  726. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  727. //判断前端更改后的商品id的出库记录在数据库中是否存在
  728. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  729. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  730. warehouseOutInfo := &models.WarehouseOutInfo{
  731. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  732. WarehouseOutId: out.ID,
  733. Count: 1,
  734. Status: 1,
  735. Ctime: time.Now().Unix(),
  736. Remark: "",
  737. OrgId: adminUserInfo.CurrentOrgId,
  738. Type: 1,
  739. Manufacturer: 0,
  740. Dealer: 0,
  741. IsSys: 1,
  742. SysRecordTime: order.StartTime,
  743. }
  744. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  745. warehouseOutInfo.Price = stockInInfo.Price
  746. warehouseOutInfo.GoodId = filtryzer
  747. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  748. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  749. if err == nil {
  750. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  751. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  752. if err == gorm.ErrRecordNotFound {
  753. details := &models.AutomaticReduceDetail{
  754. WarehouseOutId: warehouseOutInfo.ID,
  755. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  756. PatientId: patient,
  757. Ctime: time.Now().Unix(),
  758. Mtime: time.Now().Unix(),
  759. Status: 1,
  760. RecordTime: order.StartTime,
  761. OrgId: adminUserInfo.CurrentOrgId,
  762. GoodId: filtryzer,
  763. GoodTypeId: filtryzer_good_type_id,
  764. }
  765. service.AddSigleAutoReduceRecordInfo(details)
  766. } else if err == nil {
  767. if user.ID > 0 {
  768. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  769. }
  770. }
  771. }
  772. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  773. if newOut.ID > 0 {
  774. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  775. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  776. if err == gorm.ErrRecordNotFound {
  777. details := &models.AutomaticReduceDetail{
  778. WarehouseOutId: newOut.ID,
  779. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  780. PatientId: patient,
  781. Ctime: time.Now().Unix(),
  782. Mtime: time.Now().Unix(),
  783. Status: 1,
  784. RecordTime: order.StartTime,
  785. OrgId: adminUserInfo.CurrentOrgId,
  786. GoodId: filtryzer,
  787. GoodTypeId: filtryzer_good_type_id,
  788. }
  789. service.AddSigleAutoReduceRecordInfo(details)
  790. } else if err == nil {
  791. if user.ID > 0 {
  792. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  793. }
  794. }
  795. }
  796. }
  797. }
  798. if dialysisPrescription.Dialyzers != dialyzers {
  799. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  800. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  801. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  802. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  803. //判断前端更改后的商品id的出库记录在数据库中是否存在
  804. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  805. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  806. warehouseOutInfo := &models.WarehouseOutInfo{
  807. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  808. WarehouseOutId: out.ID,
  809. Count: 1,
  810. Status: 1,
  811. Ctime: time.Now().Unix(),
  812. Remark: "",
  813. OrgId: adminUserInfo.CurrentOrgId,
  814. Type: 1,
  815. Manufacturer: 0,
  816. Dealer: 0,
  817. IsSys: 1,
  818. SysRecordTime: order.StartTime,
  819. }
  820. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  821. warehouseOutInfo.Price = stockInInfo.Price
  822. warehouseOutInfo.GoodId = dialyzers
  823. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  824. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  825. if err == nil {
  826. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  827. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  828. if err == gorm.ErrRecordNotFound {
  829. details := &models.AutomaticReduceDetail{
  830. WarehouseOutId: warehouseOutInfo.ID,
  831. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  832. PatientId: patient,
  833. Ctime: time.Now().Unix(),
  834. Mtime: time.Now().Unix(),
  835. Status: 1,
  836. RecordTime: order.StartTime,
  837. OrgId: adminUserInfo.CurrentOrgId,
  838. GoodId: dialyzers,
  839. GoodTypeId: dialyzers_good_type_id,
  840. }
  841. service.AddSigleAutoReduceRecordInfo(details)
  842. } else if err == nil {
  843. if user.ID > 0 {
  844. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  845. }
  846. }
  847. }
  848. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  849. if newOut.ID > 0 {
  850. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  851. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  852. if err == gorm.ErrRecordNotFound {
  853. details := &models.AutomaticReduceDetail{
  854. WarehouseOutId: newOut.ID,
  855. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  856. PatientId: patient,
  857. Ctime: time.Now().Unix(),
  858. Mtime: time.Now().Unix(),
  859. Status: 1,
  860. RecordTime: order.StartTime,
  861. OrgId: adminUserInfo.CurrentOrgId,
  862. GoodId: dialyzers,
  863. GoodTypeId: dialyzers_good_type_id,
  864. }
  865. service.AddSigleAutoReduceRecordInfo(details)
  866. } else if err == nil {
  867. if user.ID > 0 {
  868. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  869. }
  870. }
  871. }
  872. }
  873. }
  874. if dialysisPrescription.Injector != injector {
  875. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  876. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  877. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  878. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  879. //判断前端更改后的商品id的出库记录在数据库中是否存在
  880. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  881. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  882. warehouseOutInfo := &models.WarehouseOutInfo{
  883. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  884. WarehouseOutId: out.ID,
  885. Count: 1,
  886. Status: 1,
  887. Ctime: time.Now().Unix(),
  888. Remark: "",
  889. OrgId: adminUserInfo.CurrentOrgId,
  890. Type: 1,
  891. Manufacturer: 0,
  892. Dealer: 0,
  893. IsSys: 1,
  894. SysRecordTime: order.StartTime,
  895. }
  896. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  897. warehouseOutInfo.Price = stockInInfo.Price
  898. warehouseOutInfo.GoodId = injector
  899. warehouseOutInfo.GoodTypeId = injector_good_type_id
  900. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  901. if err == nil {
  902. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  903. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  904. if err == gorm.ErrRecordNotFound {
  905. details := &models.AutomaticReduceDetail{
  906. WarehouseOutId: warehouseOutInfo.ID,
  907. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  908. PatientId: patient,
  909. Ctime: time.Now().Unix(),
  910. Mtime: time.Now().Unix(),
  911. Status: 1,
  912. RecordTime: order.StartTime,
  913. OrgId: adminUserInfo.CurrentOrgId,
  914. GoodId: injector,
  915. GoodTypeId: injector_good_type_id,
  916. }
  917. service.AddSigleAutoReduceRecordInfo(details)
  918. } else if err == nil {
  919. if user.ID > 0 {
  920. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  921. }
  922. }
  923. }
  924. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  925. if newOut.ID > 0 {
  926. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  927. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  928. if err == gorm.ErrRecordNotFound {
  929. details := &models.AutomaticReduceDetail{
  930. WarehouseOutId: newOut.ID,
  931. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  932. PatientId: patient,
  933. Ctime: time.Now().Unix(),
  934. Mtime: time.Now().Unix(),
  935. Status: 1,
  936. RecordTime: order.StartTime,
  937. OrgId: adminUserInfo.CurrentOrgId,
  938. GoodId: injector,
  939. GoodTypeId: injector_good_type_id,
  940. }
  941. service.AddSigleAutoReduceRecordInfo(details)
  942. } else if err == nil {
  943. if user.ID > 0 {
  944. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  945. }
  946. }
  947. }
  948. }
  949. }
  950. if dialysisPrescription.Bloodlines != bloodlines {
  951. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  952. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  953. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  954. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  955. //判断前端更改后的商品id的出库记录在数据库中是否存在
  956. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  957. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  958. warehouseOutInfo := &models.WarehouseOutInfo{
  959. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  960. WarehouseOutId: out.ID,
  961. Count: 1,
  962. Status: 1,
  963. Ctime: time.Now().Unix(),
  964. Remark: "",
  965. OrgId: adminUserInfo.CurrentOrgId,
  966. Type: 1,
  967. Manufacturer: 0,
  968. Dealer: 0,
  969. IsSys: 1,
  970. SysRecordTime: order.StartTime,
  971. }
  972. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  973. warehouseOutInfo.Price = stockInInfo.Price
  974. warehouseOutInfo.GoodId = bloodlines
  975. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  976. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  977. if err == nil {
  978. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  979. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  980. if err == gorm.ErrRecordNotFound {
  981. details := &models.AutomaticReduceDetail{
  982. WarehouseOutId: warehouseOutInfo.ID,
  983. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  984. PatientId: patient,
  985. Ctime: time.Now().Unix(),
  986. Mtime: time.Now().Unix(),
  987. Status: 1,
  988. RecordTime: order.StartTime,
  989. OrgId: adminUserInfo.CurrentOrgId,
  990. GoodId: bloodlines,
  991. GoodTypeId: bloodlines_good_type_id,
  992. }
  993. service.AddSigleAutoReduceRecordInfo(details)
  994. } else if err == nil {
  995. if user.ID > 0 {
  996. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  997. }
  998. }
  999. }
  1000. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1001. if newOut.ID > 0 {
  1002. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1003. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1004. if err == gorm.ErrRecordNotFound {
  1005. details := &models.AutomaticReduceDetail{
  1006. WarehouseOutId: newOut.ID,
  1007. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1008. PatientId: patient,
  1009. Ctime: time.Now().Unix(),
  1010. Mtime: time.Now().Unix(),
  1011. Status: 1,
  1012. RecordTime: order.StartTime,
  1013. OrgId: adminUserInfo.CurrentOrgId,
  1014. GoodId: bloodlines,
  1015. GoodTypeId: bloodlines_good_type_id,
  1016. }
  1017. service.AddSigleAutoReduceRecordInfo(details)
  1018. } else if err == nil {
  1019. if user.ID > 0 {
  1020. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  1021. }
  1022. }
  1023. }
  1024. }
  1025. }
  1026. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1027. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1028. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1029. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1030. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1031. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1032. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1033. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1034. warehouseOutInfo := &models.WarehouseOutInfo{
  1035. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1036. WarehouseOutId: out.ID,
  1037. Count: 1,
  1038. Status: 1,
  1039. Ctime: time.Now().Unix(),
  1040. Remark: "",
  1041. OrgId: adminUserInfo.CurrentOrgId,
  1042. Type: 1,
  1043. Manufacturer: 0,
  1044. Dealer: 0,
  1045. IsSys: 1,
  1046. SysRecordTime: order.StartTime,
  1047. }
  1048. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  1049. warehouseOutInfo.Price = stockInInfo.Price
  1050. warehouseOutInfo.GoodId = tubing_hemodialysis
  1051. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1052. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1053. if err == nil {
  1054. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1055. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1056. if err == gorm.ErrRecordNotFound {
  1057. details := &models.AutomaticReduceDetail{
  1058. WarehouseOutId: warehouseOutInfo.ID,
  1059. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1060. PatientId: patient,
  1061. Ctime: time.Now().Unix(),
  1062. Mtime: time.Now().Unix(),
  1063. Status: 1,
  1064. RecordTime: order.StartTime,
  1065. OrgId: adminUserInfo.CurrentOrgId,
  1066. GoodId: tubing_hemodialysis,
  1067. GoodTypeId: tubingHemodialysis_good_type_id,
  1068. }
  1069. service.AddSigleAutoReduceRecordInfo(details)
  1070. } else if err == nil {
  1071. if user.ID > 0 {
  1072. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  1073. }
  1074. }
  1075. }
  1076. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1077. if newOut.ID > 0 {
  1078. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1079. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1080. if err == gorm.ErrRecordNotFound {
  1081. details := &models.AutomaticReduceDetail{
  1082. WarehouseOutId: newOut.ID,
  1083. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1084. PatientId: patient,
  1085. Ctime: time.Now().Unix(),
  1086. Mtime: time.Now().Unix(),
  1087. Status: 1,
  1088. RecordTime: order.StartTime,
  1089. OrgId: adminUserInfo.CurrentOrgId,
  1090. GoodId: tubing_hemodialysis,
  1091. GoodTypeId: tubingHemodialysis_good_type_id,
  1092. }
  1093. service.AddSigleAutoReduceRecordInfo(details)
  1094. } else if err == nil {
  1095. if user.ID > 0 {
  1096. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  1097. }
  1098. }
  1099. }
  1100. }
  1101. }
  1102. if dialysisPrescription.Package != safe_package {
  1103. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1104. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1105. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1106. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1107. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1108. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1109. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1110. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1111. warehouseOutInfo := &models.WarehouseOutInfo{
  1112. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1113. WarehouseOutId: out.ID,
  1114. Count: 1,
  1115. Status: 1,
  1116. Ctime: time.Now().Unix(),
  1117. Remark: "",
  1118. OrgId: adminUserInfo.CurrentOrgId,
  1119. Type: 1,
  1120. Manufacturer: 0,
  1121. Dealer: 0,
  1122. IsSys: 1,
  1123. SysRecordTime: order.StartTime,
  1124. }
  1125. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  1126. warehouseOutInfo.Price = stockInInfo.Price
  1127. warehouseOutInfo.GoodId = safe_package
  1128. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1129. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1130. if err == nil {
  1131. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1132. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1133. if err == gorm.ErrRecordNotFound {
  1134. details := &models.AutomaticReduceDetail{
  1135. WarehouseOutId: warehouseOutInfo.ID,
  1136. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1137. PatientId: patient,
  1138. Ctime: time.Now().Unix(),
  1139. Mtime: time.Now().Unix(),
  1140. Status: 1,
  1141. RecordTime: order.StartTime,
  1142. OrgId: adminUserInfo.CurrentOrgId,
  1143. GoodId: safe_package,
  1144. GoodTypeId: safe_package_good_type_id,
  1145. }
  1146. service.AddSigleAutoReduceRecordInfo(details)
  1147. } else if err == nil {
  1148. if user.ID > 0 {
  1149. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  1150. }
  1151. }
  1152. }
  1153. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1154. if newOut.ID > 0 {
  1155. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1156. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1157. if err == gorm.ErrRecordNotFound {
  1158. details := &models.AutomaticReduceDetail{
  1159. WarehouseOutId: newOut.ID,
  1160. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1161. PatientId: patient,
  1162. Ctime: time.Now().Unix(),
  1163. Mtime: time.Now().Unix(),
  1164. Status: 1,
  1165. RecordTime: order.StartTime,
  1166. OrgId: adminUserInfo.CurrentOrgId,
  1167. GoodId: safe_package,
  1168. GoodTypeId: safe_package_good_type_id,
  1169. }
  1170. service.AddSigleAutoReduceRecordInfo(details)
  1171. } else if err == nil {
  1172. if user.ID > 0 {
  1173. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. if dialysisPrescription.ALiquid != a_liquid {
  1180. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1181. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1182. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1183. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1184. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1185. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1186. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1187. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1188. warehouseOutInfo := &models.WarehouseOutInfo{
  1189. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1190. WarehouseOutId: out.ID,
  1191. Count: 1,
  1192. Status: 1,
  1193. Ctime: time.Now().Unix(),
  1194. Remark: "",
  1195. OrgId: adminUserInfo.CurrentOrgId,
  1196. Type: 1,
  1197. Manufacturer: 0,
  1198. Dealer: 0,
  1199. IsSys: 1,
  1200. SysRecordTime: order.StartTime,
  1201. }
  1202. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  1203. warehouseOutInfo.Price = stockInInfo.Price
  1204. warehouseOutInfo.GoodId = a_liquid
  1205. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1206. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1207. if err == nil {
  1208. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1209. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1210. if err == gorm.ErrRecordNotFound {
  1211. details := &models.AutomaticReduceDetail{
  1212. WarehouseOutId: warehouseOutInfo.ID,
  1213. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1214. PatientId: patient,
  1215. Ctime: time.Now().Unix(),
  1216. Mtime: time.Now().Unix(),
  1217. Status: 1,
  1218. RecordTime: order.StartTime,
  1219. OrgId: adminUserInfo.CurrentOrgId,
  1220. GoodId: a_liquid,
  1221. GoodTypeId: aliquid_good_type_id,
  1222. }
  1223. service.AddSigleAutoReduceRecordInfo(details)
  1224. } else if err == nil {
  1225. if user.ID > 0 {
  1226. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  1227. }
  1228. }
  1229. }
  1230. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1231. if newOut.ID > 0 {
  1232. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1233. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1234. if err == gorm.ErrRecordNotFound {
  1235. details := &models.AutomaticReduceDetail{
  1236. WarehouseOutId: newOut.ID,
  1237. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1238. PatientId: patient,
  1239. Ctime: time.Now().Unix(),
  1240. Mtime: time.Now().Unix(),
  1241. Status: 1,
  1242. RecordTime: order.StartTime,
  1243. OrgId: adminUserInfo.CurrentOrgId,
  1244. GoodId: a_liquid,
  1245. GoodTypeId: aliquid_good_type_id,
  1246. }
  1247. service.AddSigleAutoReduceRecordInfo(details)
  1248. } else if err == nil {
  1249. if user.ID > 0 {
  1250. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. if appRole.UserType == 2 || appRole.UserType == 1 {
  1260. prescription_doctor := adminUserInfo.AdminUser.Id
  1261. prescription.PrescriptionDoctor = prescription_doctor
  1262. }
  1263. if dialysisPrescription.Creater == 0 { //体重称
  1264. prescription.Creater = adminUserInfo.AdminUser.Id
  1265. } else {
  1266. prescription.Creater = dialysisPrescription.Creater
  1267. }
  1268. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1269. prescription.UpdatedTime = time.Now().Unix()
  1270. prescription.Modifier = adminUserInfo.AdminUser.Id
  1271. prescription.ID = dialysisPrescription.ID
  1272. updateErr := service.UpDateDialysisPrescription(&prescription)
  1273. if updateErr == nil {
  1274. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  1275. if updateErr != nil {
  1276. utils.ErrorLog("%v", updateErr)
  1277. }
  1278. c.ServeSuccessJSON(map[string]interface{}{
  1279. "prescription": &prescription,
  1280. })
  1281. } else {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1283. }
  1284. }
  1285. }
  1286. func (c *DialysisApiController) PostSoulution() {
  1287. patient, _ := c.GetInt64("patient", 0)
  1288. recordDateStr := c.GetString("record_date")
  1289. if patient <= 0 {
  1290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1291. return
  1292. }
  1293. adminUserInfo := c.GetAdminUserInfo()
  1294. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1295. if patientInfo.ID == 0 {
  1296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1297. return
  1298. }
  1299. if len(recordDateStr) == 0 {
  1300. recordDateStr = time.Now().Format("2006-01-02")
  1301. }
  1302. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1303. if parseDateErr != nil {
  1304. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. mode_id, _ := c.GetInt64("mode_id", 0)
  1309. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1310. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1311. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1312. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1313. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1314. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1315. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1316. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1317. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1318. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1319. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1320. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1321. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1322. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1323. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1324. kalium, _ := c.GetFloat("kalium", 0)
  1325. sodium, _ := c.GetFloat("sodium", 0)
  1326. calcium, _ := c.GetFloat("calcium", 0)
  1327. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1328. glucose, _ := c.GetFloat("glucose", 0)
  1329. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1330. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1331. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1332. conductivity, _ := c.GetFloat("conductivity", 0)
  1333. remark := c.GetString("remark")
  1334. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1335. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1336. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1337. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1338. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1339. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1340. special_medicine_other := c.GetString("special_medicine_other")
  1341. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1342. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1343. blood_access, _ := c.GetInt64("blood_access", 0)
  1344. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1345. body_fluid_other := c.GetString("body_fluid_other")
  1346. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1347. niprocart, _ := c.GetInt64("niprocart", 0)
  1348. jms, _ := c.GetInt64("jms", 0)
  1349. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1350. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1351. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1352. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1353. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1354. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1355. injector, _ := c.GetInt64("injector", 0)
  1356. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1357. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1358. safe_package, _ := c.GetInt64("package", 0)
  1359. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1360. var prescription_doctor int64
  1361. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1362. if appRole.UserType == 2 || appRole.UserType == 1 {
  1363. prescription_doctor = appRole.AdminUserId
  1364. } else {
  1365. prescription_doctor = 0
  1366. }
  1367. if mode_id > 0 {
  1368. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1369. }
  1370. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1371. //
  1372. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1373. // if appRole.UserType == 3 {
  1374. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1375. // if getPermissionErr != nil {
  1376. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1377. // return
  1378. // } else if headNursePermission == nil {
  1379. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1380. // return
  1381. // }
  1382. // }
  1383. //}
  1384. prescription := models.DialysisPrescription{
  1385. UserOrgId: adminUserInfo.CurrentOrgId,
  1386. PatientId: patient,
  1387. RecordDate: recordDate.Unix(),
  1388. ModeId: mode_id,
  1389. DialysisDuration: dialysis_duration,
  1390. Dialyzer: dialyzer,
  1391. PerfusionApparatus: perfusion_apparatus,
  1392. BloodFlowVolume: blood_flow_volume,
  1393. DewaterAmount: dewater_amount,
  1394. DisplaceLiqui: displace_liqui,
  1395. ReplacementWay: replacement_way,
  1396. Anticoagulant: anticoagulant,
  1397. AnticoagulantShouji: anticoagulant_shouji,
  1398. AnticoagulantWeichi: anticoagulant_weichi,
  1399. AnticoagulantZongliang: anticoagulant_zongliang,
  1400. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1401. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1402. Kalium: kalium,
  1403. Sodium: sodium,
  1404. Calcium: calcium,
  1405. Bicarbonate: bicarbonate,
  1406. Glucose: glucose,
  1407. // DryWeight: dry_weight,
  1408. DialysateFlow: dialysate_flow,
  1409. DialysateTemperature: dialysate_temperature,
  1410. Conductivity: conductivity,
  1411. Remark: remark,
  1412. PrescriptionDoctor: prescription_doctor,
  1413. Status: 1,
  1414. CreatedTime: time.Now().Unix(),
  1415. UpdatedTime: time.Now().Unix(),
  1416. DialysisDurationMinute: dialysisDurationMinute,
  1417. DialysisDurationHour: dialysisDurationHour,
  1418. TargetUltrafiltration: targetUltrafiltration,
  1419. DialysateFormulation: dialysateFormulation,
  1420. ReplacementTotal: replacement_total,
  1421. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1422. BodyFluid: body_fluid,
  1423. SpecialMedicine: special_medicine,
  1424. SpecialMedicineOther: special_medicine_other,
  1425. DisplaceLiquiPart: displace_liqui_part,
  1426. DisplaceLiquiValue: displace_liqui_value,
  1427. BloodAccess: blood_access,
  1428. Ultrafiltration: ultrafiltration,
  1429. BodyFluidOther: body_fluid_other,
  1430. TargetKtv: target_ktv,
  1431. Niprocart: niprocart,
  1432. Jms: jms,
  1433. FistulaNeedleSet: fistula_needle_set,
  1434. FistulaNeedleSet16: fistula_needle_set_16,
  1435. Hemoperfusion: hemoperfusion,
  1436. DialyserSterilised: dialyser_sterilised,
  1437. Filtryzer: filtryzer,
  1438. Dialyzers: dialyzers,
  1439. Injector: injector,
  1440. Bloodlines: bloodlines,
  1441. TubingHemodialysis: tubing_hemodialysis,
  1442. Package: safe_package,
  1443. ALiquid: a_liquid,
  1444. }
  1445. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1446. if dialysisPrescription.ID == 0 { //新增
  1447. prescription.Creater = adminUserInfo.AdminUser.Id
  1448. } else { //修改
  1449. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1450. //if template.TemplateId == 1 {
  1451. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1452. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1453. // if getPermissionErr != nil {
  1454. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1455. // return
  1456. // } else if headNursePermission == nil {
  1457. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1458. // return
  1459. // }
  1460. // }
  1461. //}
  1462. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1463. if record.IsOpen == 1 {
  1464. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1465. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1466. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1467. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1468. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1469. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1470. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1471. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1472. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1473. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1474. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1475. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1476. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1477. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1478. if err == nil {
  1479. if order.ID > 0 {
  1480. if dialysisPrescription.Niprocart != niprocart {
  1481. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1482. //1.用上机透析日期查出当天的订单
  1483. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1484. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1485. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1486. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1487. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1488. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1489. warehouseOutInfo := &models.WarehouseOutInfo{
  1490. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1491. WarehouseOutId: out.ID,
  1492. Count: 1,
  1493. Status: 1,
  1494. Ctime: time.Now().Unix(),
  1495. Remark: "",
  1496. OrgId: adminUserInfo.CurrentOrgId,
  1497. Type: 1,
  1498. Manufacturer: 0,
  1499. Dealer: 0,
  1500. IsSys: 1,
  1501. SysRecordTime: order.StartTime,
  1502. }
  1503. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  1504. warehouseOutInfo.Price = stockInInfo.Price
  1505. warehouseOutInfo.GoodId = niprocart
  1506. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1507. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1508. if err == nil {
  1509. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1510. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1511. if err == gorm.ErrRecordNotFound {
  1512. details := &models.AutomaticReduceDetail{
  1513. WarehouseOutId: warehouseOutInfo.ID,
  1514. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1515. PatientId: patient,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: time.Now().Unix(),
  1518. Status: 1,
  1519. RecordTime: order.StartTime,
  1520. OrgId: adminUserInfo.CurrentOrgId,
  1521. GoodId: niprocart,
  1522. GoodTypeId: niprocart_good_type_id,
  1523. }
  1524. service.AddSigleAutoReduceRecordInfo(details)
  1525. } else if err == nil {
  1526. if user.ID > 0 {
  1527. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  1528. }
  1529. }
  1530. }
  1531. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1532. if newOut.ID > 0 {
  1533. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1534. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1535. if err == gorm.ErrRecordNotFound {
  1536. details := &models.AutomaticReduceDetail{
  1537. WarehouseOutId: newOut.ID,
  1538. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1539. PatientId: patient,
  1540. Ctime: time.Now().Unix(),
  1541. Mtime: time.Now().Unix(),
  1542. Status: 1,
  1543. RecordTime: order.StartTime,
  1544. OrgId: adminUserInfo.CurrentOrgId,
  1545. GoodId: niprocart,
  1546. GoodTypeId: niprocart_good_type_id,
  1547. }
  1548. service.AddSigleAutoReduceRecordInfo(details)
  1549. } else if err == nil {
  1550. if user.ID > 0 {
  1551. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. if dialysisPrescription.Jms != jms {
  1558. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1559. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1560. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1561. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1562. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1563. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1564. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1565. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1566. warehouseOutInfo := &models.WarehouseOutInfo{
  1567. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1568. WarehouseOutId: out.ID,
  1569. Count: 1,
  1570. Status: 1,
  1571. Ctime: time.Now().Unix(),
  1572. Remark: "",
  1573. OrgId: adminUserInfo.CurrentOrgId,
  1574. Type: 1,
  1575. Manufacturer: 0,
  1576. Dealer: 0,
  1577. IsSys: 1,
  1578. SysRecordTime: order.StartTime,
  1579. }
  1580. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  1581. warehouseOutInfo.Price = stockInInfo.Price
  1582. warehouseOutInfo.GoodId = jms
  1583. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1584. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1585. if err == nil {
  1586. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1587. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1588. if err == gorm.ErrRecordNotFound {
  1589. details := &models.AutomaticReduceDetail{
  1590. WarehouseOutId: warehouseOutInfo.ID,
  1591. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1592. PatientId: patient,
  1593. Ctime: time.Now().Unix(),
  1594. Mtime: time.Now().Unix(),
  1595. Status: 1,
  1596. RecordTime: order.StartTime,
  1597. OrgId: adminUserInfo.CurrentOrgId,
  1598. GoodId: jms,
  1599. GoodTypeId: jms_good_type_id,
  1600. }
  1601. service.AddSigleAutoReduceRecordInfo(details)
  1602. } else if err == nil {
  1603. if user.ID > 0 {
  1604. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  1605. }
  1606. }
  1607. }
  1608. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1609. if newOut.ID > 0 {
  1610. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1611. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1612. if err == gorm.ErrRecordNotFound {
  1613. details := &models.AutomaticReduceDetail{
  1614. WarehouseOutId: newOut.ID,
  1615. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1616. PatientId: patient,
  1617. Ctime: time.Now().Unix(),
  1618. Mtime: time.Now().Unix(),
  1619. Status: 1,
  1620. RecordTime: order.StartTime,
  1621. OrgId: adminUserInfo.CurrentOrgId,
  1622. GoodId: jms,
  1623. GoodTypeId: jms_good_type_id,
  1624. }
  1625. service.AddSigleAutoReduceRecordInfo(details)
  1626. } else if err == nil {
  1627. if user.ID > 0 {
  1628. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  1629. }
  1630. }
  1631. }
  1632. }
  1633. }
  1634. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1635. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1636. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1637. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1638. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1639. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1640. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1641. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1642. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1643. warehouseOutInfo := &models.WarehouseOutInfo{
  1644. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1645. WarehouseOutId: out.ID,
  1646. Count: 1,
  1647. Status: 1,
  1648. Ctime: time.Now().Unix(),
  1649. Remark: "",
  1650. OrgId: adminUserInfo.CurrentOrgId,
  1651. Type: 1,
  1652. Manufacturer: 0,
  1653. Dealer: 0,
  1654. IsSys: 1,
  1655. SysRecordTime: order.StartTime,
  1656. }
  1657. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  1658. warehouseOutInfo.Price = stockInInfo.Price
  1659. warehouseOutInfo.GoodId = fistula_needle_set
  1660. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1661. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1662. if err == nil {
  1663. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1664. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1665. if err == gorm.ErrRecordNotFound {
  1666. details := &models.AutomaticReduceDetail{
  1667. WarehouseOutId: warehouseOutInfo.ID,
  1668. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1669. PatientId: patient,
  1670. Ctime: time.Now().Unix(),
  1671. Mtime: time.Now().Unix(),
  1672. Status: 1,
  1673. RecordTime: order.StartTime,
  1674. OrgId: adminUserInfo.CurrentOrgId,
  1675. GoodId: fistula_needle_set,
  1676. GoodTypeId: fistula_needle_set_good_type_id,
  1677. }
  1678. service.AddSigleAutoReduceRecordInfo(details)
  1679. } else if err == nil {
  1680. if user.ID > 0 {
  1681. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1682. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  1683. }
  1684. }
  1685. }
  1686. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1687. if newOut.ID > 0 {
  1688. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1689. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1690. if err == gorm.ErrRecordNotFound {
  1691. details := &models.AutomaticReduceDetail{
  1692. WarehouseOutId: newOut.ID,
  1693. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1694. PatientId: patient,
  1695. Ctime: time.Now().Unix(),
  1696. Mtime: time.Now().Unix(),
  1697. Status: 1,
  1698. RecordTime: order.StartTime,
  1699. OrgId: adminUserInfo.CurrentOrgId,
  1700. GoodId: fistula_needle_set,
  1701. GoodTypeId: fistula_needle_set_good_type_id,
  1702. }
  1703. service.AddSigleAutoReduceRecordInfo(details)
  1704. } else if err == nil {
  1705. if user.ID > 0 {
  1706. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1707. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  1708. }
  1709. }
  1710. }
  1711. }
  1712. }
  1713. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1714. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1715. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1716. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1717. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1718. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1719. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1720. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1721. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1722. warehouseOutInfo := &models.WarehouseOutInfo{
  1723. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1724. WarehouseOutId: out.ID,
  1725. Count: 1,
  1726. Status: 1,
  1727. Ctime: time.Now().Unix(),
  1728. Remark: "",
  1729. OrgId: adminUserInfo.CurrentOrgId,
  1730. Type: 1,
  1731. Manufacturer: 0,
  1732. Dealer: 0,
  1733. IsSys: 1,
  1734. SysRecordTime: order.StartTime,
  1735. }
  1736. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  1737. warehouseOutInfo.Price = stockInInfo.Price
  1738. warehouseOutInfo.GoodId = fistula_needle_set_16
  1739. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1740. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1741. if err == nil {
  1742. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1743. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1744. if err == gorm.ErrRecordNotFound {
  1745. details := &models.AutomaticReduceDetail{
  1746. WarehouseOutId: warehouseOutInfo.ID,
  1747. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1748. PatientId: patient,
  1749. Ctime: time.Now().Unix(),
  1750. Mtime: time.Now().Unix(),
  1751. Status: 1,
  1752. RecordTime: order.StartTime,
  1753. OrgId: adminUserInfo.CurrentOrgId,
  1754. GoodId: fistula_needle_set_16,
  1755. GoodTypeId: fistula_needle_set_16_good_type_id,
  1756. }
  1757. service.AddSigleAutoReduceRecordInfo(details)
  1758. } else if err == nil {
  1759. if user.ID > 0 {
  1760. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  1761. }
  1762. }
  1763. }
  1764. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1765. if newOut.ID > 0 {
  1766. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1767. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1768. if err == gorm.ErrRecordNotFound {
  1769. details := &models.AutomaticReduceDetail{
  1770. WarehouseOutId: newOut.ID,
  1771. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1772. PatientId: patient,
  1773. Ctime: time.Now().Unix(),
  1774. Mtime: time.Now().Unix(),
  1775. Status: 1,
  1776. RecordTime: order.StartTime,
  1777. OrgId: adminUserInfo.CurrentOrgId,
  1778. GoodId: fistula_needle_set_16,
  1779. GoodTypeId: fistula_needle_set_16_good_type_id,
  1780. }
  1781. service.AddSigleAutoReduceRecordInfo(details)
  1782. } else if err == nil {
  1783. if user.ID > 0 {
  1784. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1791. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1792. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1793. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1794. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1795. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1796. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1797. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1798. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1799. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1800. warehouseOutInfo := &models.WarehouseOutInfo{
  1801. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1802. WarehouseOutId: out.ID,
  1803. Count: 1,
  1804. Status: 1,
  1805. Ctime: time.Now().Unix(),
  1806. Remark: "",
  1807. OrgId: adminUserInfo.CurrentOrgId,
  1808. Type: 1,
  1809. Manufacturer: 0,
  1810. Dealer: 0,
  1811. IsSys: 1,
  1812. SysRecordTime: order.StartTime,
  1813. }
  1814. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  1815. warehouseOutInfo.Price = stockInInfo.Price
  1816. warehouseOutInfo.GoodId = hemoperfusion
  1817. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1818. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1819. if err == nil {
  1820. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1821. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1822. if err == gorm.ErrRecordNotFound {
  1823. details := &models.AutomaticReduceDetail{
  1824. WarehouseOutId: warehouseOutInfo.ID,
  1825. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1826. PatientId: patient,
  1827. Ctime: time.Now().Unix(),
  1828. Mtime: time.Now().Unix(),
  1829. Status: 1,
  1830. RecordTime: order.StartTime,
  1831. OrgId: adminUserInfo.CurrentOrgId,
  1832. GoodId: hemoperfusion,
  1833. GoodTypeId: hemoperfusion_good_type_id,
  1834. }
  1835. service.AddSigleAutoReduceRecordInfo(details)
  1836. } else if err == nil {
  1837. if user.ID > 0 {
  1838. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  1839. }
  1840. }
  1841. }
  1842. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1843. if newOut.ID > 0 {
  1844. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1845. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1846. if err == gorm.ErrRecordNotFound {
  1847. details := &models.AutomaticReduceDetail{
  1848. WarehouseOutId: newOut.ID,
  1849. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1850. PatientId: patient,
  1851. Ctime: time.Now().Unix(),
  1852. Mtime: time.Now().Unix(),
  1853. Status: 1,
  1854. RecordTime: order.StartTime,
  1855. OrgId: adminUserInfo.CurrentOrgId,
  1856. GoodId: hemoperfusion,
  1857. GoodTypeId: hemoperfusion_good_type_id,
  1858. }
  1859. service.AddSigleAutoReduceRecordInfo(details)
  1860. } else if err == nil {
  1861. if user.ID > 0 {
  1862. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1869. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  1870. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1871. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1872. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1873. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1874. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1875. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1876. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1877. warehouseOutInfo := &models.WarehouseOutInfo{
  1878. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1879. WarehouseOutId: out.WarehouseOutId,
  1880. Count: 1,
  1881. Status: 1,
  1882. Ctime: time.Now().Unix(),
  1883. Remark: "",
  1884. OrgId: adminUserInfo.CurrentOrgId,
  1885. Type: 1,
  1886. Manufacturer: 0,
  1887. Dealer: 0,
  1888. IsSys: 1,
  1889. SysRecordTime: order.StartTime,
  1890. }
  1891. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  1892. warehouseOutInfo.Price = stockInInfo.Price
  1893. warehouseOutInfo.GoodId = dialyser_sterilised
  1894. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1895. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1896. if err == nil {
  1897. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1898. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1899. if err == gorm.ErrRecordNotFound {
  1900. details := &models.AutomaticReduceDetail{
  1901. WarehouseOutId: warehouseOutInfo.ID,
  1902. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1903. PatientId: patient,
  1904. Ctime: time.Now().Unix(),
  1905. Mtime: time.Now().Unix(),
  1906. Status: 1,
  1907. RecordTime: order.StartTime,
  1908. OrgId: adminUserInfo.CurrentOrgId,
  1909. GoodId: dialyser_sterilised,
  1910. GoodTypeId: dialyser_sterilised_good_type_id,
  1911. }
  1912. service.AddSigleAutoReduceRecordInfo(details)
  1913. } else if err == nil {
  1914. if user.ID > 0 {
  1915. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1916. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  1917. }
  1918. }
  1919. }
  1920. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1921. if newOut.ID > 0 {
  1922. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1923. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1924. if err == gorm.ErrRecordNotFound {
  1925. details := &models.AutomaticReduceDetail{
  1926. WarehouseOutId: newOut.ID,
  1927. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1928. PatientId: patient,
  1929. Ctime: time.Now().Unix(),
  1930. Mtime: time.Now().Unix(),
  1931. Status: 1,
  1932. RecordTime: order.StartTime,
  1933. OrgId: adminUserInfo.CurrentOrgId,
  1934. GoodId: dialyser_sterilised,
  1935. GoodTypeId: dialyser_sterilised_good_type_id,
  1936. }
  1937. service.AddSigleAutoReduceRecordInfo(details)
  1938. } else if err == nil {
  1939. if user.ID > 0 {
  1940. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  1941. }
  1942. }
  1943. }
  1944. }
  1945. }
  1946. if dialysisPrescription.Filtryzer != filtryzer {
  1947. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1948. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1949. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1950. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1951. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1952. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1953. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1954. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1955. warehouseOutInfo := &models.WarehouseOutInfo{
  1956. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1957. WarehouseOutId: out.ID,
  1958. Count: 1,
  1959. Status: 1,
  1960. Ctime: time.Now().Unix(),
  1961. Remark: "",
  1962. OrgId: adminUserInfo.CurrentOrgId,
  1963. Type: 1,
  1964. Manufacturer: 0,
  1965. Dealer: 0,
  1966. IsSys: 1,
  1967. SysRecordTime: order.StartTime,
  1968. }
  1969. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  1970. warehouseOutInfo.Price = stockInInfo.Price
  1971. warehouseOutInfo.GoodId = filtryzer
  1972. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1973. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1974. if err == nil {
  1975. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1976. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1977. if err == gorm.ErrRecordNotFound {
  1978. details := &models.AutomaticReduceDetail{
  1979. WarehouseOutId: warehouseOutInfo.ID,
  1980. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1981. PatientId: patient,
  1982. Ctime: time.Now().Unix(),
  1983. Mtime: time.Now().Unix(),
  1984. Status: 1,
  1985. RecordTime: order.StartTime,
  1986. OrgId: adminUserInfo.CurrentOrgId,
  1987. GoodId: filtryzer,
  1988. GoodTypeId: filtryzer_good_type_id,
  1989. }
  1990. service.AddSigleAutoReduceRecordInfo(details)
  1991. } else if err == nil {
  1992. if user.ID > 0 {
  1993. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  1994. }
  1995. }
  1996. }
  1997. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1998. if newOut.ID > 0 {
  1999. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2000. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2001. if err == gorm.ErrRecordNotFound {
  2002. details := &models.AutomaticReduceDetail{
  2003. WarehouseOutId: newOut.ID,
  2004. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2005. PatientId: patient,
  2006. Ctime: time.Now().Unix(),
  2007. Mtime: time.Now().Unix(),
  2008. Status: 1,
  2009. RecordTime: order.StartTime,
  2010. OrgId: adminUserInfo.CurrentOrgId,
  2011. GoodId: filtryzer,
  2012. GoodTypeId: filtryzer_good_type_id,
  2013. }
  2014. service.AddSigleAutoReduceRecordInfo(details)
  2015. } else if err == nil {
  2016. if user.ID > 0 {
  2017. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. if dialysisPrescription.Dialyzers != dialyzers {
  2024. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2025. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2026. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2027. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2028. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2029. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2030. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2031. warehouseOutInfo := &models.WarehouseOutInfo{
  2032. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2033. WarehouseOutId: out.ID,
  2034. Count: 1,
  2035. Status: 1,
  2036. Ctime: time.Now().Unix(),
  2037. Remark: "",
  2038. OrgId: adminUserInfo.CurrentOrgId,
  2039. Type: 1,
  2040. Manufacturer: 0,
  2041. Dealer: 0,
  2042. IsSys: 1,
  2043. SysRecordTime: order.StartTime,
  2044. }
  2045. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  2046. warehouseOutInfo.Price = stockInInfo.Price
  2047. warehouseOutInfo.GoodId = dialyzers
  2048. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  2049. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2050. if err == nil {
  2051. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2052. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2053. if err == gorm.ErrRecordNotFound {
  2054. details := &models.AutomaticReduceDetail{
  2055. WarehouseOutId: warehouseOutInfo.ID,
  2056. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2057. PatientId: patient,
  2058. Ctime: time.Now().Unix(),
  2059. Mtime: time.Now().Unix(),
  2060. Status: 1,
  2061. RecordTime: order.StartTime,
  2062. OrgId: adminUserInfo.CurrentOrgId,
  2063. GoodId: dialyzers,
  2064. GoodTypeId: dialyzers_good_type_id,
  2065. }
  2066. service.AddSigleAutoReduceRecordInfo(details)
  2067. } else if err == nil {
  2068. if user.ID > 0 {
  2069. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  2070. }
  2071. }
  2072. }
  2073. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2074. if newOut.ID > 0 {
  2075. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2076. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2077. if err == gorm.ErrRecordNotFound {
  2078. details := &models.AutomaticReduceDetail{
  2079. WarehouseOutId: newOut.ID,
  2080. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2081. PatientId: patient,
  2082. Ctime: time.Now().Unix(),
  2083. Mtime: time.Now().Unix(),
  2084. Status: 1,
  2085. RecordTime: order.StartTime,
  2086. OrgId: adminUserInfo.CurrentOrgId,
  2087. GoodId: dialyzers,
  2088. GoodTypeId: dialyzers_good_type_id,
  2089. }
  2090. service.AddSigleAutoReduceRecordInfo(details)
  2091. } else if err == nil {
  2092. if user.ID > 0 {
  2093. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. if dialysisPrescription.Injector != injector {
  2100. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2101. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2102. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2103. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2104. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2105. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2106. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2107. warehouseOutInfo := &models.WarehouseOutInfo{
  2108. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2109. WarehouseOutId: out.ID,
  2110. Count: 1,
  2111. Status: 1,
  2112. Ctime: time.Now().Unix(),
  2113. Remark: "",
  2114. OrgId: adminUserInfo.CurrentOrgId,
  2115. Type: 1,
  2116. Manufacturer: 0,
  2117. Dealer: 0,
  2118. IsSys: 1,
  2119. SysRecordTime: order.StartTime,
  2120. }
  2121. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  2122. warehouseOutInfo.Price = stockInInfo.Price
  2123. warehouseOutInfo.GoodId = injector
  2124. warehouseOutInfo.GoodTypeId = injector_good_type_id
  2125. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2126. if err == nil {
  2127. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2128. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2129. if err == gorm.ErrRecordNotFound {
  2130. details := &models.AutomaticReduceDetail{
  2131. WarehouseOutId: warehouseOutInfo.ID,
  2132. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2133. PatientId: patient,
  2134. Ctime: time.Now().Unix(),
  2135. Mtime: time.Now().Unix(),
  2136. Status: 1,
  2137. RecordTime: order.StartTime,
  2138. OrgId: adminUserInfo.CurrentOrgId,
  2139. GoodId: injector,
  2140. GoodTypeId: injector_good_type_id,
  2141. }
  2142. service.AddSigleAutoReduceRecordInfo(details)
  2143. } else if err == nil {
  2144. if user.ID > 0 {
  2145. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  2146. }
  2147. }
  2148. }
  2149. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2150. if newOut.ID > 0 {
  2151. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2152. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2153. if err == gorm.ErrRecordNotFound {
  2154. details := &models.AutomaticReduceDetail{
  2155. WarehouseOutId: newOut.ID,
  2156. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2157. PatientId: patient,
  2158. Ctime: time.Now().Unix(),
  2159. Mtime: time.Now().Unix(),
  2160. Status: 1,
  2161. RecordTime: order.StartTime,
  2162. OrgId: adminUserInfo.CurrentOrgId,
  2163. GoodId: injector,
  2164. GoodTypeId: injector_good_type_id,
  2165. }
  2166. service.AddSigleAutoReduceRecordInfo(details)
  2167. } else if err == nil {
  2168. if user.ID > 0 {
  2169. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  2170. }
  2171. }
  2172. }
  2173. }
  2174. }
  2175. if dialysisPrescription.Bloodlines != bloodlines {
  2176. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2177. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2178. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2179. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2180. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2181. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2182. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2183. warehouseOutInfo := &models.WarehouseOutInfo{
  2184. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2185. WarehouseOutId: out.ID,
  2186. Count: 1,
  2187. Status: 1,
  2188. Ctime: time.Now().Unix(),
  2189. Remark: "",
  2190. OrgId: adminUserInfo.CurrentOrgId,
  2191. Type: 1,
  2192. Manufacturer: 0,
  2193. Dealer: 0,
  2194. IsSys: 1,
  2195. SysRecordTime: order.StartTime,
  2196. }
  2197. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  2198. warehouseOutInfo.Price = stockInInfo.Price
  2199. warehouseOutInfo.GoodId = bloodlines
  2200. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  2201. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2202. if err == nil {
  2203. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2204. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2205. if err == gorm.ErrRecordNotFound {
  2206. details := &models.AutomaticReduceDetail{
  2207. WarehouseOutId: warehouseOutInfo.ID,
  2208. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2209. PatientId: patient,
  2210. Ctime: time.Now().Unix(),
  2211. Mtime: time.Now().Unix(),
  2212. Status: 1,
  2213. RecordTime: order.StartTime,
  2214. OrgId: adminUserInfo.CurrentOrgId,
  2215. GoodId: bloodlines,
  2216. GoodTypeId: bloodlines_good_type_id,
  2217. }
  2218. service.AddSigleAutoReduceRecordInfo(details)
  2219. } else if err == nil {
  2220. if user.ID > 0 {
  2221. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  2222. }
  2223. }
  2224. }
  2225. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2226. if newOut.ID > 0 {
  2227. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2228. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2229. if err == gorm.ErrRecordNotFound {
  2230. details := &models.AutomaticReduceDetail{
  2231. WarehouseOutId: newOut.ID,
  2232. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2233. PatientId: patient,
  2234. Ctime: time.Now().Unix(),
  2235. Mtime: time.Now().Unix(),
  2236. Status: 1,
  2237. RecordTime: order.StartTime,
  2238. OrgId: adminUserInfo.CurrentOrgId,
  2239. GoodId: bloodlines,
  2240. GoodTypeId: bloodlines_good_type_id,
  2241. }
  2242. service.AddSigleAutoReduceRecordInfo(details)
  2243. } else if err == nil {
  2244. if user.ID > 0 {
  2245. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  2252. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2253. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2254. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2255. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2256. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2257. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2258. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2259. warehouseOutInfo := &models.WarehouseOutInfo{
  2260. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2261. WarehouseOutId: out.ID,
  2262. Count: 1,
  2263. Status: 1,
  2264. Ctime: time.Now().Unix(),
  2265. Remark: "",
  2266. OrgId: adminUserInfo.CurrentOrgId,
  2267. Type: 1,
  2268. Manufacturer: 0,
  2269. Dealer: 0,
  2270. IsSys: 1,
  2271. SysRecordTime: order.StartTime,
  2272. }
  2273. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  2274. warehouseOutInfo.Price = stockInInfo.Price
  2275. warehouseOutInfo.GoodId = tubing_hemodialysis
  2276. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  2277. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2278. if err == nil {
  2279. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2280. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2281. if err == gorm.ErrRecordNotFound {
  2282. details := &models.AutomaticReduceDetail{
  2283. WarehouseOutId: warehouseOutInfo.ID,
  2284. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2285. PatientId: patient,
  2286. Ctime: time.Now().Unix(),
  2287. Mtime: time.Now().Unix(),
  2288. Status: 1,
  2289. RecordTime: order.StartTime,
  2290. OrgId: adminUserInfo.CurrentOrgId,
  2291. GoodId: tubing_hemodialysis,
  2292. GoodTypeId: tubingHemodialysis_good_type_id,
  2293. }
  2294. service.AddSigleAutoReduceRecordInfo(details)
  2295. } else if err == nil {
  2296. if user.ID > 0 {
  2297. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  2298. }
  2299. }
  2300. }
  2301. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2302. if newOut.ID > 0 {
  2303. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2304. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2305. if err == gorm.ErrRecordNotFound {
  2306. details := &models.AutomaticReduceDetail{
  2307. WarehouseOutId: newOut.ID,
  2308. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2309. PatientId: patient,
  2310. Ctime: time.Now().Unix(),
  2311. Mtime: time.Now().Unix(),
  2312. Status: 1,
  2313. RecordTime: order.StartTime,
  2314. OrgId: adminUserInfo.CurrentOrgId,
  2315. GoodId: tubing_hemodialysis,
  2316. GoodTypeId: tubingHemodialysis_good_type_id,
  2317. }
  2318. service.AddSigleAutoReduceRecordInfo(details)
  2319. } else if err == nil {
  2320. if user.ID > 0 {
  2321. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  2322. }
  2323. }
  2324. }
  2325. }
  2326. }
  2327. if dialysisPrescription.Package != safe_package {
  2328. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2329. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2330. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2331. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2332. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2333. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2334. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2335. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2336. warehouseOutInfo := &models.WarehouseOutInfo{
  2337. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2338. WarehouseOutId: out.ID,
  2339. Count: 1,
  2340. Status: 1,
  2341. Ctime: time.Now().Unix(),
  2342. Remark: "",
  2343. OrgId: adminUserInfo.CurrentOrgId,
  2344. Type: 1,
  2345. Manufacturer: 0,
  2346. Dealer: 0,
  2347. IsSys: 1,
  2348. SysRecordTime: order.StartTime,
  2349. }
  2350. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  2351. warehouseOutInfo.Price = stockInInfo.Price
  2352. warehouseOutInfo.GoodId = safe_package
  2353. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  2354. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2355. if err == nil {
  2356. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2357. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2358. if err == gorm.ErrRecordNotFound {
  2359. details := &models.AutomaticReduceDetail{
  2360. WarehouseOutId: warehouseOutInfo.ID,
  2361. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2362. PatientId: patient,
  2363. Ctime: time.Now().Unix(),
  2364. Mtime: time.Now().Unix(),
  2365. Status: 1,
  2366. RecordTime: order.StartTime,
  2367. OrgId: adminUserInfo.CurrentOrgId,
  2368. GoodId: safe_package,
  2369. GoodTypeId: safe_package_good_type_id,
  2370. }
  2371. service.AddSigleAutoReduceRecordInfo(details)
  2372. } else if err == nil {
  2373. if user.ID > 0 {
  2374. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  2375. }
  2376. }
  2377. }
  2378. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2379. if newOut.ID > 0 {
  2380. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2381. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2382. if err == gorm.ErrRecordNotFound {
  2383. details := &models.AutomaticReduceDetail{
  2384. WarehouseOutId: newOut.ID,
  2385. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2386. PatientId: patient,
  2387. Ctime: time.Now().Unix(),
  2388. Mtime: time.Now().Unix(),
  2389. Status: 1,
  2390. RecordTime: order.StartTime,
  2391. OrgId: adminUserInfo.CurrentOrgId,
  2392. GoodId: safe_package,
  2393. GoodTypeId: safe_package_good_type_id,
  2394. }
  2395. service.AddSigleAutoReduceRecordInfo(details)
  2396. } else if err == nil {
  2397. if user.ID > 0 {
  2398. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  2399. }
  2400. }
  2401. }
  2402. }
  2403. }
  2404. if dialysisPrescription.ALiquid != a_liquid {
  2405. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2406. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2407. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2408. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2409. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2410. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2411. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2412. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2413. warehouseOutInfo := &models.WarehouseOutInfo{
  2414. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2415. WarehouseOutId: out.ID,
  2416. Count: 1,
  2417. Status: 1,
  2418. Ctime: time.Now().Unix(),
  2419. Remark: "",
  2420. OrgId: adminUserInfo.CurrentOrgId,
  2421. Type: 1,
  2422. Manufacturer: 0,
  2423. Dealer: 0,
  2424. IsSys: 1,
  2425. SysRecordTime: order.StartTime,
  2426. }
  2427. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  2428. warehouseOutInfo.Price = stockInInfo.Price
  2429. warehouseOutInfo.GoodId = a_liquid
  2430. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  2431. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2432. if err == nil {
  2433. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2434. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2435. if err == gorm.ErrRecordNotFound {
  2436. details := &models.AutomaticReduceDetail{
  2437. WarehouseOutId: warehouseOutInfo.ID,
  2438. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2439. PatientId: patient,
  2440. Ctime: time.Now().Unix(),
  2441. Mtime: time.Now().Unix(),
  2442. Status: 1,
  2443. RecordTime: order.StartTime,
  2444. OrgId: adminUserInfo.CurrentOrgId,
  2445. GoodId: a_liquid,
  2446. GoodTypeId: aliquid_good_type_id,
  2447. }
  2448. service.AddSigleAutoReduceRecordInfo(details)
  2449. } else if err == nil {
  2450. if user.ID > 0 {
  2451. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  2452. }
  2453. }
  2454. }
  2455. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2456. if newOut.ID > 0 {
  2457. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2458. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2459. if err == gorm.ErrRecordNotFound {
  2460. details := &models.AutomaticReduceDetail{
  2461. WarehouseOutId: newOut.ID,
  2462. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2463. PatientId: patient,
  2464. Ctime: time.Now().Unix(),
  2465. Mtime: time.Now().Unix(),
  2466. Status: 1,
  2467. RecordTime: order.StartTime,
  2468. OrgId: adminUserInfo.CurrentOrgId,
  2469. GoodId: a_liquid,
  2470. GoodTypeId: aliquid_good_type_id,
  2471. }
  2472. service.AddSigleAutoReduceRecordInfo(details)
  2473. } else if err == nil {
  2474. if user.ID > 0 {
  2475. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  2476. }
  2477. }
  2478. }
  2479. }
  2480. }
  2481. }
  2482. }
  2483. }
  2484. prescription.Creater = adminUserInfo.AdminUser.Id
  2485. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2486. prescription.UpdatedTime = time.Now().Unix()
  2487. prescription.Modifier = adminUserInfo.AdminUser.Id
  2488. prescription.ID = dialysisPrescription.ID
  2489. }
  2490. solution := models.DialysisSolution{
  2491. RegistrarsId: adminUserInfo.AdminUser.Id,
  2492. UserOrgId: adminUserInfo.CurrentOrgId,
  2493. Doctor: prescription_doctor,
  2494. PatientId: patient,
  2495. ModeId: mode_id,
  2496. DialysisDuration: dialysis_duration,
  2497. PerfusionApparatus: perfusion_apparatus,
  2498. BloodFlowVolume: blood_flow_volume,
  2499. Dewater: dewater_amount,
  2500. DisplaceLiqui: displace_liqui,
  2501. ReplacementWay: replacement_way,
  2502. Anticoagulant: anticoagulant,
  2503. AnticoagulantShouji: anticoagulant_shouji,
  2504. AnticoagulantWeichi: anticoagulant_weichi,
  2505. AnticoagulantZongliang: anticoagulant_zongliang,
  2506. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2507. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2508. Kalium: kalium,
  2509. Sodium: sodium,
  2510. Calcium: calcium,
  2511. Bicarbonate: bicarbonate,
  2512. Glucose: glucose,
  2513. // DryWeight: dry_weight,
  2514. DialysateFlow: dialysate_flow,
  2515. DialysateTemperature: dialysate_temperature,
  2516. Conductivity: conductivity,
  2517. Remark: remark,
  2518. Status: 1,
  2519. CreatedTime: time.Now().Unix(),
  2520. UpdatedTime: time.Now().Unix(),
  2521. DialysisDurationMinute: dialysisDurationMinute,
  2522. DialysisDurationHour: dialysisDurationHour,
  2523. TargetUltrafiltration: targetUltrafiltration,
  2524. DialysateFormulation: dialysateFormulation,
  2525. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2526. BodyFluid: body_fluid,
  2527. SpecialMedicine: special_medicine,
  2528. SpecialMedicineOther: special_medicine_other,
  2529. DisplaceLiquiPart: displace_liqui_part,
  2530. DisplaceLiquiValue: displace_liqui_value,
  2531. BloodAccess: blood_access,
  2532. Ultrafiltration: ultrafiltration,
  2533. BodyFluidOther: body_fluid_other,
  2534. ReplacementTotal: replacement_total,
  2535. TargetKtv: target_ktv,
  2536. }
  2537. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2538. if err == nil {
  2539. c.ServeSuccessJSON(map[string]interface{}{
  2540. "solution": &solution,
  2541. "prescription": &prescription,
  2542. })
  2543. } else {
  2544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2545. }
  2546. }
  2547. func (c *DialysisApiController) PostDouleCheck() {
  2548. id, _ := c.GetInt64("patient", 0)
  2549. recordDateStr := c.GetString("record_date")
  2550. checkTimeStr := c.GetString("check_time")
  2551. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  2552. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  2553. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  2554. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  2555. dialysis_item_desc := c.GetString("dialysis_item_desc")
  2556. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  2557. vascular_access_desc := c.GetString("vascular_access_desc")
  2558. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  2559. collator, _ := c.GetInt64("collator", 0)
  2560. if id <= 0 {
  2561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2562. return
  2563. }
  2564. adminUserInfo := c.GetAdminUserInfo()
  2565. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2566. if patient.ID == 0 {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2568. return
  2569. }
  2570. if len(recordDateStr) == 0 {
  2571. recordDateStr = time.Now().Format("2006-01-02")
  2572. }
  2573. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2574. if parseDateErr != nil {
  2575. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2577. return
  2578. }
  2579. if len(checkTimeStr) == 0 {
  2580. checkTimeStr = time.Now().Format("2006-01-02 15:04")
  2581. }
  2582. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  2583. doubleCheck := models.DoubleCheck{
  2584. UserOrgId: adminUserInfo.CurrentOrgId,
  2585. PatientId: id,
  2586. DialysisItemCheck: dialysis_item_check,
  2587. DialysisParameterCheck: dialysis_parameter_check,
  2588. VascularAccessVerification: vascular_access_verification,
  2589. PipelineConnectionCheck: pipeline_connection_check,
  2590. DialysisItemDesc: dialysis_item_desc,
  2591. DialysisParameterDesc: dialysis_parameter_desc,
  2592. VascularAccessDesc: vascular_access_desc,
  2593. PipelineConnectionDesc: pipeline_connection_desc,
  2594. Collator: collator,
  2595. Status: 1,
  2596. CreatedTime: time.Now().Unix(),
  2597. UpdatedTime: time.Now().Unix(),
  2598. CheckDate: recordDate.Unix(),
  2599. }
  2600. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2601. if check.ID == 0 { //新增
  2602. doubleCheck.FirstCheckTime = checkDate.Unix()
  2603. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  2604. err := service.AddSigleDoubleCheck(&doubleCheck)
  2605. if err == nil {
  2606. c.ServeSuccessJSON(map[string]interface{}{
  2607. "doubleCheck": doubleCheck,
  2608. })
  2609. } else {
  2610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2611. }
  2612. } else { //修改
  2613. if check.Modifier != 0 {
  2614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  2615. } else {
  2616. if adminUserInfo.AdminUser.Id == check.Creater {
  2617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  2618. return
  2619. }
  2620. doubleCheck.FirstCheckTime = check.FirstCheckTime
  2621. doubleCheck.CheckTime = checkDate.Unix()
  2622. doubleCheck.Creater = check.Creater
  2623. doubleCheck.CreatedTime = check.CreatedTime
  2624. doubleCheck.UpdatedTime = time.Now().Unix()
  2625. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  2626. doubleCheck.ID = check.ID
  2627. err := service.UpdateDoubleCheck(&doubleCheck)
  2628. if err == nil {
  2629. c.ServeSuccessJSON(map[string]interface{}{
  2630. "doubleCheck": doubleCheck,
  2631. })
  2632. } else {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2634. }
  2635. }
  2636. }
  2637. }
  2638. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  2639. id, _ := c.GetInt64("patient", 0)
  2640. recordDateStr := c.GetString("record_date")
  2641. way, _ := c.GetInt64("way", 0)
  2642. consciousness, _ := c.GetInt64("consciousness", 0)
  2643. appetite, _ := c.GetInt64("appetite", 0)
  2644. condition, _ := c.GetInt64("condition", 0)
  2645. posture, _ := c.GetInt64("posture")
  2646. score := c.GetString("score")
  2647. sick_condition, _ := c.GetInt64("sick_condition", 0)
  2648. danger_level, _ := c.GetInt64("danger_level", 0)
  2649. intake, _ := c.GetInt64("intake", 0)
  2650. nutrition, _ := c.GetInt64("nutrition", 0)
  2651. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  2652. psychological_assessment_other := c.GetString("psychological_assessment_other")
  2653. sick_condition_other := c.GetString("sick_condition_other")
  2654. //precaution, _ := c.GetInt64("precaution", 0)
  2655. precaution := c.GetString("precaution")
  2656. precaution_other := c.GetString("precaution_other")
  2657. psychological_other := c.GetString("psychological_other")
  2658. admission_number := c.GetString("admission_number")
  2659. if id <= 0 {
  2660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2661. return
  2662. }
  2663. adminUserInfo := c.GetAdminUserInfo()
  2664. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2665. if patient.ID == 0 {
  2666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2667. return
  2668. }
  2669. if len(recordDateStr) == 0 {
  2670. recordDateStr = time.Now().Format("2006-01-02")
  2671. }
  2672. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2673. if parseDateErr != nil {
  2674. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2676. return
  2677. }
  2678. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2679. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  2680. UserOrgId: adminUserInfo.CurrentOrgId,
  2681. PatientId: id,
  2682. RecordDate: recordDate.Unix(),
  2683. Way: way,
  2684. Consciousness: consciousness,
  2685. Appetite: appetite,
  2686. Condition: condition,
  2687. SickCondition: sick_condition,
  2688. DangerLevel: danger_level,
  2689. Intake: intake,
  2690. Nutrition: nutrition,
  2691. PsychologicalAssessment: psychological_assessment,
  2692. PsychologicalAssessmentOther: psychological_assessment_other,
  2693. SickConditionOther: sick_condition_other,
  2694. Posture: posture,
  2695. CreatedTime: time.Now().Unix(),
  2696. UpdateTime: time.Now().Unix(),
  2697. Status: 1,
  2698. Score: score,
  2699. Precaution: precaution,
  2700. PrecautionOther: precaution_other,
  2701. PsychologicalOther: psychological_other,
  2702. AdmissionNumber: admission_number,
  2703. }
  2704. if receiveTreatment.ID == 0 { //新增
  2705. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  2706. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  2707. if err == nil {
  2708. c.ServeSuccessJSON(map[string]interface{}{
  2709. "receiveTreatmentAsses": receiveTreatmentAsses,
  2710. })
  2711. } else {
  2712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2713. }
  2714. } else { //修改
  2715. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  2716. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2717. // if getPermissionErr != nil {
  2718. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2719. // return
  2720. // } else if headNursePermission == nil {
  2721. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2722. // return
  2723. // }
  2724. //}
  2725. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  2726. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  2727. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  2728. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  2729. receiveTreatmentAsses.ID = receiveTreatment.ID
  2730. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  2731. if err == nil {
  2732. c.ServeSuccessJSON(map[string]interface{}{
  2733. "receiveTreatmentAsses": receiveTreatmentAsses,
  2734. })
  2735. } else {
  2736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2737. }
  2738. }
  2739. }
  2740. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  2741. patient, _ := c.GetInt64("patient", 0)
  2742. recordDateStr := c.GetString("record_date")
  2743. fmt.Println(recordDateStr)
  2744. if patient <= 0 {
  2745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2746. return
  2747. }
  2748. adminUserInfo := c.GetAdminUserInfo()
  2749. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2750. if patientInfo.ID == 0 {
  2751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2752. return
  2753. }
  2754. if len(recordDateStr) == 0 {
  2755. recordDateStr = time.Now().Format("2006-01-02")
  2756. }
  2757. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2758. if parseDateErr != nil {
  2759. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2761. return
  2762. }
  2763. // data := make(map[string]interface{}, 0)
  2764. var data models.AssessmentAfterDislysis
  2765. var err error
  2766. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2767. fmt.Println(err)
  2768. if err != nil {
  2769. c.ErrorLog("数据解析错误:%v", err)
  2770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2771. return
  2772. }
  2773. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2774. assessment.DialysisOrderId = data.DialysisOrderId
  2775. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2776. assessment.Status = 1
  2777. assessment.WeightAfter = data.WeightAfter
  2778. assessment.WeightLoss = data.WeightLoss
  2779. assessment.Temperature = data.Temperature
  2780. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2781. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2782. assessment.PulseFrequency = data.PulseFrequency
  2783. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2784. assessment.ActualDisplacement = data.ActualDisplacement
  2785. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2786. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2787. assessment.Cruor = data.Cruor
  2788. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2789. assessment.DialysisIntakes = data.DialysisIntakes
  2790. assessment.InternalFistula = data.InternalFistula
  2791. assessment.BloodAccessPartId = data.BloodAccessPartId
  2792. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2793. assessment.Catheter = data.Catheter
  2794. assessment.Complication = data.Complication
  2795. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2796. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2797. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2798. assessment.PatientGose = data.PatientGose
  2799. assessment.InpatientDepartment = data.InpatientDepartment
  2800. assessment.ObservationContent = data.ObservationContent
  2801. assessment.ObservationContentOther = data.ObservationContentOther
  2802. assessment.Remark = data.Remark
  2803. assessment.BreathingRate = data.BreathingRate
  2804. assessment.DialysisProcess = data.DialysisProcess
  2805. assessment.InAdvanceMinute = data.InAdvanceMinute
  2806. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2807. assessment.InAdvanceReason = data.InAdvanceReason
  2808. assessment.HemostasisOpera = data.HemostasisOpera
  2809. assessment.HemostasisMinute = data.HemostasisMinute
  2810. assessment.TremorNoise = data.TremorNoise
  2811. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2812. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2813. assessment.ArterialTube = data.ArterialTube
  2814. assessment.IntravenousTube = data.IntravenousTube
  2815. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2816. assessment.Dialyzer = data.Dialyzer
  2817. assessment.IsEat = data.IsEat
  2818. assessment.CvcA = data.CvcA
  2819. assessment.CvcV = data.CvcV
  2820. assessment.Channel = data.Channel
  2821. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2822. if assessment.ID > 0 {
  2823. if appRole.UserType == 2 || appRole.UserType == 1 {
  2824. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2825. assessment.AssessmentTime = time.Now().Unix()
  2826. } else {
  2827. if assessment.Creater == 0 {
  2828. assessment.Modifier = adminUserInfo.AdminUser.Id
  2829. assessment.Creater = adminUserInfo.AdminUser.Id
  2830. } else {
  2831. assessment.Modifier = adminUserInfo.AdminUser.Id
  2832. }
  2833. }
  2834. assessment.UpdatedTime = time.Now().Unix()
  2835. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2836. } else {
  2837. if appRole.UserType == 2 || appRole.UserType == 1 {
  2838. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2839. assessment.AssessmentTime = time.Now().Unix()
  2840. } else {
  2841. assessment.Creater = adminUserInfo.AdminUser.Id
  2842. }
  2843. assessment.CreatedTime = time.Now().Unix()
  2844. assessment.UpdatedTime = time.Now().Unix()
  2845. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2846. assessment.PatientId = patient
  2847. assessment.AssessmentDate = recordDate.Unix()
  2848. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2849. }
  2850. if err != nil {
  2851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2852. return
  2853. }
  2854. c.ServeSuccessJSON(map[string]interface{}{
  2855. "AssessmentAfterDislysis": &assessment,
  2856. })
  2857. }
  2858. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2859. patient, _ := c.GetInt64("patient", 0)
  2860. recordDateStr := c.GetString("record_date")
  2861. if patient <= 0 {
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2863. return
  2864. }
  2865. adminUserInfo := c.GetAdminUserInfo()
  2866. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2867. if patientInfo.ID == 0 {
  2868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2869. return
  2870. }
  2871. if len(recordDateStr) == 0 {
  2872. recordDateStr = time.Now().Format("2006-01-02")
  2873. }
  2874. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2875. if parseDateErr != nil {
  2876. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. weight_before, _ := c.GetFloat("weight_before", 0)
  2881. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2882. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2883. temperature, _ := c.GetFloat("temperature", 0)
  2884. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2885. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2886. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2887. last_post_dialysis := c.GetString("last_post_dialysis")
  2888. dialysis_interphase := c.GetString("dialysis_interphase")
  2889. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2890. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2891. bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2892. internalFistula := c.GetString("internal_fistula")
  2893. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2894. catheter := c.GetString("catheter")
  2895. catheter_bend, _ := c.GetInt("catheter_bend")
  2896. complication := c.GetString("complication")
  2897. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2898. hemorrhage := c.GetString("hemorrhage")
  2899. hemorrhage_other := c.GetString("hemorrhage_other")
  2900. remark := c.GetString("remark")
  2901. puncture_method := c.GetString("puncture_method")
  2902. dialysis_count, _ := c.GetInt64("dialysis_count", 0)
  2903. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2904. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2905. ductus_arantii := c.GetString("ductus_arantii")
  2906. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2907. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2908. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2909. puncture_way, _ := c.GetInt64("puncture_way", 0)
  2910. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2911. internal_fistula_other := c.GetString("internal_fistula_other")
  2912. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2913. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  2914. is_infect, _ := c.GetInt64("is_infect", 0)
  2915. exposed, _ := c.GetFloat("exposed", 0)
  2916. skin, _ := c.GetInt64("skin", 0)
  2917. skin_other := c.GetString("skin_other")
  2918. infect_other := c.GetString("infect_other")
  2919. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2920. machine_type := c.GetString("machine_type")
  2921. puncture_needle := c.GetString("puncture_needle")
  2922. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2923. DialysisCount: dialysis_count,
  2924. EmergencyTreatment: emergency_treatment,
  2925. EmergencyTreatmentOther: emergency_treatment_other,
  2926. DuctusArantii: ductus_arantii,
  2927. VenousCatheterization: venous_catheterization,
  2928. VenousCatheterizationPart: venous_catheterization_part,
  2929. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2930. PunctureWay: puncture_way,
  2931. BloodAccessInternalFistula: blood_access_internal_fistula,
  2932. BloodAccessNoise: blood_access_noise,
  2933. InternalFistulaOther: internal_fistula_other,
  2934. Evaluator: adminUserInfo.AdminUser.Id,
  2935. UserOrgId: adminUserInfo.CurrentOrgId,
  2936. PatientId: patient,
  2937. AssessmentDate: recordDate.Unix(),
  2938. Temperature: temperature,
  2939. PulseFrequency: pulse_frequency,
  2940. SystolicBloodPressure: systolic_blood_pressure,
  2941. DiastolicBloodPressure: diastolic_blood_pressure,
  2942. WeightBefore: weight_before,
  2943. DryWeight: dry_weight,
  2944. AdditionalWeight: additional_weight,
  2945. DialysisInterphase: dialysis_interphase,
  2946. LastPostDialysis: last_post_dialysis,
  2947. SymptomBeforeDialysis: symptom_before_dialysis,
  2948. InternalFistula: internalFistula,
  2949. InternalFistulaSkin: internal_fistula_skin,
  2950. Catheter: catheter,
  2951. CatheterBend: catheter_bend,
  2952. Complication: complication,
  2953. CreatedTime: time.Now().Unix(),
  2954. Status: 1,
  2955. Remark: remark,
  2956. IsHemorrhage: is_hemorrhage,
  2957. Hemorrhage: hemorrhage,
  2958. HemorrhageOther: hemorrhage_other,
  2959. BloodAccessPartId: bloodAccessPartId,
  2960. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2961. PunctureMethod: puncture_method,
  2962. BreathingRate: breathing_rate,
  2963. IsInfect: is_infect,
  2964. Exposed: exposed,
  2965. Skin: skin,
  2966. SkinOther: skin_other,
  2967. InfectOther: infect_other,
  2968. DuctusArantiiOther: ductus_arantii_other,
  2969. MachineType: machine_type,
  2970. PunctureNeedle: puncture_needle,
  2971. }
  2972. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2973. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2974. if evaluation.ID == 0 { //新增
  2975. if appRole.UserType == 2 || appRole.UserType == 1 {
  2976. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2977. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2978. } else {
  2979. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2980. }
  2981. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2982. if err == nil {
  2983. c.ServeSuccessJSON(map[string]interface{}{
  2984. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2985. })
  2986. } else {
  2987. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2989. }
  2990. } else { //修改
  2991. //if appRole.UserType == 3 {
  2992. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2993. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2994. // if getPermissionErr != nil {
  2995. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2996. // return
  2997. // } else if headNursePermission == nil {
  2998. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2999. // return
  3000. // }
  3001. // }
  3002. //}
  3003. if appRole.UserType == 2 || appRole.UserType == 1 {
  3004. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3005. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  3006. } else {
  3007. if evaluation.Creater == 0 {
  3008. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  3009. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  3010. } else {
  3011. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  3012. }
  3013. }
  3014. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  3015. assessmentBeforeDislysis.ID = evaluation.ID
  3016. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  3017. //
  3018. //新增逻辑
  3019. var dewater_amount float64
  3020. dewater_amount = 0
  3021. if evaluation.DryWeight > 0 {
  3022. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3023. if dewater_amount <= 0 {
  3024. dewater_amount = 0
  3025. }
  3026. } else {
  3027. dewater_amount = 0
  3028. }
  3029. // 计算透析处方的相关超滤量
  3030. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3031. var lastDialysisPrescribe *models.DialysisPrescription
  3032. var dialysisSolution *models.DialysisSolution
  3033. var dialysisPrescribe *models.DialysisPrescription
  3034. var mode_id int64
  3035. if schedual != nil {
  3036. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  3037. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3038. // 获取透析模版
  3039. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3040. mode_id = schedual.ModeId
  3041. } else {
  3042. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  3043. // 获取透析模版
  3044. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3045. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  3046. if dialysisPrescribe == nil && dialysisSolution != nil {
  3047. mode_id = dialysisSolution.ModeId
  3048. }
  3049. if dialysisPrescribe == nil && dialysisSolution == nil {
  3050. mode_id = 0
  3051. }
  3052. }
  3053. // 插入透析处方
  3054. if dialysisPrescribe == nil && dialysisSolution != nil {
  3055. var newprescribe models.DialysisPrescription
  3056. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  3057. newprescribe.PatientId = dialysisSolution.PatientId
  3058. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3059. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3060. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3061. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3062. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3063. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3064. newprescribe.ModeId = dialysisSolution.ModeId
  3065. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3066. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3067. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3068. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3069. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3070. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3071. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3072. newprescribe.Glucose = dialysisSolution.Glucose
  3073. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3074. newprescribe.Kalium = dialysisSolution.Kalium
  3075. newprescribe.Sodium = dialysisSolution.Sodium
  3076. newprescribe.Calcium = dialysisSolution.Calcium
  3077. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3078. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3079. newprescribe.Conductivity = dialysisSolution.Conductivity
  3080. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3081. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3082. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3083. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3084. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3085. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3086. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3087. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3088. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3089. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3090. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3091. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3092. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3093. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3094. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3095. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3096. newprescribe.CreatedTime = time.Now().Unix()
  3097. newprescribe.UpdatedTime = time.Now().Unix()
  3098. newprescribe.RecordDate = recordDate.Unix()
  3099. newprescribe.DewaterAmount = dewater_amount
  3100. newprescribe.TargetUltrafiltration = dewater_amount
  3101. newprescribe.Status = 1
  3102. err := service.AddSigleRecord(&newprescribe)
  3103. if err != nil {
  3104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3105. }
  3106. }
  3107. if dialysisPrescribe == nil && dialysisSolution == nil {
  3108. if lastDialysisPrescribe != nil {
  3109. var newprescribe models.DialysisPrescription
  3110. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  3111. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  3112. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3113. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3114. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3115. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3116. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3117. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3118. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3119. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3120. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3121. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3122. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3123. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3124. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3125. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3126. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3127. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3128. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3129. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3130. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3131. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3132. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3133. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3134. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3135. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3136. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3137. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3138. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3139. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3140. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3141. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3142. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3143. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3144. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3145. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3146. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3147. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3148. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3149. newprescribe.CreatedTime = time.Now().Unix()
  3150. newprescribe.UpdatedTime = time.Now().Unix()
  3151. newprescribe.RecordDate = recordDate.Unix()
  3152. newprescribe.DewaterAmount = dewater_amount
  3153. newprescribe.TargetUltrafiltration = dewater_amount
  3154. newprescribe.Status = 1
  3155. err := service.AddSigleRecord(&newprescribe)
  3156. if err != nil {
  3157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3158. }
  3159. } else {
  3160. var newprescribe models.DialysisPrescription
  3161. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3162. newprescribe.PatientId = patient
  3163. newprescribe.ModeId = mode_id
  3164. newprescribe.CreatedTime = time.Now().Unix()
  3165. newprescribe.UpdatedTime = time.Now().Unix()
  3166. newprescribe.RecordDate = recordDate.Unix()
  3167. newprescribe.DewaterAmount = dewater_amount
  3168. newprescribe.TargetUltrafiltration = dewater_amount
  3169. newprescribe.Status = 1
  3170. err := service.AddSigleRecord(&newprescribe)
  3171. if err != nil {
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3173. }
  3174. }
  3175. }
  3176. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3177. if err == nil {
  3178. c.ServeSuccessJSON(map[string]interface{}{
  3179. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3180. })
  3181. } else {
  3182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3183. }
  3184. }
  3185. }
  3186. func (c *DialysisApiController) PostTreatmentSummary() {
  3187. patient, _ := c.GetInt64("patient", 0)
  3188. recordDateStr := c.GetString("record_date")
  3189. if patient <= 0 {
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3191. return
  3192. }
  3193. adminUserInfo := c.GetAdminUserInfo()
  3194. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3195. if patientInfo.ID == 0 {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3197. return
  3198. }
  3199. if len(recordDateStr) == 0 {
  3200. recordDateStr = time.Now().Format("2006-01-02")
  3201. }
  3202. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3203. if parseDateErr != nil {
  3204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3206. return
  3207. }
  3208. mission := c.GetString("mission")
  3209. dialysis_summary := c.GetString("dialysis_summary")
  3210. nursingRecord := c.GetString("nursing_record")
  3211. specialRecord := c.GetString("special_record")
  3212. sj_nurse := adminUserInfo.AdminUser.Id
  3213. zl_nurse := adminUserInfo.AdminUser.Id
  3214. hd_nurse := adminUserInfo.AdminUser.Id
  3215. xj_nurse := adminUserInfo.AdminUser.Id
  3216. zl_doctor := adminUserInfo.AdminUser.Id
  3217. treatmentSummary := models.TreatmentSummary{
  3218. UserOrgId: adminUserInfo.CurrentOrgId,
  3219. PatientId: patient,
  3220. AssessmentDate: recordDate.Unix(),
  3221. Mission: mission,
  3222. DialysisSummary: dialysis_summary,
  3223. SjNurse: sj_nurse,
  3224. ZlNurse: zl_nurse,
  3225. HdNurse: hd_nurse,
  3226. XjNurse: xj_nurse,
  3227. ZlDoctor: zl_doctor,
  3228. Status: 1,
  3229. CreatedTime: time.Now().Unix(),
  3230. NursingRecord: nursingRecord,
  3231. SpecialRecord: specialRecord,
  3232. }
  3233. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3234. if tempTreatmentSummary.ID == 0 { //新增
  3235. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3236. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3237. if err == nil {
  3238. c.ServeSuccessJSON(map[string]interface{}{
  3239. "summary": treatmentSummary,
  3240. })
  3241. } else {
  3242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3243. }
  3244. } else { //修改
  3245. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3246. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3247. // if getPermissionErr != nil {
  3248. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3249. // return
  3250. // } else if headNursePermission == nil {
  3251. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3252. // return
  3253. // }
  3254. //}
  3255. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3256. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3257. treatmentSummary.UpdatedTime = time.Now().Unix()
  3258. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3259. treatmentSummary.ID = tempTreatmentSummary.ID
  3260. err := service.UpdateSummeRecord(&treatmentSummary)
  3261. if err == nil {
  3262. c.ServeSuccessJSON(map[string]interface{}{
  3263. "summary": treatmentSummary,
  3264. })
  3265. } else {
  3266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3267. }
  3268. }
  3269. }
  3270. func (c *DialysisApiController) GetDeviceList() {
  3271. adminUserInfo := c.GetAdminUserInfo()
  3272. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3273. c.ServeSuccessJSON(map[string]interface{}{
  3274. "device": device,
  3275. })
  3276. }
  3277. func (c *DialysisApiController) GetAllDeviceZone() {
  3278. adminUserInfo := c.GetAdminUserInfo()
  3279. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3280. if err == nil {
  3281. c.ServeSuccessJSON(map[string]interface{}{
  3282. "zone": zone,
  3283. })
  3284. }
  3285. }
  3286. func (c *DialysisApiController) GetDialysisWatch() {
  3287. page, _ := c.GetInt64("page", 1)
  3288. limit, _ := c.GetInt64("limit", 10)
  3289. schedulType, _ := c.GetInt64("schedul_type", 0)
  3290. startTime, _ := c.GetInt64("schedul_time", 0)
  3291. partitionType, _ := c.GetInt64("partition_type", 0)
  3292. keywords := c.GetString("keywords")
  3293. adminUserInfo := c.GetAdminUserInfo()
  3294. if len(keywords) > 0 {
  3295. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3296. if err == nil {
  3297. c.ServeSuccessJSON(map[string]interface{}{
  3298. "schedule": dialysisSchedule,
  3299. "total": total,
  3300. })
  3301. } else {
  3302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3303. }
  3304. } else {
  3305. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3306. if err == nil {
  3307. c.ServeSuccessJSON(map[string]interface{}{
  3308. "schedule": dialysisSchedule,
  3309. "total": total,
  3310. })
  3311. } else {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3313. }
  3314. }
  3315. }
  3316. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3317. patientId, _ := c.GetInt64("id", 0)
  3318. record_date, _ := c.GetInt64("record_date", 0)
  3319. adminUserInfo := c.GetAdminUserInfo()
  3320. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3321. var dialysisStatus int64
  3322. if dialysisOrder == nil { //没有透析记录
  3323. dialysisStatus = 0 //未透析
  3324. } else {
  3325. dialysisStatus = dialysisOrder.Stage
  3326. }
  3327. //用户基本信息
  3328. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3329. //接诊评估
  3330. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3331. //透前评估
  3332. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3333. //临时医嘱
  3334. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3335. //双人核对
  3336. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3337. //透析监测
  3338. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3339. //透后评估
  3340. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3341. //透析小结
  3342. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3343. //透析处方
  3344. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3345. if dialysisPrescription.ID == 0 {
  3346. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3347. c.ServeSuccessJSON(map[string]interface{}{
  3348. "patientInfo": schedualPatientInfo,
  3349. "dialysisPrescription": solution,
  3350. "receiverTreatmentAccess": receiverTreatmentAccess,
  3351. "predialysisEvaluation": PredialysisEvaluation,
  3352. "doctorAdvice": DoctorAdvice,
  3353. "doubleCheck": DoubleCheck,
  3354. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3355. "treatmentSummary": TreatmentSummary,
  3356. "monitorRecord": Record,
  3357. "dialysisStatus": dialysisStatus,
  3358. "dialysisOrder": dialysisOrder,
  3359. "isSolution": 1,
  3360. })
  3361. } else {
  3362. c.ServeSuccessJSON(map[string]interface{}{
  3363. "patientInfo": schedualPatientInfo,
  3364. "dialysisPrescription": dialysisPrescription,
  3365. "receiverTreatmentAccess": receiverTreatmentAccess,
  3366. "predialysisEvaluation": PredialysisEvaluation,
  3367. "doctorAdvice": DoctorAdvice,
  3368. "doubleCheck": DoubleCheck,
  3369. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3370. "treatmentSummary": TreatmentSummary,
  3371. "monitorRecord": Record,
  3372. "dialysisStatus": dialysisStatus,
  3373. "dialysisOrder": dialysisOrder,
  3374. "isSolution": 2,
  3375. })
  3376. }
  3377. }
  3378. func (c *DialysisApiController) CreateDoctorAdvice() {
  3379. patient, _ := c.GetInt64("id", 0)
  3380. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3381. record_date, _ := c.GetInt64("record_date", 0)
  3382. if patient <= 0 {
  3383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3384. return
  3385. }
  3386. adminUserInfo := c.GetAdminUserInfo()
  3387. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3388. if patientInfo.ID == 0 {
  3389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3390. return
  3391. }
  3392. var advice models.DoctorAdvice
  3393. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3394. if code > 0 {
  3395. c.ServeFailJSONWithSGJErrorCode(code)
  3396. return
  3397. }
  3398. if advice.ParentId > 0 {
  3399. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3400. if old.ID == 0 || old.PatientId != patient {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3402. return
  3403. }
  3404. if old.StopState == 1 || old.ExecutionState == 1 {
  3405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3406. return
  3407. }
  3408. if old.ParentId > 0 {
  3409. advice.ParentId = old.ParentId
  3410. }
  3411. advice.StartTime = old.StartTime
  3412. advice.AdviceDoctor = old.AdviceDoctor
  3413. advice.DeliveryWay = old.DeliveryWay
  3414. advice.ExecutionFrequency = old.ExecutionFrequency
  3415. }
  3416. advice.RecordDate = record_date
  3417. advice.DialysisOrderId = dialysis_id
  3418. advice.Status = 1
  3419. advice.CreatedTime = time.Now().Unix()
  3420. advice.UpdatedTime = time.Now().Unix()
  3421. advice.StopState = 2
  3422. advice.ExecutionState = 2
  3423. advice.AdviceType = 2
  3424. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3425. advice.PatientId = patient
  3426. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3427. err := service.CreateDoctorAdvice(&advice)
  3428. if err != nil {
  3429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3430. return
  3431. }
  3432. for _, subAdvice := range subAdivice {
  3433. subAdvice.ParentId = advice.ID
  3434. subAdvice.PatientId = patient
  3435. subAdvice.RecordDate = record_date
  3436. subAdvice.CreatedTime = time.Now().Unix()
  3437. subAdvice.UpdatedTime = time.Now().Unix()
  3438. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3439. }
  3440. service.CreateSubDoctorAdvice(subAdivice)
  3441. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3442. c.ServeSuccessJSON(map[string]interface{}{
  3443. "msg": "ok",
  3444. "advice": advice,
  3445. "subAdvice": subAdivices,
  3446. })
  3447. return
  3448. }
  3449. func (c *DialysisApiController) EditDoctorAdvice() {
  3450. patient, _ := c.GetInt64("patient", 0)
  3451. id, _ := c.GetInt64("id", 0)
  3452. parent_id, _ := c.GetInt64("parent_id", 0)
  3453. execution_time := c.GetString("execution_time")
  3454. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3455. // checker, _ := c.GetInt64("checker", 0)
  3456. if id <= 0 || patient <= 0 {
  3457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3458. return
  3459. }
  3460. adminUserInfo := c.GetAdminUserInfo()
  3461. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3462. if advice.ID == 0 || advice.PatientId != patient {
  3463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3464. return
  3465. }
  3466. if len(execution_time) <= 0 {
  3467. utils.ErrorLog("execution_time")
  3468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3469. return
  3470. }
  3471. execution_staff := adminUserInfo.AdminUser.Id
  3472. checker := adminUserInfo.AdminUser.Id
  3473. timeLayout2 := "2006-01-02 15:04"
  3474. loc, _ := time.LoadLocation("Local")
  3475. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3476. if errs != nil {
  3477. utils.ErrorLog(errs.Error())
  3478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3479. return
  3480. }
  3481. advices := models.DoctorAdvice{
  3482. ExecutionStaff: execution_staff,
  3483. ExecutionTime: theTime.Unix(),
  3484. Checker: checker,
  3485. UpdatedTime: time.Now().Unix(),
  3486. }
  3487. var err error
  3488. if parent_id > 0 {
  3489. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3490. } else {
  3491. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3492. }
  3493. if err != nil {
  3494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3495. return
  3496. }
  3497. c.ServeSuccessJSON(map[string]interface{}{
  3498. "msg": "ok",
  3499. "advice": advice,
  3500. })
  3501. return
  3502. }
  3503. func (c *DialysisApiController) GetDoctorAdvice() {
  3504. patient, _ := c.GetInt64("patient_id", 0)
  3505. parent_id, _ := c.GetInt64("parent_id", 0)
  3506. adviceId, _ := c.GetInt64("id", 0)
  3507. if patient <= 0 {
  3508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3509. return
  3510. }
  3511. dminUserInfo := c.GetAdminUserInfo()
  3512. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3513. if patientInfo.ID == 0 {
  3514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3515. return
  3516. }
  3517. var subAdvice []*models.DoctorAdvice
  3518. var advice models.DoctorAdvice
  3519. if parent_id > 0 {
  3520. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3521. if advice.ID == 0 || advice.PatientId != patient {
  3522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3523. return
  3524. }
  3525. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3526. } else {
  3527. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3528. if advice.ID == 0 || advice.PatientId != patient {
  3529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3530. return
  3531. }
  3532. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3533. }
  3534. c.ServeSuccessJSON(map[string]interface{}{
  3535. "msg": "ok",
  3536. "advice": advice,
  3537. "subAdvice": subAdvice,
  3538. })
  3539. }
  3540. func (this *DialysisApiController) DelMonitor() {
  3541. recordID, _ := this.GetInt64("record_id")
  3542. patientID, _ := this.GetInt64("patient_id")
  3543. if recordID <= 0 || patientID <= 0 {
  3544. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3545. return
  3546. }
  3547. adminInfo := this.GetAdminUserInfo()
  3548. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3549. if getPatientErr != nil {
  3550. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3552. return
  3553. } else if patient == nil {
  3554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3555. return
  3556. }
  3557. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3558. if getMonitorErr != nil {
  3559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3560. return
  3561. }
  3562. //if monitor != nil {
  3563. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3564. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3565. // if getPermissionErr != nil {
  3566. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3567. // return
  3568. // } else if headNursePermission == nil {
  3569. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3570. // return
  3571. // }
  3572. // }
  3573. //}
  3574. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3575. if err != nil {
  3576. this.ErrorLog("删除透析监测记录失败:%v", err)
  3577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3578. return
  3579. }
  3580. this.ServeSuccessJSON(map[string]interface{}{
  3581. "record_id": monitor.ID,
  3582. })
  3583. }
  3584. func (c *DialysisApiController) CreateMonitor() {
  3585. patient, _ := c.GetInt64("id", 0)
  3586. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3587. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3588. operate_time, _ := c.GetInt64("operate_time", 0)
  3589. // monitoring_time := c.GetString("monitoring_time")
  3590. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3591. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  3592. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3593. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3594. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3595. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3596. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3597. venous_pressure_unit := c.GetString("venous_pressure_unit")
  3598. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3599. transmembrane_pressure_unit := c.GetString("transmembrane_pressure_unit")
  3600. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3601. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3602. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3603. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3604. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3605. temperature, _ := c.GetFloat("temperature", 0)
  3606. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3607. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3608. conductivity, _ := c.GetFloat("conductivity", 0)
  3609. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3610. heparin, _ := c.GetFloat("heparin", 0)
  3611. ktv, _ := c.GetFloat("ktv", 0)
  3612. symptom := c.GetString("symptom")
  3613. dispose := c.GetString("dispose")
  3614. result := c.GetString("results")
  3615. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3616. monitoring_date = monitoring_date / 1000
  3617. // operate_time = operate_time / 1000
  3618. if patient <= 0 {
  3619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3620. return
  3621. }
  3622. adminUserInfo := c.GetAdminUserInfo()
  3623. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3624. if patientInfo.ID == 0 {
  3625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3626. return
  3627. }
  3628. monitorRecord := models.MonitoringRecord{
  3629. PatientId: patient,
  3630. MonitoringDate: monitoring_date,
  3631. DialysisOrderId: dialysis_order_id,
  3632. OperateTime: operate_time,
  3633. // MonitoringTime: monitoring_time,
  3634. PulseFrequency: pulse_frequency,
  3635. BreathingRate: breathing_rated,
  3636. SystolicBloodPressure: systolic_blood_pressure,
  3637. DiastolicBloodPressure: diastolic_blood_pressure,
  3638. BloodPressureType: blood_pressure_type,
  3639. BloodFlowVolume: blood_flow_volume,
  3640. VenousPressure: venous_pressure,
  3641. VenousPressureUnit: venous_pressure_unit,
  3642. TransmembranePressure: transmembrane_pressure,
  3643. TransmembranePressureUnit: transmembrane_pressure_unit,
  3644. UltrafiltrationRate: ultrafiltration_rate,
  3645. UltrafiltrationVolume: ultrafiltration_volume,
  3646. SodiumConcentration: sodium_concentration,
  3647. ArterialPressure: arterial_pressure,
  3648. DialysateTemperature: dialysate_temperature,
  3649. Temperature: temperature,
  3650. ReplacementRate: replacement_rate,
  3651. DisplacementQuantity: displacement_quantity,
  3652. Ktv: ktv,
  3653. Symptom: symptom,
  3654. Dispose: dispose,
  3655. Result: result,
  3656. MonitoringNurse: monitoring_nurse,
  3657. Status: 1,
  3658. CreatedTime: time.Now().Unix(),
  3659. UpdatedTime: time.Now().Unix(),
  3660. UserOrgId: adminUserInfo.CurrentOrgId,
  3661. Conductivity: conductivity,
  3662. DisplacementFlowQuantity: displacement_flow_quantity,
  3663. Heparin: heparin,
  3664. }
  3665. err := service.CreateMonitor(&monitorRecord)
  3666. if err != nil {
  3667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3668. return
  3669. }
  3670. c.ServeSuccessJSON(map[string]interface{}{
  3671. "msg": "ok",
  3672. "monitor": monitorRecord,
  3673. })
  3674. return
  3675. }
  3676. // 已弃用
  3677. // func (c *DialysisApiController) CreateRecordData() {
  3678. // patient, _ := c.GetInt64("id", 0)
  3679. // status, _ := c.GetInt64("status", 0)
  3680. // now := time.Now()
  3681. // year, month, day := now.Date()
  3682. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3683. // todayTimeStamp := today_time.Unix()
  3684. // if patient <= 0 {
  3685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3686. // return
  3687. // }
  3688. // adminUserInfo := c.GetAdminUserInfo()
  3689. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3690. // if patientInfo.ID == 0 {
  3691. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3692. // return
  3693. // }
  3694. // record := &models.DialysisOrder{
  3695. // DialysisDate: todayTimeStamp,
  3696. // UserOrgId: adminUserInfo.CurrentOrgId,
  3697. // PatientId: patient,
  3698. // Stage: status,
  3699. // Status: 1,
  3700. // CreatedTime: time.Now().Unix(),
  3701. // UpdatedTime: time.Now().Unix(),
  3702. // }
  3703. // if status == 1 {
  3704. // //创建透析记录
  3705. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3706. // if err == nil {
  3707. // c.ServeSuccessJSON(map[string]interface{}{
  3708. // "dialysisOrder": record,
  3709. // })
  3710. // } else {
  3711. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3712. // }
  3713. // } else {
  3714. // record_id, _ := c.GetInt64("record_id", 0)
  3715. // //修改透析记录状态
  3716. // errs := service.ModifyDialysisRecord(record_id)
  3717. // //结束时候透析次数加1
  3718. // service.UpdateSolutionByPatientId(patient)
  3719. // if errs == nil {
  3720. // c.ServeSuccessJSON(map[string]interface{}{
  3721. // "dialysisOrder": record,
  3722. // })
  3723. // } else {
  3724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3725. // }
  3726. // }
  3727. // }
  3728. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3729. dataBody := make(map[string]interface{}, 0)
  3730. err := json.Unmarshal(data, &dataBody)
  3731. if err != nil {
  3732. utils.ErrorLog(err.Error())
  3733. code = enums.ErrorCodeParamWrong
  3734. return
  3735. }
  3736. timeLayout := "2006-01-02 "
  3737. timeLayout2 := "2006-01-02 15:04"
  3738. loc, _ := time.LoadLocation("Local")
  3739. if action == "create" {
  3740. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3741. utils.ErrorLog("advice_type")
  3742. code = enums.ErrorCodeParamWrong
  3743. return
  3744. }
  3745. adviceType := int64(dataBody["advice_type"].(float64))
  3746. if adviceType != 1 && adviceType != 2 {
  3747. utils.ErrorLog("advice_type != 1&&2")
  3748. code = enums.ErrorCodeParamWrong
  3749. return
  3750. }
  3751. advice.AdviceType = adviceType
  3752. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3753. utils.ErrorLog("advice_date")
  3754. code = enums.ErrorCodeParamWrong
  3755. return
  3756. }
  3757. adviceDate, _ := dataBody["advice_date"].(string)
  3758. if len(adviceDate) == 0 {
  3759. utils.ErrorLog("len(adviceDate) == 0")
  3760. code = enums.ErrorCodeParamWrong
  3761. return
  3762. }
  3763. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3764. if err != nil {
  3765. utils.ErrorLog(err.Error())
  3766. code = enums.ErrorCodeParamWrong
  3767. return
  3768. }
  3769. advice.AdviceDate = theTime.Unix()
  3770. }
  3771. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3772. utils.ErrorLog("start_time")
  3773. code = enums.ErrorCodeParamWrong
  3774. return
  3775. }
  3776. startDate, _ := dataBody["start_time"].(string)
  3777. if len(startDate) == 0 {
  3778. utils.ErrorLog("len(startDate) == 0")
  3779. code = enums.ErrorCodeParamWrong
  3780. return
  3781. }
  3782. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3783. if err != nil {
  3784. utils.ErrorLog(err.Error())
  3785. code = enums.ErrorCodeParamWrong
  3786. return
  3787. }
  3788. advice.StartTime = theTime.Unix()
  3789. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3790. utils.ErrorLog("advice_name")
  3791. code = enums.ErrorCodeParamWrong
  3792. return
  3793. }
  3794. adviceName, _ := dataBody["advice_name"].(string)
  3795. if len(adviceName) == 0 {
  3796. utils.ErrorLog("len(advice_name) == 0")
  3797. code = enums.ErrorCodeParamWrong
  3798. return
  3799. }
  3800. advice.AdviceName = adviceName
  3801. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3802. utils.ErrorLog("delivery_way")
  3803. code = enums.ErrorCodeParamWrong
  3804. return
  3805. }
  3806. deliveryWay, _ := dataBody["delivery_way"].(string)
  3807. if len(deliveryWay) == 0 {
  3808. utils.ErrorLog("len(deliveryWay) == 0")
  3809. code = enums.ErrorCodeParamWrong
  3810. return
  3811. }
  3812. advice.DeliveryWay = deliveryWay
  3813. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3814. utils.ErrorLog("execution_frequency")
  3815. code = enums.ErrorCodeParamWrong
  3816. return
  3817. }
  3818. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3819. if len(execution_frequency) == 0 {
  3820. utils.ErrorLog("len(execution_frequency) == 0")
  3821. code = enums.ErrorCodeParamWrong
  3822. return
  3823. }
  3824. advice.ExecutionFrequency = execution_frequency
  3825. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3826. adviceDsc, _ := dataBody["advice_desc"].(string)
  3827. advice.AdviceDesc = adviceDsc
  3828. }
  3829. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3830. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3831. advice.DrugSpecUnit = drugSpecUnit
  3832. }
  3833. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3834. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3835. advice.SingleDose = singleDose
  3836. }
  3837. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3838. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3839. advice.SingleDoseUnit = singleDoseUnit
  3840. }
  3841. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3842. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3843. advice.PrescribingNumber = prescribingNumber
  3844. }
  3845. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3846. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3847. advice.PrescribingNumberUnit = prescribingNumberUnit
  3848. }
  3849. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3850. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3851. if len(thisContagions) > 0 {
  3852. for _, item := range thisContagions {
  3853. items := item.(map[string]interface{})
  3854. advice_name, _ := items["advice_name"].(string)
  3855. advice_desc, _ := items["advice_desc"].(string)
  3856. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3857. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3858. single_dose_unit, _ := items["single_dose_unit"].(string)
  3859. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3860. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3861. advice := &models.DoctorAdvice{
  3862. AdviceName: advice_name,
  3863. AdviceDesc: advice_desc,
  3864. SingleDose: single_dose,
  3865. SingleDoseUnit: single_dose_unit,
  3866. DrugSpecUnit: drug_spec_unit,
  3867. PrescribingNumber: prescribing_number,
  3868. PrescribingNumberUnit: prescribing_number_unit,
  3869. }
  3870. subAdvice = append(subAdvice, advice)
  3871. }
  3872. }
  3873. }
  3874. return
  3875. }
  3876. func (c *DialysisApiController) GetDialysisOrder() {
  3877. xtno := c.GetString("xtno")
  3878. xtdate := c.GetString("xtdate")
  3879. timeLayout := "2006-01-02"
  3880. loc, _ := time.LoadLocation("Local")
  3881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3882. if err != nil {
  3883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3884. return
  3885. }
  3886. xttime := theTime.Unix()
  3887. operatorIDs := make([]int64, 0)
  3888. adminUserInfo := c.GetAdminUserInfo()
  3889. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3890. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3891. //透析单
  3892. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3893. if dialysisOrder != nil {
  3894. if dialysisOrder.FinishNurse > 0 {
  3895. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3896. }
  3897. if dialysisOrder.StartNurse > 0 {
  3898. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3899. }
  3900. }
  3901. //透前评估
  3902. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3903. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3904. //透后评估
  3905. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3906. if AssessmentAfterDislysis.Modifier > 0 {
  3907. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3908. }
  3909. //透析处方
  3910. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3911. if dialysisPrescription.PrescriptionDoctor > 0 {
  3912. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3913. }
  3914. //获取病人的透析模式
  3915. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3916. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3917. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3918. //fmt.Print("nurse------------", err)
  3919. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3920. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3921. //获取透析处方
  3922. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3923. //获取临时医嘱
  3924. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3925. //获取医嘱内容
  3926. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3927. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3928. //fmt.Print("err-----------------------------------------------------------------", err)
  3929. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3930. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3931. //获取上次的透后体重
  3932. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3933. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3934. //获取透析次数
  3935. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3936. if len(DoctorAdvice) > 0 {
  3937. for _, item := range DoctorAdvice {
  3938. if item.AdviceDoctor > 0 {
  3939. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3940. }
  3941. if item.ExecutionStaff > 0 {
  3942. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3943. }
  3944. if item.Checker > 0 {
  3945. operatorIDs = append(operatorIDs, item.Checker)
  3946. }
  3947. }
  3948. }
  3949. //透析监测
  3950. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3951. //透析检测
  3952. monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3953. //透析小结
  3954. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3955. //接诊评估
  3956. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3957. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3958. //相关操作对应的操作人
  3959. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3960. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3961. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3962. c.ServeSuccessJSON(map[string]interface{}{
  3963. "xtdate": xtdate,
  3964. "users": adminUser,
  3965. "patientInfo": patientInfo,
  3966. "PredialysisEvaluation": PredialysisEvaluation,
  3967. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3968. "dialysisPrescription": dialysisPrescription,
  3969. "advices": DoctorAdvice,
  3970. "monitors": Record,
  3971. "summary": TreatmentSummary,
  3972. "receiverTreatmentAccess": receiverTreatmentAccess,
  3973. "dialysisOrder": dialysisOrder,
  3974. "operators": operators,
  3975. "org_template_info": templateInfo,
  3976. "check": check,
  3977. "schedule": schedule,
  3978. "dialysisway": dialysisway,
  3979. "order": order,
  3980. "doctorAdvice": doctorAdvice,
  3981. "doctor": doctor,
  3982. "nurse": nurse,
  3983. "doctorAdevieInfo": doctorAdevieInfo,
  3984. "total": total,
  3985. "startNuse": startNuse,
  3986. "DoctorName": DoctorName,
  3987. "monitor": monitor,
  3988. "assessmentAfterDislysis": assessmentAfterDislysis,
  3989. "predialysName": predialysName,
  3990. "FinishNuse": FinishNuse,
  3991. })
  3992. }
  3993. //
  3994. func (c *DialysisApiController) GetLongAdvice() {
  3995. patient_id, _ := c.GetInt64("patient_id")
  3996. adminUserInfo := c.GetAdminUserInfo()
  3997. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3998. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3999. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4000. c.ServeSuccessJSON(map[string]interface{}{
  4001. "status": "1",
  4002. })
  4003. return
  4004. } else { //开启推送提醒
  4005. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4006. var advice_three []*models.DoctorAdvice
  4007. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4008. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  4009. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  4010. for _, advice := range advices {
  4011. if advice.FrequencyType == 3 {
  4012. t := time.Now()
  4013. week := int(t.Weekday())
  4014. switch week {
  4015. case 1:
  4016. if strings.Index(advice.WeekDay, "周一") == -1 {
  4017. advice_three = append(advice_three, advice)
  4018. }
  4019. break
  4020. case 2:
  4021. if strings.Index(advice.WeekDay, "周二") == -1 {
  4022. advice_three = append(advice_three, advice)
  4023. }
  4024. break
  4025. case 3:
  4026. if strings.Index(advice.WeekDay, "周三") == -1 {
  4027. advice_three = append(advice_three, advice)
  4028. }
  4029. break
  4030. case 4:
  4031. if strings.Index(advice.WeekDay, "周四") == -1 {
  4032. advice_three = append(advice_three, advice)
  4033. }
  4034. break
  4035. case 5:
  4036. if strings.Index(advice.WeekDay, "周五") == -1 {
  4037. advice_three = append(advice_three, advice)
  4038. }
  4039. break
  4040. case 6:
  4041. if strings.Index(advice.WeekDay, "周六") == -1 {
  4042. advice_three = append(advice_three, advice)
  4043. }
  4044. break
  4045. case 0:
  4046. if strings.Index(advice.WeekDay, "周日") == -1 {
  4047. advice_three = append(advice_three, advice)
  4048. }
  4049. break
  4050. }
  4051. }
  4052. }
  4053. for _, advice := range advices_two {
  4054. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4055. now := p.Unix()
  4056. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4057. dayStr2 := "-" + dayStr
  4058. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4059. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4060. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4061. for _, ad := range advices {
  4062. advice_three = append(advice_three, ad)
  4063. }
  4064. }
  4065. if err == nil {
  4066. c.ServeSuccessJSON(map[string]interface{}{
  4067. "status": "2",
  4068. "advices": advices,
  4069. "advices_two": RemoveRepeatedElement(advice_three),
  4070. "is_open_remind": config.IsOpenRemind,
  4071. })
  4072. }
  4073. }
  4074. }
  4075. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4076. newArr = make([]*models.DoctorAdvice, 0)
  4077. for i := 0; i < len(arr); i++ {
  4078. repeat := false
  4079. for j := i + 1; j < len(arr); j++ {
  4080. if arr[i].ID == arr[j].ID {
  4081. repeat = true
  4082. break
  4083. }
  4084. }
  4085. if !repeat {
  4086. newArr = append(newArr, arr[i])
  4087. }
  4088. }
  4089. return
  4090. }
  4091. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4092. patient, _ := c.GetInt64("id", 0)
  4093. groupNo, _ := c.GetInt64("groupno", 0)
  4094. if patient <= 0 {
  4095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4096. return
  4097. }
  4098. adminUserInfo := c.GetAdminUserInfo()
  4099. dataBody := make(map[string]interface{}, 0)
  4100. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4101. if err != nil {
  4102. utils.ErrorLog(err.Error())
  4103. return
  4104. }
  4105. utils.ErrorLog("%v", dataBody)
  4106. timeLayout := "2006-01-02 15:04"
  4107. loc, _ := time.LoadLocation("Local")
  4108. timeLayout2 := "2006-01-02"
  4109. loc2, _ := time.LoadLocation("Local")
  4110. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4111. utils.ErrorLog("advice_type")
  4112. return
  4113. }
  4114. adviceType := int64(2)
  4115. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4116. utils.ErrorLog("advice_date")
  4117. return
  4118. }
  4119. adviceDate, _ := dataBody["advice_date"].(string)
  4120. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4121. AdviceDate := theTime.Unix()
  4122. RecordDate := theTime.Unix()
  4123. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4124. utils.ErrorLog("start_time")
  4125. return
  4126. }
  4127. startTime, _ := dataBody["start_time"].(string)
  4128. if len(startTime) == 0 {
  4129. utils.ErrorLog("len(start_time) == 0")
  4130. return
  4131. }
  4132. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4133. if err != nil {
  4134. utils.ErrorLog(err.Error())
  4135. return
  4136. }
  4137. StartTime := theTime.Unix()
  4138. Remark := ""
  4139. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4140. remark, _ := dataBody["remark"].(string)
  4141. Remark = remark
  4142. }
  4143. var advices []*models.GroupAdvice
  4144. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4145. utils.ErrorLog("advices")
  4146. return
  4147. }
  4148. adviceNames := dataBody["advices"].([]interface{})
  4149. for _, adviceNameMap := range adviceNames {
  4150. adviceNameM := adviceNameMap.(map[string]interface{})
  4151. var advice models.GroupAdvice
  4152. advice.Remark = Remark
  4153. advice.AdviceType = adviceType
  4154. advice.StartTime = StartTime
  4155. advice.AdviceDate = AdviceDate
  4156. advice.RecordDate = RecordDate
  4157. advice.Status = 1
  4158. advice.CreatedTime = time.Now().Unix()
  4159. advice.UpdatedTime = time.Now().Unix()
  4160. advice.StopState = 2
  4161. advice.ExecutionState = 2
  4162. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4163. advice.PatientId = patient
  4164. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4165. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4166. utils.ErrorLog("advice_name")
  4167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4168. return
  4169. }
  4170. adviceName, _ := adviceNameM["advice_name"].(string)
  4171. if len(adviceName) == 0 {
  4172. utils.ErrorLog("len(advice_name) == 0")
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. advice.AdviceName = adviceName
  4177. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4178. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4179. advice.DrugSpec = drugSpec
  4180. }
  4181. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4182. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4183. advice.AdviceDesc = adviceDesc
  4184. }
  4185. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4186. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4187. advice.DrugSpecUnit = drugSpecUnit
  4188. }
  4189. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4190. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4191. // advice.SingleDose = singleDose
  4192. //}
  4193. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4194. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4195. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4196. }
  4197. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4198. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4199. advice.SingleDoseUnit = singleDoseUnit
  4200. }
  4201. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4202. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4203. // advice.PrescribingNumber = prescribingNumber
  4204. //}
  4205. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4206. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4207. }
  4208. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4209. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4210. advice.PrescribingNumberUnit = prescribingNumberUnit
  4211. }
  4212. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4213. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4214. advice.DeliveryWay = deliveryWay
  4215. }
  4216. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4217. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4218. advice.ExecutionFrequency = executionFrequency
  4219. }
  4220. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4221. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4222. advice.FrequencyType = frequency_type
  4223. }
  4224. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4225. day_count := int64(adviceNameM["day_count"].(float64))
  4226. advice.DayCount = day_count
  4227. }
  4228. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4229. week_day, _ := adviceNameM["week_day"].(string)
  4230. advice.WeekDay = week_day
  4231. }
  4232. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4233. template_id, _ := adviceNameM["template_id"].(string)
  4234. advice.TemplateId = template_id
  4235. }
  4236. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4237. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4238. advice.ExecutionFrequency = executionFrequency
  4239. }
  4240. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4241. children := adviceNameM["child"].([]interface{})
  4242. if len(children) > 0 {
  4243. for _, childrenMap := range children {
  4244. childMap := childrenMap.(map[string]interface{})
  4245. var child models.GroupAdvice
  4246. child.Remark = Remark
  4247. child.AdviceType = adviceType
  4248. child.StartTime = StartTime
  4249. child.AdviceDate = AdviceDate
  4250. child.RecordDate = RecordDate
  4251. child.Status = 1
  4252. child.CreatedTime = time.Now().Unix()
  4253. child.UpdatedTime = time.Now().Unix()
  4254. child.StopState = 2
  4255. child.ExecutionState = 2
  4256. child.UserOrgId = adminUserInfo.CurrentOrgId
  4257. child.PatientId = patient
  4258. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4259. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4260. utils.ErrorLog("child advice_name")
  4261. return
  4262. }
  4263. childAdviceName, _ := childMap["advice_name"].(string)
  4264. if len(childAdviceName) == 0 {
  4265. utils.ErrorLog("len(child advice_name) == 0")
  4266. return
  4267. }
  4268. child.AdviceName = childAdviceName
  4269. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4270. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4271. child.AdviceDesc = childAdviceDesc
  4272. }
  4273. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4274. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4275. child.DrugSpec = childDrugSpec
  4276. }
  4277. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4278. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4279. child.DrugSpecUnit = childDrugSpecUnit
  4280. }
  4281. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4282. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4283. child.SingleDose = childSingleDose
  4284. }
  4285. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4286. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4287. child.SingleDoseUnit = childSingleDoseUnit
  4288. }
  4289. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4290. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4291. child.PrescribingNumber = childPrescribingNumber
  4292. }
  4293. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4294. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4295. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4296. }
  4297. child.DeliveryWay = advice.DeliveryWay
  4298. child.ExecutionFrequency = advice.ExecutionFrequency
  4299. advice.Children = append(advice.Children, &child)
  4300. }
  4301. }
  4302. }
  4303. advices = append(advices, &advice)
  4304. }
  4305. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4306. if err != nil {
  4307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4308. return
  4309. }
  4310. c.ServeSuccessJSON(map[string]interface{}{
  4311. "msg": "ok",
  4312. "advices": list,
  4313. })
  4314. return
  4315. }
  4316. func (c *DialysisApiController) GetSolution() {
  4317. patient_id, _ := c.GetInt64("patient_id")
  4318. mode_id, _ := c.GetInt64("mode_id")
  4319. adminUserInfo := c.GetAdminUserInfo()
  4320. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4321. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4322. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
  4323. if err != nil {
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4325. return
  4326. }
  4327. c.ServeSuccessJSON(map[string]interface{}{
  4328. "solution": solution,
  4329. "prescription": prescription,
  4330. "system_prescription": system_prescription,
  4331. })
  4332. }
  4333. func (c *DialysisApiController) GetSchedule() {
  4334. schedual_type, _ := c.GetInt64("schedual_type")
  4335. adminUserInfo := c.GetAdminUserInfo()
  4336. timeLayout := "2006-01-02 15:04:05"
  4337. date := time.Now().Format("2006-01-02") + " 00:00:00"
  4338. loc, _ := time.LoadLocation("Local")
  4339. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4340. scheduleTime := theStartTime.Unix()
  4341. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4342. c.ServeSuccessJSON(map[string]interface{}{
  4343. "number": deviceNumber,
  4344. })
  4345. }
  4346. func (this *DialysisApiController) GetTodayMonitor() {
  4347. thisTime := time.Now()
  4348. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4349. timeLayout := "2006-01-02 15:04:05"
  4350. loc, _ := time.LoadLocation("Local")
  4351. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4352. theAssessmentDateTime := theStartTime.Unix()
  4353. patientID, _ := this.GetInt64("patient_id")
  4354. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4355. adminInfo := this.GetAdminUserInfo()
  4356. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4357. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4358. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4359. var ultrafiltration_rate float64
  4360. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4361. if prescription.ID > 0 {
  4362. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4363. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4364. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4365. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4366. }
  4367. // 只针对方济医院
  4368. if template.TemplateId == 1 {
  4369. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4370. ultrafiltration_rate = value
  4371. }
  4372. }
  4373. }
  4374. record.UltrafiltrationRate = ultrafiltration_rate
  4375. record.UltrafiltrationVolume = 0
  4376. if template.TemplateId == 1 {
  4377. if ultrafiltration_rate > 0 {
  4378. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4379. record.UltrafiltrationVolume = value
  4380. }
  4381. }
  4382. if template.TemplateId == 6 {
  4383. if ultrafiltration_rate > 0 {
  4384. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4385. record.UltrafiltrationVolume = ultrafiltration_volume
  4386. }
  4387. }
  4388. this.ServeSuccessJSON(map[string]interface{}{
  4389. "monitor": record,
  4390. })
  4391. }
  4392. func (c *DialysisApiController) UploadDryWeight() {
  4393. patient_id, _ := c.GetInt64("id")
  4394. dry_weight, _ := c.GetFloat("dry_weight")
  4395. doctor_id, _ := c.GetInt64("doctor_id")
  4396. remark := c.GetString("remark")
  4397. adminUserInfo := c.GetAdminUserInfo()
  4398. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4399. fmt.Println(err)
  4400. if err == gorm.ErrRecordNotFound {
  4401. dryWeight := &models.SgjPatientDryweight{
  4402. PatientId: patient_id,
  4403. DryWeight: dry_weight,
  4404. Remakes: remark,
  4405. Ctime: time.Now().Unix(),
  4406. Mtime: time.Now().Unix(),
  4407. Creator: doctor_id,
  4408. Status: 1,
  4409. UserOrgId: adminUserInfo.CurrentOrgId,
  4410. AdjustedValue: "/",
  4411. UserId: adminUserInfo.AdminUser.Id,
  4412. }
  4413. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4414. if createErr == nil {
  4415. c.ServeSuccessJSON(map[string]interface{}{
  4416. "msg": "提交成功",
  4417. "weight": dryWeight,
  4418. })
  4419. }
  4420. } else {
  4421. dryWeight := &models.SgjPatientDryweight{
  4422. PatientId: patient_id,
  4423. DryWeight: dry_weight,
  4424. Remakes: remark,
  4425. Ctime: time.Now().Unix(),
  4426. Mtime: time.Now().Unix(),
  4427. Creator: doctor_id,
  4428. Status: 1,
  4429. UserOrgId: adminUserInfo.CurrentOrgId,
  4430. AdjustedValue: "/",
  4431. UserId: adminUserInfo.AdminUser.Id,
  4432. }
  4433. var value float64
  4434. value = dry_weight - weightAdjust.DryWeight
  4435. fmt.Println(value)
  4436. if value < 0 {
  4437. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4438. } else if value == 0 {
  4439. dryWeight.AdjustedValue = "/"
  4440. } else if value > 0 {
  4441. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4442. }
  4443. fmt.Println(value)
  4444. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4445. if createErr == nil {
  4446. c.ServeSuccessJSON(map[string]interface{}{
  4447. "msg": "提交成功",
  4448. "weight": dryWeight,
  4449. })
  4450. }
  4451. }
  4452. }
  4453. func (this *DialysisApiController) GetFuncPurview() {
  4454. adminUserInfo := this.GetAdminUserInfo()
  4455. user_id := adminUserInfo.AdminUser.Id
  4456. app_id := adminUserInfo.CurrentAppId
  4457. org_id := adminUserInfo.CurrentOrgId
  4458. create_url := this.GetString("create_url")
  4459. modify_url := this.GetString("modify_url")
  4460. modify_other_url := this.GetString("modify_other_url")
  4461. del_url := this.GetString("del_url")
  4462. del_other_url := this.GetString("del_other_url")
  4463. exce_url := this.GetString("exce_url")
  4464. check_url := this.GetString("check_url")
  4465. modify_exce_url := this.GetString("modify_exce_url")
  4466. module, _ := this.GetInt64("module", 0)
  4467. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4468. var is_has_create bool
  4469. var is_has_modify bool
  4470. var is_has_modify_other bool
  4471. var is_has_del bool
  4472. var is_has_del_other bool
  4473. var is_has_exce bool
  4474. var is_has_check bool
  4475. var is_has_modify_exce bool
  4476. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4477. if adminUserInfo.AdminUser.Id != org.Creator {
  4478. if app_role != nil {
  4479. if len(app_role.RoleIds) > 0 {
  4480. roles := strings.Split(app_role.RoleIds, ",")
  4481. var userRolePurviews string
  4482. for _, item := range roles {
  4483. role_id, _ := strconv.ParseInt(item, 10, 64)
  4484. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4485. if len(userRolePurviews) == 0 {
  4486. userRolePurviews = purviews
  4487. } else {
  4488. userRolePurviews = userRolePurviews + "," + purviews
  4489. }
  4490. }
  4491. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4492. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4493. for _, item := range funcPurviews {
  4494. //for _, url := range strings.Split(item.Urlfor,","){
  4495. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4496. is_has_create = true
  4497. }
  4498. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4499. is_has_modify = true
  4500. }
  4501. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4502. is_has_modify_other = true
  4503. }
  4504. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4505. is_has_del = true
  4506. }
  4507. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4508. is_has_del_other = true
  4509. }
  4510. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4511. is_has_exce = true
  4512. }
  4513. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4514. is_has_check = true
  4515. }
  4516. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4517. is_has_modify_exce = true
  4518. }
  4519. }
  4520. } else {
  4521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4522. return
  4523. }
  4524. this.ServeSuccessJSON(map[string]interface{}{
  4525. "is_has_create": is_has_create,
  4526. "is_has_modify": is_has_modify,
  4527. "is_has_modify_other": is_has_modify_other,
  4528. "is_has_del": is_has_del,
  4529. "is_has_del_other": is_has_del_other,
  4530. "is_has_exce": is_has_exce,
  4531. "is_has_check": is_has_check,
  4532. "is_has_modify_exce": is_has_modify_exce,
  4533. "module": module,
  4534. })
  4535. } else {
  4536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4537. return
  4538. }
  4539. } else {
  4540. this.ServeSuccessJSON(map[string]interface{}{
  4541. "is_has_create": true,
  4542. "is_has_modify": true,
  4543. "is_has_modify_other": true,
  4544. "is_has_del": true,
  4545. "is_has_del_other": true,
  4546. "is_has_exce": true,
  4547. "is_has_check": true,
  4548. "is_has_modify_exce": true,
  4549. "module": true,
  4550. })
  4551. }
  4552. }