dialysis_api_controller.go 277KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "math"
  16. )
  17. // type DialysisTestAPIController struct {
  18. // MobileBaseAPIController
  19. // }
  20. // [get]/m/api/test
  21. // func (this *DialysisTestAPIController) Test() {
  22. // orgID := int64(3907)
  23. // now := time.Now()
  24. // nextWeek := now.AddDate(0, 0, 7)
  25. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  26. // nextTwoWeek := now.AddDate(0, 0, 14)
  27. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  28. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  29. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  30. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  31. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. // return
  33. // }
  34. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  35. // if exchangeErr != nil {
  36. // this.ErrorLog("%v", exchangeErr)
  37. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. // return
  39. // }
  40. // this.ServeSuccessJSON(map[string]interface{}{
  41. // // "now": now,
  42. // // "next_week": nextWeek,f
  43. // // "next_week_mon": nextWeekMon,
  44. // // "next_week_sun": nextWeekSun,
  45. // // "next_two_week_mon": nextTwoWeekMon,
  46. // // "next_two_week_sun": nextTwoWeekSun,
  47. // "next_week_schs": nextWeekSchs,
  48. // "next_two_week_schs": nextTwoWeekSchs,
  49. // })
  50. // }
  51. type DialysisAPIController struct {
  52. MobileBaseAPIAuthController
  53. }
  54. // /m/api/scheduals [get]
  55. // @param type:int
  56. // @param date:string
  57. func (this *DialysisAPIController) Scheduals() {
  58. schedualType, _ := this.GetInt64("type")
  59. schedualDate := this.GetString("date")
  60. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  61. schedualType = 0
  62. }
  63. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  64. if parseDateErr != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. adminInfo := this.GetMobileAdminUserInfo()
  69. orgID := adminInfo.Org.Id
  70. redis := service.RedisClient()
  71. defer redis.Close()
  72. // cur_date := time.Now().Format("2006-01-02")
  73. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  74. scheduals_json_str, _ := redis.Get(key).Result()
  75. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  76. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  77. if err != nil {
  78. this.ErrorLog("获取排班信息失败:%v", err)
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  80. } else {
  81. if len(scheduals) > 0 {
  82. //缓存数据
  83. scheduals_json, err := json.Marshal(scheduals)
  84. if err == nil {
  85. redis.Set(key, scheduals_json, time.Second*30)
  86. }
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "scheduals": scheduals,
  90. })
  91. }
  92. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  93. var dat []map[string]interface{}
  94. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  95. } else {
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "scheduals": dat,
  99. "redis": "true",
  100. "date": schedualDate,
  101. })
  102. }
  103. }
  104. // /m/api/waiting_scheduals [get]
  105. // @param date:string
  106. func (this *DialysisAPIController) WaitingScheduals() {
  107. schedualDate := this.GetString("date")
  108. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  109. if parseDateErr != nil && len(schedualDate) != 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. adminInfo := this.GetMobileAdminUserInfo()
  114. orgID := adminInfo.Org.Id
  115. redis := service.RedisClient()
  116. defer redis.Close()
  117. // cur_date := time.Now().Format("2006-01-02")
  118. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  119. wait_scheduals, _ := redis.Get(key).Result()
  120. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  121. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  122. if err != nil {
  123. this.ErrorLog("获取排班信息失败:%v", err)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. } else {
  126. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  127. for _, s := range scheduals {
  128. returnScheduals = append(returnScheduals, s)
  129. }
  130. if len(returnScheduals) > 0 {
  131. //缓存数据
  132. wait_scheduals_json, err := json.Marshal(scheduals)
  133. if err == nil {
  134. redis.Set(key, wait_scheduals_json, time.Second*30)
  135. }
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "scheduals": scheduals,
  139. })
  140. }
  141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  142. var dat []map[string]interface{}
  143. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  144. } else {
  145. }
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "scheduals": dat,
  148. "redis": "true",
  149. "date": schedualDate,
  150. })
  151. }
  152. }
  153. //else{
  154. // fmt.Println("33333333")
  155. //
  156. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  157. // if err != nil {
  158. // this.ErrorLog("获取排班信息失败:%v", err)
  159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. // } else {
  161. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  162. // for _, s := range scheduals {
  163. //
  164. // returnScheduals = append(returnScheduals, s)
  165. // }
  166. //
  167. // this.ServeSuccessJSON(map[string]interface{}{
  168. // "scheduals": returnScheduals,
  169. // })
  170. // }
  171. //
  172. // }
  173. //if err == nil{
  174. //
  175. //
  176. //
  177. //
  178. //
  179. //}else{
  180. //}
  181. // /m/api/dialysis/record [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisAPIController) DialysisRecord() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetMobileAdminUserInfo()
  201. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  202. if getPatientErr != nil {
  203. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. } else if patient == nil {
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  211. // this.TraceLog("==================================%+v", schedual)
  212. if getSchedualErr != nil {
  213. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  218. if getRTARErr != nil {
  219. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  224. if getPEErr != nil {
  225. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  230. if getLPEErr != nil {
  231. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  236. if getDoctorAdvicesErr != nil {
  237. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  242. if getDialysisOrderErr != nil {
  243. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. return
  246. }
  247. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  248. if getDoubleCheckErr != nil {
  249. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  254. if getMonitorRecordsErr != nil {
  255. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  257. return
  258. }
  259. var lastMonitorRecord *models.MonitoringRecord
  260. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  261. if getLastErr != nil {
  262. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  264. return
  265. }
  266. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  267. if getAADErr != nil {
  268. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  270. return
  271. }
  272. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  273. if getLAADErr != nil {
  274. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  276. return
  277. }
  278. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  279. if getTreatmentSummaryErr != nil {
  280. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  282. return
  283. }
  284. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  285. //if getDialysisPrescribeErr != nil {
  286. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  287. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  288. // return
  289. //}
  290. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  291. //if getDialysisSolutionErr != nil {
  292. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  293. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  294. // return
  295. //}
  296. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  297. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  298. //if getDialysisPrescribeErr != nil {
  299. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  300. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  301. // return
  302. //}
  303. //获取系统透析处方模版
  304. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  305. //if getSystemDialysisPrescribeErr != nil {
  306. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  307. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  308. // return
  309. //}
  310. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  311. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  312. if getLPEErr != nil {
  313. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  315. return
  316. }
  317. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  318. if getDryErr != nil {
  319. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. return
  322. }
  323. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  324. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  325. goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  326. goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  327. operators, err := service.GetAllStarfEs(adminInfo.Org.Id)
  328. fmt.Println("报错", err)
  329. returnData := map[string]interface{}{
  330. "patient": patient,
  331. "schedual": schedual,
  332. "prescription": dialysisPrescribe,
  333. "solution": dialysisSolution,
  334. "last_prescription": lastDialysisPrescribe,
  335. "receiver_treatment_access": receiverTreatmentAccess,
  336. "predialysis_evaluation": predialysisEvaluation,
  337. "doctor_advices": doctorAdvices,
  338. "double_check": doubleCheck,
  339. "assessment_after_dislysis": assessmentAfterDislysis,
  340. "treatment_summary": treatmentSummary,
  341. "monitor_records": monitorRecords,
  342. "dialysis_order": dialysisOrder,
  343. "operators": operators,
  344. "last_predialysis_evaluation": lastPredialysisEvaluation,
  345. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  346. "last_monitor_record": lastMonitorRecord,
  347. //"special_premission": headNurses,
  348. "config": gobalConfig,
  349. "types": goodTypes,
  350. "goodInfos": goodInfos,
  351. "dry_weight": lastDryWeightDislysis,
  352. "system_prescription": systemDialysisPrescribe,
  353. }
  354. this.ServeSuccessJSON(returnData)
  355. }
  356. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  357. adminInfo := c.GetMobileAdminUserInfo()
  358. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  359. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  360. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  361. returnData := map[string]interface{}{
  362. "admin_users": adminUsers,
  363. "devices": devices,
  364. "device_numbers": device_numbers,
  365. }
  366. c.ServeSuccessJSON(returnData)
  367. }
  368. func (c *DialysisAPIController) PostAtreatmentInfo() {
  369. id, _ := c.GetInt64("patient", 0)
  370. recordDateStr := c.GetString("record_date")
  371. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  372. summaryContent := c.GetString("summaryContent")
  373. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  374. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  375. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  376. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  377. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  378. nursingRecord := c.GetString("nursing_record")
  379. fmt.Println("护理记录", nursingRecord)
  380. specialRecord := c.GetString("special_record")
  381. fmt.Println("特殊记录", specialRecord)
  382. adminUserInfo := c.GetMobileAdminUserInfo()
  383. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  384. checkStaffId = adminUserInfo.AdminUser.Id
  385. deboardNurseId = adminUserInfo.AdminUser.Id
  386. treatDoctor = adminUserInfo.AdminUser.Id
  387. if id <= 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  392. if patient.ID == 0 {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  394. return
  395. }
  396. if len(recordDateStr) == 0 {
  397. recordDateStr = time.Now().Format("2006-01-02")
  398. }
  399. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  400. if parseDateErr != nil {
  401. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  403. return
  404. }
  405. //now := time.Now()
  406. //year, month, day := now.Date()
  407. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  408. //todayTimeStamp := today_time.Unix()
  409. summary := models.TreatmentSummary{
  410. UserOrgId: adminUserInfo.Org.Id,
  411. PatientId: id,
  412. AssessmentDate: recordDate.Unix(),
  413. Mission: propagandaAndEducationContent,
  414. DialysisSummary: summaryContent,
  415. SjNurse: changeMedicalNurseId,
  416. ZlNurse: treatNurseId,
  417. HdNurse: checkStaffId,
  418. XjNurse: deboardNurseId,
  419. ZlDoctor: treatDoctor,
  420. CreatedTime: time.Now().Unix(),
  421. Status: 1,
  422. NursingRecord: nursingRecord,
  423. SpecialRecord: specialRecord,
  424. }
  425. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  426. if treatmentSummary.ID == 0 { //新增
  427. summary.Creater = adminUserInfo.AdminUser.Id
  428. service.AddSigleSummaryRecord(&summary)
  429. c.ServeSuccessJSON(map[string]interface{}{
  430. "summary": summary,
  431. })
  432. } else { //修改
  433. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  434. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  435. // if getPermissionErr != nil {
  436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  437. // return
  438. // } else if headNursePermission == nil {
  439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  440. // return
  441. // }
  442. //}
  443. summary.Creater = treatmentSummary.Creater
  444. summary.CreatedTime = treatmentSummary.CreatedTime
  445. summary.Modifier = adminUserInfo.AdminUser.Id
  446. summary.ID = treatmentSummary.ID
  447. service.UpdateSummeRecord(&summary)
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "summary": summary,
  450. })
  451. }
  452. }
  453. func (c *DialysisAPIController) PostDoubleCheck() {
  454. id, _ := c.GetInt64("patient", 0)
  455. recordDateStr := c.GetString("record_date")
  456. checkTimeStr := c.GetString("check_time")
  457. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  458. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  459. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  460. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  461. dialysis_item_desc := c.GetString("dialysis_item_desc")
  462. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  463. vascular_access_desc := c.GetString("vascular_access_desc")
  464. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  465. collator, _ := c.GetInt64("collator", 0)
  466. if id <= 0 {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. adminUserInfo := c.GetMobileAdminUserInfo()
  471. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  472. if patient.ID == 0 {
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  474. return
  475. }
  476. if len(recordDateStr) == 0 {
  477. recordDateStr = time.Now().Format("2006-01-02")
  478. }
  479. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  480. if parseDateErr != nil {
  481. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  483. return
  484. }
  485. if len(checkTimeStr) == 0 {
  486. checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
  487. }
  488. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  489. //now := time.Now()
  490. //year, month, day := now.Date()
  491. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  492. //todayTimeStamp := today_time.Unix()
  493. doubleCheck := models.DoubleCheck{
  494. UserOrgId: adminUserInfo.Org.Id,
  495. PatientId: id,
  496. DialysisItemCheck: dialysis_item_check,
  497. DialysisParameterCheck: dialysis_parameter_check,
  498. VascularAccessVerification: vascular_access_verification,
  499. PipelineConnectionCheck: pipeline_connection_check,
  500. DialysisItemDesc: dialysis_item_desc,
  501. DialysisParameterDesc: dialysis_parameter_desc,
  502. VascularAccessDesc: vascular_access_desc,
  503. PipelineConnectionDesc: pipeline_connection_desc,
  504. Collator: collator,
  505. Status: 1,
  506. CreatedTime: time.Now().Unix(),
  507. UpdatedTime: time.Now().Unix(),
  508. CheckDate: recordDate.Unix(),
  509. }
  510. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  511. if check.ID == 0 { //新增
  512. doubleCheck.FirstCheckTime = checkDate.Unix()
  513. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  514. err := service.AddSigleDoubleCheck(&doubleCheck)
  515. if err == nil {
  516. c.ServeSuccessJSON(map[string]interface{}{
  517. "doubleCheck": &doubleCheck,
  518. })
  519. }
  520. } else { //修改
  521. if check.Modifier != 0 {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  523. } else {
  524. if adminUserInfo.AdminUser.Id == check.Creater {
  525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  526. return
  527. }
  528. doubleCheck.FirstCheckTime = check.FirstCheckTime
  529. doubleCheck.CheckTime = checkDate.Unix()
  530. doubleCheck.Creater = check.Creater
  531. doubleCheck.CreatedTime = check.CreatedTime
  532. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  533. doubleCheck.ID = check.ID
  534. err := service.UpdateDoubleCheck(&doubleCheck)
  535. if err == nil {
  536. c.ServeSuccessJSON(map[string]interface{}{
  537. "doubleCheck": &doubleCheck,
  538. })
  539. }
  540. }
  541. }
  542. }
  543. func (c *DialysisAPIController) PostAcceptsAssessment() {
  544. id, _ := c.GetInt64("patient", 0)
  545. recordDateStr := c.GetString("record_date")
  546. way, _ := c.GetInt64("way", 0)
  547. consciousness, _ := c.GetInt64("consciousness", 0)
  548. appetite, _ := c.GetInt64("appetite", 0)
  549. condition, _ := c.GetInt64("condition", 0)
  550. posture, _ := c.GetInt64("posture")
  551. sick_condition, _ := c.GetInt64("sick_condition", 0)
  552. danger_level, _ := c.GetInt64("danger_level", 0)
  553. intake, _ := c.GetInt64("intake", 0)
  554. nutrition, _ := c.GetInt64("nutrition", 0)
  555. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  556. psychological_assessment_other := c.GetString("psychological_assessment_other")
  557. score := c.GetString("score")
  558. sick_condition_other := c.GetString("sick_condition_other")
  559. //precaution, _ := c.GetInt64("precaution", 0)
  560. precaution := c.GetString("precaution")
  561. precaution_other := c.GetString("precaution_other")
  562. psychological_other := c.GetString("psychological_other")
  563. admission_number := c.GetString("admission_number")
  564. if id <= 0 {
  565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  570. if patient.ID == 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  572. return
  573. }
  574. //now := time.Now()
  575. //year, month, day := now.Date()
  576. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  577. //todayTimeStamp := today_time.Unix()
  578. if len(recordDateStr) == 0 {
  579. recordDateStr = time.Now().Format("2006-01-02")
  580. }
  581. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  582. if parseDateErr != nil {
  583. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  588. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  589. UserOrgId: adminUserInfo.Org.Id,
  590. PatientId: id,
  591. RecordDate: recordDate.Unix(),
  592. Way: way,
  593. Consciousness: consciousness,
  594. Appetite: appetite,
  595. Condition: condition,
  596. SickCondition: sick_condition,
  597. DangerLevel: danger_level,
  598. Intake: intake,
  599. Nutrition: nutrition,
  600. PsychologicalAssessment: psychological_assessment,
  601. PsychologicalAssessmentOther: psychological_assessment_other,
  602. SickConditionOther: sick_condition_other,
  603. Posture: posture,
  604. CreatedTime: time.Now().Unix(),
  605. UpdateTime: time.Now().Unix(),
  606. Status: 1,
  607. Score: score,
  608. Precaution: precaution,
  609. PrecautionOther: precaution_other,
  610. PsychologicalOther: psychological_other,
  611. AdmissionNumber: admission_number,
  612. }
  613. if receiveTreatment.ID == 0 { //新增
  614. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  615. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  616. if err == nil {
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "receiveTreatmentAsses": receiveTreatmentAsses,
  619. })
  620. }
  621. } else { //修改
  622. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  623. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  624. // if getPermissionErr != nil {
  625. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  626. // return
  627. // } else if headNursePermission == nil {
  628. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  629. // return
  630. // }
  631. //}
  632. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  633. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  634. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  635. receiveTreatmentAsses.ID = receiveTreatment.ID
  636. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  637. if err == nil {
  638. c.ServeSuccessJSON(map[string]interface{}{
  639. "receiveTreatmentAsses": receiveTreatmentAsses,
  640. })
  641. }
  642. }
  643. }
  644. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  645. id, _ := c.GetInt64("patient", 0)
  646. recordDateStr := c.GetString("record_date")
  647. weightAfter, _ := c.GetFloat("weight_after", 0)
  648. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  649. weightReduce, _ := c.GetFloat("weight_loss", 0)
  650. temperature, _ := c.GetFloat("temperature", 0)
  651. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  652. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  653. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  654. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  655. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  656. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  657. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  658. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  659. cruor := c.GetString("cruor")
  660. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  661. internalFistula := c.GetString("internal_fistula")
  662. catheter := c.GetString("catheter")
  663. complications := c.GetString("complication")
  664. remark := c.GetString("remark")
  665. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  666. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  667. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  668. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  669. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  670. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  671. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  672. patientGose, _ := c.GetInt64("patient_gose", 0)
  673. inpatientDepartment := c.GetString("inpatient_department")
  674. observationContent := c.GetString("observation_content")
  675. observationContentOther := c.GetString("observation_content_other")
  676. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  677. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  678. in_advance_reason := c.GetString("in_advance_reason")
  679. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  680. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  681. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  682. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  683. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  684. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  685. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  686. dialyzer, _ := c.GetInt64("dialyzer", 0)
  687. in_advance_reason_other := c.GetString("in_advance_reason_other")
  688. is_eat, _ := c.GetInt64("is_eat", 0)
  689. cvc_a, _ := c.GetFloat("cvc_a", 0)
  690. cvc_v, _ := c.GetFloat("cvc_v", 0)
  691. channels, _ := c.GetInt64("channel", 0)
  692. return_blood, _ := c.GetInt64("return_blood", 0)
  693. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  694. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  695. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  696. blood_flow, _ := c.GetInt64("blood_flow", 0)
  697. sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  698. sealing_fluid_special := c.GetString("sealing_fluid_special")
  699. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  700. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  701. setting_pressure := c.GetString("setting_pressure")
  702. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  703. diastolic_pressure := c.GetString("diastolic_pressure")
  704. if id <= 0 {
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. adminUserInfo := c.GetMobileAdminUserInfo()
  709. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  710. if patient.ID == 0 {
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  712. return
  713. }
  714. if len(recordDateStr) == 0 {
  715. recordDateStr = time.Now().Format("2006-01-02")
  716. }
  717. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  718. if parseDateErr != nil {
  719. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. //now := time.Now()
  724. //year, month, day := now.Date()
  725. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  726. //todayTimeStamp := today_time.Unix()
  727. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  728. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  729. UserOrgId: adminUserInfo.Org.Id,
  730. PatientId: id,
  731. AssessmentDate: recordDate.Unix(),
  732. Temperature: temperature,
  733. PulseFrequency: pulse_frequency,
  734. BreathingRate: breathing_rate,
  735. SystolicBloodPressure: systolic_blood_pressure,
  736. DiastolicBloodPressure: diastolic_blood_pressure,
  737. ActualUltrafiltration: actual_ultrafiltration,
  738. ActualDisplacement: actual_displacement,
  739. ActualTreatmentHour: actualtreatHour,
  740. ActualTreatmentMinute: actualtreatmin,
  741. WeightAfter: weightAfter,
  742. AdditionalWeight: additionalWeight,
  743. WeightLoss: weightReduce,
  744. Cruor: cruor,
  745. SymptomAfterDialysis: symptomsAfterDialysi,
  746. InternalFistula: internalFistula,
  747. Catheter: catheter,
  748. Complication: complications,
  749. DialysisIntakes: dialysateVolume,
  750. CreatedTime: time.Now().Unix(),
  751. Status: 1,
  752. Remark: remark,
  753. BloodAccessPartId: blood_access_part_id,
  754. BloodAccessPartOperaId: blood_access_part_opera_id,
  755. DialysisIntakesUnit: dialysis_intakes_unit,
  756. PuncturePointOozingBlood: puncturePointOozingBlood,
  757. PuncturePointHaematoma: puncturePointHaematoma,
  758. InternalFistulaTremorAc: internalFistulaTremorAc,
  759. PatientGose: patientGose,
  760. InpatientDepartment: inpatientDepartment,
  761. ObservationContent: observationContent,
  762. ObservationContentOther: observationContentOther,
  763. DialysisProcess: dialysis_process,
  764. InAdvanceMinute: in_advance_minute,
  765. InAdvanceReason: in_advance_reason,
  766. HemostasisMinute: hemostasis_minute,
  767. HemostasisOpera: hemostasis_opera,
  768. TremorNoise: tremor_noise,
  769. DisequilibriumSyndrome: disequilibrium_syndrome,
  770. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  771. ArterialTube: arterial_tube,
  772. IntravenousTube: intravenous_tube,
  773. Dialyzer: dialyzer,
  774. InAdvanceReasonOther: in_advance_reason_other,
  775. IsEat: is_eat,
  776. CvcA: cvc_a,
  777. CvcV: cvc_v,
  778. Channel: channels,
  779. ReturnBlood: return_blood,
  780. RehydrationVolume: rehydration_volume,
  781. DialysisDuring: dialysis_during,
  782. StrokeVolume: stroke_volume,
  783. BloodFlow: blood_flow,
  784. SealingFluidDispose: sealing_fluid_dispose,
  785. SealingFluidSpecial: sealing_fluid_special,
  786. DosageOfAnticoagulants: dosage_of_anticoagulants,
  787. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  788. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  789. SettingPressure: setting_pressure,
  790. DiastolicPressure: diastolic_pressure,
  791. }
  792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  793. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  794. if assessmentAfter.ID == 0 { //新增
  795. if appRole.UserType == 2 || appRole.UserType == 1 {
  796. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  797. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  798. } else {
  799. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  800. }
  801. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  802. if err == nil {
  803. c.ServeSuccessJSON(map[string]interface{}{
  804. "assessmentAfterDislysis": assessmentAfterDislysis,
  805. })
  806. }
  807. } else { //修改
  808. if appRole.UserType == 2 || appRole.UserType == 1 {
  809. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  810. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  811. } else {
  812. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  813. if assessmentAfterDislysis.Creater == 0 {
  814. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  815. }
  816. }
  817. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  818. assessmentAfterDislysis.ID = assessmentAfter.ID
  819. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  820. if err == nil {
  821. c.ServeSuccessJSON(map[string]interface{}{
  822. "assessmentAfterDislysis": assessmentAfterDislysis,
  823. })
  824. }
  825. }
  826. }
  827. func (c *DialysisAPIController) PostDialysisPrescription() {
  828. id, _ := c.GetInt64("patient", 0)
  829. recordDateStr := c.GetString("record_date")
  830. if id <= 0 {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. adminUserInfo := c.GetMobileAdminUserInfo()
  835. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  836. if patient.ID == 0 {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  838. return
  839. }
  840. if len(recordDateStr) == 0 {
  841. recordDateStr = time.Now().Format("2006-01-02")
  842. }
  843. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  844. if parseDateErr != nil {
  845. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  847. return
  848. }
  849. mode_id, _ := c.GetInt64("mode_id", 0)
  850. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  851. dialyzer, _ := c.GetInt64("dialyzer", 0)
  852. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  853. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  854. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  855. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  856. replacement_total, _ := c.GetFloat("replacement_total", 0)
  857. replacement_way, _ := c.GetInt64("replacement_way", 0)
  858. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  859. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  860. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  861. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  862. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  863. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  864. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  865. kalium, _ := c.GetFloat("kalium", 0)
  866. sodium, _ := c.GetFloat("sodium", 0)
  867. calcium, _ := c.GetFloat("calcium", 0)
  868. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  869. glucose, _ := c.GetFloat("glucose", 0)
  870. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  871. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  872. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  873. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  874. conductivity, _ := c.GetFloat("conductivity", 0)
  875. remark := c.GetString("remark")
  876. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  877. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  878. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  879. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  880. body_fluid, _ := c.GetInt64("body_fluid", 0)
  881. special_medicine, _ := c.GetInt64("special_medicine", 0)
  882. special_medicine_other := c.GetString("special_medicine_other")
  883. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  884. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  885. blood_access, _ := c.GetInt64("blood_access", 0)
  886. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  887. body_fluid_other := c.GetString("body_fluid_other")
  888. niprocart, _ := c.GetInt64("niprocart", 0)
  889. jms, _ := c.GetInt64("jms", 0)
  890. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  891. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  892. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  893. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  894. filtryzer, _ := c.GetInt64("filtryzer", 0)
  895. target_ktv, _ := c.GetFloat("target_ktv", 0)
  896. dialyzers, _ := c.GetInt64("dialyzers", 0)
  897. injector, _ := c.GetInt64("injector", 0)
  898. bloodlines, _ := c.GetInt64("bloodlines", 0)
  899. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  900. safe_package, _ := c.GetInt64("package", 0)
  901. a_liquid, _ := c.GetInt64("a_liquid", 0)
  902. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  903. fmt.Println("预冲量====", pre_impulse)
  904. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  905. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  906. //
  907. //if template.TemplateId == 2 || template.TemplateId == 6 {
  908. // if appRole.UserType == 3 {
  909. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  910. // if getPermissionErr != nil {
  911. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  912. // return
  913. // } else if headNursePermission == nil {
  914. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  915. // return
  916. // }
  917. // }
  918. //}
  919. //TODO 需要根据角色去判断
  920. prescription := models.DialysisPrescription{
  921. UserOrgId: adminUserInfo.Org.Id,
  922. PatientId: id,
  923. RecordDate: recordDate.Unix(),
  924. ModeId: mode_id,
  925. DialysisDuration: dialysis_duration,
  926. Dialyzer: dialyzer,
  927. PerfusionApparatus: perfusion_apparatus,
  928. BloodFlowVolume: blood_flow_volume,
  929. DewaterAmount: dewater_amount,
  930. DisplaceLiqui: displace_liqui,
  931. ReplacementWay: replacement_way,
  932. Anticoagulant: anticoagulant,
  933. AnticoagulantShouji: anticoagulant_shouji,
  934. AnticoagulantWeichi: anticoagulant_weichi,
  935. AnticoagulantZongliang: anticoagulant_zongliang,
  936. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  937. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  938. Kalium: kalium,
  939. Sodium: sodium,
  940. Calcium: calcium,
  941. Bicarbonate: bicarbonate,
  942. Glucose: glucose,
  943. // DryWeight: dry_weight,
  944. DialysateFlow: dialysate_flow,
  945. DialysateTemperature: dialysate_temperature,
  946. // PrescriptionDoctor: prescription_doctor,
  947. ReplacementTotal: replacement_total,
  948. Conductivity: conductivity,
  949. Remark: remark,
  950. Status: 1,
  951. CreatedTime: time.Now().Unix(),
  952. UpdatedTime: time.Now().Unix(),
  953. DialysisDurationMinute: dialysisDurationMinute,
  954. DialysisDurationHour: dialysisDurationHour,
  955. TargetUltrafiltration: targetUltrafiltration,
  956. DialysateFormulation: dialysateFormulation,
  957. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  958. BodyFluid: body_fluid,
  959. SpecialMedicine: special_medicine,
  960. SpecialMedicineOther: special_medicine_other,
  961. DisplaceLiquiPart: displace_liqui_part,
  962. DisplaceLiquiValue: displace_liqui_value,
  963. BloodAccess: blood_access,
  964. Ultrafiltration: ultrafiltration,
  965. BodyFluidOther: body_fluid_other,
  966. Niprocart: niprocart,
  967. Jms: jms,
  968. FistulaNeedleSet: fistula_needle_set,
  969. FistulaNeedleSet16: fistula_needle_set_16,
  970. Hemoperfusion: hemoperfusion,
  971. DialyserSterilised: dialyser_sterilised,
  972. Filtryzer: filtryzer,
  973. Dialyzers: dialyzers,
  974. Injector: injector,
  975. Bloodlines: bloodlines,
  976. TubingHemodialysis: tubing_hemodialysis,
  977. Package: safe_package,
  978. ALiquid: a_liquid,
  979. TargetKtv: target_ktv,
  980. PreImpulse: pre_impulse,
  981. }
  982. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  983. if dialysisPrescription.ID == 0 { //新增
  984. //if mode_id > 0 {
  985. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  986. //}
  987. if appRole.UserType == 2 || appRole.UserType == 1 {
  988. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  989. }
  990. prescription.Creater = adminUserInfo.AdminUser.Id
  991. err := service.AddSigleRecord(&prescription)
  992. if err == nil {
  993. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  994. if updateErr != nil {
  995. utils.ErrorLog("%v", updateErr)
  996. }
  997. c.ServeSuccessJSON(map[string]interface{}{
  998. "prescription": prescription,
  999. })
  1000. }
  1001. } else { //修改
  1002. //if mode_id > 0 {
  1003. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1004. //}
  1005. //if template.TemplateId == 1 {
  1006. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1007. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1008. // if getPermissionErr != nil {
  1009. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1010. // return
  1011. // } else if headNursePermission == nil {
  1012. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1013. // return
  1014. // }
  1015. // }
  1016. //}
  1017. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1018. if record.IsOpen == 1 {
  1019. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1020. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1021. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1022. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1023. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1024. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1025. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1026. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1027. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1028. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1029. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1030. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1031. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1032. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1033. if err == nil {
  1034. if order.ID > 0 {
  1035. if dialysisPrescription.Niprocart != niprocart {
  1036. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1037. //1.用上机透析日期查出当天的订单
  1038. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1039. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1040. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1041. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1042. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1043. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1044. warehouseOutInfo := &models.WarehouseOutInfo{
  1045. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1046. WarehouseOutId: out.ID,
  1047. Count: 1,
  1048. Status: 1,
  1049. Ctime: time.Now().Unix(),
  1050. Remark: "",
  1051. OrgId: adminUserInfo.Org.Id,
  1052. Type: 1,
  1053. Manufacturer: 0,
  1054. Dealer: 0,
  1055. IsSys: 1,
  1056. SysRecordTime: order.StartTime,
  1057. }
  1058. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  1059. warehouseOutInfo.Price = stockInInfo.Price
  1060. warehouseOutInfo.GoodId = niprocart
  1061. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1062. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1063. if err == nil {
  1064. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1065. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1066. if err == gorm.ErrRecordNotFound {
  1067. details := &models.AutomaticReduceDetail{
  1068. WarehouseOutId: warehouseOutInfo.ID,
  1069. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1070. PatientId: id,
  1071. Ctime: time.Now().Unix(),
  1072. Mtime: time.Now().Unix(),
  1073. Status: 1,
  1074. RecordTime: order.StartTime,
  1075. OrgId: adminUserInfo.Org.Id,
  1076. GoodId: niprocart,
  1077. GoodTypeId: niprocart_good_type_id,
  1078. }
  1079. service.AddSigleAutoReduceRecordInfo(details)
  1080. } else if err == nil {
  1081. if user.ID > 0 {
  1082. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  1083. }
  1084. }
  1085. }
  1086. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1087. if newOut.ID > 0 {
  1088. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1089. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1090. if err == gorm.ErrRecordNotFound {
  1091. details := &models.AutomaticReduceDetail{
  1092. WarehouseOutId: newOut.ID,
  1093. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1094. PatientId: id,
  1095. Ctime: time.Now().Unix(),
  1096. Mtime: time.Now().Unix(),
  1097. Status: 1,
  1098. RecordTime: order.StartTime,
  1099. OrgId: adminUserInfo.Org.Id,
  1100. GoodId: niprocart,
  1101. GoodTypeId: niprocart_good_type_id,
  1102. }
  1103. service.AddSigleAutoReduceRecordInfo(details)
  1104. } else if err == nil {
  1105. if user.ID > 0 {
  1106. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  1107. }
  1108. }
  1109. }
  1110. }
  1111. }
  1112. if dialysisPrescription.Jms != jms {
  1113. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1114. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1115. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1116. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1117. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1118. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1119. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1120. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1121. warehouseOutInfo := &models.WarehouseOutInfo{
  1122. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1123. WarehouseOutId: out.ID,
  1124. Count: 1,
  1125. Status: 1,
  1126. Ctime: time.Now().Unix(),
  1127. Remark: "",
  1128. OrgId: adminUserInfo.Org.Id,
  1129. Type: 1,
  1130. Manufacturer: 0,
  1131. Dealer: 0,
  1132. IsSys: 1,
  1133. SysRecordTime: order.StartTime,
  1134. }
  1135. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  1136. warehouseOutInfo.Price = stockInInfo.Price
  1137. warehouseOutInfo.GoodId = jms
  1138. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1139. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1140. if err == nil {
  1141. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1142. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1143. if err == gorm.ErrRecordNotFound {
  1144. details := &models.AutomaticReduceDetail{
  1145. WarehouseOutId: warehouseOutInfo.ID,
  1146. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1147. PatientId: id,
  1148. Ctime: time.Now().Unix(),
  1149. Mtime: time.Now().Unix(),
  1150. Status: 1,
  1151. RecordTime: order.StartTime,
  1152. OrgId: adminUserInfo.Org.Id,
  1153. GoodId: jms,
  1154. GoodTypeId: jms_good_type_id,
  1155. }
  1156. service.AddSigleAutoReduceRecordInfo(details)
  1157. } else if err == nil {
  1158. if user.ID > 0 {
  1159. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1160. }
  1161. }
  1162. }
  1163. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1164. if newOut.ID > 0 {
  1165. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1166. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1167. if err == gorm.ErrRecordNotFound {
  1168. details := &models.AutomaticReduceDetail{
  1169. WarehouseOutId: newOut.ID,
  1170. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1171. PatientId: id,
  1172. Ctime: time.Now().Unix(),
  1173. Mtime: time.Now().Unix(),
  1174. Status: 1,
  1175. RecordTime: order.StartTime,
  1176. OrgId: adminUserInfo.Org.Id,
  1177. GoodId: jms,
  1178. GoodTypeId: jms_good_type_id,
  1179. }
  1180. service.AddSigleAutoReduceRecordInfo(details)
  1181. } else if err == nil {
  1182. if user.ID > 0 {
  1183. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1190. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1191. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1192. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1193. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1194. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1195. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1196. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1197. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1198. warehouseOutInfo := &models.WarehouseOutInfo{
  1199. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1200. WarehouseOutId: out.ID,
  1201. Count: 1,
  1202. Status: 1,
  1203. Ctime: time.Now().Unix(),
  1204. Remark: "",
  1205. OrgId: adminUserInfo.Org.Id,
  1206. Type: 1,
  1207. Manufacturer: 0,
  1208. Dealer: 0,
  1209. IsSys: 1,
  1210. SysRecordTime: order.StartTime,
  1211. }
  1212. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  1213. warehouseOutInfo.Price = stockInInfo.Price
  1214. warehouseOutInfo.GoodId = fistula_needle_set
  1215. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1216. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1217. if err == nil {
  1218. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1219. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1220. if err == gorm.ErrRecordNotFound {
  1221. details := &models.AutomaticReduceDetail{
  1222. WarehouseOutId: warehouseOutInfo.ID,
  1223. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1224. PatientId: id,
  1225. Ctime: time.Now().Unix(),
  1226. Mtime: time.Now().Unix(),
  1227. Status: 1,
  1228. RecordTime: order.StartTime,
  1229. OrgId: adminUserInfo.Org.Id,
  1230. GoodId: fistula_needle_set,
  1231. GoodTypeId: fistula_needle_set_good_type_id,
  1232. }
  1233. service.AddSigleAutoReduceRecordInfo(details)
  1234. } else if err == nil {
  1235. if user.ID > 0 {
  1236. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1237. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1238. }
  1239. }
  1240. }
  1241. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1242. if newOut.ID > 0 {
  1243. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1244. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1245. if err == gorm.ErrRecordNotFound {
  1246. details := &models.AutomaticReduceDetail{
  1247. WarehouseOutId: newOut.ID,
  1248. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1249. PatientId: id,
  1250. Ctime: time.Now().Unix(),
  1251. Mtime: time.Now().Unix(),
  1252. Status: 1,
  1253. RecordTime: order.StartTime,
  1254. OrgId: adminUserInfo.Org.Id,
  1255. GoodId: fistula_needle_set,
  1256. GoodTypeId: fistula_needle_set_good_type_id,
  1257. }
  1258. service.AddSigleAutoReduceRecordInfo(details)
  1259. } else if err == nil {
  1260. if user.ID > 0 {
  1261. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1262. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1269. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1270. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1271. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1272. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1273. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1274. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1275. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1276. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1277. warehouseOutInfo := &models.WarehouseOutInfo{
  1278. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1279. WarehouseOutId: out.ID,
  1280. Count: 1,
  1281. Status: 1,
  1282. Ctime: time.Now().Unix(),
  1283. Remark: "",
  1284. OrgId: adminUserInfo.Org.Id,
  1285. Type: 1,
  1286. Manufacturer: 0,
  1287. Dealer: 0,
  1288. IsSys: 1,
  1289. SysRecordTime: order.StartTime,
  1290. }
  1291. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  1292. warehouseOutInfo.Price = stockInInfo.Price
  1293. warehouseOutInfo.GoodId = fistula_needle_set_16
  1294. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1295. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1296. if err == nil {
  1297. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1298. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1299. if err == gorm.ErrRecordNotFound {
  1300. details := &models.AutomaticReduceDetail{
  1301. WarehouseOutId: warehouseOutInfo.ID,
  1302. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1303. PatientId: id,
  1304. Ctime: time.Now().Unix(),
  1305. Mtime: time.Now().Unix(),
  1306. Status: 1,
  1307. RecordTime: order.StartTime,
  1308. OrgId: adminUserInfo.Org.Id,
  1309. GoodId: fistula_needle_set_16,
  1310. GoodTypeId: fistula_needle_set_16_good_type_id,
  1311. }
  1312. service.AddSigleAutoReduceRecordInfo(details)
  1313. } else if err == nil {
  1314. if user.ID > 0 {
  1315. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1316. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1317. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  1318. }
  1319. }
  1320. }
  1321. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1322. if newOut.ID > 0 {
  1323. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1324. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1325. if err == gorm.ErrRecordNotFound {
  1326. details := &models.AutomaticReduceDetail{
  1327. WarehouseOutId: newOut.ID,
  1328. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1329. PatientId: id,
  1330. Ctime: time.Now().Unix(),
  1331. Mtime: time.Now().Unix(),
  1332. Status: 1,
  1333. RecordTime: order.StartTime,
  1334. OrgId: adminUserInfo.Org.Id,
  1335. GoodId: fistula_needle_set_good_type_id,
  1336. GoodTypeId: fistula_needle_set_16_good_type_id,
  1337. }
  1338. service.AddSigleAutoReduceRecordInfo(details)
  1339. } else if err == nil {
  1340. if user.ID > 0 {
  1341. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1348. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1349. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1350. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1351. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1352. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1353. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1354. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1355. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1356. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1357. warehouseOutInfo := &models.WarehouseOutInfo{
  1358. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1359. WarehouseOutId: out.ID,
  1360. Count: 1,
  1361. Status: 1,
  1362. Ctime: time.Now().Unix(),
  1363. Remark: "",
  1364. OrgId: adminUserInfo.Org.Id,
  1365. Type: 1,
  1366. Manufacturer: 0,
  1367. Dealer: 0,
  1368. IsSys: 1,
  1369. SysRecordTime: order.StartTime,
  1370. }
  1371. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  1372. warehouseOutInfo.Price = stockInInfo.Price
  1373. warehouseOutInfo.GoodId = hemoperfusion
  1374. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1375. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1376. if err == nil {
  1377. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1378. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1379. if err == gorm.ErrRecordNotFound {
  1380. details := &models.AutomaticReduceDetail{
  1381. WarehouseOutId: warehouseOutInfo.ID,
  1382. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1383. PatientId: id,
  1384. Ctime: time.Now().Unix(),
  1385. Mtime: time.Now().Unix(),
  1386. Status: 1,
  1387. RecordTime: order.StartTime,
  1388. OrgId: adminUserInfo.Org.Id,
  1389. GoodId: hemoperfusion,
  1390. GoodTypeId: hemoperfusion_good_type_id,
  1391. }
  1392. service.AddSigleAutoReduceRecordInfo(details)
  1393. } else if err == nil {
  1394. if user.ID > 0 {
  1395. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1396. }
  1397. }
  1398. }
  1399. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1400. if newOut.ID > 0 {
  1401. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1402. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1403. if err == gorm.ErrRecordNotFound {
  1404. details := &models.AutomaticReduceDetail{
  1405. WarehouseOutId: newOut.ID,
  1406. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1407. PatientId: id,
  1408. Ctime: time.Now().Unix(),
  1409. Mtime: time.Now().Unix(),
  1410. Status: 1,
  1411. RecordTime: order.StartTime,
  1412. OrgId: adminUserInfo.Org.Id,
  1413. GoodId: hemoperfusion,
  1414. GoodTypeId: hemoperfusion_good_type_id,
  1415. }
  1416. service.AddSigleAutoReduceRecordInfo(details)
  1417. } else if err == nil {
  1418. if user.ID > 0 {
  1419. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  1420. }
  1421. }
  1422. }
  1423. }
  1424. }
  1425. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1426. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1427. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1428. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1429. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1430. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1431. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1432. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1433. if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
  1434. warehouseOutInfo := &models.WarehouseOutInfo{
  1435. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1436. WarehouseOutId: out.WarehouseOutId,
  1437. Count: 1,
  1438. Status: 1,
  1439. Ctime: time.Now().Unix(),
  1440. Remark: "",
  1441. OrgId: adminUserInfo.Org.Id,
  1442. Type: 1,
  1443. Manufacturer: 0,
  1444. Dealer: 0,
  1445. IsSys: 1,
  1446. SysRecordTime: order.StartTime,
  1447. }
  1448. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  1449. warehouseOutInfo.Price = stockInInfo.Price
  1450. warehouseOutInfo.GoodId = dialyser_sterilised
  1451. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1452. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1453. if err == nil {
  1454. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1455. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1456. if err == gorm.ErrRecordNotFound {
  1457. details := &models.AutomaticReduceDetail{
  1458. WarehouseOutId: warehouseOutInfo.ID,
  1459. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1460. PatientId: id,
  1461. Ctime: time.Now().Unix(),
  1462. Mtime: time.Now().Unix(),
  1463. Status: 1,
  1464. RecordTime: order.StartTime,
  1465. OrgId: adminUserInfo.Org.Id,
  1466. GoodId: dialyser_sterilised,
  1467. GoodTypeId: dialyser_sterilised_good_type_id,
  1468. }
  1469. service.AddSigleAutoReduceRecordInfo(details)
  1470. } else if err == nil {
  1471. if user.ID > 0 {
  1472. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1473. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  1474. }
  1475. }
  1476. }
  1477. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1478. if newOut.ID > 0 {
  1479. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1480. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1481. if err == gorm.ErrRecordNotFound {
  1482. details := &models.AutomaticReduceDetail{
  1483. WarehouseOutId: newOut.ID,
  1484. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1485. PatientId: id,
  1486. Ctime: time.Now().Unix(),
  1487. Mtime: time.Now().Unix(),
  1488. Status: 1,
  1489. RecordTime: order.StartTime,
  1490. OrgId: adminUserInfo.Org.Id,
  1491. GoodId: dialyser_sterilised,
  1492. GoodTypeId: dialyser_sterilised_good_type_id,
  1493. }
  1494. service.AddSigleAutoReduceRecordInfo(details)
  1495. } else if err == nil {
  1496. if user.ID > 0 {
  1497. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  1498. }
  1499. }
  1500. }
  1501. }
  1502. }
  1503. if dialysisPrescription.Filtryzer != filtryzer {
  1504. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1505. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1506. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1507. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1508. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1509. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1510. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1511. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1512. warehouseOutInfo := &models.WarehouseOutInfo{
  1513. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1514. WarehouseOutId: out.ID,
  1515. Count: 1,
  1516. Status: 1,
  1517. Ctime: time.Now().Unix(),
  1518. Remark: "",
  1519. OrgId: adminUserInfo.Org.Id,
  1520. Type: 1,
  1521. Manufacturer: 0,
  1522. Dealer: 0,
  1523. IsSys: 1,
  1524. SysRecordTime: order.StartTime,
  1525. }
  1526. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  1527. warehouseOutInfo.Price = stockInInfo.Price
  1528. warehouseOutInfo.GoodId = filtryzer
  1529. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1530. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1531. if err == nil {
  1532. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1533. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1534. if err == gorm.ErrRecordNotFound {
  1535. details := &models.AutomaticReduceDetail{
  1536. WarehouseOutId: warehouseOutInfo.ID,
  1537. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1538. PatientId: id,
  1539. Ctime: time.Now().Unix(),
  1540. Mtime: time.Now().Unix(),
  1541. Status: 1,
  1542. RecordTime: order.StartTime,
  1543. OrgId: adminUserInfo.Org.Id,
  1544. GoodId: filtryzer,
  1545. GoodTypeId: filtryzer_good_type_id,
  1546. }
  1547. service.AddSigleAutoReduceRecordInfo(details)
  1548. } else if err == nil {
  1549. if user.ID > 0 {
  1550. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  1551. }
  1552. }
  1553. }
  1554. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1555. if newOut.ID > 0 {
  1556. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1557. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1558. if err == gorm.ErrRecordNotFound {
  1559. details := &models.AutomaticReduceDetail{
  1560. WarehouseOutId: newOut.ID,
  1561. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1562. PatientId: id,
  1563. Ctime: time.Now().Unix(),
  1564. Mtime: time.Now().Unix(),
  1565. Status: 1,
  1566. RecordTime: order.StartTime,
  1567. OrgId: adminUserInfo.Org.Id,
  1568. GoodId: filtryzer,
  1569. GoodTypeId: filtryzer_good_type_id,
  1570. }
  1571. service.AddSigleAutoReduceRecordInfo(details)
  1572. } else if err == nil {
  1573. if user.ID > 0 {
  1574. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  1575. }
  1576. }
  1577. }
  1578. }
  1579. }
  1580. if dialysisPrescription.Dialyzers != dialyzers {
  1581. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1582. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1583. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1584. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1585. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1586. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1587. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1588. warehouseOutInfo := &models.WarehouseOutInfo{
  1589. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1590. WarehouseOutId: out.ID,
  1591. Count: 1,
  1592. Status: 1,
  1593. Ctime: time.Now().Unix(),
  1594. Remark: "",
  1595. OrgId: adminUserInfo.Org.Id,
  1596. Type: 1,
  1597. Manufacturer: 0,
  1598. Dealer: 0,
  1599. IsSys: 1,
  1600. SysRecordTime: order.StartTime,
  1601. }
  1602. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  1603. warehouseOutInfo.Price = stockInInfo.Price
  1604. warehouseOutInfo.GoodId = dialyzers
  1605. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  1606. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1607. if err == nil {
  1608. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1609. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1610. if err == gorm.ErrRecordNotFound {
  1611. details := &models.AutomaticReduceDetail{
  1612. WarehouseOutId: warehouseOutInfo.ID,
  1613. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1614. PatientId: id,
  1615. Ctime: time.Now().Unix(),
  1616. Mtime: time.Now().Unix(),
  1617. Status: 1,
  1618. RecordTime: order.StartTime,
  1619. OrgId: adminUserInfo.Org.Id,
  1620. GoodId: dialyzers,
  1621. GoodTypeId: dialyzers_good_type_id,
  1622. }
  1623. service.AddSigleAutoReduceRecordInfo(details)
  1624. } else if err == nil {
  1625. if user.ID > 0 {
  1626. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  1627. }
  1628. }
  1629. }
  1630. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1631. if newOut.ID > 0 {
  1632. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1633. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1634. if err == gorm.ErrRecordNotFound {
  1635. details := &models.AutomaticReduceDetail{
  1636. WarehouseOutId: newOut.ID,
  1637. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1638. PatientId: id,
  1639. Ctime: time.Now().Unix(),
  1640. Mtime: time.Now().Unix(),
  1641. Status: 1,
  1642. RecordTime: order.StartTime,
  1643. OrgId: adminUserInfo.Org.Id,
  1644. GoodId: dialyzers,
  1645. GoodTypeId: dialyzers_good_type_id,
  1646. }
  1647. service.AddSigleAutoReduceRecordInfo(details)
  1648. } else if err == nil {
  1649. if user.ID > 0 {
  1650. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. if dialysisPrescription.Injector != injector {
  1657. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1658. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1659. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1660. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1661. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1662. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1663. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1664. warehouseOutInfo := &models.WarehouseOutInfo{
  1665. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1666. WarehouseOutId: out.ID,
  1667. Count: 1,
  1668. Status: 1,
  1669. Ctime: time.Now().Unix(),
  1670. Remark: "",
  1671. OrgId: adminUserInfo.Org.Id,
  1672. Type: 1,
  1673. Manufacturer: 0,
  1674. Dealer: 0,
  1675. IsSys: 1,
  1676. SysRecordTime: order.StartTime,
  1677. }
  1678. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  1679. warehouseOutInfo.Price = stockInInfo.Price
  1680. warehouseOutInfo.GoodId = injector
  1681. warehouseOutInfo.GoodTypeId = injector_good_type_id
  1682. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1683. if err == nil {
  1684. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1685. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1686. if err == gorm.ErrRecordNotFound {
  1687. details := &models.AutomaticReduceDetail{
  1688. WarehouseOutId: warehouseOutInfo.ID,
  1689. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1690. PatientId: id,
  1691. Ctime: time.Now().Unix(),
  1692. Mtime: time.Now().Unix(),
  1693. Status: 1,
  1694. RecordTime: order.StartTime,
  1695. OrgId: adminUserInfo.Org.Id,
  1696. GoodId: injector,
  1697. GoodTypeId: injector_good_type_id,
  1698. }
  1699. service.AddSigleAutoReduceRecordInfo(details)
  1700. } else if err == nil {
  1701. if user.ID > 0 {
  1702. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  1703. }
  1704. }
  1705. }
  1706. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1707. if newOut.ID > 0 {
  1708. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1709. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1710. if err == gorm.ErrRecordNotFound {
  1711. details := &models.AutomaticReduceDetail{
  1712. WarehouseOutId: newOut.ID,
  1713. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1714. PatientId: id,
  1715. Ctime: time.Now().Unix(),
  1716. Mtime: time.Now().Unix(),
  1717. Status: 1,
  1718. RecordTime: order.StartTime,
  1719. OrgId: adminUserInfo.Org.Id,
  1720. GoodId: injector,
  1721. GoodTypeId: injector_good_type_id,
  1722. }
  1723. service.AddSigleAutoReduceRecordInfo(details)
  1724. } else if err == nil {
  1725. if user.ID > 0 {
  1726. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  1727. }
  1728. }
  1729. }
  1730. }
  1731. }
  1732. if dialysisPrescription.Bloodlines != bloodlines {
  1733. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1734. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1735. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1736. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1737. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1738. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1739. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1740. warehouseOutInfo := &models.WarehouseOutInfo{
  1741. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1742. WarehouseOutId: out.ID,
  1743. Count: 1,
  1744. Status: 1,
  1745. Ctime: time.Now().Unix(),
  1746. Remark: "",
  1747. OrgId: adminUserInfo.Org.Id,
  1748. Type: 1,
  1749. Manufacturer: 0,
  1750. Dealer: 0,
  1751. IsSys: 1,
  1752. SysRecordTime: order.StartTime,
  1753. }
  1754. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  1755. warehouseOutInfo.Price = stockInInfo.Price
  1756. warehouseOutInfo.GoodId = bloodlines
  1757. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  1758. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1759. if err == nil {
  1760. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1761. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1762. if err == gorm.ErrRecordNotFound {
  1763. details := &models.AutomaticReduceDetail{
  1764. WarehouseOutId: warehouseOutInfo.ID,
  1765. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1766. PatientId: id,
  1767. Ctime: time.Now().Unix(),
  1768. Mtime: time.Now().Unix(),
  1769. Status: 1,
  1770. RecordTime: order.StartTime,
  1771. OrgId: adminUserInfo.Org.Id,
  1772. GoodId: bloodlines,
  1773. GoodTypeId: bloodlines_good_type_id,
  1774. }
  1775. service.AddSigleAutoReduceRecordInfo(details)
  1776. } else if err == nil {
  1777. if user.ID > 0 {
  1778. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  1779. }
  1780. }
  1781. }
  1782. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1783. if newOut.ID > 0 {
  1784. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1785. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1786. if err == gorm.ErrRecordNotFound {
  1787. details := &models.AutomaticReduceDetail{
  1788. WarehouseOutId: newOut.ID,
  1789. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1790. PatientId: id,
  1791. Ctime: time.Now().Unix(),
  1792. Mtime: time.Now().Unix(),
  1793. Status: 1,
  1794. RecordTime: order.StartTime,
  1795. OrgId: adminUserInfo.Org.Id,
  1796. GoodId: bloodlines,
  1797. GoodTypeId: bloodlines_good_type_id,
  1798. }
  1799. service.AddSigleAutoReduceRecordInfo(details)
  1800. } else if err == nil {
  1801. if user.ID > 0 {
  1802. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1809. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1810. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1811. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1812. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1813. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1814. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1815. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1816. warehouseOutInfo := &models.WarehouseOutInfo{
  1817. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1818. WarehouseOutId: out.ID,
  1819. Count: 1,
  1820. Status: 1,
  1821. Ctime: time.Now().Unix(),
  1822. Remark: "",
  1823. OrgId: adminUserInfo.Org.Id,
  1824. Type: 1,
  1825. Manufacturer: 0,
  1826. Dealer: 0,
  1827. IsSys: 1,
  1828. SysRecordTime: order.StartTime,
  1829. }
  1830. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  1831. warehouseOutInfo.Price = stockInInfo.Price
  1832. warehouseOutInfo.GoodId = tubing_hemodialysis
  1833. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1834. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1835. if err == nil {
  1836. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1837. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1838. if err == gorm.ErrRecordNotFound {
  1839. details := &models.AutomaticReduceDetail{
  1840. WarehouseOutId: warehouseOutInfo.ID,
  1841. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1842. PatientId: id,
  1843. Ctime: time.Now().Unix(),
  1844. Mtime: time.Now().Unix(),
  1845. Status: 1,
  1846. RecordTime: order.StartTime,
  1847. OrgId: adminUserInfo.Org.Id,
  1848. GoodId: tubing_hemodialysis,
  1849. GoodTypeId: tubingHemodialysis_good_type_id,
  1850. }
  1851. service.AddSigleAutoReduceRecordInfo(details)
  1852. } else if err == nil {
  1853. if user.ID > 0 {
  1854. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  1855. }
  1856. }
  1857. }
  1858. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1859. if newOut.ID > 0 {
  1860. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1861. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1862. if err == gorm.ErrRecordNotFound {
  1863. details := &models.AutomaticReduceDetail{
  1864. WarehouseOutId: newOut.ID,
  1865. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1866. PatientId: id,
  1867. Ctime: time.Now().Unix(),
  1868. Mtime: time.Now().Unix(),
  1869. Status: 1,
  1870. RecordTime: order.StartTime,
  1871. OrgId: adminUserInfo.Org.Id,
  1872. GoodId: tubing_hemodialysis,
  1873. GoodTypeId: tubingHemodialysis_good_type_id,
  1874. }
  1875. service.AddSigleAutoReduceRecordInfo(details)
  1876. } else if err == nil {
  1877. if user.ID > 0 {
  1878. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. if dialysisPrescription.Package != safe_package {
  1885. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1886. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1887. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1888. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1889. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1890. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1891. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1892. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1893. warehouseOutInfo := &models.WarehouseOutInfo{
  1894. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1895. WarehouseOutId: out.ID,
  1896. Count: 1,
  1897. Status: 1,
  1898. Ctime: time.Now().Unix(),
  1899. Remark: "",
  1900. OrgId: adminUserInfo.Org.Id,
  1901. Type: 1,
  1902. Manufacturer: 0,
  1903. Dealer: 0,
  1904. IsSys: 1,
  1905. SysRecordTime: order.StartTime,
  1906. }
  1907. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  1908. warehouseOutInfo.Price = stockInInfo.Price
  1909. warehouseOutInfo.GoodId = safe_package
  1910. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1911. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1912. if err == nil {
  1913. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1914. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1915. if err == gorm.ErrRecordNotFound {
  1916. details := &models.AutomaticReduceDetail{
  1917. WarehouseOutId: warehouseOutInfo.ID,
  1918. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1919. PatientId: id,
  1920. Ctime: time.Now().Unix(),
  1921. Mtime: time.Now().Unix(),
  1922. Status: 1,
  1923. RecordTime: order.StartTime,
  1924. OrgId: adminUserInfo.Org.Id,
  1925. GoodId: safe_package,
  1926. GoodTypeId: safe_package_good_type_id,
  1927. }
  1928. service.AddSigleAutoReduceRecordInfo(details)
  1929. } else if err == nil {
  1930. if user.ID > 0 {
  1931. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  1932. }
  1933. }
  1934. }
  1935. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1936. if newOut.ID > 0 {
  1937. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1938. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1939. if err == gorm.ErrRecordNotFound {
  1940. details := &models.AutomaticReduceDetail{
  1941. WarehouseOutId: newOut.ID,
  1942. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1943. PatientId: id,
  1944. Ctime: time.Now().Unix(),
  1945. Mtime: time.Now().Unix(),
  1946. Status: 1,
  1947. RecordTime: order.StartTime,
  1948. OrgId: adminUserInfo.Org.Id,
  1949. GoodId: safe_package,
  1950. GoodTypeId: safe_package_good_type_id,
  1951. }
  1952. service.AddSigleAutoReduceRecordInfo(details)
  1953. } else if err == nil {
  1954. if user.ID > 0 {
  1955. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. if dialysisPrescription.ALiquid != a_liquid {
  1962. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1963. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1964. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1965. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1966. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1967. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1968. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1969. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1970. warehouseOutInfo := &models.WarehouseOutInfo{
  1971. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1972. WarehouseOutId: out.ID,
  1973. Count: 1,
  1974. Status: 1,
  1975. Ctime: time.Now().Unix(),
  1976. Remark: "",
  1977. OrgId: adminUserInfo.Org.Id,
  1978. Type: 1,
  1979. Manufacturer: 0,
  1980. Dealer: 0,
  1981. IsSys: 1,
  1982. SysRecordTime: order.StartTime,
  1983. }
  1984. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  1985. warehouseOutInfo.Price = stockInInfo.Price
  1986. warehouseOutInfo.GoodId = a_liquid
  1987. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1988. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1989. if err == nil {
  1990. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1991. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1992. if err == gorm.ErrRecordNotFound {
  1993. details := &models.AutomaticReduceDetail{
  1994. WarehouseOutId: warehouseOutInfo.ID,
  1995. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1996. PatientId: id,
  1997. Ctime: time.Now().Unix(),
  1998. Mtime: time.Now().Unix(),
  1999. Status: 1,
  2000. RecordTime: order.StartTime,
  2001. OrgId: adminUserInfo.Org.Id,
  2002. GoodId: a_liquid,
  2003. GoodTypeId: aliquid_good_type_id,
  2004. }
  2005. service.AddSigleAutoReduceRecordInfo(details)
  2006. } else if err == nil {
  2007. if user.ID > 0 {
  2008. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  2009. }
  2010. }
  2011. }
  2012. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2013. if newOut.ID > 0 {
  2014. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  2015. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  2016. if err == gorm.ErrRecordNotFound {
  2017. details := &models.AutomaticReduceDetail{
  2018. WarehouseOutId: newOut.ID,
  2019. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2020. PatientId: id,
  2021. Ctime: time.Now().Unix(),
  2022. Mtime: time.Now().Unix(),
  2023. Status: 1,
  2024. RecordTime: order.StartTime,
  2025. OrgId: adminUserInfo.Org.Id,
  2026. GoodId: a_liquid,
  2027. GoodTypeId: aliquid_good_type_id,
  2028. }
  2029. service.AddSigleAutoReduceRecordInfo(details)
  2030. } else if err == nil {
  2031. if user.ID > 0 {
  2032. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. }
  2041. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2042. prescription.Modifier = adminUserInfo.AdminUser.Id
  2043. if appRole.UserType == 2 || appRole.UserType == 1 {
  2044. prescription_doctor := adminUserInfo.AdminUser.Id
  2045. prescription.PrescriptionDoctor = prescription_doctor
  2046. }
  2047. if dialysisPrescription.Creater == 0 { //体重称
  2048. prescription.Creater = adminUserInfo.AdminUser.Id
  2049. } else {
  2050. prescription.Creater = dialysisPrescription.Creater
  2051. }
  2052. prescription.ID = dialysisPrescription.ID
  2053. err := service.UpDateDialysisPrescription(&prescription)
  2054. if err == nil {
  2055. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2056. if updateErr != nil {
  2057. utils.ErrorLog("%v", updateErr)
  2058. }
  2059. c.ServeSuccessJSON(map[string]interface{}{
  2060. "prescription": prescription,
  2061. })
  2062. }
  2063. }
  2064. }
  2065. func (c *DialysisAPIController) Finish() {
  2066. id, _ := c.GetInt64("patient", 0)
  2067. recordDateStr := c.GetString("record_date")
  2068. nurseID, _ := c.GetInt64("nurse")
  2069. end_time := c.GetString("end_time")
  2070. if id <= 0 || nurseID <= 0 {
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2072. return
  2073. }
  2074. adminUserInfo := c.GetMobileAdminUserInfo()
  2075. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2076. if patient.ID == 0 {
  2077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2078. return
  2079. }
  2080. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2081. if getNurseErr != nil {
  2082. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2084. return
  2085. } else if nurse == nil {
  2086. c.ErrorLog("护士不存在")
  2087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2088. return
  2089. }
  2090. if len(recordDateStr) == 0 {
  2091. recordDateStr = time.Now().Format("2006-01-02")
  2092. }
  2093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2094. if parseDateErr != nil {
  2095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2100. if parseEndDateErr != nil {
  2101. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2103. return
  2104. }
  2105. //now := time.Now()
  2106. //year, month, day := now.Date()
  2107. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2108. //todayTimeStamp := today_time.Unix()
  2109. // 获取当天的第一条透析纪录
  2110. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2111. if getMonitorRecordsErr != nil {
  2112. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. return
  2115. }
  2116. // 获取当前的最后一条透析纪录
  2117. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  2118. if getMonitorRecordsErr != nil {
  2119. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2121. return
  2122. }
  2123. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2124. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2125. if getAADErr != nil {
  2126. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2128. return
  2129. }
  2130. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2131. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2132. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2133. if assessmentAfterDislysis != nil {
  2134. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2135. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2136. } else {
  2137. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2138. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2139. tempassessmentAfterDislysis.Status = 1
  2140. tempassessmentAfterDislysis.PatientId = id
  2141. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2142. }
  2143. if dialysisOrder.Stage == 1 {
  2144. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2145. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2146. fmt.Println(value)
  2147. a, b := math.Modf(value)
  2148. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2149. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2150. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2151. fmt.Println(hour)
  2152. fmt.Println(minute)
  2153. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2154. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2155. }
  2156. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2157. //var num1 int64
  2158. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2159. //fmt.Println(num1)
  2160. //sub := float64(num1 / 3600)
  2161. //fmt.Println(sub)
  2162. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2163. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2164. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2165. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2166. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2167. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2168. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2169. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2170. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2171. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2172. }
  2173. if lastAssessmentAfterDislysis != nil {
  2174. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2175. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2176. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2177. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2178. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2179. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2180. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2181. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2182. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2183. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2184. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2185. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2186. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2187. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2188. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2189. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2190. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2191. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2192. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2193. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2194. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2195. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2196. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2197. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2198. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2199. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2200. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2201. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2202. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2203. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2204. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2205. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2206. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2207. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2208. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2209. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2210. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2211. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2212. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2213. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2214. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2215. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2216. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2217. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2218. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2219. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2220. }
  2221. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2222. if err != nil {
  2223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2224. return
  2225. }
  2226. if dialysisOrder == nil {
  2227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2228. return
  2229. }
  2230. if dialysisOrder.Stage == 2 {
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2232. return
  2233. }
  2234. if dialysisOrder.Stage == 1 {
  2235. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2236. //结束时候透析次数加1
  2237. service.UpdateSolutionByPatientId(id)
  2238. dialysisOrder.Stage = 2
  2239. dialysisOrder.FinishNurse = nurseID
  2240. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2241. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2242. dialysisOrder.EndTime = endDate.Unix()
  2243. if err == nil {
  2244. c.ServeSuccessJSON(map[string]interface{}{
  2245. "dialysisOrder": dialysisOrder,
  2246. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2247. })
  2248. } else {
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2250. }
  2251. }
  2252. }
  2253. func (c *DialysisAPIController) GetAllZone() {
  2254. adminUserInfo := c.GetMobileAdminUserInfo()
  2255. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2256. if err == nil {
  2257. c.ServeSuccessJSON(map[string]interface{}{
  2258. "zone": zone,
  2259. })
  2260. }
  2261. }
  2262. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2263. adminUserInfo := c.GetMobileAdminUserInfo()
  2264. page, _ := c.GetInt64("page", 1)
  2265. limit, _ := c.GetInt64("limit", 10)
  2266. schedulType, _ := c.GetInt64("schedul_type", 0)
  2267. startTime, _ := c.GetInt64("schedul_time", 0)
  2268. partitionType, _ := c.GetInt64("partition_type", 0)
  2269. keywords := c.GetString("keywords")
  2270. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2271. if err == nil {
  2272. c.ServeSuccessJSON(map[string]interface{}{
  2273. "schedule": dialysisSchedule,
  2274. })
  2275. }
  2276. return
  2277. }
  2278. // /m/api/dialysis/start [post]
  2279. // @param patient_id:int
  2280. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2281. // @param nurse:int 上机护士
  2282. // @param bed:int 床位号
  2283. func (this *DialysisAPIController) StartDialysis() {
  2284. patientID, _ := this.GetInt64("patient_id")
  2285. recordDateStr := this.GetString("record_date")
  2286. nurseID, _ := this.GetInt64("nurse")
  2287. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2288. blood_drawing, _ := this.GetInt64("blood_drawing")
  2289. schedual_type, _ := this.GetInt64("schedual_type")
  2290. bedID, _ := this.GetInt64("bed")
  2291. start_time := this.GetString("start_time")
  2292. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2294. return
  2295. }
  2296. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2297. if parseStartDateErr != nil {
  2298. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2300. return
  2301. }
  2302. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2303. if parseErr != nil {
  2304. this.ErrorLog("时间解析失败:%v", parseErr)
  2305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2306. return
  2307. }
  2308. adminUserInfo := this.GetMobileAdminUserInfo()
  2309. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2310. if getPatientErr != nil {
  2311. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2313. return
  2314. } else if patient == nil {
  2315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2316. return
  2317. }
  2318. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2319. if getNurseErr != nil {
  2320. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2322. return
  2323. } else if nurse == nil {
  2324. this.ErrorLog("护士不存在")
  2325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2326. return
  2327. }
  2328. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2329. if getNurseErr != nil {
  2330. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2332. return
  2333. } else if nurse == nil {
  2334. this.ErrorLog("护士不存在")
  2335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2336. return
  2337. }
  2338. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2339. if getDeviceNumberErr != nil {
  2340. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2342. return
  2343. } else if deviceNumber == nil {
  2344. this.ErrorLog("床位号不存在")
  2345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2346. return
  2347. }
  2348. _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2349. if configs.IsOpen == 1 {
  2350. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2351. if prescription.ID == 0 {
  2352. this.ErrorLog("上机失败,还没开处方")
  2353. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  2354. return
  2355. }
  2356. }
  2357. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2358. if getRecordErr != nil {
  2359. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2361. return
  2362. } else if dialysisRecord != nil {
  2363. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2364. return
  2365. }
  2366. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2367. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2368. timeLayout := "2006-01-02 15:04:05"
  2369. loc, _ := time.LoadLocation("Local")
  2370. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2371. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2372. schedulestartTime := theStartTime.Unix()
  2373. scheduleendTime := theEndTime.Unix()
  2374. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2375. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2376. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2377. //查询该床位是否有人用了
  2378. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2379. if err == gorm.ErrRecordNotFound { //空床位
  2380. // 修改了床位逻辑
  2381. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2382. if daySchedule.ID > 0 {
  2383. daySchedule.PartitionId = deviceNumber.ZoneID
  2384. daySchedule.BedId = bedID
  2385. daySchedule.ScheduleType = schedual_type
  2386. daySchedule.UpdatedTime = time.Now().Unix()
  2387. err := service.UpdateSchedule(&daySchedule)
  2388. if err != nil {
  2389. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2390. return
  2391. }
  2392. }
  2393. } else if err == nil {
  2394. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2395. if order_err == nil {
  2396. if order.ID > 0 { //该机位被其他人占用了
  2397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2398. return
  2399. } else {
  2400. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2401. if daySchedule.ID > 0 {
  2402. daySchedule.PartitionId = deviceNumber.ZoneID
  2403. daySchedule.BedId = bedID
  2404. daySchedule.ScheduleType = schedual_type
  2405. daySchedule.UpdatedTime = time.Now().Unix()
  2406. err := service.UpdateSchedule(&daySchedule)
  2407. if err != nil {
  2408. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2409. return
  2410. }
  2411. }
  2412. }
  2413. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  2414. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2415. if daySchedule.ID > 0 {
  2416. daySchedule.PartitionId = deviceNumber.ZoneID
  2417. daySchedule.BedId = bedID
  2418. daySchedule.ScheduleType = schedual_type
  2419. daySchedule.UpdatedTime = time.Now().Unix()
  2420. err := service.UpdateSchedule(&daySchedule)
  2421. if err != nil {
  2422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2423. return
  2424. }
  2425. }
  2426. }
  2427. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2429. return
  2430. }
  2431. } else if err != nil {
  2432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2433. return
  2434. }
  2435. dialysisRecord = &models.DialysisOrder{
  2436. DialysisDate: recordDate.Unix(),
  2437. UserOrgId: adminUserInfo.Org.Id,
  2438. PatientId: patientID,
  2439. Stage: 1,
  2440. BedID: bedID,
  2441. StartNurse: nurseID,
  2442. Status: 1,
  2443. StartTime: startDate.Unix(),
  2444. CreatedTime: time.Now().Unix(),
  2445. UpdatedTime: time.Now().Unix(),
  2446. PunctureNurse: puncture_nurse,
  2447. Creator: adminUserInfo.AdminUser.Id,
  2448. Modifier: adminUserInfo.AdminUser.Id,
  2449. SchedualType: schedual_type,
  2450. }
  2451. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2452. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2453. var tempdispose string
  2454. // 只针对中能建
  2455. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2456. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2457. }
  2458. var ultrafiltration_rate float64
  2459. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2460. if prescription.ID > 0 {
  2461. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2462. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2463. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  2464. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2465. }
  2466. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2467. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2468. }
  2469. // 只针对方济医院
  2470. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2471. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2472. ultrafiltration_rate = value
  2473. }
  2474. }
  2475. }
  2476. record := models.MonitoringRecord{
  2477. UserOrgId: adminUserInfo.Org.Id,
  2478. PatientId: patientID,
  2479. DialysisOrderId: dialysisRecord.ID,
  2480. MonitoringDate: schedulestartTime,
  2481. OperateTime: startDate.Unix(),
  2482. // MonitoringTime: recordTime,
  2483. MonitoringNurse: nurseID,
  2484. Dispose: tempdispose,
  2485. UltrafiltrationRate: ultrafiltration_rate,
  2486. UltrafiltrationVolume: 0,
  2487. Status: 1,
  2488. CreatedTime: time.Now().Unix(),
  2489. UpdatedTime: time.Now().Unix(),
  2490. }
  2491. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2492. if newdialysisRecord.ID > 0 {
  2493. err := service.CreateMonitor(&record)
  2494. if err != nil {
  2495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2496. return
  2497. }
  2498. }
  2499. //是否启动自动扣减功能
  2500. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2501. //启动的话
  2502. if config.IsOpen == 1 {
  2503. niprocart, _ := beego.AppConfig.Int64("niprocart")
  2504. jms, _ := beego.AppConfig.Int64("jms")
  2505. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  2506. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  2507. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  2508. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  2509. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  2510. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  2511. injector, _ := beego.AppConfig.Int64("injector")
  2512. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  2513. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  2514. safe_package, _ := beego.AppConfig.Int64("package")
  2515. aliquid, _ := beego.AppConfig.Int64("aliquid")
  2516. //库存自动扣减功能
  2517. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2518. if prescription.ID > 0 {
  2519. out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
  2520. if err == gorm.ErrRecordNotFound {
  2521. //没有记录,则创建出库单
  2522. timeStr := time.Now().Format("2006-01-02")
  2523. timeArr := strings.Split(timeStr, "-")
  2524. total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  2525. total = total + 1
  2526. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2527. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2528. number = number + total
  2529. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2530. creater := adminUserInfo.AdminUser.Id
  2531. warehouseOut := models.WarehouseOut{
  2532. WarehouseOutOrderNumber: warehousing_out_order,
  2533. OperationTime: time.Now().Unix(),
  2534. OrgId: adminUserInfo.Org.Id,
  2535. Creater: creater,
  2536. Ctime: time.Now().Unix(),
  2537. Status: 1,
  2538. WarehouseOutTime: recordDate.Unix(),
  2539. Dealer: 0,
  2540. Manufacturer: 0,
  2541. Type: 1,
  2542. IsSys: 1,
  2543. }
  2544. err := service.AddSigleWarehouseOut(&warehouseOut)
  2545. if err != nil {
  2546. utils.TraceLog("创建出库单失败 err = %v", err)
  2547. } else {
  2548. if prescription.Niprocart > 0 {
  2549. warehouseOutInfo := &models.WarehouseOutInfo{
  2550. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2551. WarehouseOutId: warehouseOut.ID,
  2552. Count: 1,
  2553. Status: 1,
  2554. Ctime: time.Now().Unix(),
  2555. Remark: "",
  2556. OrgId: adminUserInfo.Org.Id,
  2557. Type: 1,
  2558. Manufacturer: 0,
  2559. Dealer: 0,
  2560. IsSys: 1,
  2561. SysRecordTime: startDate.Unix(),
  2562. }
  2563. //查出入库记录中最后一条记录
  2564. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2565. warehouseOutInfo.Price = stockInInfo.Price
  2566. warehouseOutInfo.GoodId = prescription.Niprocart
  2567. warehouseOutInfo.GoodTypeId = niprocart
  2568. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2569. if err == nil {
  2570. details := &models.AutomaticReduceDetail{
  2571. WarehouseOutId: warehouseOutInfo.ID,
  2572. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2573. PatientId: patientID,
  2574. Ctime: time.Now().Unix(),
  2575. Mtime: time.Now().Unix(),
  2576. Status: 1,
  2577. RecordTime: startDate.Unix(),
  2578. OrgId: adminUserInfo.Org.Id,
  2579. GoodId: prescription.Niprocart,
  2580. GoodTypeId: niprocart,
  2581. }
  2582. service.AddSigleAutoReduceRecordInfo(details)
  2583. }
  2584. }
  2585. if prescription.Jms > 0 {
  2586. warehouseOutInfo := &models.WarehouseOutInfo{
  2587. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2588. WarehouseOutId: warehouseOut.ID,
  2589. Count: 1,
  2590. Status: 1,
  2591. Ctime: time.Now().Unix(),
  2592. Remark: "",
  2593. OrgId: adminUserInfo.Org.Id,
  2594. Type: 1,
  2595. Manufacturer: 0,
  2596. Dealer: 0,
  2597. IsSys: 1,
  2598. SysRecordTime: startDate.Unix(),
  2599. }
  2600. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2601. warehouseOutInfo.Price = stockInInfo.Price
  2602. warehouseOutInfo.GoodId = prescription.Jms
  2603. warehouseOutInfo.GoodTypeId = jms
  2604. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2605. if err == nil {
  2606. details := &models.AutomaticReduceDetail{
  2607. WarehouseOutId: warehouseOutInfo.ID,
  2608. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2609. PatientId: patientID,
  2610. Ctime: time.Now().Unix(),
  2611. Mtime: time.Now().Unix(),
  2612. Status: 1,
  2613. RecordTime: startDate.Unix(),
  2614. OrgId: adminUserInfo.Org.Id,
  2615. GoodId: prescription.Jms,
  2616. GoodTypeId: jms,
  2617. }
  2618. service.AddSigleAutoReduceRecordInfo(details)
  2619. }
  2620. }
  2621. if prescription.FistulaNeedleSet > 0 {
  2622. warehouseOutInfo := &models.WarehouseOutInfo{
  2623. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2624. WarehouseOutId: warehouseOut.ID,
  2625. Count: 1,
  2626. Status: 1,
  2627. Ctime: time.Now().Unix(),
  2628. Remark: "",
  2629. OrgId: adminUserInfo.Org.Id,
  2630. Type: 1,
  2631. Manufacturer: 0,
  2632. Dealer: 0,
  2633. IsSys: 1,
  2634. SysRecordTime: startDate.Unix(),
  2635. }
  2636. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  2637. warehouseOutInfo.Price = stockInInfo.Price
  2638. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  2639. warehouseOutInfo.GoodTypeId = fistula_needle_set
  2640. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2641. if err == nil {
  2642. details := &models.AutomaticReduceDetail{
  2643. WarehouseOutId: warehouseOutInfo.ID,
  2644. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2645. PatientId: patientID,
  2646. Ctime: time.Now().Unix(),
  2647. Mtime: time.Now().Unix(),
  2648. Status: 1,
  2649. RecordTime: startDate.Unix(),
  2650. OrgId: adminUserInfo.Org.Id,
  2651. GoodId: prescription.FistulaNeedleSet,
  2652. GoodTypeId: fistula_needle_set,
  2653. }
  2654. service.AddSigleAutoReduceRecordInfo(details)
  2655. }
  2656. }
  2657. if prescription.FistulaNeedleSet16 > 0 {
  2658. warehouseOutInfo := &models.WarehouseOutInfo{
  2659. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2660. WarehouseOutId: warehouseOut.ID,
  2661. Count: 1,
  2662. Status: 1,
  2663. Ctime: time.Now().Unix(),
  2664. Remark: "",
  2665. OrgId: adminUserInfo.Org.Id,
  2666. Type: 1,
  2667. Manufacturer: 0,
  2668. Dealer: 0,
  2669. IsSys: 1,
  2670. SysRecordTime: startDate.Unix(),
  2671. }
  2672. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  2673. warehouseOutInfo.Price = stockInInfo.Price
  2674. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  2675. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  2676. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2677. if err == nil {
  2678. details := &models.AutomaticReduceDetail{
  2679. WarehouseOutId: warehouseOutInfo.ID,
  2680. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2681. PatientId: patientID,
  2682. Ctime: time.Now().Unix(),
  2683. Mtime: time.Now().Unix(),
  2684. Status: 1,
  2685. RecordTime: startDate.Unix(),
  2686. OrgId: adminUserInfo.Org.Id,
  2687. GoodId: prescription.FistulaNeedleSet16,
  2688. GoodTypeId: fistula_needle_set_16,
  2689. }
  2690. service.AddSigleAutoReduceRecordInfo(details)
  2691. }
  2692. }
  2693. if prescription.Hemoperfusion > 0 {
  2694. warehouseOutInfo := &models.WarehouseOutInfo{
  2695. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2696. WarehouseOutId: warehouseOut.ID,
  2697. Count: 1,
  2698. Status: 1,
  2699. Ctime: time.Now().Unix(),
  2700. Remark: "",
  2701. OrgId: adminUserInfo.Org.Id,
  2702. Type: 1,
  2703. Manufacturer: 0,
  2704. Dealer: 0,
  2705. IsSys: 1,
  2706. SysRecordTime: startDate.Unix(),
  2707. }
  2708. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  2709. warehouseOutInfo.Price = stockInInfo.Price
  2710. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  2711. warehouseOutInfo.GoodTypeId = hemoperfusion
  2712. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2713. if err == nil {
  2714. details := &models.AutomaticReduceDetail{
  2715. WarehouseOutId: warehouseOutInfo.ID,
  2716. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2717. PatientId: patientID,
  2718. Ctime: time.Now().Unix(),
  2719. Mtime: time.Now().Unix(),
  2720. Status: 1,
  2721. RecordTime: startDate.Unix(),
  2722. OrgId: adminUserInfo.Org.Id,
  2723. GoodId: prescription.Hemoperfusion,
  2724. GoodTypeId: hemoperfusion,
  2725. }
  2726. service.AddSigleAutoReduceRecordInfo(details)
  2727. }
  2728. }
  2729. if prescription.DialyserSterilised > 0 {
  2730. warehouseOutInfo := &models.WarehouseOutInfo{
  2731. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2732. WarehouseOutId: warehouseOut.ID,
  2733. Count: 1,
  2734. Status: 1,
  2735. Ctime: time.Now().Unix(),
  2736. Remark: "",
  2737. OrgId: adminUserInfo.Org.Id,
  2738. Type: 1,
  2739. Manufacturer: 0,
  2740. Dealer: 0,
  2741. IsSys: 1,
  2742. SysRecordTime: startDate.Unix(),
  2743. }
  2744. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  2745. warehouseOutInfo.Price = stockInInfo.Price
  2746. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  2747. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  2748. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2749. if err == nil {
  2750. details := &models.AutomaticReduceDetail{
  2751. WarehouseOutId: warehouseOutInfo.ID,
  2752. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2753. PatientId: patientID,
  2754. Ctime: time.Now().Unix(),
  2755. Mtime: time.Now().Unix(),
  2756. Status: 1,
  2757. RecordTime: startDate.Unix(),
  2758. OrgId: adminUserInfo.Org.Id,
  2759. GoodId: prescription.DialyserSterilised,
  2760. GoodTypeId: dialyser_sterilised,
  2761. }
  2762. service.AddSigleAutoReduceRecordInfo(details)
  2763. }
  2764. }
  2765. if prescription.Filtryzer > 0 {
  2766. warehouseOutInfo := &models.WarehouseOutInfo{
  2767. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2768. WarehouseOutId: warehouseOut.ID,
  2769. Count: 1,
  2770. Status: 1,
  2771. Ctime: time.Now().Unix(),
  2772. Remark: "",
  2773. OrgId: adminUserInfo.Org.Id,
  2774. Type: 1,
  2775. Manufacturer: 0,
  2776. Dealer: 0,
  2777. IsSys: 1,
  2778. SysRecordTime: startDate.Unix(),
  2779. }
  2780. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  2781. warehouseOutInfo.Price = stockInInfo.Price
  2782. warehouseOutInfo.GoodId = prescription.Filtryzer
  2783. warehouseOutInfo.GoodTypeId = filtryzer
  2784. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2785. if err == nil {
  2786. details := &models.AutomaticReduceDetail{
  2787. WarehouseOutId: warehouseOutInfo.ID,
  2788. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2789. PatientId: patientID,
  2790. Ctime: time.Now().Unix(),
  2791. Mtime: time.Now().Unix(),
  2792. Status: 1,
  2793. RecordTime: startDate.Unix(),
  2794. OrgId: adminUserInfo.Org.Id,
  2795. GoodId: prescription.Filtryzer,
  2796. GoodTypeId: filtryzer,
  2797. }
  2798. service.AddSigleAutoReduceRecordInfo(details)
  2799. }
  2800. }
  2801. if prescription.Dialyzers > 0 {
  2802. warehouseOutInfo := &models.WarehouseOutInfo{
  2803. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2804. WarehouseOutId: warehouseOut.ID,
  2805. Count: 1,
  2806. Status: 1,
  2807. Ctime: time.Now().Unix(),
  2808. Remark: "",
  2809. OrgId: adminUserInfo.Org.Id,
  2810. Type: 1,
  2811. Manufacturer: 0,
  2812. Dealer: 0,
  2813. IsSys: 1,
  2814. SysRecordTime: startDate.Unix(),
  2815. }
  2816. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  2817. warehouseOutInfo.Price = stockInInfo.Price
  2818. warehouseOutInfo.GoodId = prescription.Dialyzers
  2819. warehouseOutInfo.GoodTypeId = dialyzers
  2820. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2821. if err == nil {
  2822. details := &models.AutomaticReduceDetail{
  2823. WarehouseOutId: warehouseOutInfo.ID,
  2824. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2825. PatientId: patientID,
  2826. Ctime: time.Now().Unix(),
  2827. Mtime: time.Now().Unix(),
  2828. Status: 1,
  2829. RecordTime: startDate.Unix(),
  2830. OrgId: adminUserInfo.Org.Id,
  2831. GoodId: prescription.Dialyzers,
  2832. GoodTypeId: dialyzers,
  2833. }
  2834. service.AddSigleAutoReduceRecordInfo(details)
  2835. }
  2836. }
  2837. if prescription.Injector > 0 {
  2838. warehouseOutInfo := &models.WarehouseOutInfo{
  2839. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2840. WarehouseOutId: warehouseOut.ID,
  2841. Count: 1,
  2842. Status: 1,
  2843. Ctime: time.Now().Unix(),
  2844. Remark: "",
  2845. OrgId: adminUserInfo.Org.Id,
  2846. Type: 1,
  2847. Manufacturer: 0,
  2848. Dealer: 0,
  2849. IsSys: 1,
  2850. SysRecordTime: startDate.Unix(),
  2851. }
  2852. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  2853. warehouseOutInfo.Price = stockInInfo.Price
  2854. warehouseOutInfo.GoodId = prescription.Injector
  2855. warehouseOutInfo.GoodTypeId = injector
  2856. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2857. if err == nil {
  2858. details := &models.AutomaticReduceDetail{
  2859. WarehouseOutId: warehouseOutInfo.ID,
  2860. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2861. PatientId: patientID,
  2862. Ctime: time.Now().Unix(),
  2863. Mtime: time.Now().Unix(),
  2864. Status: 1,
  2865. RecordTime: startDate.Unix(),
  2866. OrgId: adminUserInfo.Org.Id,
  2867. GoodId: prescription.Injector,
  2868. GoodTypeId: injector,
  2869. }
  2870. service.AddSigleAutoReduceRecordInfo(details)
  2871. }
  2872. }
  2873. if prescription.Bloodlines > 0 {
  2874. warehouseOutInfo := &models.WarehouseOutInfo{
  2875. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2876. WarehouseOutId: warehouseOut.ID,
  2877. Count: 1,
  2878. Status: 1,
  2879. Ctime: time.Now().Unix(),
  2880. Remark: "",
  2881. OrgId: adminUserInfo.Org.Id,
  2882. Type: 1,
  2883. Manufacturer: 0,
  2884. Dealer: 0,
  2885. IsSys: 1,
  2886. SysRecordTime: startDate.Unix(),
  2887. }
  2888. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  2889. warehouseOutInfo.Price = stockInInfo.Price
  2890. warehouseOutInfo.GoodId = prescription.Bloodlines
  2891. warehouseOutInfo.GoodTypeId = bloodlines
  2892. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2893. if err == nil {
  2894. details := &models.AutomaticReduceDetail{
  2895. WarehouseOutId: warehouseOutInfo.ID,
  2896. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2897. PatientId: patientID,
  2898. Ctime: time.Now().Unix(),
  2899. Mtime: time.Now().Unix(),
  2900. Status: 1,
  2901. RecordTime: startDate.Unix(),
  2902. OrgId: adminUserInfo.Org.Id,
  2903. GoodId: prescription.Bloodlines,
  2904. GoodTypeId: bloodlines,
  2905. }
  2906. service.AddSigleAutoReduceRecordInfo(details)
  2907. }
  2908. }
  2909. if prescription.TubingHemodialysis > 0 {
  2910. warehouseOutInfo := &models.WarehouseOutInfo{
  2911. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2912. WarehouseOutId: warehouseOut.ID,
  2913. Count: 1,
  2914. Status: 1,
  2915. Ctime: time.Now().Unix(),
  2916. Remark: "",
  2917. OrgId: adminUserInfo.Org.Id,
  2918. Type: 1,
  2919. Manufacturer: 0,
  2920. Dealer: 0,
  2921. IsSys: 1,
  2922. SysRecordTime: startDate.Unix(),
  2923. }
  2924. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  2925. warehouseOutInfo.Price = stockInInfo.Price
  2926. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  2927. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  2928. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2929. if err == nil {
  2930. details := &models.AutomaticReduceDetail{
  2931. WarehouseOutId: warehouseOutInfo.ID,
  2932. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2933. PatientId: patientID,
  2934. Ctime: time.Now().Unix(),
  2935. Mtime: time.Now().Unix(),
  2936. Status: 1,
  2937. RecordTime: startDate.Unix(),
  2938. OrgId: adminUserInfo.Org.Id,
  2939. GoodId: prescription.TubingHemodialysis,
  2940. GoodTypeId: tubingHemodialysis,
  2941. }
  2942. service.AddSigleAutoReduceRecordInfo(details)
  2943. }
  2944. }
  2945. if prescription.Package > 0 {
  2946. warehouseOutInfo := &models.WarehouseOutInfo{
  2947. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2948. WarehouseOutId: warehouseOut.ID,
  2949. Count: 1,
  2950. Status: 1,
  2951. Ctime: time.Now().Unix(),
  2952. Remark: "",
  2953. OrgId: adminUserInfo.Org.Id,
  2954. Type: 1,
  2955. Manufacturer: 0,
  2956. Dealer: 0,
  2957. IsSys: 1,
  2958. SysRecordTime: startDate.Unix(),
  2959. }
  2960. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  2961. warehouseOutInfo.Price = stockInInfo.Price
  2962. warehouseOutInfo.GoodId = prescription.Package
  2963. warehouseOutInfo.GoodTypeId = safe_package
  2964. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2965. if err == nil {
  2966. details := &models.AutomaticReduceDetail{
  2967. WarehouseOutId: warehouseOutInfo.ID,
  2968. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2969. PatientId: patientID,
  2970. Ctime: time.Now().Unix(),
  2971. Mtime: time.Now().Unix(),
  2972. Status: 1,
  2973. RecordTime: startDate.Unix(),
  2974. OrgId: adminUserInfo.Org.Id,
  2975. GoodId: prescription.Package,
  2976. GoodTypeId: safe_package,
  2977. }
  2978. service.AddSigleAutoReduceRecordInfo(details)
  2979. }
  2980. }
  2981. if prescription.ALiquid > 0 {
  2982. warehouseOutInfo := &models.WarehouseOutInfo{
  2983. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2984. WarehouseOutId: warehouseOut.ID,
  2985. Count: 1,
  2986. Status: 1,
  2987. Ctime: time.Now().Unix(),
  2988. Remark: "",
  2989. OrgId: adminUserInfo.Org.Id,
  2990. Type: 1,
  2991. Manufacturer: 0,
  2992. Dealer: 0,
  2993. IsSys: 1,
  2994. SysRecordTime: startDate.Unix(),
  2995. }
  2996. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  2997. warehouseOutInfo.Price = stockInInfo.Price
  2998. warehouseOutInfo.GoodId = prescription.ALiquid
  2999. warehouseOutInfo.GoodTypeId = aliquid
  3000. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3001. if err == nil {
  3002. details := &models.AutomaticReduceDetail{
  3003. WarehouseOutId: warehouseOutInfo.ID,
  3004. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3005. PatientId: patientID,
  3006. Ctime: time.Now().Unix(),
  3007. Mtime: time.Now().Unix(),
  3008. Status: 1,
  3009. RecordTime: startDate.Unix(),
  3010. OrgId: adminUserInfo.Org.Id,
  3011. GoodId: prescription.ALiquid,
  3012. GoodTypeId: aliquid,
  3013. }
  3014. service.AddSigleAutoReduceRecordInfo(details)
  3015. }
  3016. }
  3017. }
  3018. } else if err == nil {
  3019. if out.ID > 0 {
  3020. if prescription.Niprocart > 0 {
  3021. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.ID)
  3022. if err == gorm.ErrRecordNotFound {
  3023. warehouseOutInfo := &models.WarehouseOutInfo{
  3024. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3025. WarehouseOutId: out.ID,
  3026. Status: 1,
  3027. Ctime: time.Now().Unix(),
  3028. Remark: "",
  3029. OrgId: adminUserInfo.Org.Id,
  3030. Type: 1,
  3031. Manufacturer: 0,
  3032. Dealer: 0,
  3033. IsSys: 1,
  3034. SysRecordTime: startDate.Unix(),
  3035. }
  3036. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  3037. warehouseOutInfo.Price = stockInInfo.Price
  3038. warehouseOutInfo.GoodId = prescription.Niprocart
  3039. warehouseOutInfo.GoodTypeId = niprocart
  3040. warehouseOutInfo.Count = 1
  3041. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3042. if err == nil {
  3043. details := &models.AutomaticReduceDetail{
  3044. WarehouseOutId: warehouseOutInfo.ID,
  3045. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3046. PatientId: patientID,
  3047. Ctime: time.Now().Unix(),
  3048. Mtime: time.Now().Unix(),
  3049. Status: 1,
  3050. RecordTime: startDate.Unix(),
  3051. OrgId: adminUserInfo.Org.Id,
  3052. GoodId: prescription.Niprocart,
  3053. GoodTypeId: niprocart,
  3054. }
  3055. service.AddSigleAutoReduceRecordInfo(details)
  3056. }
  3057. } else if err == nil { //记录存在,则将数量加1
  3058. if outInfo.ID > 0 {
  3059. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3060. }
  3061. details := &models.AutomaticReduceDetail{
  3062. WarehouseOutId: outInfo.ID,
  3063. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3064. PatientId: patientID,
  3065. Ctime: time.Now().Unix(),
  3066. Mtime: time.Now().Unix(),
  3067. Status: 1,
  3068. RecordTime: startDate.Unix(),
  3069. OrgId: adminUserInfo.Org.Id,
  3070. GoodId: prescription.Niprocart,
  3071. GoodTypeId: niprocart,
  3072. }
  3073. service.AddSigleAutoReduceRecordInfo(details)
  3074. }
  3075. }
  3076. if prescription.Jms > 0 {
  3077. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.ID)
  3078. if err == gorm.ErrRecordNotFound {
  3079. warehouseOutInfo := &models.WarehouseOutInfo{
  3080. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3081. WarehouseOutId: out.ID,
  3082. Status: 1,
  3083. Ctime: time.Now().Unix(),
  3084. Remark: "",
  3085. OrgId: adminUserInfo.Org.Id,
  3086. Type: 1,
  3087. Manufacturer: 0,
  3088. Dealer: 0,
  3089. IsSys: 1,
  3090. SysRecordTime: startDate.Unix(),
  3091. }
  3092. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  3093. warehouseOutInfo.Price = stockInInfo.Price
  3094. warehouseOutInfo.GoodId = prescription.Jms
  3095. warehouseOutInfo.GoodTypeId = jms
  3096. warehouseOutInfo.Count = 1
  3097. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3098. if err == nil {
  3099. details := &models.AutomaticReduceDetail{
  3100. WarehouseOutId: warehouseOutInfo.ID,
  3101. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3102. PatientId: patientID,
  3103. Ctime: time.Now().Unix(),
  3104. Mtime: time.Now().Unix(),
  3105. Status: 1,
  3106. RecordTime: startDate.Unix(),
  3107. OrgId: adminUserInfo.Org.Id,
  3108. GoodId: prescription.Jms,
  3109. GoodTypeId: jms,
  3110. }
  3111. service.AddSigleAutoReduceRecordInfo(details)
  3112. }
  3113. } else if err == nil { //记录存在,则将数量加1
  3114. if outInfo.ID > 0 {
  3115. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3116. }
  3117. details := &models.AutomaticReduceDetail{
  3118. WarehouseOutId: outInfo.ID,
  3119. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3120. PatientId: patientID,
  3121. Ctime: time.Now().Unix(),
  3122. Mtime: time.Now().Unix(),
  3123. Status: 1,
  3124. RecordTime: startDate.Unix(),
  3125. OrgId: adminUserInfo.Org.Id,
  3126. GoodId: prescription.Jms,
  3127. GoodTypeId: jms,
  3128. }
  3129. service.AddSigleAutoReduceRecordInfo(details)
  3130. }
  3131. }
  3132. if prescription.FistulaNeedleSet > 0 {
  3133. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.ID)
  3134. if err == gorm.ErrRecordNotFound {
  3135. warehouseOutInfo := &models.WarehouseOutInfo{
  3136. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3137. WarehouseOutId: out.ID,
  3138. Status: 1,
  3139. Ctime: time.Now().Unix(),
  3140. Remark: "",
  3141. OrgId: adminUserInfo.Org.Id,
  3142. Type: 1,
  3143. Manufacturer: 0,
  3144. Dealer: 0,
  3145. IsSys: 1,
  3146. SysRecordTime: startDate.Unix(),
  3147. }
  3148. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  3149. warehouseOutInfo.Price = stockInInfo.Price
  3150. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  3151. warehouseOutInfo.GoodTypeId = fistula_needle_set
  3152. warehouseOutInfo.Count = 1
  3153. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3154. if err == nil {
  3155. details := &models.AutomaticReduceDetail{
  3156. WarehouseOutId: warehouseOutInfo.ID,
  3157. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3158. PatientId: patientID,
  3159. Ctime: time.Now().Unix(),
  3160. Mtime: time.Now().Unix(),
  3161. Status: 1,
  3162. RecordTime: startDate.Unix(),
  3163. OrgId: adminUserInfo.Org.Id,
  3164. GoodId: prescription.FistulaNeedleSet,
  3165. GoodTypeId: fistula_needle_set,
  3166. }
  3167. service.AddSigleAutoReduceRecordInfo(details)
  3168. }
  3169. } else if err == nil { //记录存在,则将数量加1
  3170. if outInfo.ID > 0 {
  3171. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3172. }
  3173. details := &models.AutomaticReduceDetail{
  3174. WarehouseOutId: outInfo.ID,
  3175. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3176. PatientId: patientID,
  3177. Ctime: time.Now().Unix(),
  3178. Mtime: time.Now().Unix(),
  3179. Status: 1,
  3180. RecordTime: startDate.Unix(),
  3181. OrgId: adminUserInfo.Org.Id,
  3182. GoodId: prescription.FistulaNeedleSet,
  3183. GoodTypeId: fistula_needle_set,
  3184. }
  3185. service.AddSigleAutoReduceRecordInfo(details)
  3186. }
  3187. }
  3188. if prescription.FistulaNeedleSet16 > 0 {
  3189. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.ID)
  3190. if err == gorm.ErrRecordNotFound {
  3191. warehouseOutInfo := &models.WarehouseOutInfo{
  3192. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3193. WarehouseOutId: out.ID,
  3194. Status: 1,
  3195. Ctime: time.Now().Unix(),
  3196. Remark: "",
  3197. OrgId: adminUserInfo.Org.Id,
  3198. Type: 1,
  3199. Manufacturer: 0,
  3200. Dealer: 0,
  3201. IsSys: 1,
  3202. SysRecordTime: startDate.Unix(),
  3203. }
  3204. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  3205. warehouseOutInfo.Price = stockInInfo.Price
  3206. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  3207. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  3208. warehouseOutInfo.Count = 1
  3209. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3210. if err == nil {
  3211. details := &models.AutomaticReduceDetail{
  3212. WarehouseOutId: warehouseOutInfo.ID,
  3213. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3214. PatientId: patientID,
  3215. Ctime: time.Now().Unix(),
  3216. Mtime: time.Now().Unix(),
  3217. Status: 1,
  3218. RecordTime: startDate.Unix(),
  3219. OrgId: adminUserInfo.Org.Id,
  3220. GoodId: prescription.FistulaNeedleSet16,
  3221. GoodTypeId: fistula_needle_set_16,
  3222. }
  3223. service.AddSigleAutoReduceRecordInfo(details)
  3224. }
  3225. } else if err == nil { //记录存在,则将数量加1
  3226. if outInfo.ID > 0 {
  3227. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3228. }
  3229. details := &models.AutomaticReduceDetail{
  3230. WarehouseOutId: outInfo.ID,
  3231. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3232. PatientId: patientID,
  3233. Ctime: time.Now().Unix(),
  3234. Mtime: time.Now().Unix(),
  3235. Status: 1,
  3236. RecordTime: startDate.Unix(),
  3237. OrgId: adminUserInfo.Org.Id,
  3238. GoodId: prescription.FistulaNeedleSet16,
  3239. GoodTypeId: fistula_needle_set_16,
  3240. }
  3241. service.AddSigleAutoReduceRecordInfo(details)
  3242. }
  3243. }
  3244. if prescription.Hemoperfusion > 0 {
  3245. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.ID)
  3246. if err == gorm.ErrRecordNotFound {
  3247. warehouseOutInfo := &models.WarehouseOutInfo{
  3248. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3249. WarehouseOutId: out.ID,
  3250. Status: 1,
  3251. Ctime: time.Now().Unix(),
  3252. Remark: "",
  3253. OrgId: adminUserInfo.Org.Id,
  3254. Type: 1,
  3255. Manufacturer: 0,
  3256. Dealer: 0,
  3257. IsSys: 1,
  3258. SysRecordTime: startDate.Unix(),
  3259. }
  3260. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  3261. warehouseOutInfo.Price = stockInInfo.Price
  3262. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  3263. warehouseOutInfo.GoodTypeId = hemoperfusion
  3264. warehouseOutInfo.Count = 1
  3265. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3266. if err == nil {
  3267. details := &models.AutomaticReduceDetail{
  3268. WarehouseOutId: warehouseOutInfo.ID,
  3269. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3270. PatientId: patientID,
  3271. Ctime: time.Now().Unix(),
  3272. Mtime: time.Now().Unix(),
  3273. Status: 1,
  3274. RecordTime: startDate.Unix(),
  3275. OrgId: adminUserInfo.Org.Id,
  3276. GoodId: prescription.Hemoperfusion,
  3277. GoodTypeId: hemoperfusion,
  3278. }
  3279. service.AddSigleAutoReduceRecordInfo(details)
  3280. }
  3281. } else if err == nil { //记录存在,则将数量加1
  3282. if outInfo.ID > 0 {
  3283. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3284. }
  3285. details := &models.AutomaticReduceDetail{
  3286. WarehouseOutId: outInfo.ID,
  3287. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3288. PatientId: patientID,
  3289. Ctime: time.Now().Unix(),
  3290. Mtime: time.Now().Unix(),
  3291. Status: 1,
  3292. RecordTime: startDate.Unix(),
  3293. OrgId: adminUserInfo.Org.Id,
  3294. GoodId: prescription.Hemoperfusion,
  3295. GoodTypeId: hemoperfusion,
  3296. }
  3297. service.AddSigleAutoReduceRecordInfo(details)
  3298. }
  3299. }
  3300. if prescription.DialyserSterilised > 0 {
  3301. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.ID)
  3302. if err == gorm.ErrRecordNotFound {
  3303. warehouseOutInfo := &models.WarehouseOutInfo{
  3304. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3305. WarehouseOutId: out.ID,
  3306. Status: 1,
  3307. Ctime: time.Now().Unix(),
  3308. Remark: "",
  3309. OrgId: adminUserInfo.Org.Id,
  3310. Type: 1,
  3311. Manufacturer: 0,
  3312. Dealer: 0,
  3313. IsSys: 1,
  3314. SysRecordTime: startDate.Unix(),
  3315. }
  3316. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  3317. warehouseOutInfo.Price = stockInInfo.Price
  3318. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  3319. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  3320. warehouseOutInfo.Count = 1
  3321. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3322. if err == nil {
  3323. details := &models.AutomaticReduceDetail{
  3324. WarehouseOutId: warehouseOutInfo.ID,
  3325. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3326. PatientId: patientID,
  3327. Ctime: time.Now().Unix(),
  3328. Mtime: time.Now().Unix(),
  3329. Status: 1,
  3330. RecordTime: startDate.Unix(),
  3331. OrgId: adminUserInfo.Org.Id,
  3332. GoodId: prescription.DialyserSterilised,
  3333. GoodTypeId: dialyser_sterilised,
  3334. }
  3335. service.AddSigleAutoReduceRecordInfo(details)
  3336. }
  3337. } else if err == nil { //记录存在,则将数量加1
  3338. if outInfo.ID > 0 {
  3339. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3340. }
  3341. details := &models.AutomaticReduceDetail{
  3342. WarehouseOutId: outInfo.ID,
  3343. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3344. PatientId: patientID,
  3345. Ctime: time.Now().Unix(),
  3346. Mtime: time.Now().Unix(),
  3347. Status: 1,
  3348. RecordTime: startDate.Unix(),
  3349. OrgId: adminUserInfo.Org.Id,
  3350. GoodId: prescription.DialyserSterilised,
  3351. GoodTypeId: dialyser_sterilised,
  3352. }
  3353. service.AddSigleAutoReduceRecordInfo(details)
  3354. }
  3355. }
  3356. if prescription.Filtryzer > 0 {
  3357. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.ID)
  3358. if err == gorm.ErrRecordNotFound {
  3359. warehouseOutInfo := &models.WarehouseOutInfo{
  3360. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3361. WarehouseOutId: out.ID,
  3362. Status: 1,
  3363. Ctime: time.Now().Unix(),
  3364. Remark: "",
  3365. OrgId: adminUserInfo.Org.Id,
  3366. Type: 1,
  3367. Manufacturer: 0,
  3368. Dealer: 0,
  3369. IsSys: 1,
  3370. SysRecordTime: startDate.Unix(),
  3371. }
  3372. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  3373. warehouseOutInfo.Price = stockInInfo.Price
  3374. warehouseOutInfo.GoodId = prescription.Filtryzer
  3375. warehouseOutInfo.GoodTypeId = filtryzer
  3376. warehouseOutInfo.Count = 1
  3377. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3378. if err == nil {
  3379. details := &models.AutomaticReduceDetail{
  3380. WarehouseOutId: warehouseOutInfo.ID,
  3381. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3382. PatientId: patientID,
  3383. Ctime: time.Now().Unix(),
  3384. Mtime: time.Now().Unix(),
  3385. Status: 1,
  3386. RecordTime: startDate.Unix(),
  3387. OrgId: adminUserInfo.Org.Id,
  3388. GoodId: prescription.Filtryzer,
  3389. GoodTypeId: filtryzer,
  3390. }
  3391. service.AddSigleAutoReduceRecordInfo(details)
  3392. }
  3393. } else if err == nil { //记录存在,则将耗材使用数量加1
  3394. if outInfo.ID > 0 {
  3395. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3396. }
  3397. //插入病人耗材使用记录
  3398. details := &models.AutomaticReduceDetail{
  3399. WarehouseOutId: outInfo.ID,
  3400. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3401. PatientId: patientID,
  3402. Ctime: time.Now().Unix(),
  3403. Mtime: time.Now().Unix(),
  3404. Status: 1,
  3405. RecordTime: startDate.Unix(),
  3406. OrgId: adminUserInfo.Org.Id,
  3407. GoodId: prescription.Filtryzer,
  3408. GoodTypeId: filtryzer,
  3409. }
  3410. service.AddSigleAutoReduceRecordInfo(details)
  3411. }
  3412. }
  3413. if prescription.Dialyzers > 0 {
  3414. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.ID)
  3415. if err == gorm.ErrRecordNotFound {
  3416. warehouseOutInfo := &models.WarehouseOutInfo{
  3417. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3418. WarehouseOutId: out.ID,
  3419. Status: 1,
  3420. Ctime: time.Now().Unix(),
  3421. Remark: "",
  3422. OrgId: adminUserInfo.Org.Id,
  3423. Type: 1,
  3424. Manufacturer: 0,
  3425. Dealer: 0,
  3426. IsSys: 1,
  3427. SysRecordTime: startDate.Unix(),
  3428. }
  3429. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  3430. warehouseOutInfo.Price = stockInInfo.Price
  3431. warehouseOutInfo.GoodId = prescription.Dialyzers
  3432. warehouseOutInfo.GoodTypeId = dialyzers
  3433. warehouseOutInfo.Count = 1
  3434. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3435. if err == nil {
  3436. details := &models.AutomaticReduceDetail{
  3437. WarehouseOutId: warehouseOutInfo.ID,
  3438. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3439. PatientId: patientID,
  3440. Ctime: time.Now().Unix(),
  3441. Mtime: time.Now().Unix(),
  3442. Status: 1,
  3443. RecordTime: startDate.Unix(),
  3444. OrgId: adminUserInfo.Org.Id,
  3445. GoodId: prescription.Dialyzers,
  3446. GoodTypeId: dialyzers,
  3447. }
  3448. service.AddSigleAutoReduceRecordInfo(details)
  3449. }
  3450. } else if err == nil { //记录存在,则将耗材使用数量加1
  3451. if outInfo.ID > 0 {
  3452. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3453. }
  3454. //插入病人耗材使用记录
  3455. details := &models.AutomaticReduceDetail{
  3456. WarehouseOutId: outInfo.ID,
  3457. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3458. PatientId: patientID,
  3459. Ctime: time.Now().Unix(),
  3460. Mtime: time.Now().Unix(),
  3461. Status: 1,
  3462. RecordTime: startDate.Unix(),
  3463. OrgId: adminUserInfo.Org.Id,
  3464. GoodId: prescription.Dialyzers,
  3465. GoodTypeId: dialyzers,
  3466. }
  3467. service.AddSigleAutoReduceRecordInfo(details)
  3468. }
  3469. }
  3470. if prescription.Injector > 0 {
  3471. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.ID)
  3472. if err == gorm.ErrRecordNotFound {
  3473. warehouseOutInfo := &models.WarehouseOutInfo{
  3474. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3475. WarehouseOutId: out.ID,
  3476. Status: 1,
  3477. Ctime: time.Now().Unix(),
  3478. Remark: "",
  3479. OrgId: adminUserInfo.Org.Id,
  3480. Type: 1,
  3481. Manufacturer: 0,
  3482. Dealer: 0,
  3483. IsSys: 1,
  3484. SysRecordTime: startDate.Unix(),
  3485. }
  3486. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  3487. warehouseOutInfo.Price = stockInInfo.Price
  3488. warehouseOutInfo.GoodId = prescription.Injector
  3489. warehouseOutInfo.GoodTypeId = injector
  3490. warehouseOutInfo.Count = 1
  3491. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3492. if err == nil {
  3493. details := &models.AutomaticReduceDetail{
  3494. WarehouseOutId: warehouseOutInfo.ID,
  3495. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3496. PatientId: patientID,
  3497. Ctime: time.Now().Unix(),
  3498. Mtime: time.Now().Unix(),
  3499. Status: 1,
  3500. RecordTime: startDate.Unix(),
  3501. OrgId: adminUserInfo.Org.Id,
  3502. GoodId: prescription.Injector,
  3503. GoodTypeId: injector,
  3504. }
  3505. service.AddSigleAutoReduceRecordInfo(details)
  3506. }
  3507. } else if err == nil { //记录存在,则将耗材使用数量加1
  3508. if outInfo.ID > 0 {
  3509. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3510. }
  3511. //插入病人耗材使用记录
  3512. details := &models.AutomaticReduceDetail{
  3513. WarehouseOutId: outInfo.ID,
  3514. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3515. PatientId: patientID,
  3516. Ctime: time.Now().Unix(),
  3517. Mtime: time.Now().Unix(),
  3518. Status: 1,
  3519. RecordTime: startDate.Unix(),
  3520. OrgId: adminUserInfo.Org.Id,
  3521. GoodId: prescription.Injector,
  3522. GoodTypeId: injector,
  3523. }
  3524. service.AddSigleAutoReduceRecordInfo(details)
  3525. }
  3526. }
  3527. if prescription.Bloodlines > 0 {
  3528. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.ID)
  3529. if err == gorm.ErrRecordNotFound {
  3530. warehouseOutInfo := &models.WarehouseOutInfo{
  3531. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3532. WarehouseOutId: out.ID,
  3533. Status: 1,
  3534. Ctime: time.Now().Unix(),
  3535. Remark: "",
  3536. OrgId: adminUserInfo.Org.Id,
  3537. Type: 1,
  3538. Manufacturer: 0,
  3539. Dealer: 0,
  3540. IsSys: 1,
  3541. SysRecordTime: startDate.Unix(),
  3542. }
  3543. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  3544. warehouseOutInfo.Price = stockInInfo.Price
  3545. warehouseOutInfo.GoodId = prescription.Bloodlines
  3546. warehouseOutInfo.GoodTypeId = bloodlines
  3547. warehouseOutInfo.Count = 1
  3548. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3549. if err == nil {
  3550. details := &models.AutomaticReduceDetail{
  3551. WarehouseOutId: warehouseOutInfo.ID,
  3552. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3553. PatientId: patientID,
  3554. Ctime: time.Now().Unix(),
  3555. Mtime: time.Now().Unix(),
  3556. Status: 1,
  3557. RecordTime: startDate.Unix(),
  3558. OrgId: adminUserInfo.Org.Id,
  3559. GoodId: prescription.Bloodlines,
  3560. GoodTypeId: bloodlines,
  3561. }
  3562. service.AddSigleAutoReduceRecordInfo(details)
  3563. }
  3564. } else if err == nil { //记录存在,则将耗材使用数量加1
  3565. if outInfo.ID > 0 {
  3566. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3567. }
  3568. //插入病人耗材使用记录
  3569. details := &models.AutomaticReduceDetail{
  3570. WarehouseOutId: outInfo.ID,
  3571. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3572. PatientId: patientID,
  3573. Ctime: time.Now().Unix(),
  3574. Mtime: time.Now().Unix(),
  3575. Status: 1,
  3576. RecordTime: startDate.Unix(),
  3577. OrgId: adminUserInfo.Org.Id,
  3578. GoodId: prescription.Bloodlines,
  3579. GoodTypeId: bloodlines,
  3580. }
  3581. service.AddSigleAutoReduceRecordInfo(details)
  3582. }
  3583. }
  3584. if prescription.TubingHemodialysis > 0 {
  3585. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.ID)
  3586. if err == gorm.ErrRecordNotFound {
  3587. warehouseOutInfo := &models.WarehouseOutInfo{
  3588. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3589. WarehouseOutId: out.ID,
  3590. Status: 1,
  3591. Ctime: time.Now().Unix(),
  3592. Remark: "",
  3593. OrgId: adminUserInfo.Org.Id,
  3594. Type: 1,
  3595. Manufacturer: 0,
  3596. Dealer: 0,
  3597. IsSys: 1,
  3598. SysRecordTime: startDate.Unix(),
  3599. }
  3600. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  3601. warehouseOutInfo.Price = stockInInfo.Price
  3602. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  3603. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  3604. warehouseOutInfo.Count = 1
  3605. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3606. if err == nil {
  3607. details := &models.AutomaticReduceDetail{
  3608. WarehouseOutId: warehouseOutInfo.ID,
  3609. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3610. PatientId: patientID,
  3611. Ctime: time.Now().Unix(),
  3612. Mtime: time.Now().Unix(),
  3613. Status: 1,
  3614. RecordTime: startDate.Unix(),
  3615. OrgId: adminUserInfo.Org.Id,
  3616. GoodId: prescription.TubingHemodialysis,
  3617. GoodTypeId: tubingHemodialysis,
  3618. }
  3619. service.AddSigleAutoReduceRecordInfo(details)
  3620. }
  3621. } else if err == nil { //记录存在,则将耗材使用数量加1
  3622. if outInfo.ID > 0 {
  3623. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3624. }
  3625. //插入病人耗材使用记录
  3626. details := &models.AutomaticReduceDetail{
  3627. WarehouseOutId: outInfo.ID,
  3628. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3629. PatientId: patientID,
  3630. Ctime: time.Now().Unix(),
  3631. Mtime: time.Now().Unix(),
  3632. Status: 1,
  3633. RecordTime: startDate.Unix(),
  3634. OrgId: adminUserInfo.Org.Id,
  3635. GoodId: prescription.TubingHemodialysis,
  3636. GoodTypeId: tubingHemodialysis,
  3637. }
  3638. service.AddSigleAutoReduceRecordInfo(details)
  3639. }
  3640. }
  3641. if prescription.Package > 0 {
  3642. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.ID)
  3643. if err == gorm.ErrRecordNotFound {
  3644. warehouseOutInfo := &models.WarehouseOutInfo{
  3645. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3646. WarehouseOutId: out.ID,
  3647. Status: 1,
  3648. Ctime: time.Now().Unix(),
  3649. Remark: "",
  3650. OrgId: adminUserInfo.Org.Id,
  3651. Type: 1,
  3652. Manufacturer: 0,
  3653. Dealer: 0,
  3654. IsSys: 1,
  3655. SysRecordTime: startDate.Unix(),
  3656. }
  3657. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  3658. warehouseOutInfo.Price = stockInInfo.Price
  3659. warehouseOutInfo.GoodId = prescription.Package
  3660. warehouseOutInfo.GoodTypeId = safe_package
  3661. warehouseOutInfo.Count = 1
  3662. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3663. if err == nil {
  3664. details := &models.AutomaticReduceDetail{
  3665. WarehouseOutId: warehouseOutInfo.ID,
  3666. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3667. PatientId: patientID,
  3668. Ctime: time.Now().Unix(),
  3669. Mtime: time.Now().Unix(),
  3670. Status: 1,
  3671. RecordTime: startDate.Unix(),
  3672. OrgId: adminUserInfo.Org.Id,
  3673. GoodId: prescription.Package,
  3674. GoodTypeId: safe_package,
  3675. }
  3676. service.AddSigleAutoReduceRecordInfo(details)
  3677. }
  3678. } else if err == nil { //记录存在,则将耗材使用数量加1
  3679. if outInfo.ID > 0 {
  3680. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3681. }
  3682. //插入病人耗材使用记录
  3683. details := &models.AutomaticReduceDetail{
  3684. WarehouseOutId: outInfo.ID,
  3685. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3686. PatientId: patientID,
  3687. Ctime: time.Now().Unix(),
  3688. Mtime: time.Now().Unix(),
  3689. Status: 1,
  3690. RecordTime: startDate.Unix(),
  3691. OrgId: adminUserInfo.Org.Id,
  3692. GoodId: prescription.Package,
  3693. GoodTypeId: safe_package,
  3694. }
  3695. service.AddSigleAutoReduceRecordInfo(details)
  3696. }
  3697. }
  3698. if prescription.ALiquid > 0 {
  3699. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.ID)
  3700. if err == gorm.ErrRecordNotFound {
  3701. warehouseOutInfo := &models.WarehouseOutInfo{
  3702. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3703. WarehouseOutId: out.ID,
  3704. Status: 1,
  3705. Ctime: time.Now().Unix(),
  3706. Remark: "",
  3707. OrgId: adminUserInfo.Org.Id,
  3708. Type: 1,
  3709. Manufacturer: 0,
  3710. Dealer: 0,
  3711. IsSys: 1,
  3712. SysRecordTime: startDate.Unix(),
  3713. }
  3714. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3715. warehouseOutInfo.Price = stockInInfo.Price
  3716. warehouseOutInfo.GoodId = prescription.ALiquid
  3717. warehouseOutInfo.GoodTypeId = aliquid
  3718. warehouseOutInfo.Count = 1
  3719. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3720. if err == nil {
  3721. details := &models.AutomaticReduceDetail{
  3722. WarehouseOutId: warehouseOutInfo.ID,
  3723. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3724. PatientId: patientID,
  3725. Ctime: time.Now().Unix(),
  3726. Mtime: time.Now().Unix(),
  3727. Status: 1,
  3728. RecordTime: startDate.Unix(),
  3729. OrgId: adminUserInfo.Org.Id,
  3730. GoodId: prescription.ALiquid,
  3731. GoodTypeId: aliquid,
  3732. }
  3733. service.AddSigleAutoReduceRecordInfo(details)
  3734. }
  3735. } else if err == nil { //记录存在,则将耗材使用数量加1
  3736. if outInfo.ID > 0 {
  3737. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3738. }
  3739. //插入病人耗材使用记录
  3740. details := &models.AutomaticReduceDetail{
  3741. WarehouseOutId: outInfo.ID,
  3742. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3743. PatientId: patientID,
  3744. Ctime: time.Now().Unix(),
  3745. Mtime: time.Now().Unix(),
  3746. Status: 1,
  3747. RecordTime: startDate.Unix(),
  3748. OrgId: adminUserInfo.Org.Id,
  3749. GoodId: prescription.ALiquid,
  3750. GoodTypeId: aliquid,
  3751. }
  3752. service.AddSigleAutoReduceRecordInfo(details)
  3753. }
  3754. }
  3755. }
  3756. }
  3757. } else {
  3758. this.ErrorLog("上机失败,还没开处方")
  3759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  3760. return
  3761. }
  3762. }
  3763. if createErr != nil {
  3764. this.ErrorLog("上机失败:%v", createErr)
  3765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3766. return
  3767. }
  3768. this.ServeSuccessJSON(map[string]interface{}{
  3769. "dialysis_order": newdialysisRecord,
  3770. "monitor": record,
  3771. })
  3772. }
  3773. func (c *DialysisAPIController) PostSolution() {
  3774. id, _ := c.GetInt64("patient", 0)
  3775. recordDateStr := c.GetString("record_date")
  3776. if id <= 0 {
  3777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3778. return
  3779. }
  3780. adminUserInfo := c.GetMobileAdminUserInfo()
  3781. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3782. if patient.ID == 0 {
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3784. return
  3785. }
  3786. if len(recordDateStr) == 0 {
  3787. recordDateStr = time.Now().Format("2006-01-02")
  3788. }
  3789. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3790. if parseDateErr != nil {
  3791. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3793. return
  3794. }
  3795. mode_id, _ := c.GetInt64("mode_id", 0)
  3796. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3797. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3798. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3799. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3800. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3801. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3802. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3803. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3804. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3805. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3806. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3807. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3808. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3809. kalium, _ := c.GetFloat("kalium", 0)
  3810. sodium, _ := c.GetFloat("sodium", 0)
  3811. calcium, _ := c.GetFloat("calcium", 0)
  3812. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3813. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3814. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3815. glucose, _ := c.GetFloat("glucose", 0)
  3816. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3817. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3818. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3819. conductivity, _ := c.GetFloat("conductivity", 0)
  3820. remark := c.GetString("remark")
  3821. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3822. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3823. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3824. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3825. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3826. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3827. special_medicine_other := c.GetString("special_medicine_other")
  3828. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3829. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3830. blood_access, _ := c.GetInt64("blood_access", 0)
  3831. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3832. body_fluid_other := c.GetString("body_fluid_other")
  3833. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3834. niprocart, _ := c.GetInt64("niprocart", 0)
  3835. jms, _ := c.GetInt64("jms", 0)
  3836. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3837. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3838. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3839. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3840. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3841. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3842. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3843. injector, _ := c.GetInt64("injector", 0)
  3844. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3845. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3846. safe_package, _ := c.GetInt64("package", 0)
  3847. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3848. if mode_id > 0 {
  3849. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  3850. }
  3851. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3852. //
  3853. //if appRole.UserType == 2 || appRole.UserType == 1 {
  3854. // prescription_doctor = appRole.AdminUserId
  3855. //} else {
  3856. // prescription_doctor = 0
  3857. //}
  3858. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3859. //
  3860. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3861. // if appRole.UserType == 3 {
  3862. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3863. // if getPermissionErr != nil {
  3864. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3865. // return
  3866. // } else if headNursePermission == nil {
  3867. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3868. // return
  3869. // }
  3870. // }
  3871. //}
  3872. prescription := models.DialysisPrescription{
  3873. UserOrgId: adminUserInfo.Org.Id,
  3874. PatientId: id,
  3875. RecordDate: recordDate.Unix(),
  3876. ModeId: mode_id,
  3877. DialysisDuration: dialysis_duration,
  3878. Dialyzer: dialyzer,
  3879. PerfusionApparatus: perfusion_apparatus,
  3880. BloodFlowVolume: blood_flow_volume,
  3881. DewaterAmount: dewater_amount,
  3882. DisplaceLiqui: displace_liqui,
  3883. ReplacementWay: replacement_way,
  3884. Anticoagulant: anticoagulant,
  3885. AnticoagulantShouji: anticoagulant_shouji,
  3886. AnticoagulantWeichi: anticoagulant_weichi,
  3887. AnticoagulantZongliang: anticoagulant_zongliang,
  3888. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3889. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3890. Kalium: kalium,
  3891. Sodium: sodium,
  3892. Calcium: calcium,
  3893. Bicarbonate: bicarbonate,
  3894. Glucose: glucose,
  3895. // DryWeight: dry_weight,
  3896. DialysateFlow: dialysate_flow,
  3897. DialysateTemperature: dialysate_temperature,
  3898. Conductivity: conductivity,
  3899. Remark: remark,
  3900. PrescriptionDoctor: prescription_doctor,
  3901. Status: 1,
  3902. CreatedTime: time.Now().Unix(),
  3903. UpdatedTime: time.Now().Unix(),
  3904. DialysisDurationMinute: dialysisDurationMinute,
  3905. DialysisDurationHour: dialysisDurationHour,
  3906. TargetUltrafiltration: targetUltrafiltration,
  3907. DialysateFormulation: dialysateFormulation,
  3908. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3909. BodyFluid: body_fluid,
  3910. SpecialMedicine: special_medicine,
  3911. SpecialMedicineOther: special_medicine_other,
  3912. DisplaceLiquiPart: displace_liqui_part,
  3913. DisplaceLiquiValue: displace_liqui_value,
  3914. BloodAccess: blood_access,
  3915. Ultrafiltration: ultrafiltration,
  3916. BodyFluidOther: body_fluid_other,
  3917. ReplacementTotal: replacement_total,
  3918. Niprocart: niprocart,
  3919. Jms: jms,
  3920. FistulaNeedleSet: fistula_needle_set,
  3921. FistulaNeedleSet16: fistula_needle_set_16,
  3922. Hemoperfusion: hemoperfusion,
  3923. DialyserSterilised: dialyser_sterilised,
  3924. Filtryzer: filtryzer,
  3925. TargetKtv: target_ktv,
  3926. Dialyzers: dialyzers,
  3927. Injector: injector,
  3928. Bloodlines: bloodlines,
  3929. TubingHemodialysis: tubing_hemodialysis,
  3930. Package: safe_package,
  3931. ALiquid: a_liquid,
  3932. }
  3933. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3934. if dialysisPrescription.ID == 0 { //新增
  3935. prescription.Creater = adminUserInfo.AdminUser.Id
  3936. } else { //修改
  3937. prescription.Creater = adminUserInfo.AdminUser.Id
  3938. //if/**/
  3939. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3940. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3941. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3942. // if getPermissionErr != nil {
  3943. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3944. // return
  3945. // } else if headNursePermission == nil {
  3946. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3947. // return
  3948. // }
  3949. //}
  3950. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  3951. if record.IsOpen == 1 {
  3952. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  3953. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  3954. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  3955. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  3956. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  3957. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  3958. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  3959. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  3960. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  3961. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  3962. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  3963. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  3964. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  3965. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  3966. if err == nil {
  3967. if order.ID > 0 {
  3968. if dialysisPrescription.Niprocart != niprocart {
  3969. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3970. //1.用上机透析日期查出当天的订单
  3971. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3972. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3973. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3974. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3975. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3976. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3977. warehouseOutInfo := &models.WarehouseOutInfo{
  3978. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3979. WarehouseOutId: out.ID,
  3980. Count: 1,
  3981. Status: 1,
  3982. Ctime: time.Now().Unix(),
  3983. Remark: "",
  3984. OrgId: adminUserInfo.Org.Id,
  3985. Type: 1,
  3986. Manufacturer: 0,
  3987. Dealer: 0,
  3988. IsSys: 1,
  3989. SysRecordTime: order.StartTime,
  3990. }
  3991. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  3992. warehouseOutInfo.Price = stockInInfo.Price
  3993. warehouseOutInfo.GoodId = niprocart
  3994. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  3995. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3996. if err == nil {
  3997. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3998. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  3999. if err == gorm.ErrRecordNotFound {
  4000. details := &models.AutomaticReduceDetail{
  4001. WarehouseOutId: warehouseOutInfo.ID,
  4002. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4003. PatientId: id,
  4004. Ctime: time.Now().Unix(),
  4005. Mtime: time.Now().Unix(),
  4006. Status: 1,
  4007. RecordTime: order.StartTime,
  4008. OrgId: adminUserInfo.Org.Id,
  4009. GoodId: niprocart,
  4010. GoodTypeId: niprocart_good_type_id,
  4011. }
  4012. service.AddSigleAutoReduceRecordInfo(details)
  4013. } else if err == nil {
  4014. if user.ID > 0 {
  4015. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  4016. }
  4017. }
  4018. }
  4019. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4020. if newOut.ID > 0 {
  4021. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4022. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4023. if err == gorm.ErrRecordNotFound {
  4024. details := &models.AutomaticReduceDetail{
  4025. WarehouseOutId: newOut.ID,
  4026. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4027. PatientId: id,
  4028. Ctime: time.Now().Unix(),
  4029. Mtime: time.Now().Unix(),
  4030. Status: 1,
  4031. RecordTime: order.StartTime,
  4032. OrgId: adminUserInfo.Org.Id,
  4033. GoodId: niprocart,
  4034. GoodTypeId: niprocart_good_type_id,
  4035. }
  4036. service.AddSigleAutoReduceRecordInfo(details)
  4037. } else if err == nil {
  4038. if user.ID > 0 {
  4039. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  4040. }
  4041. }
  4042. }
  4043. }
  4044. }
  4045. if dialysisPrescription.Jms != jms {
  4046. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4047. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4048. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4049. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4050. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  4051. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4052. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4053. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4054. warehouseOutInfo := &models.WarehouseOutInfo{
  4055. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4056. WarehouseOutId: out.ID,
  4057. Count: 1,
  4058. Status: 1,
  4059. Ctime: time.Now().Unix(),
  4060. Remark: "",
  4061. OrgId: adminUserInfo.Org.Id,
  4062. Type: 1,
  4063. Manufacturer: 0,
  4064. Dealer: 0,
  4065. IsSys: 1,
  4066. SysRecordTime: order.StartTime,
  4067. }
  4068. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  4069. warehouseOutInfo.Price = stockInInfo.Price
  4070. warehouseOutInfo.GoodId = jms
  4071. warehouseOutInfo.GoodTypeId = jms_good_type_id
  4072. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4073. if err == nil {
  4074. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4075. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4076. if err == gorm.ErrRecordNotFound {
  4077. details := &models.AutomaticReduceDetail{
  4078. WarehouseOutId: warehouseOutInfo.ID,
  4079. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4080. PatientId: id,
  4081. Ctime: time.Now().Unix(),
  4082. Mtime: time.Now().Unix(),
  4083. Status: 1,
  4084. RecordTime: order.StartTime,
  4085. OrgId: adminUserInfo.Org.Id,
  4086. GoodId: jms,
  4087. GoodTypeId: jms_good_type_id,
  4088. }
  4089. service.AddSigleAutoReduceRecordInfo(details)
  4090. } else if err == nil {
  4091. if user.ID > 0 {
  4092. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4093. }
  4094. }
  4095. }
  4096. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4097. if newOut.ID > 0 {
  4098. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4099. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4100. if err == gorm.ErrRecordNotFound {
  4101. details := &models.AutomaticReduceDetail{
  4102. WarehouseOutId: newOut.ID,
  4103. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4104. PatientId: id,
  4105. Ctime: time.Now().Unix(),
  4106. Mtime: time.Now().Unix(),
  4107. Status: 1,
  4108. RecordTime: order.StartTime,
  4109. OrgId: adminUserInfo.Org.Id,
  4110. GoodId: jms,
  4111. GoodTypeId: jms_good_type_id,
  4112. }
  4113. service.AddSigleAutoReduceRecordInfo(details)
  4114. } else if err == nil {
  4115. if user.ID > 0 {
  4116. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  4117. }
  4118. }
  4119. }
  4120. }
  4121. }
  4122. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  4123. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4124. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4125. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4126. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4127. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  4128. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4129. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4130. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4131. warehouseOutInfo := &models.WarehouseOutInfo{
  4132. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4133. WarehouseOutId: out.ID,
  4134. Count: 1,
  4135. Status: 1,
  4136. Ctime: time.Now().Unix(),
  4137. Remark: "",
  4138. OrgId: adminUserInfo.Org.Id,
  4139. Type: 1,
  4140. Manufacturer: 0,
  4141. Dealer: 0,
  4142. IsSys: 1,
  4143. SysRecordTime: order.StartTime,
  4144. }
  4145. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  4146. warehouseOutInfo.Price = stockInInfo.Price
  4147. warehouseOutInfo.GoodId = fistula_needle_set
  4148. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  4149. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4150. if err == nil {
  4151. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4152. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4153. if err == gorm.ErrRecordNotFound {
  4154. details := &models.AutomaticReduceDetail{
  4155. WarehouseOutId: warehouseOutInfo.ID,
  4156. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4157. PatientId: id,
  4158. Ctime: time.Now().Unix(),
  4159. Mtime: time.Now().Unix(),
  4160. Status: 1,
  4161. RecordTime: order.StartTime,
  4162. OrgId: adminUserInfo.Org.Id,
  4163. GoodId: fistula_needle_set,
  4164. GoodTypeId: fistula_needle_set_good_type_id,
  4165. }
  4166. service.AddSigleAutoReduceRecordInfo(details)
  4167. } else if err == nil {
  4168. if user.ID > 0 {
  4169. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4170. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4171. }
  4172. }
  4173. }
  4174. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4175. if newOut.ID > 0 {
  4176. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4177. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4178. if err == gorm.ErrRecordNotFound {
  4179. details := &models.AutomaticReduceDetail{
  4180. WarehouseOutId: newOut.ID,
  4181. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4182. PatientId: id,
  4183. Ctime: time.Now().Unix(),
  4184. Mtime: time.Now().Unix(),
  4185. Status: 1,
  4186. RecordTime: order.StartTime,
  4187. OrgId: adminUserInfo.Org.Id,
  4188. GoodId: fistula_needle_set,
  4189. GoodTypeId: fistula_needle_set_good_type_id,
  4190. }
  4191. service.AddSigleAutoReduceRecordInfo(details)
  4192. } else if err == nil {
  4193. if user.ID > 0 {
  4194. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4195. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  4196. }
  4197. }
  4198. }
  4199. }
  4200. }
  4201. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  4202. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4203. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4204. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4205. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4206. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4207. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4208. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4209. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4210. warehouseOutInfo := &models.WarehouseOutInfo{
  4211. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4212. WarehouseOutId: out.ID,
  4213. Count: 1,
  4214. Status: 1,
  4215. Ctime: time.Now().Unix(),
  4216. Remark: "",
  4217. OrgId: adminUserInfo.Org.Id,
  4218. Type: 1,
  4219. Manufacturer: 0,
  4220. Dealer: 0,
  4221. IsSys: 1,
  4222. SysRecordTime: order.StartTime,
  4223. }
  4224. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  4225. warehouseOutInfo.Price = stockInInfo.Price
  4226. warehouseOutInfo.GoodId = fistula_needle_set_16
  4227. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  4228. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4229. if err == nil {
  4230. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4231. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4232. if err == gorm.ErrRecordNotFound {
  4233. details := &models.AutomaticReduceDetail{
  4234. WarehouseOutId: warehouseOutInfo.ID,
  4235. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4236. PatientId: id,
  4237. Ctime: time.Now().Unix(),
  4238. Mtime: time.Now().Unix(),
  4239. Status: 1,
  4240. RecordTime: order.StartTime,
  4241. OrgId: adminUserInfo.Org.Id,
  4242. GoodId: fistula_needle_set_16,
  4243. GoodTypeId: fistula_needle_set_16_good_type_id,
  4244. }
  4245. service.AddSigleAutoReduceRecordInfo(details)
  4246. } else if err == nil {
  4247. if user.ID > 0 {
  4248. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4249. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4250. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  4251. }
  4252. }
  4253. }
  4254. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4255. if newOut.ID > 0 {
  4256. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4257. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4258. if err == gorm.ErrRecordNotFound {
  4259. details := &models.AutomaticReduceDetail{
  4260. WarehouseOutId: newOut.ID,
  4261. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4262. PatientId: id,
  4263. Ctime: time.Now().Unix(),
  4264. Mtime: time.Now().Unix(),
  4265. Status: 1,
  4266. RecordTime: order.StartTime,
  4267. OrgId: adminUserInfo.Org.Id,
  4268. GoodId: fistula_needle_set_good_type_id,
  4269. GoodTypeId: fistula_needle_set_16_good_type_id,
  4270. }
  4271. service.AddSigleAutoReduceRecordInfo(details)
  4272. } else if err == nil {
  4273. if user.ID > 0 {
  4274. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  4275. }
  4276. }
  4277. }
  4278. }
  4279. }
  4280. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  4281. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4282. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4283. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4284. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4285. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  4286. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4287. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4288. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4289. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4290. warehouseOutInfo := &models.WarehouseOutInfo{
  4291. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4292. WarehouseOutId: out.ID,
  4293. Count: 1,
  4294. Status: 1,
  4295. Ctime: time.Now().Unix(),
  4296. Remark: "",
  4297. OrgId: adminUserInfo.Org.Id,
  4298. Type: 1,
  4299. Manufacturer: 0,
  4300. Dealer: 0,
  4301. IsSys: 1,
  4302. SysRecordTime: order.StartTime,
  4303. }
  4304. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  4305. warehouseOutInfo.Price = stockInInfo.Price
  4306. warehouseOutInfo.GoodId = hemoperfusion
  4307. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  4308. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4309. if err == nil {
  4310. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4311. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4312. if err == gorm.ErrRecordNotFound {
  4313. details := &models.AutomaticReduceDetail{
  4314. WarehouseOutId: warehouseOutInfo.ID,
  4315. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4316. PatientId: id,
  4317. Ctime: time.Now().Unix(),
  4318. Mtime: time.Now().Unix(),
  4319. Status: 1,
  4320. RecordTime: order.StartTime,
  4321. OrgId: adminUserInfo.Org.Id,
  4322. GoodId: hemoperfusion,
  4323. GoodTypeId: hemoperfusion_good_type_id,
  4324. }
  4325. service.AddSigleAutoReduceRecordInfo(details)
  4326. } else if err == nil {
  4327. if user.ID > 0 {
  4328. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4329. }
  4330. }
  4331. }
  4332. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4333. if newOut.ID > 0 {
  4334. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4335. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4336. if err == gorm.ErrRecordNotFound {
  4337. details := &models.AutomaticReduceDetail{
  4338. WarehouseOutId: newOut.ID,
  4339. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4340. PatientId: id,
  4341. Ctime: time.Now().Unix(),
  4342. Mtime: time.Now().Unix(),
  4343. Status: 1,
  4344. RecordTime: order.StartTime,
  4345. OrgId: adminUserInfo.Org.Id,
  4346. GoodId: hemoperfusion,
  4347. GoodTypeId: hemoperfusion_good_type_id,
  4348. }
  4349. service.AddSigleAutoReduceRecordInfo(details)
  4350. } else if err == nil {
  4351. if user.ID > 0 {
  4352. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  4353. }
  4354. }
  4355. }
  4356. }
  4357. }
  4358. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  4359. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4360. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4361. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4362. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4363. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4364. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4365. warehouseOutInfo := &models.WarehouseOutInfo{
  4366. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4367. WarehouseOutId: out.WarehouseOutId,
  4368. Count: 1,
  4369. Status: 1,
  4370. Ctime: time.Now().Unix(),
  4371. Remark: "",
  4372. OrgId: adminUserInfo.Org.Id,
  4373. Type: 1,
  4374. Manufacturer: 0,
  4375. Dealer: 0,
  4376. IsSys: 1,
  4377. SysRecordTime: order.StartTime,
  4378. }
  4379. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  4380. warehouseOutInfo.Price = stockInInfo.Price
  4381. warehouseOutInfo.GoodId = dialyser_sterilised
  4382. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  4383. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4384. if err == nil {
  4385. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4386. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4387. if err == gorm.ErrRecordNotFound {
  4388. details := &models.AutomaticReduceDetail{
  4389. WarehouseOutId: warehouseOutInfo.ID,
  4390. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4391. PatientId: id,
  4392. Ctime: time.Now().Unix(),
  4393. Mtime: time.Now().Unix(),
  4394. Status: 1,
  4395. RecordTime: order.StartTime,
  4396. OrgId: adminUserInfo.Org.Id,
  4397. GoodId: dialyser_sterilised,
  4398. GoodTypeId: dialyser_sterilised_good_type_id,
  4399. }
  4400. service.AddSigleAutoReduceRecordInfo(details)
  4401. } else if err == nil {
  4402. if user.ID > 0 {
  4403. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4404. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  4405. }
  4406. }
  4407. }
  4408. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4409. if newOut.ID > 0 {
  4410. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4411. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4412. if err == gorm.ErrRecordNotFound {
  4413. details := &models.AutomaticReduceDetail{
  4414. WarehouseOutId: newOut.ID,
  4415. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4416. PatientId: id,
  4417. Ctime: time.Now().Unix(),
  4418. Mtime: time.Now().Unix(),
  4419. Status: 1,
  4420. RecordTime: order.StartTime,
  4421. OrgId: adminUserInfo.Org.Id,
  4422. GoodId: dialyser_sterilised,
  4423. GoodTypeId: dialyser_sterilised_good_type_id,
  4424. }
  4425. service.AddSigleAutoReduceRecordInfo(details)
  4426. } else if err == nil {
  4427. if user.ID > 0 {
  4428. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  4429. }
  4430. }
  4431. }
  4432. }
  4433. }
  4434. if dialysisPrescription.Filtryzer != filtryzer {
  4435. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4436. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4437. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4438. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4439. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  4440. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4441. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4442. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4443. warehouseOutInfo := &models.WarehouseOutInfo{
  4444. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4445. WarehouseOutId: out.ID,
  4446. Count: 1,
  4447. Status: 1,
  4448. Ctime: time.Now().Unix(),
  4449. Remark: "",
  4450. OrgId: adminUserInfo.Org.Id,
  4451. Type: 1,
  4452. Manufacturer: 0,
  4453. Dealer: 0,
  4454. IsSys: 1,
  4455. SysRecordTime: order.StartTime,
  4456. }
  4457. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  4458. warehouseOutInfo.Price = stockInInfo.Price
  4459. warehouseOutInfo.GoodId = filtryzer
  4460. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  4461. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4462. if err == nil {
  4463. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4464. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4465. if err == gorm.ErrRecordNotFound {
  4466. details := &models.AutomaticReduceDetail{
  4467. WarehouseOutId: warehouseOutInfo.ID,
  4468. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4469. PatientId: id,
  4470. Ctime: time.Now().Unix(),
  4471. Mtime: time.Now().Unix(),
  4472. Status: 1,
  4473. RecordTime: order.StartTime,
  4474. OrgId: adminUserInfo.Org.Id,
  4475. GoodId: filtryzer,
  4476. GoodTypeId: filtryzer_good_type_id,
  4477. }
  4478. service.AddSigleAutoReduceRecordInfo(details)
  4479. } else if err == nil {
  4480. if user.ID > 0 {
  4481. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  4482. }
  4483. }
  4484. }
  4485. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4486. if newOut.ID > 0 {
  4487. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4488. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4489. if err == gorm.ErrRecordNotFound {
  4490. details := &models.AutomaticReduceDetail{
  4491. WarehouseOutId: newOut.ID,
  4492. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4493. PatientId: id,
  4494. Ctime: time.Now().Unix(),
  4495. Mtime: time.Now().Unix(),
  4496. Status: 1,
  4497. RecordTime: order.StartTime,
  4498. OrgId: adminUserInfo.Org.Id,
  4499. GoodId: filtryzer,
  4500. GoodTypeId: filtryzer_good_type_id,
  4501. }
  4502. service.AddSigleAutoReduceRecordInfo(details)
  4503. } else if err == nil {
  4504. if user.ID > 0 {
  4505. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  4506. }
  4507. }
  4508. }
  4509. }
  4510. }
  4511. if dialysisPrescription.Dialyzers != dialyzers {
  4512. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4513. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4514. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4515. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4516. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4517. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4518. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4519. warehouseOutInfo := &models.WarehouseOutInfo{
  4520. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4521. WarehouseOutId: out.ID,
  4522. Count: 1,
  4523. Status: 1,
  4524. Ctime: time.Now().Unix(),
  4525. Remark: "",
  4526. OrgId: adminUserInfo.Org.Id,
  4527. Type: 1,
  4528. Manufacturer: 0,
  4529. Dealer: 0,
  4530. IsSys: 1,
  4531. SysRecordTime: order.StartTime,
  4532. }
  4533. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  4534. warehouseOutInfo.Price = stockInInfo.Price
  4535. warehouseOutInfo.GoodId = dialyzers
  4536. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  4537. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4538. if err == nil {
  4539. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4540. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4541. if err == gorm.ErrRecordNotFound {
  4542. details := &models.AutomaticReduceDetail{
  4543. WarehouseOutId: warehouseOutInfo.ID,
  4544. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4545. PatientId: id,
  4546. Ctime: time.Now().Unix(),
  4547. Mtime: time.Now().Unix(),
  4548. Status: 1,
  4549. RecordTime: order.StartTime,
  4550. OrgId: adminUserInfo.Org.Id,
  4551. GoodId: dialyzers,
  4552. GoodTypeId: dialyzers_good_type_id,
  4553. }
  4554. service.AddSigleAutoReduceRecordInfo(details)
  4555. } else if err == nil {
  4556. if user.ID > 0 {
  4557. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  4558. }
  4559. }
  4560. }
  4561. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4562. if newOut.ID > 0 {
  4563. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4564. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4565. if err == gorm.ErrRecordNotFound {
  4566. details := &models.AutomaticReduceDetail{
  4567. WarehouseOutId: newOut.ID,
  4568. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4569. PatientId: id,
  4570. Ctime: time.Now().Unix(),
  4571. Mtime: time.Now().Unix(),
  4572. Status: 1,
  4573. RecordTime: order.StartTime,
  4574. OrgId: adminUserInfo.Org.Id,
  4575. GoodId: dialyzers,
  4576. GoodTypeId: dialyzers_good_type_id,
  4577. }
  4578. service.AddSigleAutoReduceRecordInfo(details)
  4579. } else if err == nil {
  4580. if user.ID > 0 {
  4581. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  4582. }
  4583. }
  4584. }
  4585. }
  4586. }
  4587. if dialysisPrescription.Injector != injector {
  4588. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4589. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4590. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4591. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4592. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4593. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4594. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4595. warehouseOutInfo := &models.WarehouseOutInfo{
  4596. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4597. WarehouseOutId: out.ID,
  4598. Count: 1,
  4599. Status: 1,
  4600. Ctime: time.Now().Unix(),
  4601. Remark: "",
  4602. OrgId: adminUserInfo.Org.Id,
  4603. Type: 1,
  4604. Manufacturer: 0,
  4605. Dealer: 0,
  4606. IsSys: 1,
  4607. SysRecordTime: order.StartTime,
  4608. }
  4609. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  4610. warehouseOutInfo.Price = stockInInfo.Price
  4611. warehouseOutInfo.GoodId = injector
  4612. warehouseOutInfo.GoodTypeId = injector_good_type_id
  4613. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4614. if err == nil {
  4615. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4616. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4617. if err == gorm.ErrRecordNotFound {
  4618. details := &models.AutomaticReduceDetail{
  4619. WarehouseOutId: warehouseOutInfo.ID,
  4620. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4621. PatientId: id,
  4622. Ctime: time.Now().Unix(),
  4623. Mtime: time.Now().Unix(),
  4624. Status: 1,
  4625. RecordTime: order.StartTime,
  4626. OrgId: adminUserInfo.Org.Id,
  4627. GoodId: injector,
  4628. GoodTypeId: injector_good_type_id,
  4629. }
  4630. service.AddSigleAutoReduceRecordInfo(details)
  4631. } else if err == nil {
  4632. if user.ID > 0 {
  4633. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  4634. }
  4635. }
  4636. }
  4637. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4638. if newOut.ID > 0 {
  4639. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4640. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4641. if err == gorm.ErrRecordNotFound {
  4642. details := &models.AutomaticReduceDetail{
  4643. WarehouseOutId: newOut.ID,
  4644. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4645. PatientId: id,
  4646. Ctime: time.Now().Unix(),
  4647. Mtime: time.Now().Unix(),
  4648. Status: 1,
  4649. RecordTime: order.StartTime,
  4650. OrgId: adminUserInfo.Org.Id,
  4651. GoodId: injector,
  4652. GoodTypeId: injector_good_type_id,
  4653. }
  4654. service.AddSigleAutoReduceRecordInfo(details)
  4655. } else if err == nil {
  4656. if user.ID > 0 {
  4657. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  4658. }
  4659. }
  4660. }
  4661. }
  4662. }
  4663. if dialysisPrescription.Bloodlines != bloodlines {
  4664. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4665. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4666. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4667. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4668. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4669. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4670. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4671. warehouseOutInfo := &models.WarehouseOutInfo{
  4672. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4673. WarehouseOutId: out.ID,
  4674. Count: 1,
  4675. Status: 1,
  4676. Ctime: time.Now().Unix(),
  4677. Remark: "",
  4678. OrgId: adminUserInfo.Org.Id,
  4679. Type: 1,
  4680. Manufacturer: 0,
  4681. Dealer: 0,
  4682. IsSys: 1,
  4683. SysRecordTime: order.StartTime,
  4684. }
  4685. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  4686. warehouseOutInfo.Price = stockInInfo.Price
  4687. warehouseOutInfo.GoodId = bloodlines
  4688. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  4689. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4690. if err == nil {
  4691. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4692. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4693. if err == gorm.ErrRecordNotFound {
  4694. details := &models.AutomaticReduceDetail{
  4695. WarehouseOutId: warehouseOutInfo.ID,
  4696. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4697. PatientId: id,
  4698. Ctime: time.Now().Unix(),
  4699. Mtime: time.Now().Unix(),
  4700. Status: 1,
  4701. RecordTime: order.StartTime,
  4702. OrgId: adminUserInfo.Org.Id,
  4703. GoodId: bloodlines,
  4704. GoodTypeId: bloodlines_good_type_id,
  4705. }
  4706. service.AddSigleAutoReduceRecordInfo(details)
  4707. } else if err == nil {
  4708. if user.ID > 0 {
  4709. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  4710. }
  4711. }
  4712. }
  4713. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4714. if newOut.ID > 0 {
  4715. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4716. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4717. if err == gorm.ErrRecordNotFound {
  4718. details := &models.AutomaticReduceDetail{
  4719. WarehouseOutId: newOut.ID,
  4720. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4721. PatientId: id,
  4722. Ctime: time.Now().Unix(),
  4723. Mtime: time.Now().Unix(),
  4724. Status: 1,
  4725. RecordTime: order.StartTime,
  4726. OrgId: adminUserInfo.Org.Id,
  4727. GoodId: bloodlines,
  4728. GoodTypeId: bloodlines_good_type_id,
  4729. }
  4730. service.AddSigleAutoReduceRecordInfo(details)
  4731. } else if err == nil {
  4732. if user.ID > 0 {
  4733. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  4734. }
  4735. }
  4736. }
  4737. }
  4738. }
  4739. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  4740. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4741. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4742. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4743. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4744. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4745. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4746. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4747. warehouseOutInfo := &models.WarehouseOutInfo{
  4748. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4749. WarehouseOutId: out.ID,
  4750. Count: 1,
  4751. Status: 1,
  4752. Ctime: time.Now().Unix(),
  4753. Remark: "",
  4754. OrgId: adminUserInfo.Org.Id,
  4755. Type: 1,
  4756. Manufacturer: 0,
  4757. Dealer: 0,
  4758. IsSys: 1,
  4759. SysRecordTime: order.StartTime,
  4760. }
  4761. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  4762. warehouseOutInfo.Price = stockInInfo.Price
  4763. warehouseOutInfo.GoodId = tubing_hemodialysis
  4764. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  4765. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4766. if err == nil {
  4767. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4768. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4769. if err == gorm.ErrRecordNotFound {
  4770. details := &models.AutomaticReduceDetail{
  4771. WarehouseOutId: warehouseOutInfo.ID,
  4772. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4773. PatientId: id,
  4774. Ctime: time.Now().Unix(),
  4775. Mtime: time.Now().Unix(),
  4776. Status: 1,
  4777. RecordTime: order.StartTime,
  4778. OrgId: adminUserInfo.Org.Id,
  4779. GoodId: tubing_hemodialysis,
  4780. GoodTypeId: tubingHemodialysis_good_type_id,
  4781. }
  4782. service.AddSigleAutoReduceRecordInfo(details)
  4783. } else if err == nil {
  4784. if user.ID > 0 {
  4785. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  4786. }
  4787. }
  4788. }
  4789. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4790. if newOut.ID > 0 {
  4791. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4792. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4793. if err == gorm.ErrRecordNotFound {
  4794. details := &models.AutomaticReduceDetail{
  4795. WarehouseOutId: newOut.ID,
  4796. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4797. PatientId: id,
  4798. Ctime: time.Now().Unix(),
  4799. Mtime: time.Now().Unix(),
  4800. Status: 1,
  4801. RecordTime: order.StartTime,
  4802. OrgId: adminUserInfo.Org.Id,
  4803. GoodId: tubing_hemodialysis,
  4804. GoodTypeId: tubingHemodialysis_good_type_id,
  4805. }
  4806. service.AddSigleAutoReduceRecordInfo(details)
  4807. } else if err == nil {
  4808. if user.ID > 0 {
  4809. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  4810. }
  4811. }
  4812. }
  4813. }
  4814. }
  4815. if dialysisPrescription.Package != safe_package {
  4816. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4817. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4818. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4819. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4820. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4821. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4822. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4823. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4824. warehouseOutInfo := &models.WarehouseOutInfo{
  4825. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4826. WarehouseOutId: out.ID,
  4827. Count: 1,
  4828. Status: 1,
  4829. Ctime: time.Now().Unix(),
  4830. Remark: "",
  4831. OrgId: adminUserInfo.Org.Id,
  4832. Type: 1,
  4833. Manufacturer: 0,
  4834. Dealer: 0,
  4835. IsSys: 1,
  4836. SysRecordTime: order.StartTime,
  4837. }
  4838. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  4839. warehouseOutInfo.Price = stockInInfo.Price
  4840. warehouseOutInfo.GoodId = safe_package
  4841. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  4842. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4843. if err == nil {
  4844. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4845. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4846. if err == gorm.ErrRecordNotFound {
  4847. details := &models.AutomaticReduceDetail{
  4848. WarehouseOutId: warehouseOutInfo.ID,
  4849. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4850. PatientId: id,
  4851. Ctime: time.Now().Unix(),
  4852. Mtime: time.Now().Unix(),
  4853. Status: 1,
  4854. RecordTime: order.StartTime,
  4855. OrgId: adminUserInfo.Org.Id,
  4856. GoodId: safe_package,
  4857. GoodTypeId: safe_package_good_type_id,
  4858. }
  4859. service.AddSigleAutoReduceRecordInfo(details)
  4860. } else if err == nil {
  4861. if user.ID > 0 {
  4862. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  4863. }
  4864. }
  4865. }
  4866. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4867. if newOut.ID > 0 {
  4868. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4869. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4870. if err == gorm.ErrRecordNotFound {
  4871. details := &models.AutomaticReduceDetail{
  4872. WarehouseOutId: newOut.ID,
  4873. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4874. PatientId: id,
  4875. Ctime: time.Now().Unix(),
  4876. Mtime: time.Now().Unix(),
  4877. Status: 1,
  4878. RecordTime: order.StartTime,
  4879. OrgId: adminUserInfo.Org.Id,
  4880. GoodId: safe_package,
  4881. GoodTypeId: safe_package_good_type_id,
  4882. }
  4883. service.AddSigleAutoReduceRecordInfo(details)
  4884. } else if err == nil {
  4885. if user.ID > 0 {
  4886. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  4887. }
  4888. }
  4889. }
  4890. }
  4891. }
  4892. if dialysisPrescription.ALiquid != a_liquid {
  4893. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4894. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4895. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4896. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4897. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4898. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4899. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4900. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4901. warehouseOutInfo := &models.WarehouseOutInfo{
  4902. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4903. WarehouseOutId: out.ID,
  4904. Count: 1,
  4905. Status: 1,
  4906. Ctime: time.Now().Unix(),
  4907. Remark: "",
  4908. OrgId: adminUserInfo.Org.Id,
  4909. Type: 1,
  4910. Manufacturer: 0,
  4911. Dealer: 0,
  4912. IsSys: 1,
  4913. SysRecordTime: order.StartTime,
  4914. }
  4915. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  4916. warehouseOutInfo.Price = stockInInfo.Price
  4917. warehouseOutInfo.GoodId = a_liquid
  4918. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  4919. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4920. if err == nil {
  4921. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4922. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4923. if err == gorm.ErrRecordNotFound {
  4924. details := &models.AutomaticReduceDetail{
  4925. WarehouseOutId: warehouseOutInfo.ID,
  4926. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4927. PatientId: id,
  4928. Ctime: time.Now().Unix(),
  4929. Mtime: time.Now().Unix(),
  4930. Status: 1,
  4931. RecordTime: order.StartTime,
  4932. OrgId: adminUserInfo.Org.Id,
  4933. GoodId: a_liquid,
  4934. GoodTypeId: aliquid_good_type_id,
  4935. }
  4936. service.AddSigleAutoReduceRecordInfo(details)
  4937. } else if err == nil {
  4938. if user.ID > 0 {
  4939. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  4940. }
  4941. }
  4942. }
  4943. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4944. if newOut.ID > 0 {
  4945. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4946. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4947. if err == gorm.ErrRecordNotFound {
  4948. details := &models.AutomaticReduceDetail{
  4949. WarehouseOutId: newOut.ID,
  4950. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4951. PatientId: id,
  4952. Ctime: time.Now().Unix(),
  4953. Mtime: time.Now().Unix(),
  4954. Status: 1,
  4955. RecordTime: order.StartTime,
  4956. OrgId: adminUserInfo.Org.Id,
  4957. GoodId: a_liquid,
  4958. GoodTypeId: aliquid_good_type_id,
  4959. }
  4960. service.AddSigleAutoReduceRecordInfo(details)
  4961. } else if err == nil {
  4962. if user.ID > 0 {
  4963. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  4964. }
  4965. }
  4966. }
  4967. }
  4968. }
  4969. }
  4970. }
  4971. }
  4972. //prescription.Creater = dialysisPrescription.Creater
  4973. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4974. prescription.Modifier = adminUserInfo.AdminUser.Id
  4975. prescription.ID = dialysisPrescription.ID
  4976. }
  4977. solution := models.DialysisSolution{
  4978. RegistrarsId: adminUserInfo.AdminUser.Id,
  4979. UserOrgId: adminUserInfo.Org.Id,
  4980. Doctor: prescription_doctor,
  4981. PatientId: id,
  4982. ModeId: mode_id,
  4983. DialysisDuration: dialysis_duration,
  4984. PerfusionApparatus: perfusion_apparatus,
  4985. BloodFlowVolume: blood_flow_volume,
  4986. Dewater: dewater_amount,
  4987. DisplaceLiqui: displace_liqui,
  4988. ReplacementWay: replacement_way,
  4989. Anticoagulant: anticoagulant,
  4990. AnticoagulantShouji: anticoagulant_shouji,
  4991. AnticoagulantWeichi: anticoagulant_weichi,
  4992. AnticoagulantZongliang: anticoagulant_zongliang,
  4993. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4994. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4995. Kalium: kalium,
  4996. Sodium: sodium,
  4997. Calcium: calcium,
  4998. Bicarbonate: bicarbonate,
  4999. Glucose: glucose,
  5000. // DryWeight: dry_weight,
  5001. DialysateFlow: dialysate_flow,
  5002. DialysateTemperature: dialysate_temperature,
  5003. Conductivity: conductivity,
  5004. Remark: remark,
  5005. Status: 1,
  5006. CreatedTime: time.Now().Unix(),
  5007. UpdatedTime: time.Now().Unix(),
  5008. DialysisDurationMinute: dialysisDurationMinute,
  5009. DialysisDurationHour: dialysisDurationHour,
  5010. TargetUltrafiltration: targetUltrafiltration,
  5011. DialysateFormulation: dialysateFormulation,
  5012. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  5013. BodyFluid: body_fluid,
  5014. SpecialMedicine: special_medicine,
  5015. SpecialMedicineOther: special_medicine_other,
  5016. DisplaceLiquiPart: displace_liqui_part,
  5017. DisplaceLiquiValue: displace_liqui_value,
  5018. BloodAccess: blood_access,
  5019. Ultrafiltration: ultrafiltration,
  5020. BodyFluidOther: body_fluid_other,
  5021. ReplacementTotal: replacement_total,
  5022. TargetKtv: target_ktv,
  5023. }
  5024. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  5025. c.ServeSuccessJSON(map[string]interface{}{
  5026. "solution": &solution,
  5027. "prescription": &prescription,
  5028. })
  5029. }
  5030. func (c *DialysisAPIController) GetAcceptsAssessment() {
  5031. patient, _ := c.GetInt64("patient", 0)
  5032. adminUserInfo := c.GetMobileAdminUserInfo()
  5033. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  5034. c.ServeSuccessJSON(map[string]interface{}{
  5035. "receiveTreatmentAsses": receiveTreatmentAsses,
  5036. })
  5037. }
  5038. func (this *DialysisAPIController) PostSignInfo() {
  5039. patientID, _ := this.GetInt64("patient_id")
  5040. recordDateStr := this.GetString("date")
  5041. if patientID <= 0 {
  5042. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5043. return
  5044. }
  5045. if len(recordDateStr) == 0 {
  5046. recordDateStr = time.Now().Format("2006-01-02")
  5047. }
  5048. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5049. if parseDateErr != nil {
  5050. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  5051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5052. return
  5053. }
  5054. adminInfo := this.GetMobileAdminUserInfo()
  5055. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  5056. if err != nil {
  5057. this.ErrorLog("签名失败:%v", err)
  5058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5059. return
  5060. }
  5061. this.ServeSuccessJSON(map[string]interface{}{
  5062. "doctor_id": adminInfo.AdminUser.Id,
  5063. })
  5064. }
  5065. func (this *DialysisAPIController) GetLastMonitorRecord() {
  5066. patientID, _ := this.GetInt64("patient_id")
  5067. adminInfo := this.GetMobileAdminUserInfo()
  5068. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  5069. this.ServeSuccessJSON(map[string]interface{}{
  5070. "monitor": record,
  5071. })
  5072. }
  5073. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  5074. thisTime := time.Now()
  5075. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5076. timeLayout := "2006-01-02 15:04:05"
  5077. loc, _ := time.LoadLocation("Local")
  5078. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5079. theAssessmentDateTime := theStartTime.Unix()
  5080. patientID, _ := this.GetInt64("patient_id")
  5081. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5082. adminInfo := this.GetMobileAdminUserInfo()
  5083. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5084. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5085. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  5086. var ultrafiltration_rate float64
  5087. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  5088. if prescription.ID > 0 {
  5089. fmt.Println("444444444")
  5090. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5091. fmt.Println("4444444445555")
  5092. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5093. if template.TemplateId == 6 {
  5094. fmt.Println("12222222")
  5095. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5096. record.UltrafiltrationRate = ultrafiltration_rate
  5097. }
  5098. if template.TemplateId == 20 || template.TemplateId == 22 {
  5099. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5100. record.UltrafiltrationRate = ultrafiltration_rate
  5101. }
  5102. // 只针对方济医院
  5103. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  5104. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5105. ultrafiltration_rate = value
  5106. record.UltrafiltrationRate = ultrafiltration_rate
  5107. }
  5108. }
  5109. }
  5110. // record.UltrafiltrationRate = ultrafiltration_rate
  5111. record.UltrafiltrationVolume = 0
  5112. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  5113. if ultrafiltration_rate > 0 {
  5114. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5115. record.UltrafiltrationVolume = value
  5116. }
  5117. }
  5118. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  5119. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5120. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5121. record.UltrafiltrationVolume = ultrafiltration_volume
  5122. }
  5123. }
  5124. this.ServeSuccessJSON(map[string]interface{}{
  5125. "monitor": record,
  5126. })
  5127. }
  5128. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5129. record_id, _ := this.GetInt64("id")
  5130. nurseID, _ := this.GetInt64("nurse")
  5131. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5132. bedID, _ := this.GetInt64("bed")
  5133. start_time := this.GetString("start_time")
  5134. schedual_type, _ := this.GetInt64("schedual_type")
  5135. if record_id == 0 {
  5136. this.ErrorLog("id:%v", record_id)
  5137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5138. return
  5139. }
  5140. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5141. if parseStartDateErr != nil {
  5142. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5143. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5144. return
  5145. }
  5146. adminUserInfo := this.GetMobileAdminUserInfo()
  5147. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5148. if getNurseErr != nil {
  5149. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5151. return
  5152. } else if nurse == nil {
  5153. this.ErrorLog("护士不存在")
  5154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5155. return
  5156. }
  5157. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5158. if getNurseErr != nil {
  5159. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5161. return
  5162. } else if nurse == nil {
  5163. this.ErrorLog("护士不存在")
  5164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5165. return
  5166. }
  5167. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5168. if getDeviceNumberErr != nil {
  5169. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5171. return
  5172. } else if deviceNumber == nil {
  5173. this.ErrorLog("床位号不存在")
  5174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5175. return
  5176. }
  5177. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5178. //
  5179. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5180. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5181. // if getPermissionErr != nil {
  5182. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5183. // return
  5184. // } else if headNursePermission == nil {
  5185. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5186. // return
  5187. // }
  5188. //}
  5189. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5190. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5191. timeLayout := "2006-01-02 15:04:05"
  5192. loc, _ := time.LoadLocation("Local")
  5193. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5194. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5195. schedulestartTime := theStartTime.Unix()
  5196. scheduleendTime := theEndTime.Unix()
  5197. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5198. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5199. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5200. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5201. if err == gorm.ErrRecordNotFound { //空床位
  5202. // 修改了床位逻辑
  5203. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5204. if daySchedule.ID > 0 {
  5205. daySchedule.BedId = bedID
  5206. daySchedule.PartitionId = deviceNumber.ZoneID
  5207. daySchedule.ScheduleType = schedual_type
  5208. daySchedule.UpdatedTime = time.Now().Unix()
  5209. err := service.UpdateSchedule(&daySchedule)
  5210. if err != nil {
  5211. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5212. return
  5213. }
  5214. }
  5215. } else if err == nil {
  5216. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5217. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5218. if daySchedule.ID > 0 {
  5219. daySchedule.BedId = bedID
  5220. daySchedule.PartitionId = deviceNumber.ZoneID
  5221. daySchedule.ScheduleType = schedual_type
  5222. daySchedule.UpdatedTime = time.Now().Unix()
  5223. err := service.UpdateSchedule(&daySchedule)
  5224. if err != nil {
  5225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5226. return
  5227. }
  5228. }
  5229. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5231. return
  5232. }
  5233. } else if err != nil {
  5234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5235. return
  5236. }
  5237. }
  5238. dialysisRecord := &models.DialysisOrder{
  5239. ID: record_id,
  5240. UserOrgId: adminUserInfo.Org.Id,
  5241. BedID: bedID,
  5242. StartNurse: nurseID,
  5243. StartTime: startDate.Unix(),
  5244. PunctureNurse: puncture_nurse,
  5245. Creator: adminUserInfo.AdminUser.Id,
  5246. Modifier: adminUserInfo.AdminUser.Id,
  5247. SchedualType: schedual_type,
  5248. }
  5249. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5250. if updateErr != nil {
  5251. this.ErrorLog("修改上机失败:%v", updateErr)
  5252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5253. return
  5254. }
  5255. if updateErr == nil {
  5256. if tempDialysisRecord.Stage == 2 {
  5257. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5258. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5259. fmt.Println(value)
  5260. a, b := math.Modf(value)
  5261. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5262. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5263. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5264. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5265. if updateAssessmentErr != nil {
  5266. utils.ErrorLog("%v", updateAssessmentErr)
  5267. }
  5268. }
  5269. }
  5270. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5271. this.ServeSuccessJSON(map[string]interface{}{
  5272. "dialysis_order": dialysisRecords,
  5273. })
  5274. }
  5275. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5276. record_id, _ := c.GetInt64("id")
  5277. nurseID, _ := c.GetInt64("nurse")
  5278. end_time := c.GetString("end_time")
  5279. if record_id <= 0 || nurseID <= 0 {
  5280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5281. return
  5282. }
  5283. adminUserInfo := c.GetMobileAdminUserInfo()
  5284. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5285. if getNurseErr != nil {
  5286. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5288. return
  5289. } else if nurse == nil {
  5290. c.ErrorLog("护士不存在")
  5291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5292. return
  5293. }
  5294. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5295. if parseEndDateErr != nil {
  5296. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5298. return
  5299. }
  5300. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5301. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5302. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5303. // if getPermissionErr != nil {
  5304. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5305. // return
  5306. // } else if headNursePermission == nil {
  5307. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5308. // return
  5309. // }
  5310. //}
  5311. dialysisRecord := &models.DialysisOrder{
  5312. ID: record_id,
  5313. UserOrgId: adminUserInfo.Org.Id,
  5314. EndTime: endDate.Unix(),
  5315. FinishNurse: nurseID,
  5316. FinishModifier: adminUserInfo.AdminUser.Id,
  5317. }
  5318. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5319. if updateErr != nil {
  5320. c.ErrorLog("修改下机失败:%v", updateErr)
  5321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5322. return
  5323. }
  5324. if updateErr == nil {
  5325. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5326. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5327. a, b := math.Modf(value)
  5328. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5329. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5330. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5331. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5332. if updateAssessmentErr != nil {
  5333. utils.ErrorLog("%v", updateAssessmentErr)
  5334. }
  5335. }
  5336. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5337. c.ServeSuccessJSON(map[string]interface{}{
  5338. "dialysis_order": dialysisRecords,
  5339. })
  5340. }
  5341. func (c *DialysisAPIController) GetLongAdvice() {
  5342. patient_id, _ := c.GetInt64("id")
  5343. adminUserInfo := c.GetMobileAdminUserInfo()
  5344. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5345. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5346. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5347. c.ServeSuccessJSON(map[string]interface{}{
  5348. "status": "1",
  5349. })
  5350. return
  5351. } else { //开启推送提醒
  5352. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5353. var advice_three []*models.DoctorAdvice
  5354. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  5355. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  5356. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  5357. for _, advice := range advices {
  5358. if advice.FrequencyType == 3 {
  5359. t := time.Now()
  5360. week := int(t.Weekday())
  5361. switch week {
  5362. case 1:
  5363. if strings.Index(advice.WeekDay, "周一") == -1 {
  5364. advice_three = append(advice_three, advice)
  5365. }
  5366. break
  5367. case 2:
  5368. if strings.Index(advice.WeekDay, "周二") == -1 {
  5369. advice_three = append(advice_three, advice)
  5370. }
  5371. break
  5372. case 3:
  5373. if strings.Index(advice.WeekDay, "周三") == -1 {
  5374. advice_three = append(advice_three, advice)
  5375. }
  5376. break
  5377. case 4:
  5378. if strings.Index(advice.WeekDay, "周四") == -1 {
  5379. advice_three = append(advice_three, advice)
  5380. }
  5381. break
  5382. case 5:
  5383. if strings.Index(advice.WeekDay, "周五") == -1 {
  5384. advice_three = append(advice_three, advice)
  5385. }
  5386. break
  5387. case 6:
  5388. if strings.Index(advice.WeekDay, "周六") == -1 {
  5389. advice_three = append(advice_three, advice)
  5390. }
  5391. break
  5392. case 0:
  5393. if strings.Index(advice.WeekDay, "周日") == -1 {
  5394. advice_three = append(advice_three, advice)
  5395. }
  5396. break
  5397. }
  5398. }
  5399. }
  5400. for _, advice := range advices_two {
  5401. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5402. now := p.Unix()
  5403. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5404. dayStr2 := "-" + dayStr
  5405. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5406. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5407. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5408. for _, ad := range advices {
  5409. advice_three = append(advice_three, ad)
  5410. }
  5411. }
  5412. if err == nil {
  5413. c.ServeSuccessJSON(map[string]interface{}{
  5414. "status": "2",
  5415. "advices": advices,
  5416. "advices_two": RemoveRepeatedElement(advice_three),
  5417. "is_open_remind": config.IsOpenRemind,
  5418. })
  5419. }
  5420. }
  5421. }
  5422. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5423. newArr = make([]*models.DoctorAdvice, 0)
  5424. for i := 0; i < len(arr); i++ {
  5425. repeat := false
  5426. for j := i + 1; j < len(arr); j++ {
  5427. if arr[i].ID == arr[j].ID {
  5428. repeat = true
  5429. break
  5430. }
  5431. }
  5432. if !repeat {
  5433. newArr = append(newArr, arr[i])
  5434. }
  5435. }
  5436. return
  5437. }
  5438. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5439. patient, _ := c.GetInt64("id", 0)
  5440. groupNo, _ := c.GetInt64("groupno", 0)
  5441. if patient <= 0 {
  5442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5443. return
  5444. }
  5445. adminUserInfo := c.GetMobileAdminUserInfo()
  5446. dataBody := make(map[string]interface{}, 0)
  5447. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5448. if err != nil {
  5449. utils.ErrorLog(err.Error())
  5450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5451. return
  5452. }
  5453. utils.ErrorLog("%v", dataBody)
  5454. timeLayout := "2006-01-02 15:04"
  5455. loc, _ := time.LoadLocation("Local")
  5456. timeLayout2 := "2006-01-02"
  5457. loc2, _ := time.LoadLocation("Local")
  5458. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5459. utils.ErrorLog("advice_type")
  5460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5461. return
  5462. }
  5463. adviceType := int64(2)
  5464. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5465. utils.ErrorLog("advice_date")
  5466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5467. return
  5468. }
  5469. adviceDate, _ := dataBody["advice_date"].(string)
  5470. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5471. AdviceDate := theTime.Unix()
  5472. RecordDate := theTime.Unix()
  5473. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5474. utils.ErrorLog("start_time")
  5475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5476. return
  5477. }
  5478. startTime, _ := dataBody["start_time"].(string)
  5479. if len(startTime) == 0 {
  5480. utils.ErrorLog("len(start_time) == 0")
  5481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5482. return
  5483. }
  5484. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5485. if err != nil {
  5486. utils.ErrorLog(err.Error())
  5487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5488. return
  5489. }
  5490. StartTime := theTime.Unix()
  5491. Remark := ""
  5492. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5493. remark, _ := dataBody["remark"].(string)
  5494. Remark = remark
  5495. }
  5496. var advices []*models.GroupAdvice
  5497. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5498. utils.ErrorLog("advices")
  5499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5500. return
  5501. }
  5502. adviceNames := dataBody["advices"].([]interface{})
  5503. for _, adviceNameMap := range adviceNames {
  5504. adviceNameM := adviceNameMap.(map[string]interface{})
  5505. var advice models.GroupAdvice
  5506. advice.Remark = Remark
  5507. advice.AdviceType = adviceType
  5508. advice.StartTime = StartTime
  5509. advice.AdviceDate = AdviceDate
  5510. advice.RecordDate = RecordDate
  5511. advice.Status = 1
  5512. advice.CreatedTime = time.Now().Unix()
  5513. advice.UpdatedTime = time.Now().Unix()
  5514. advice.StopState = 2
  5515. advice.ExecutionState = 2
  5516. advice.UserOrgId = adminUserInfo.Org.Id
  5517. advice.PatientId = patient
  5518. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5519. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5520. utils.ErrorLog("advice_name")
  5521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5522. return
  5523. }
  5524. adviceName, _ := adviceNameM["advice_name"].(string)
  5525. if len(adviceName) == 0 {
  5526. utils.ErrorLog("len(advice_name) == 0")
  5527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5528. return
  5529. }
  5530. advice.AdviceName = adviceName
  5531. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5532. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5533. advice.DrugSpec = drugSpec
  5534. }
  5535. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5536. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5537. advice.AdviceDesc = adviceDesc
  5538. }
  5539. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5540. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5541. advice.DrugSpecUnit = drugSpecUnit
  5542. }
  5543. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5544. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5545. // advice.SingleDose = singleDose
  5546. //}
  5547. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5548. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5549. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5550. }
  5551. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5552. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5553. advice.SingleDoseUnit = singleDoseUnit
  5554. }
  5555. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5556. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5557. // advice.PrescribingNumber = prescribingNumber
  5558. //}
  5559. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5560. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5561. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5562. }
  5563. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5564. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5565. advice.PrescribingNumberUnit = prescribingNumberUnit
  5566. }
  5567. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5568. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5569. advice.DeliveryWay = deliveryWay
  5570. }
  5571. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5572. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5573. advice.ExecutionFrequency = executionFrequency
  5574. }
  5575. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5576. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5577. advice.FrequencyType = frequency_type
  5578. }
  5579. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5580. day_count := int64(adviceNameM["day_count"].(float64))
  5581. advice.DayCount = day_count
  5582. }
  5583. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5584. week_day, _ := adviceNameM["week_day"].(string)
  5585. advice.WeekDay = week_day
  5586. }
  5587. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5588. template_id, _ := adviceNameM["template_id"].(string)
  5589. advice.TemplateId = template_id
  5590. }
  5591. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5592. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5593. advice.ExecutionFrequency = executionFrequency
  5594. }
  5595. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5596. children := adviceNameM["child"].([]interface{})
  5597. if len(children) > 0 {
  5598. for _, childrenMap := range children {
  5599. childMap := childrenMap.(map[string]interface{})
  5600. var child models.GroupAdvice
  5601. child.Remark = Remark
  5602. child.AdviceType = adviceType
  5603. child.StartTime = StartTime
  5604. child.AdviceDate = AdviceDate
  5605. child.RecordDate = RecordDate
  5606. child.Status = 1
  5607. child.CreatedTime = time.Now().Unix()
  5608. child.UpdatedTime = time.Now().Unix()
  5609. child.StopState = 2
  5610. child.ExecutionState = 2
  5611. child.UserOrgId = adminUserInfo.Org.Id
  5612. child.PatientId = patient
  5613. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5614. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5615. utils.ErrorLog("child advice_name")
  5616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5617. return
  5618. }
  5619. childAdviceName, _ := childMap["advice_name"].(string)
  5620. if len(childAdviceName) == 0 {
  5621. utils.ErrorLog("len(child advice_name) == 0")
  5622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5623. return
  5624. }
  5625. child.AdviceName = childAdviceName
  5626. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5627. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5628. child.AdviceDesc = childAdviceDesc
  5629. }
  5630. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5631. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5632. child.DrugSpec = childDrugSpec
  5633. }
  5634. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5635. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5636. child.DrugSpecUnit = childDrugSpecUnit
  5637. }
  5638. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5639. child.SingleDose = childMap["single_dose"].(float64)
  5640. }
  5641. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5642. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5643. child.SingleDoseUnit = childSingleDoseUnit
  5644. }
  5645. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5646. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5647. }
  5648. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5649. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5650. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5651. }
  5652. child.DeliveryWay = advice.DeliveryWay
  5653. child.ExecutionFrequency = advice.ExecutionFrequency
  5654. advice.Children = append(advice.Children, &child)
  5655. }
  5656. }
  5657. }
  5658. advices = append(advices, &advice)
  5659. }
  5660. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5661. if err != nil {
  5662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5663. return
  5664. }
  5665. c.ServeSuccessJSON(map[string]interface{}{
  5666. "msg": "ok",
  5667. "advices": list,
  5668. })
  5669. return
  5670. }
  5671. func (c *DialysisAPIController) UploadDryWeight() {
  5672. patient_id, _ := c.GetInt64("id")
  5673. dry_weight, _ := c.GetFloat("dry_weight")
  5674. doctor_id, _ := c.GetInt64("doctor_id")
  5675. remark := c.GetString("remark")
  5676. adminUserInfo := c.GetMobileAdminUserInfo()
  5677. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5678. if err == gorm.ErrRecordNotFound {
  5679. dryWeight := &models.SgjPatientDryweight{
  5680. PatientId: patient_id,
  5681. DryWeight: dry_weight,
  5682. Remakes: remark,
  5683. Ctime: time.Now().Unix(),
  5684. Mtime: time.Now().Unix(),
  5685. Creator: doctor_id,
  5686. Status: 1,
  5687. UserOrgId: adminUserInfo.Org.Id,
  5688. AdjustedValue: "/",
  5689. UserId: adminUserInfo.AdminUser.Id,
  5690. }
  5691. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5692. if createErr == nil {
  5693. c.ServeSuccessJSON(map[string]interface{}{
  5694. "msg": "提交成功",
  5695. "weight": dryWeight,
  5696. })
  5697. }
  5698. } else {
  5699. dryWeight := &models.SgjPatientDryweight{
  5700. PatientId: patient_id,
  5701. DryWeight: dry_weight,
  5702. Remakes: remark,
  5703. Ctime: time.Now().Unix(),
  5704. Mtime: time.Now().Unix(),
  5705. Creator: doctor_id,
  5706. Status: 1,
  5707. UserOrgId: adminUserInfo.Org.Id,
  5708. AdjustedValue: "/",
  5709. UserId: adminUserInfo.AdminUser.Id,
  5710. }
  5711. var value float64
  5712. value = dry_weight - weightAdjust.DryWeight
  5713. if value < 0 {
  5714. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5715. } else if value == 0 {
  5716. dryWeight.AdjustedValue = "/"
  5717. } else if value > 0 {
  5718. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5719. }
  5720. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5721. if createErr == nil {
  5722. c.ServeSuccessJSON(map[string]interface{}{
  5723. "msg": "提交成功",
  5724. "weight": dryWeight,
  5725. })
  5726. }
  5727. }
  5728. }
  5729. func (c *DialysisAPIController) GetSolution() {
  5730. patient_id, _ := c.GetInt64("patient_id")
  5731. mode_id, _ := c.GetInt64("mode_id")
  5732. adminUserInfo := c.GetMobileAdminUserInfo()
  5733. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5734. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5735. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  5736. if err != nil {
  5737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5738. return
  5739. }
  5740. c.ServeSuccessJSON(map[string]interface{}{
  5741. "solution": solution,
  5742. "prescription": prescription,
  5743. "system_prescription": system_prescription,
  5744. })
  5745. }
  5746. func (c *DialysisAPIController) GetSchedule() {
  5747. schedual_type, _ := c.GetInt64("schedual_type")
  5748. adminUserInfo := c.GetMobileAdminUserInfo()
  5749. timeLayout := "2006-01-02 15:04:05"
  5750. date := time.Now().Format("2006-01-02") + " 00:00:00"
  5751. loc, _ := time.LoadLocation("Local")
  5752. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5753. scheduleTime := theStartTime.Unix()
  5754. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5755. c.ServeSuccessJSON(map[string]interface{}{
  5756. "number": deviceNumber,
  5757. })
  5758. }
  5759. func (c *DialysisAPIController) GetPatientId() {
  5760. id, _ := c.GetInt64("id")
  5761. patientId, _ := service.GetPatientId(id)
  5762. c.ServeSuccessJSON(map[string]interface{}{
  5763. "patient": patientId,
  5764. })
  5765. }
  5766. func (this *DialysisAPIController) GetDialysisSchedule() {
  5767. schedualDate := this.GetString("date")
  5768. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5769. if parseDateErr != nil {
  5770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5771. return
  5772. }
  5773. adminInfo := this.GetMobileAdminUserInfo()
  5774. orgID := adminInfo.Org.Id
  5775. redis := service.RedisClient()
  5776. defer redis.Close()
  5777. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5778. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5779. if len(scheduals) > 0 {
  5780. //缓存数据
  5781. scheduals_json, err := json.Marshal(scheduals)
  5782. if err == nil {
  5783. redis.Set(key, scheduals_json, time.Second*30)
  5784. }
  5785. }
  5786. this.ServeSuccessJSON(map[string]interface{}{
  5787. "scheduals": scheduals,
  5788. })
  5789. }