dialysis_api_controller.go 269KB

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