dialysis_api_controller.go 269KB

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