patient_api_controller.go 221KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/jinzhu/gorm"
  9. //"github.com/jinzhu/gorm"
  10. "math"
  11. "math/rand"
  12. "reflect"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "fmt"
  18. "github.com/astaxie/beego"
  19. )
  20. type PatientApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func PatientApiRegistRouters() {
  24. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  25. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  26. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  27. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  28. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  29. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  30. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  31. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  33. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  34. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  35. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  36. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  37. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  38. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  39. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  40. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  41. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  42. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  43. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  44. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  45. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  46. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  47. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  48. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  49. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  50. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  51. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  52. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  53. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  54. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  55. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  56. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  57. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  58. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  59. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  60. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  61. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  62. beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
  63. //长期医嘱新接口
  64. beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
  65. beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
  66. beego.Router("/api/patient/getexportlist", &PatientApiController{}, "Get:GetExportList")
  67. beego.Router("/api/patient/savefalloutbedprint", &PatientApiController{}, "Post:SaveFallOutBedPrint")
  68. beego.Router("/api/patient/getfalloutbedprintlist", &PatientApiController{}, "Get:GetFallOutBedPrintList")
  69. beego.Router("/api/patient/savefilterinformed", &PatientApiController{}, "Post:SaveFilterInformed")
  70. beego.Router("/api/patient/getfilterinformed", &PatientApiController{}, "Get:GetFilterInformed")
  71. beego.Router("/api/patient/saveprofundainformed", &PatientApiController{}, "Post:SaveProfundaInformed")
  72. beego.Router("/api/patient/getprofundainformed", &PatientApiController{}, "Get:GetProfundaInformed")
  73. beego.Router("/api/patient/arterovenous", &PatientApiController{}, "Post:SaveArterOvenous")
  74. beego.Router("/api/patient/getarterovernous", &PatientApiController{}, "Get:GetArterOverNous")
  75. beego.Router("/api/patient/savehighrikinformed", &PatientApiController{}, "Post:SaveHighRikInformed")
  76. beego.Router("/api/patient/gethighriskinformed", &PatientApiController{}, "Get:GetHighRiskInformed")
  77. beego.Router("/api/patient/saveanticoagulation", &PatientApiController{}, "Post:SaveAnticoagulation")
  78. beego.Router("/api/patient/getanticoagulationInformed", &PatientApiController{}, "Get:GetAnticoagulationInformed")
  79. beego.Router("/api/patient/savecriticalinfomed", &PatientApiController{}, "Post:SaveCriticalInfomed")
  80. beego.Router("/api/patient/getcriticalinformed", &PatientApiController{}, "Get:GetCriticalInformed")
  81. beego.Router("/api/patient/savehemoperfusioninformed", &PatientApiController{}, "Post:SaveHemoperfusionInformed")
  82. beego.Router("/api/patient/gethemoperfusioninformed", &PatientApiController{}, "Get:GetHemoperfusionInformed")
  83. beego.Router("/api/patient/savebringinformed", &PatientApiController{}, "Post:SaveBringInformed")
  84. beego.Router("/api/patient/getinformedcontsent", &PatientApiController{}, "Get:GetInformedContsent")
  85. beego.Router("/api/patient/savecatheterization", &PatientApiController{}, "Post:SaveCatheterization")
  86. beego.Router("/api/patient/getcatheterization", &PatientApiController{}, "Get:GetCatheterization")
  87. beego.Router("/api/patient/savedialyzerInformed", &PatientApiController{}, "Post:SaveDialyzerInformed")
  88. beego.Router("/api/patient/getdialyzerinformed", &PatientApiController{}, "Get:GetDialyzerInformed")
  89. beego.Router("/api/patient/savetheapyinformed", &PatientApiController{}, "Post:SaveTheapyInformed")
  90. beego.Router("api/patient/gettherapyinformed", &PatientApiController{}, "Get:GetTherapyInformed")
  91. }
  92. func (c *PatientApiController) GetExportList() {
  93. startTime := c.GetString("start_time")
  94. endTime := c.GetString("end_time")
  95. schedulType, _ := c.GetInt64("schedul_type", 0)
  96. timeLayout := "2006-01-02"
  97. loc, _ := time.LoadLocation("Local")
  98. adminUserInfo := c.GetAdminUserInfo()
  99. var theStartTIme int64
  100. if len(startTime) > 0 {
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. theStartTIme = theTime.Unix()
  107. }
  108. var theEndtTIme int64
  109. if len(endTime) > 0 {
  110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  111. if err != nil {
  112. utils.ErrorLog(err.Error())
  113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  114. return
  115. }
  116. theEndtTIme = theTime.Unix()
  117. }
  118. timeNowStr := time.Now().Format("2006-01-02")
  119. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  120. schedule, _ := service.GetPatientScheudleListTwenty(adminUserInfo.CurrentOrgId, schedulType, theStartTIme, theEndtTIme, timeNewDate.Unix())
  121. fmt.Println("schedule23333333333333333", schedule)
  122. patientsList, _ := service.GetAllpatient(adminUserInfo.CurrentOrgId)
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "schedule": schedule,
  125. "patientsList": patientsList,
  126. })
  127. return
  128. }
  129. // GetPatientsList 取患者列表
  130. func (c *PatientApiController) GetPatientsList() {
  131. var err error
  132. defer func() {
  133. if rec := recover(); rec != nil {
  134. err = fmt.Errorf("程序异常:%v", rec)
  135. }
  136. if err != nil {
  137. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  138. }
  139. }()
  140. page, _ := c.GetInt64("page", 1)
  141. limit, _ := c.GetInt64("limit", 10)
  142. schedulType, _ := c.GetInt64("schedul_type", 0)
  143. bindingState, _ := c.GetInt64("binding_state", 0)
  144. lapseto, _ := c.GetInt64("lapseto", 0)
  145. source, _ := c.GetInt64("source", 0)
  146. startTime := c.GetString("start_time", "")
  147. endTime := c.GetString("end_time", "")
  148. keywords := c.GetString("keywords", "")
  149. contagion, _ := c.GetInt64("contagion", 0)
  150. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  151. isscheduling, _ := c.GetInt64("isscheduling", 0)
  152. isprescription, _ := c.GetInt64("isprescription", 0)
  153. patientSoureType, _ := c.GetInt64("patientSoureType")
  154. nurse, _ := c.GetInt64("nurse")
  155. if page <= 0 {
  156. page = 1
  157. }
  158. if limit <= 0 {
  159. limit = 10
  160. }
  161. adminUserInfo := c.GetAdminUserInfo()
  162. timeLayout := "2006-01-02"
  163. loc, _ := time.LoadLocation("Local")
  164. var isStartTime bool
  165. var theStartTIme int64
  166. if len(startTime) > 0 {
  167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  168. if err != nil {
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  170. return
  171. }
  172. isStartTime = true
  173. theStartTIme = theTime.Unix()
  174. }
  175. var isEndTime bool
  176. var theEndtTIme int64
  177. if len(endTime) > 0 {
  178. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  179. if err != nil {
  180. utils.ErrorLog(err.Error())
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  182. return
  183. }
  184. isEndTime = true
  185. theEndtTIme = theTime.Unix()
  186. }
  187. var patients []*models.Patients
  188. var total int64
  189. patients, total, err = service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime, patientSoureType, nurse)
  190. c.ServeSuccessJSON(map[string]interface{}{
  191. "patients": patients,
  192. "total": total,
  193. })
  194. return
  195. }
  196. // GetPatientTotal
  197. func (c *PatientApiController) GetPatientTotal() {
  198. adminUserInfo := c.GetAdminUserInfo()
  199. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  200. c.ServeSuccessJSON(map[string]interface{}{
  201. "total": total,
  202. })
  203. return
  204. }
  205. func (c *PatientApiController) GetPatientsAllList() {
  206. adminUserInfo := c.GetAdminUserInfo()
  207. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  208. c.ServeSuccessJSON(map[string]interface{}{
  209. "patients": patients,
  210. "total": total,
  211. })
  212. return
  213. }
  214. // GenerateDialysisNo 生成透析号
  215. func (c *PatientApiController) GenerateDialysisNo() {
  216. adminUserInfo := c.GetAdminUserInfo()
  217. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  218. if dialysisNo == 0 {
  219. dialysisNo = 1
  220. } else {
  221. dialysisNo++
  222. }
  223. no := strconv.FormatInt(dialysisNo, 10)
  224. rep := 3 - len(no)
  225. if rep > 0 {
  226. no = strings.Repeat("0", rep) + no
  227. }
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "no": no,
  230. })
  231. return
  232. }
  233. // CreatePatient 创建患者
  234. func (c *PatientApiController) CreatePatient() {
  235. record_date := c.GetString("record_date")
  236. is_infectious, _ := c.GetInt64("is_infectious")
  237. remind_cycle, _ := c.GetInt64("remind_cycle")
  238. adminUserInfo := c.GetAdminUserInfo()
  239. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  240. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  241. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  243. // return
  244. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  245. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  246. // return
  247. //}
  248. var patient models.Patients
  249. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  250. fmt.Println(code)
  251. fmt.Println(patient)
  252. if code > 0 {
  253. c.ServeFailJSONWithSGJErrorCode(code)
  254. return
  255. }
  256. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  257. if thisPatient.ID > 0 {
  258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  259. return
  260. }
  261. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  262. if thisPatient.ID > 0 {
  263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  264. return
  265. }
  266. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  267. if thisPatient.ID > 0 {
  268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  269. return
  270. }
  271. patient.RemindCycle = remind_cycle
  272. patient.IsInfectious = is_infectious
  273. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  274. patient.Status = 1
  275. patient.CreatedTime = time.Now().Unix()
  276. patient.UserOrgId = adminUserInfo.CurrentOrgId
  277. patient.UpdatedTime = time.Now().Unix()
  278. patient.BindingState = 2
  279. // patient.Lapseto = 1
  280. err := service.CreatePatient(&patient, contagions, diseases)
  281. fmt.Println("创建病人失败err")
  282. if err != nil {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  284. return
  285. }
  286. //获取老表的最后一条数据
  287. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  288. patientsNew := models.XtPatientsNew{
  289. UserOrgId: adminUserInfo.CurrentOrgId,
  290. UserId: 0,
  291. Avatar: patients.Avatar,
  292. PatientType: patients.PatientType,
  293. DialysisNo: patients.DialysisNo,
  294. AdmissionNumber: patients.AdmissionNumber,
  295. Source: patients.Source,
  296. Lapseto: patients.Lapseto,
  297. PartitionId: patients.PartitionId,
  298. BedId: patients.BedId,
  299. Name: patients.Name,
  300. Alias: patients.Alias,
  301. Gender: patients.Gender,
  302. MaritalStatus: patients.MaritalStatus,
  303. IdCardNo: patients.IdCardNo,
  304. Birthday: patients.Birthday,
  305. ReimbursementWayId: patients.ReimbursementWayId,
  306. HealthCareType: patients.HealthCareType,
  307. HealthCareNo: patients.HealthCareNo,
  308. HealthCareDueDate: patients.HealthCareDueDate,
  309. Height: patients.Height,
  310. BloodType: patients.BloodType,
  311. Rh: patients.Rh,
  312. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  313. EducationLevel: patients.EducationLevel,
  314. Profession: patients.Profession,
  315. Phone: patients.Phone,
  316. HomeTelephone: patients.HomeTelephone,
  317. RelativePhone: patients.RelativePhone,
  318. RelativeRelations: patients.RelativeRelations,
  319. HomeAddress: patients.HomeAddress,
  320. WorkUnit: patients.WorkUnit,
  321. UnitAddress: patients.UnitAddress,
  322. Children: patients.Children,
  323. ReceivingDate: patients.ReceivingDate,
  324. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  325. FirstDialysisDate: patients.FirstDialysisDate,
  326. FirstDialysisHospital: patients.FirstDialysisHospital,
  327. PredialysisCondition: patients.PredialysisCondition,
  328. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  329. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  330. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  331. InductionPeriod: patients.InductionPeriod,
  332. InitialDialysis: patients.InitialDialysis,
  333. TotalDialysis: patients.TotalDialysis,
  334. AttendingDoctorId: patients.AttendingDoctorId,
  335. HeadNurseId: patients.HeadNurseId,
  336. Evaluate: patients.Evaluate,
  337. Diagnose: patients.Diagnose,
  338. Remark: patients.Remark,
  339. RegistrarsId: patients.RegistrarsId,
  340. Registrars: patients.Registrars,
  341. QrCode: patients.QrCode,
  342. BindingState: patients.BindingState,
  343. PatientComplains: patients.PatientComplains,
  344. PresentHistory: patients.PresentHistory,
  345. PastHistory: patients.PresentHistory,
  346. Temperature: patients.Temperature,
  347. Pulse: patients.Pulse,
  348. Respiratory: patients.Respiratory,
  349. Sbp: patients.SBP,
  350. Dbp: patients.DBP,
  351. Status: patients.Status,
  352. CreatedTime: patients.CreatedTime,
  353. UpdatedTime: patients.UpdatedTime,
  354. Nation: patients.Nation,
  355. NativePlace: patients.NativePlace,
  356. Age: patients.Age,
  357. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  358. IsInfectious: patients.IsInfectious,
  359. RemindCycle: patients.RemindCycle,
  360. ResponseResult: patients.ResponseResult,
  361. IsOpenRemind: patients.IsOpenRemind,
  362. FirstTreatmentDate: patients.FirstTreatmentDate,
  363. DialysisAge: patients.DialysisAge,
  364. ExpenseKind: patients.ExpenseKind,
  365. TellPhone: patients.TellPhone,
  366. ContactName: patients.ContactName,
  367. BloodPatients: 1,
  368. SlowPatients: 0,
  369. MemberPatients: 0,
  370. EcommerPatients: "",
  371. BloodId: patients.ID,
  372. SlowId: 0,
  373. MemberId: 0,
  374. MemberFistdate: 0,
  375. MemberPatienttype: 0,
  376. MemberTreatement: 0,
  377. EquitmentId: "",
  378. UserSysBeforeCount: patient.UserSysBeforeCount,
  379. TrobleShoot: patient.TrobleShoot,
  380. TreatmentPlan: patient.TreatmentPlan,
  381. Doctor: patient.Doctor,
  382. RecordNumber: patient.RecordNumber,
  383. PatientSource: patient.PatientSource,
  384. PatientEndTime: patient.PatientEndTime,
  385. PatientStartTime: patient.PatientStartTime,
  386. InfectiousRemark: patient.InfectiousRemark,
  387. AllergicHistory: patient.AllergicHistory,
  388. PatientAddress: patient.PatientAddress,
  389. }
  390. err = service.CreatePatientsNew(&patientsNew)
  391. fmt.Print("创建失败", err)
  392. allergic := models.XtPatientAllergic{
  393. UserOrgId: adminUserInfo.CurrentOrgId,
  394. PatientId: patient.ID,
  395. StartTime: patient.PatientStartTime,
  396. EndTime: patient.PatientEndTime,
  397. PatientSource: patient.PatientSource,
  398. PatientAddress: patient.PatientAddress,
  399. Remake: patient.Remark,
  400. Status: 1,
  401. Ctime: time.Now().Unix(),
  402. }
  403. if len(patient.PatientAddress) > 0 {
  404. service.CreateAllergic(allergic)
  405. }
  406. if len(record_date) > 0 {
  407. var recordTime int64
  408. timeLayout := "2006-01-02"
  409. loc, _ := time.LoadLocation("Local")
  410. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  411. if err != nil {
  412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  413. return
  414. }
  415. recordTime = theTime.Unix()
  416. inspections := make([]models.Inspection, 0)
  417. for _, item := range formItems {
  418. var inspection models.Inspection
  419. inspection.OrgId = adminUserInfo.CurrentOrgId
  420. inspection.PatientId = patient.ID
  421. inspection.ProjectId = item.ProjectId
  422. inspection.ItemId = item.ItemId
  423. inspection.ItemName = item.ItemName
  424. inspection.ProjectName = item.ProjectName
  425. inspection.InspectType = item.RangeType
  426. inspection.InspectValue = item.Value
  427. inspection.InspectDate = recordTime
  428. inspection.Status = 1
  429. inspection.CreatedTime = time.Now().Unix()
  430. inspection.UpdatedTime = time.Now().Unix()
  431. inspections = append(inspections, inspection)
  432. }
  433. err = service.CreatePatientInspection(inspections)
  434. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  435. var record_time int64
  436. switch remind_cycle {
  437. case 1: //1个月
  438. ts := time.Unix(infectiousRecord.InspectDate, 0)
  439. record_time = ts.AddDate(0, 1, 0).Unix()
  440. break
  441. case 2: //2个月
  442. ts := time.Unix(infectiousRecord.InspectDate, 0)
  443. record_time = ts.AddDate(0, 2, 0).Unix()
  444. break
  445. case 3: //3个月
  446. ts := time.Unix(infectiousRecord.InspectDate, 0)
  447. record_time = ts.AddDate(0, 3, 0).Unix()
  448. break
  449. case 4: //6个月
  450. ts := time.Unix(infectiousRecord.InspectDate, 0)
  451. record_time = ts.AddDate(0, 6, 0).Unix()
  452. break
  453. case 5: //12个月
  454. ts := time.Unix(infectiousRecord.InspectDate, 0)
  455. record_time = ts.AddDate(0, 12, 0).Unix()
  456. break
  457. }
  458. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  459. if errs != nil {
  460. utils.ErrorLog("更新日期出错:%v", errs)
  461. }
  462. }
  463. redis := service.RedisClient()
  464. defer redis.Close()
  465. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  466. c.ServeSuccessJSON(map[string]interface{}{
  467. "msg": "ok",
  468. })
  469. return
  470. }
  471. // EditPatient 修改
  472. func (c *PatientApiController) EditPatient() {
  473. id, _ := c.GetInt64("id", 0)
  474. record_date := c.GetString("record_date")
  475. is_infectious, _ := c.GetInt64("is_infectious")
  476. remind_cycle, _ := c.GetInt64("remind_cycle")
  477. if id <= 0 {
  478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  479. return
  480. }
  481. adminUserInfo := c.GetAdminUserInfo()
  482. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  483. if patient.ID == 0 {
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  485. return
  486. }
  487. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  488. if code > 0 {
  489. c.ServeFailJSONWithSGJErrorCode(code)
  490. return
  491. }
  492. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  493. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  495. return
  496. }
  497. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  498. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  500. return
  501. }
  502. patient.UpdatedTime = time.Now().Unix()
  503. patient.IsInfectious = is_infectious
  504. patient.RemindCycle = remind_cycle
  505. err := service.UpdatePatient(&patient, contagions, diseases)
  506. if err != nil {
  507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  508. return
  509. }
  510. ////更新转归状态
  511. //lapseto := models.PatientLapseto{
  512. // LapsetoType: patient.Lapseto,
  513. // LapsetoTime: time.Now().Unix(),
  514. // UpdatedTime: time.Now().Unix(),
  515. //}
  516. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  517. //fmt.Println("更新转归失败", err)
  518. if err != nil {
  519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  520. return
  521. }
  522. patientsNew := models.XtPatientsNew{
  523. UserOrgId: patient.UserOrgId,
  524. UserId: patient.UserId,
  525. Avatar: patient.Avatar,
  526. PatientType: patient.PatientType,
  527. DialysisNo: patient.DialysisNo,
  528. AdmissionNumber: patient.AdmissionNumber,
  529. Source: patient.Source,
  530. PartitionId: patient.PartitionId,
  531. BedId: patient.BedId,
  532. Name: patient.Name,
  533. Alias: patient.Alias,
  534. Gender: patient.Gender,
  535. MaritalStatus: patient.MaritalStatus,
  536. IdCardNo: patient.IdCardNo,
  537. Birthday: patient.Birthday,
  538. ReimbursementWayId: patient.ReimbursementWayId,
  539. HealthCareType: patient.HealthCareType,
  540. HealthCareNo: patient.HealthCareNo,
  541. HealthCareDueDate: patient.HealthCareDueDate,
  542. Height: patient.Height,
  543. BloodType: patient.BloodType,
  544. Rh: patient.Rh,
  545. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  546. EducationLevel: patient.EducationLevel,
  547. Profession: patient.Profession,
  548. Phone: patient.Phone,
  549. HomeTelephone: patient.HomeTelephone,
  550. RelativePhone: patient.RelativePhone,
  551. RelativeRelations: patient.RelativeRelations,
  552. HomeAddress: patient.HomeAddress,
  553. WorkUnit: patient.WorkUnit,
  554. UnitAddress: patient.UnitAddress,
  555. Children: patient.Children,
  556. ReceivingDate: patient.ReceivingDate,
  557. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  558. FirstDialysisDate: patient.FirstDialysisDate,
  559. FirstDialysisHospital: patient.FirstDialysisHospital,
  560. PredialysisCondition: patient.PredialysisCondition,
  561. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  562. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  563. InductionPeriod: patient.InductionPeriod,
  564. InitialDialysis: patient.InitialDialysis,
  565. TotalDialysis: patient.TotalDialysis,
  566. AttendingDoctorId: patient.AttendingDoctorId,
  567. HeadNurseId: patient.HeadNurseId,
  568. Evaluate: patient.Evaluate,
  569. Diagnose: patient.Diagnose,
  570. Remark: patient.Remark,
  571. RegistrarsId: patient.RegistrarsId,
  572. Registrars: patient.Registrars,
  573. QrCode: patient.QrCode,
  574. BindingState: patient.BindingState,
  575. PatientComplains: patient.PatientComplains,
  576. PresentHistory: patient.PresentHistory,
  577. PastHistory: patient.PastHistory,
  578. Temperature: patient.Temperature,
  579. Pulse: patient.Pulse,
  580. Respiratory: patient.Respiratory,
  581. Sbp: patient.SBP,
  582. Dbp: patient.DBP,
  583. Nation: patient.Nation,
  584. NativePlace: patient.NativePlace,
  585. Age: patient.Age,
  586. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  587. IsInfectious: patient.IsInfectious,
  588. RemindCycle: patient.RemindCycle,
  589. ResponseResult: patient.ResponseResult,
  590. IsOpenRemind: patient.IsOpenRemind,
  591. FirstTreatmentDate: patient.FirstTreatmentDate,
  592. DialysisAge: patient.DialysisAge,
  593. ExpenseKind: patient.ExpenseKind,
  594. TellPhone: patient.TellPhone,
  595. ContactName: patient.ContactName,
  596. UpdatedTime: time.Now().Unix(),
  597. BloodPatients: 1,
  598. Lapseto: patient.Lapseto,
  599. TrobleShoot: patient.TrobleShoot,
  600. SchRemark: patient.SchRemark,
  601. TreatmentPlan: patient.TreatmentPlan,
  602. RecordNumber: patient.RecordNumber,
  603. PatientSource: patient.PatientSource,
  604. PatientStartTime: patient.PatientStartTime,
  605. PatientEndTime: patient.PatientEndTime,
  606. InfectiousRemark: patient.InfectiousRemark,
  607. AllergicHistory: patient.AllergicHistory,
  608. PatientAddress: patient.PatientAddress,
  609. }
  610. // //更新病人ID获取新表病人ID
  611. err = service.UpdatepatientTwo(&patientsNew, id)
  612. allergic := models.XtPatientAllergic{
  613. PatientId: patient.ID,
  614. UserOrgId: adminUserInfo.CurrentOrgId,
  615. StartTime: patient.PatientStartTime,
  616. EndTime: patient.PatientEndTime,
  617. PatientSource: patient.PatientSource,
  618. Status: 1,
  619. Ctime: time.Now().Unix(),
  620. Mtime: time.Now().Unix(),
  621. Remake: patient.Remark,
  622. PatientAddress: patient.PatientAddress,
  623. }
  624. if len(patient.PatientAddress) > 0 {
  625. service.CreateAllergic(allergic)
  626. }
  627. nowTimeUinx := time.Now()
  628. today := nowTimeUinx.Format("2006-01-02")
  629. redis := service.RedisClient()
  630. defer redis.Close()
  631. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  632. redis.Set(key, "", time.Second*60*60*18)
  633. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  634. redis.Set(keyOne, "", time.Second*60*60*18)
  635. if len(record_date) > 0 {
  636. var recordTime int64
  637. timeLayout := "2006-01-02"
  638. loc, _ := time.LoadLocation("Local")
  639. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  640. if err != nil {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  642. return
  643. }
  644. recordTime = theTime.Unix()
  645. inspections := make([]models.Inspection, 0)
  646. for _, item := range formItems {
  647. var inspection models.Inspection
  648. inspection.OrgId = adminUserInfo.CurrentOrgId
  649. inspection.PatientId = patient.ID
  650. inspection.ProjectId = item.ProjectId
  651. inspection.ItemId = item.ItemId
  652. inspection.ItemName = item.ItemName
  653. inspection.ProjectName = item.ProjectName
  654. inspection.InspectType = item.RangeType
  655. inspection.InspectValue = item.Value
  656. inspection.InspectDate = recordTime
  657. inspection.Status = 1
  658. inspection.CreatedTime = time.Now().Unix()
  659. inspection.UpdatedTime = time.Now().Unix()
  660. inspections = append(inspections, inspection)
  661. }
  662. err = service.CreatePatientInspection(inspections)
  663. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  664. var record_time int64
  665. switch remind_cycle {
  666. case 1: //1个月
  667. ts := time.Unix(infectiousRecord.InspectDate, 0)
  668. record_time = ts.AddDate(0, 1, 0).Unix()
  669. break
  670. case 2: //2个月
  671. ts := time.Unix(infectiousRecord.InspectDate, 0)
  672. record_time = ts.AddDate(0, 2, 0).Unix()
  673. break
  674. case 3: //3个月
  675. ts := time.Unix(infectiousRecord.InspectDate, 0)
  676. record_time = ts.AddDate(0, 3, 0).Unix()
  677. break
  678. case 4: //6个月
  679. ts := time.Unix(infectiousRecord.InspectDate, 0)
  680. record_time = ts.AddDate(0, 6, 0).Unix()
  681. break
  682. case 5: //12个月
  683. ts := time.Unix(infectiousRecord.InspectDate, 0)
  684. record_time = ts.AddDate(0, 12, 0).Unix()
  685. break
  686. }
  687. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  688. if errs != nil {
  689. utils.ErrorLog("更新日期出错:%v", errs)
  690. }
  691. }
  692. c.ServeSuccessJSON(map[string]interface{}{
  693. "msg": "ok",
  694. })
  695. return
  696. }
  697. func (c *PatientApiController) EditLapseto() {
  698. id, _ := c.GetInt64("id", 0)
  699. if id <= 0 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. start_time := c.GetString("start_time")
  704. end_time := c.GetString("end_time")
  705. timeLayout := "2006-01-02"
  706. loc, _ := time.LoadLocation("Local")
  707. var startTime int64
  708. if len(start_time) > 0 {
  709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  710. if err != nil {
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. startTime = theTime.Unix()
  715. }
  716. var endTime int64
  717. if len(end_time) > 0 {
  718. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  719. if err != nil {
  720. utils.ErrorLog(err.Error())
  721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  722. return
  723. }
  724. endTime = theTime.Unix()
  725. }
  726. patient_address := c.GetString("patient_address")
  727. adminUserInfo := c.GetAdminUserInfo()
  728. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  729. if patient.ID == 0 {
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  731. return
  732. }
  733. patientBody := make(map[string]interface{}, 0)
  734. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  735. if err != nil {
  736. utils.ErrorLog(err.Error())
  737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  738. return
  739. }
  740. var lapseto models.PatientLapseto
  741. lapseto.PatientId = patient.ID
  742. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  743. utils.ErrorLog("lapseto_type")
  744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  745. return
  746. }
  747. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  748. lapseto.LapsetoType = lapsetoType
  749. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  750. utils.ErrorLog("lapseto_time")
  751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  752. return
  753. }
  754. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  755. //if len(lapsetoTime) == 0 {
  756. // utils.ErrorLog("len(lapsetoTime) == 0")
  757. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  758. // return
  759. //}
  760. out_reason, _ := patientBody["out_reason"].(string)
  761. //if len(out_reason) == 0 {
  762. // utils.ErrorLog("len(out_reason) == 0")
  763. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  764. // return
  765. //}
  766. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  767. //if err != nil {
  768. // utils.ErrorLog("lapsetoTimeUnix")
  769. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  770. // return
  771. //}
  772. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  773. lapseto.UpdatedTime = time.Now().Unix()
  774. lapseto.CreatedTime = time.Now().Unix()
  775. lapseto.Status = 1
  776. patient.Lapseto = lapseto.LapsetoType
  777. patient.OutReason = out_reason
  778. patient.DeathTime = lapsetoTimeUnix.Unix()
  779. patient.PatientStartTime = startTime
  780. patient.PatientEndTime = endTime
  781. patient.PatientAddress = patient_address
  782. //if patient.Lapseto == 1 {
  783. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  784. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  785. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  786. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  787. // return
  788. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  789. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  790. // return
  791. // }
  792. //}
  793. err = service.EditPatientLapseto(&patient, &lapseto)
  794. if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  795. timeStr := time.Now().Format("2006-01-02")
  796. timeLayout := "2006-01-02 15:04:05"
  797. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  798. timenow := timeStringToTime.Unix()
  799. service.UpdateScheduleByDeathTime(id, timenow)
  800. service.UpdateScheduleItemByPatientId(id)
  801. }
  802. allergic := models.XtPatientAllergic{
  803. UserOrgId: adminUserInfo.CurrentOrgId,
  804. PatientId: patient.ID,
  805. StartTime: patient.PatientStartTime,
  806. EndTime: patient.PatientEndTime,
  807. PatientSource: patient.Lapseto,
  808. PatientAddress: patient.PatientAddress,
  809. Remake: patient.Remark,
  810. Status: 1,
  811. Ctime: time.Now().Unix(),
  812. }
  813. if lapseto.LapsetoType == 2 || lapseto.LapsetoType == 3 {
  814. allergic.StartTime = lapseto.LapsetoTime
  815. allergic.EndTime = lapseto.LapsetoTime
  816. }
  817. service.CreateAllergic(allergic)
  818. if err != nil {
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  820. return
  821. }
  822. c.ServeSuccessJSON(map[string]interface{}{
  823. "msg": "ok",
  824. })
  825. return
  826. }
  827. func (c *PatientApiController) GetPatient() {
  828. id, _ := c.GetInt64("id", 0)
  829. if id <= 0 {
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. adminUserInfo := c.GetAdminUserInfo()
  834. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  835. if patient.ID == 0 {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  837. return
  838. }
  839. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  840. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  841. diseases := service.GetPatientDiseases(patient.ID)
  842. contagions := service.GetPatientContagions(patient.ID)
  843. c.ServeSuccessJSON(map[string]interface{}{
  844. "patient": patient,
  845. "diseases": diseases,
  846. "contagions": contagions,
  847. "infections": infections,
  848. })
  849. return
  850. }
  851. func (c *PatientApiController) CreateDialysisSolution() {
  852. id, _ := c.GetInt64("patient", 0)
  853. if id <= 0 {
  854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  855. return
  856. }
  857. adminUserInfo := c.GetAdminUserInfo()
  858. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  859. if patient.ID == 0 {
  860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  861. return
  862. }
  863. var solution models.DialysisSolution
  864. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  865. if code > 0 {
  866. c.ServeFailJSONWithSGJErrorCode(code)
  867. return
  868. }
  869. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  870. //if thisSolution.ID > 0 {
  871. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  872. // return
  873. //}
  874. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  875. solution.Doctor = adminUserInfo.AdminUser.Id
  876. solution.Status = 1
  877. solution.PatientId = id
  878. solution.CreatedTime = time.Now().Unix()
  879. solution.UserOrgId = adminUserInfo.CurrentOrgId
  880. solution.UpdatedTime = time.Now().Unix()
  881. solution.SubName = ""
  882. solution.ParentId = 0
  883. solution.SolutionStatus = 1
  884. //records, _ := service.GetAllSchedules()
  885. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  886. for _, sch := range schs {
  887. var DialysisMachineName string
  888. if len(solution.DialysisDialyszers) > 0 {
  889. DialysisMachineName = solution.DialysisDialyszers
  890. }
  891. if len(solution.DialyzerPerfusionApparatus) > 0 {
  892. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  893. }
  894. if len(solution.DialysisIrrigation) > 0 {
  895. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  896. }
  897. sch.DialysisMachineName = DialysisMachineName
  898. service.UpdateSch(sch)
  899. }
  900. err := service.CreatePatientDialysisSolution(&solution)
  901. //获取最新1条
  902. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  903. //更新状态
  904. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  905. if err != nil {
  906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  907. return
  908. }
  909. c.ServeSuccessJSON(map[string]interface{}{
  910. "msg": "ok",
  911. "solution": solution,
  912. })
  913. return
  914. }
  915. func (c *PatientApiController) UpdateDialysisSolution() {
  916. patient, _ := c.GetInt64("patient", 0)
  917. id, _ := c.GetInt64("id", 0)
  918. if id <= 0 || patient <= 0 {
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. adminUserInfo := c.GetAdminUserInfo()
  923. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  924. if solution.ID == 0 || solution.PatientId != patient {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  926. return
  927. }
  928. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  929. if code > 0 {
  930. c.ServeFailJSONWithSGJErrorCode(code)
  931. return
  932. }
  933. solution.UpdatedTime = time.Now().Unix()
  934. err := service.UpdatePatientDialysisSolution(&solution)
  935. nowTimeUinx := time.Now()
  936. today := nowTimeUinx.Format("2006-01-02")
  937. timeLayout := "2006-01-02"
  938. loc, _ := time.LoadLocation("Local")
  939. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  940. if adminUserInfo.CurrentOrgId == 9538 {
  941. prescription := models.DialysisPrescription{
  942. Dialyzer: solution.Dialyzer,
  943. Anticoagulant: solution.Anticoagulant,
  944. AnticoagulantShouji: solution.AnticoagulantShouji,
  945. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  946. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  947. ModeId: solution.ModeId,
  948. DialysisDurationHour: solution.DialysisDurationHour,
  949. Kalium: solution.Kalium,
  950. Sodium: solution.Sodium,
  951. Calcium: solution.Calcium,
  952. TargetUltrafiltration: solution.TargetUltrafiltration,
  953. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  954. BloodAccess: solution.BloodAccess,
  955. DialysateFlow: solution.DialysateFlow,
  956. DialysateTemperature: solution.DialysateTemperature,
  957. DialysisIrrigation: solution.DialysisIrrigation,
  958. DialysisDialyszers: solution.DialysisDialyszers,
  959. PlasmaSeparator: solution.PlasmaSeparator,
  960. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  961. OxygenUptake: solution.OxygenUptake,
  962. OxygenFlow: solution.OxygenFlow,
  963. OxygenTime: solution.OxygenTime,
  964. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  965. Amylaceum: solution.Amylaceum,
  966. DialysisStrainer: solution.DialysisStrainer,
  967. Chaptalization: solution.Chaptalization,
  968. BloodAccessPartId: solution.BloodAccessPartId,
  969. }
  970. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  971. }
  972. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  973. for _, sch := range schs {
  974. var DialysisMachineName string
  975. if len(solution.DialysisDialyszers) > 0 {
  976. DialysisMachineName = solution.DialysisDialyszers
  977. }
  978. if len(solution.DialyzerPerfusionApparatus) > 0 {
  979. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  980. }
  981. if len(solution.DialysisIrrigation) > 0 {
  982. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  983. }
  984. sch.DialysisMachineName = DialysisMachineName
  985. service.UpdateSch(sch)
  986. }
  987. if err != nil {
  988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  989. return
  990. }
  991. c.ServeSuccessJSON(map[string]interface{}{
  992. "msg": "ok",
  993. "solution": solution,
  994. })
  995. return
  996. }
  997. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  998. patient, _ := c.GetInt64("patient", 0)
  999. id, _ := c.GetInt64("id", 0)
  1000. if id <= 0 || patient <= 0 {
  1001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. adminUserInfo := c.GetAdminUserInfo()
  1005. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1006. if solution.ID == 0 || solution.PatientId != patient {
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1008. return
  1009. }
  1010. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  1011. if code > 0 {
  1012. c.ServeFailJSONWithSGJErrorCode(code)
  1013. return
  1014. }
  1015. solution.UpdatedTime = time.Now().Unix()
  1016. solution.AffirmState = 1
  1017. err := service.UpdatePatientDialysisSolution(&solution)
  1018. if err != nil {
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  1020. return
  1021. }
  1022. c.ServeSuccessJSON(map[string]interface{}{
  1023. "msg": "ok",
  1024. "solution": solution,
  1025. })
  1026. return
  1027. }
  1028. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1029. id, _ := c.GetInt64("id", 0)
  1030. page, _ := c.GetInt64("page", 0)
  1031. limit, _ := c.GetInt64("limit", 0)
  1032. if id <= 0 {
  1033. c.ServeSuccessJSON(map[string]interface{}{
  1034. "solutions": nil,
  1035. })
  1036. return
  1037. }
  1038. if page <= 0 {
  1039. page = 1
  1040. }
  1041. if limit <= 0 {
  1042. limit = 10
  1043. }
  1044. adminUserInfo := c.GetAdminUserInfo()
  1045. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  1046. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  1047. c.ServeSuccessJSON(map[string]interface{}{
  1048. "solutions": solutions,
  1049. "total": total,
  1050. "stockType": stockType,
  1051. })
  1052. return
  1053. }
  1054. func (c *PatientApiController) DeleteDialysisSolution() {
  1055. id, _ := c.GetInt64("id", 0)
  1056. if id <= 0 {
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1058. return
  1059. }
  1060. adminUserInfo := c.GetAdminUserInfo()
  1061. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  1062. if solution.ID == 0 {
  1063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  1064. return
  1065. }
  1066. if solution.UseState == 1 {
  1067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  1068. return
  1069. }
  1070. solution.UpdatedTime = time.Now().Unix()
  1071. solution.Status = 0
  1072. err := service.DeleteSolution(&solution)
  1073. if err != nil {
  1074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  1075. return
  1076. }
  1077. c.ServeSuccessJSON(map[string]interface{}{
  1078. "msg": "ok",
  1079. })
  1080. return
  1081. }
  1082. // GetDryWeights 取患者干体重调整铺
  1083. func (c *PatientApiController) GetDryWeights() {
  1084. page, _ := c.GetInt64("page", 1)
  1085. limit, _ := c.GetInt64("limit", 10)
  1086. id, _ := c.GetInt64("id", 0)
  1087. if id <= 0 {
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. adminUserInfo := c.GetAdminUserInfo()
  1092. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  1093. c.ServeSuccessJSON(map[string]interface{}{
  1094. "weights": weights,
  1095. "total": total,
  1096. })
  1097. return
  1098. }
  1099. func (c *PatientApiController) CreateDryWeights() {
  1100. patient, _ := c.GetInt64("id", 0)
  1101. if patient <= 0 {
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. adminUserInfo := c.GetAdminUserInfo()
  1106. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1107. if patientInfo.ID == 0 {
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1109. return
  1110. }
  1111. var theWeight models.DryWeightAdjust
  1112. dataBody := make(map[string]interface{}, 0)
  1113. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1114. if err != nil {
  1115. utils.ErrorLog(err.Error())
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  1124. theWeight.Weight = weight
  1125. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  1126. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. // return
  1128. // }
  1129. // doctor := int64(dataBody["doctor"].(float64))
  1130. // theWeight.Doctor = doctor
  1131. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1132. remark, _ := dataBody["remark"].(string)
  1133. theWeight.Remark = remark
  1134. }
  1135. theWeight.CreatedTime = time.Now().Unix()
  1136. theWeight.UpdatedTime = time.Now().Unix()
  1137. theWeight.Status = 1
  1138. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  1139. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  1140. theWeight.PatientId = patient
  1141. theWeight.Doctor = adminUserInfo.AdminUser.Id
  1142. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  1143. if old.ID > 0 {
  1144. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1145. }
  1146. err = service.CreateDryWeightAdjust(&theWeight)
  1147. if err != nil {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1149. return
  1150. }
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "ok",
  1153. "weight": theWeight,
  1154. })
  1155. return
  1156. }
  1157. func (c *PatientApiController) CreateGroupAdvice() {
  1158. var err error
  1159. defer func() {
  1160. if rec := recover(); rec != nil {
  1161. err = fmt.Errorf("程序异常:%v", rec)
  1162. }
  1163. if err != nil {
  1164. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1165. }
  1166. }()
  1167. patient, _ := c.GetInt64("id", 0)
  1168. groupNo, _ := c.GetInt64("groupno", 0)
  1169. if patient <= 0 {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. adminUserInfo := c.GetAdminUserInfo()
  1174. var patientInfo models.Patients
  1175. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1176. if patientInfo.ID == 0 {
  1177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1178. return
  1179. }
  1180. dataBody := make(map[string]interface{}, 0)
  1181. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1182. if err != nil {
  1183. utils.ErrorLog(err.Error())
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. utils.ErrorLog("%v", dataBody)
  1188. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1189. if appRole.UserType == 3 {
  1190. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. if getPermissionErr != nil {
  1192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. return
  1194. } else if headNursePermission == nil {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1196. return
  1197. }
  1198. }
  1199. timeLayout := "2006-01-02"
  1200. loc, _ := time.LoadLocation("Local")
  1201. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1202. utils.ErrorLog("advice_type")
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. adviceType := int64(dataBody["advice_type"].(float64))
  1207. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1208. utils.ErrorLog("advice_type != 1&&2")
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1213. utils.ErrorLog("advice_date")
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1218. utils.ErrorLog("start_time")
  1219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1220. return
  1221. }
  1222. startTime2, _ := dataBody["start_time"].(string)
  1223. time_arr := strings.Split(startTime2, " ")
  1224. if len(time_arr) > 0 {
  1225. startTime2 = time_arr[0]
  1226. }
  1227. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1228. utils.ErrorLog("advice_date")
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. adviceDate := startTime2
  1233. if len(adviceDate) == 0 {
  1234. utils.ErrorLog("len(adviceDate) == 0")
  1235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1236. return
  1237. }
  1238. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1239. if err != nil {
  1240. utils.ErrorLog(err.Error())
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1242. return
  1243. }
  1244. AdviceDate := theTime.Unix()
  1245. RecordDate := theTime.Unix()
  1246. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1247. utils.ErrorLog("start_time")
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1249. return
  1250. }
  1251. startTime, _ := dataBody["start_time"].(string)
  1252. if len(startTime) == 0 {
  1253. utils.ErrorLog("len(start_time) == 0")
  1254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1255. return
  1256. }
  1257. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1258. if err != nil {
  1259. utils.ErrorLog(err.Error())
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. StartTime := theTime.Unix()
  1264. Remark := ""
  1265. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1266. remark, _ := dataBody["remark"].(string)
  1267. Remark = remark
  1268. }
  1269. var advices []*models.GroupAdvice
  1270. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1271. utils.ErrorLog("adviceNames")
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1273. return
  1274. }
  1275. adviceNames := dataBody["adviceNames"].([]interface{})
  1276. for _, adviceNameMap := range adviceNames {
  1277. adviceNameM := adviceNameMap.(map[string]interface{})
  1278. var advice models.GroupAdvice
  1279. advice.Remark = Remark
  1280. advice.AdviceType = adviceType
  1281. advice.StartTime = StartTime
  1282. advice.AdviceDate = AdviceDate
  1283. advice.RecordDate = RecordDate
  1284. advice.Status = 1
  1285. advice.CreatedTime = time.Now().Unix()
  1286. advice.UpdatedTime = time.Now().Unix()
  1287. advice.StopState = 2
  1288. advice.ExecutionState = 2
  1289. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1290. advice.PatientId = patientInfo.ID
  1291. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1292. advice.IsSettle = 2
  1293. //创建步骤表
  1294. finish := models.XtDialysisFinish{
  1295. IsFinish: 1,
  1296. UserOrgId: adminUserInfo.CurrentOrgId,
  1297. Status: 1,
  1298. Ctime: time.Now().Unix(),
  1299. Mtime: 0,
  1300. Module: 4,
  1301. RecordDate: advice.RecordDate,
  1302. Sourse: 1,
  1303. PatientId: patient,
  1304. }
  1305. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.RecordDate, 4, patient)
  1306. if dialysisFinish.ID == 0 {
  1307. service.CreateDialysisFinish(finish)
  1308. }
  1309. // 查询信息规挡的设置天数
  1310. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1311. if infor.ID > 0 && infor.WeekDay > 0 {
  1312. var cha_time int64
  1313. timeNowStr := time.Now().Format("2006-01-02")
  1314. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1315. //今日的日期减去设置的日期
  1316. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1317. if cha_time >= advice.AdviceDate {
  1318. //查询审核是否允许
  1319. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1320. //申请状态不允许的情况 拒绝修改
  1321. if infor.ApplicationStatus != 1 {
  1322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1323. return
  1324. }
  1325. }
  1326. }
  1327. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1328. utils.ErrorLog("advice_name")
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1330. return
  1331. }
  1332. adviceName, _ := adviceNameM["advice_name"].(string)
  1333. if len(adviceName) == 0 {
  1334. utils.ErrorLog("len(advice_name) == 0")
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1336. return
  1337. }
  1338. advice.AdviceName = adviceName
  1339. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1340. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1341. advice.DrugSpec = drugSpec
  1342. }
  1343. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1344. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1345. advice.AdviceDesc = adviceDesc
  1346. }
  1347. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1348. template_id, _ := adviceNameM["template_id"].(string)
  1349. advice.TemplateId = template_id
  1350. }
  1351. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1352. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1353. advice.DrugSpecUnit = drugSpecUnit
  1354. }
  1355. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1356. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1357. advice.SingleDose = singleDose
  1358. }
  1359. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1360. singleDose := adviceNameM["single_dose"].(float64)
  1361. advice.SingleDose = singleDose
  1362. }
  1363. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1364. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1365. advice.SingleDoseUnit = singleDoseUnit
  1366. }
  1367. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1368. tmp := adviceNameM["single_dose_unit"].(float64)
  1369. singleDoseUnit := service.TypeConversion(tmp)
  1370. advice.SingleDoseUnit = singleDoseUnit
  1371. }
  1372. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1373. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1374. advice.PrescribingNumber = prescribingNumber
  1375. }
  1376. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1377. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1378. advice.PrescribingNumber = prescribingNumber
  1379. }
  1380. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1381. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1382. advice.PrescribingNumberUnit = prescribingNumberUnit
  1383. }
  1384. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1385. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1386. advice.DeliveryWay = deliveryWay
  1387. }
  1388. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1389. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1390. advice.ExecutionFrequency = executionFrequency
  1391. }
  1392. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1393. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1394. advice.Way = int64(way)
  1395. }
  1396. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1397. way := int64(adviceNameM["way"].(float64))
  1398. advice.Way = way
  1399. }
  1400. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1401. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1402. advice.DrugId = int64(drug_id)
  1403. }
  1404. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1405. drug_id := int64(adviceNameM["drug_id"].(float64))
  1406. advice.DrugId = drug_id
  1407. }
  1408. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1409. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1410. advice.DrugNameId = drug_name_id
  1411. }
  1412. remark, _ := adviceNameM["remark"].(string)
  1413. advice.Remark = remark
  1414. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1415. if advice.PrescribingNumber == 0 {
  1416. advice.PrescribingNumber = 1
  1417. }
  1418. //查询该患者今日有没有双人核对
  1419. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1420. fmt.Println("chek", check)
  1421. if check.ID > 0 {
  1422. advice.Checker = check.Modifier
  1423. advice.CheckState = 1
  1424. advice.CheckTime = time.Now().Unix()
  1425. }
  1426. }
  1427. if adviceType == 1 {
  1428. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1429. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1430. advice.FrequencyType = frequency_type
  1431. }
  1432. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1433. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1434. advice.DayCount = day_count
  1435. }
  1436. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1437. week_day, _ := adviceNameM["week_days"].(string)
  1438. advice.WeekDay = week_day
  1439. }
  1440. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1441. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1442. var startTime int64
  1443. if len(push_start_time) > 0 {
  1444. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1445. startTime = theTime.Unix()
  1446. }
  1447. advice.PushStartTime = startTime
  1448. }
  1449. }
  1450. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1451. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1452. advice.ExecutionFrequency = executionFrequency
  1453. }
  1454. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1455. children := adviceNameM["children"].([]interface{})
  1456. if len(children) > 0 {
  1457. for _, childrenMap := range children {
  1458. childMap := childrenMap.(map[string]interface{})
  1459. var child models.GroupAdvice
  1460. child.Remark = Remark
  1461. child.AdviceType = adviceType
  1462. child.StartTime = StartTime
  1463. child.AdviceDate = AdviceDate
  1464. child.RecordDate = RecordDate
  1465. child.Status = 1
  1466. child.CreatedTime = time.Now().Unix()
  1467. child.UpdatedTime = time.Now().Unix()
  1468. child.StopState = 2
  1469. child.ExecutionState = 2
  1470. child.UserOrgId = adminUserInfo.CurrentOrgId
  1471. child.PatientId = patientInfo.ID
  1472. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1473. child.IsSettle = 2
  1474. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1475. utils.ErrorLog("child advice_name")
  1476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1477. return
  1478. }
  1479. childAdviceName, _ := childMap["advice_name"].(string)
  1480. if len(childAdviceName) == 0 {
  1481. utils.ErrorLog("len(child advice_name) == 0")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. child.AdviceName = childAdviceName
  1486. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1487. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1488. child.AdviceDesc = childAdviceDesc
  1489. }
  1490. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1491. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1492. child.DrugSpec = childDrugSpec
  1493. }
  1494. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1495. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1496. child.DrugSpecUnit = childDrugSpecUnit
  1497. }
  1498. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1499. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1500. child.SingleDose = childSingleDose
  1501. }
  1502. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1503. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1504. child.SingleDoseUnit = childSingleDoseUnit
  1505. }
  1506. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1507. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1508. child.PrescribingNumber = childPrescribingNumber
  1509. }
  1510. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1511. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1512. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1513. }
  1514. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1515. drug_id := int64(childMap["drug_id"].(float64))
  1516. child.DrugId = drug_id
  1517. }
  1518. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1519. way := int64(childMap["way"].(float64))
  1520. child.Way = way
  1521. }
  1522. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1523. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1524. child.DrugNameId = drug_name_id
  1525. }
  1526. child.DeliveryWay = advice.DeliveryWay
  1527. child.ExecutionFrequency = advice.ExecutionFrequency
  1528. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1529. if child.PrescribingNumber == 0 {
  1530. child.PrescribingNumber = 1
  1531. }
  1532. //查询该患者今日有没有双人核对
  1533. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1534. if check.ID > 0 {
  1535. child.Checker = check.Modifier
  1536. child.CheckState = 1
  1537. child.CheckTime = time.Now().Unix()
  1538. }
  1539. }
  1540. advice.Children = append(advice.Children, &child)
  1541. }
  1542. }
  1543. }
  1544. advices = append(advices, &advice)
  1545. }
  1546. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1547. for _, item := range advices {
  1548. //记录日志
  1549. byterequest, _ := json.Marshal(item)
  1550. adviceLog := models.XtDoctorAdviceLog{
  1551. UserOrgId: item.UserOrgId,
  1552. PatientId: item.PatientId,
  1553. AdminUserId: adminUserInfo.AdminUser.Id,
  1554. Module: 1,
  1555. ErrLog: string(byterequest),
  1556. Status: 1,
  1557. Ctime: time.Now().Unix(),
  1558. Mtime: 0,
  1559. Source: "电导端批量插入医嘱",
  1560. RecordDate: item.AdviceDate,
  1561. }
  1562. service.CreateDoctorAdviceLog(adviceLog)
  1563. }
  1564. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1565. redis := service.RedisClient()
  1566. defer redis.Close()
  1567. redis.Set(key, "", time.Second)
  1568. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1569. redis.Set(keyOne, "", time.Second)
  1570. if err != nil {
  1571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1572. return
  1573. }
  1574. c.ServeSuccessJSON(map[string]interface{}{
  1575. "msg": "ok",
  1576. "advices": list,
  1577. })
  1578. return
  1579. }
  1580. func (c *PatientApiController) CreateDoctorAdvice() {
  1581. patient, _ := c.GetInt64("id", 0)
  1582. if patient <= 0 {
  1583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1584. return
  1585. }
  1586. adminUserInfo := c.GetAdminUserInfo()
  1587. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1588. if patientInfo.ID == 0 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1590. return
  1591. }
  1592. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1593. if appRole.UserType == 3 {
  1594. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1595. if getPermissionErr != nil {
  1596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1597. return
  1598. } else if headNursePermission == nil {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1600. return
  1601. }
  1602. }
  1603. var advice models.DoctorAdvice
  1604. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1605. if code > 0 {
  1606. c.ServeFailJSONWithSGJErrorCode(code)
  1607. return
  1608. }
  1609. if advice.ParentId > 0 {
  1610. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1611. if old.ID == 0 || old.PatientId != patient {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1613. return
  1614. }
  1615. if old.StopState == 1 || old.ExecutionState == 1 {
  1616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1617. return
  1618. }
  1619. if old.ParentId > 0 {
  1620. advice.ParentId = old.ParentId
  1621. }
  1622. advice.StartTime = old.StartTime
  1623. advice.AdviceDoctor = old.AdviceDoctor
  1624. advice.DeliveryWay = old.DeliveryWay
  1625. advice.ExecutionFrequency = old.ExecutionFrequency
  1626. advice.GroupNo = old.GroupNo
  1627. }
  1628. advice.Status = 1
  1629. advice.CreatedTime = time.Now().Unix()
  1630. advice.UpdatedTime = time.Now().Unix()
  1631. advice.StopState = 2
  1632. advice.ExecutionState = 2
  1633. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1634. advice.PatientId = patient
  1635. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1636. // 查询信息规挡的设置天数
  1637. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1638. if infor.ID > 0 && infor.WeekDay > 0 {
  1639. var cha_time int64
  1640. timeNowStr := time.Now().Format("2006-01-02")
  1641. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1642. //今日的日期减去设置的日期
  1643. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1644. if cha_time >= advice.AdviceDate {
  1645. //查询审核是否允许
  1646. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1647. //申请状态不允许的情况 拒绝修改
  1648. if infor.ApplicationStatus != 1 {
  1649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1650. return
  1651. }
  1652. }
  1653. }
  1654. if advice.UserOrgId == 3877 || advice.UserOrgId == 10340 || advice.UserOrgId == 9671 {
  1655. if advice.PrescribingNumber == 0 {
  1656. advice.PrescribingNumber = 1
  1657. }
  1658. //查询该患者今日有没有双人核对
  1659. check, _ := service.MobileGetDoubleCheckSix(advice.UserOrgId, patientInfo.ID, advice.AdviceDate)
  1660. if check.ID > 0 {
  1661. advice.Checker = check.Modifier
  1662. advice.CheckState = 1
  1663. advice.CheckTime = time.Now().Unix()
  1664. }
  1665. }
  1666. err := service.CreateDoctorAdvice(&advice)
  1667. //记录日志
  1668. byterequest, _ := json.Marshal(advice)
  1669. adviceLog := models.XtDoctorAdviceLog{
  1670. UserOrgId: advice.UserOrgId,
  1671. PatientId: advice.PatientId,
  1672. AdminUserId: adminUserInfo.AdminUser.Id,
  1673. Module: 1,
  1674. ErrLog: string(byterequest),
  1675. Status: 1,
  1676. Ctime: time.Now().Unix(),
  1677. Mtime: 0,
  1678. Source: "电脑新增医嘱",
  1679. RecordDate: advice.RecordDate,
  1680. }
  1681. service.CreateDoctorAdviceLog(adviceLog)
  1682. //创建步骤表
  1683. finish := models.XtDialysisFinish{
  1684. IsFinish: 1,
  1685. UserOrgId: adminUserInfo.CurrentOrgId,
  1686. Status: 1,
  1687. Ctime: time.Now().Unix(),
  1688. Mtime: 0,
  1689. Module: 4,
  1690. RecordDate: advice.AdviceDate,
  1691. Sourse: 1,
  1692. PatientId: patient,
  1693. }
  1694. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, advice.AdviceDate, 4, patient)
  1695. if dialysisFinish.ID == 0 {
  1696. service.CreateDialysisFinish(finish)
  1697. }
  1698. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1699. redis := service.RedisClient()
  1700. defer redis.Close()
  1701. redis.Set(key, "", time.Second)
  1702. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1703. redis.Set(keyOne, "", time.Second)
  1704. if err != nil {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1706. return
  1707. }
  1708. c.ServeSuccessJSON(map[string]interface{}{
  1709. "msg": "ok",
  1710. "advice": advice,
  1711. })
  1712. return
  1713. }
  1714. func (c *PatientApiController) ExecGroupAdvice() {
  1715. groupNo, _ := c.GetInt64("groupno", 0)
  1716. executionTime := c.GetString("execution_time")
  1717. if groupNo <= 0 {
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1719. return
  1720. }
  1721. if len(executionTime) <= 0 {
  1722. utils.ErrorLog("execution_time")
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1724. return
  1725. }
  1726. adminUserInfo := c.GetAdminUserInfo()
  1727. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1728. if advice.ID == 0 {
  1729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1730. return
  1731. }
  1732. if advice.ExecutionState == 1 {
  1733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1734. return
  1735. }
  1736. executionStaff := adminUserInfo.AdminUser.Id
  1737. // checker := adminUserInfo.AdminUser.Id
  1738. timeLayout := "2006-01-02 15:04:05"
  1739. loc, _ := time.LoadLocation("Local")
  1740. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1741. if err != nil {
  1742. utils.ErrorLog(err.Error())
  1743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1744. return
  1745. }
  1746. if advice.StartTime > theTime.Unix() {
  1747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1748. return
  1749. }
  1750. exceAdvice := models.DoctorAdvice{
  1751. ExecutionStaff: executionStaff,
  1752. ExecutionTime: theTime.Unix(),
  1753. UpdatedTime: time.Now().Unix(),
  1754. }
  1755. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1756. if err != nil {
  1757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1758. return
  1759. }
  1760. //查询自动扣减是否开启
  1761. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1762. //查询已经执行的医嘱
  1763. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1764. if drugStockConfig.IsOpen == 1 {
  1765. for _, item := range advicelist {
  1766. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1767. //查询这个患者这个患者这个药已经出库的所有数量
  1768. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1769. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1770. var total_count int64
  1771. var drug_count int64
  1772. for _, it := range advicelist {
  1773. if it.PrescribingNumberUnit == medical.MaxUnit {
  1774. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1775. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1776. total_count += prenumber * medical.MinNumber
  1777. }
  1778. if it.PrescribingNumberUnit == medical.MinUnit {
  1779. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1780. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1781. total_count += prenumber
  1782. }
  1783. }
  1784. for _, its := range drugoutlist {
  1785. if its.CountUnit == medical.MaxUnit {
  1786. drug_count += its.Count * medical.MinNumber
  1787. }
  1788. if its.CountUnit == medical.MinUnit {
  1789. drug_count += its.Count
  1790. }
  1791. }
  1792. if total_count == drug_count {
  1793. c.ServeSuccessJSON(map[string]interface{}{
  1794. "msg": "1",
  1795. "advice": advice,
  1796. })
  1797. return
  1798. }
  1799. var total int64
  1800. var prescribing_number_total int64
  1801. //查询默认出库仓库
  1802. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1803. //查询该药品在默认仓库是否有库存
  1804. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1805. //判断单位是否相等
  1806. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1807. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1808. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1809. //转化为最小单位
  1810. total = list.Count*medical.MinNumber + list.StockMinNumber
  1811. prescribing_number_total = count * medical.MinNumber
  1812. }
  1813. if medical.MinUnit == advice.PrescribingNumberUnit {
  1814. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1815. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1816. total = list.Count*medical.MinNumber + list.StockMinNumber
  1817. prescribing_number_total = count
  1818. }
  1819. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1820. c.ServeSuccessJSON(map[string]interface{}{
  1821. "msg": "3",
  1822. "advice": advice,
  1823. })
  1824. return
  1825. }
  1826. if prescribing_number_total > total {
  1827. c.ServeSuccessJSON(map[string]interface{}{
  1828. "msg": "2",
  1829. "advice": advice,
  1830. })
  1831. return
  1832. }
  1833. if prescribing_number_total <= total {
  1834. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1835. if medical.IsUse == 2 {
  1836. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1837. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1838. if drugOutInfo.ID == 0 {
  1839. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1840. }
  1841. }
  1842. if pharmacyConfig.IsOpen != 1 {
  1843. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  1844. if drugOutInfo.ID == 0 {
  1845. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1846. }
  1847. }
  1848. //查询默认仓库
  1849. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1850. //查询默认仓库剩余多少库存
  1851. var sum_count int64
  1852. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1853. for _, its := range stockInfo {
  1854. if its.MaxUnit == medical.MaxUnit {
  1855. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1856. }
  1857. sum_count += its.StockMaxNumber + its.StockMinNumber
  1858. }
  1859. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1860. break
  1861. c.ServeSuccessJSON(map[string]interface{}{
  1862. "msg": "1",
  1863. "advice": advice,
  1864. })
  1865. return
  1866. }
  1867. if medical.IsUse == 1 {
  1868. c.ServeSuccessJSON(map[string]interface{}{
  1869. "msg": "1",
  1870. "advice": advice,
  1871. })
  1872. return
  1873. }
  1874. }
  1875. }
  1876. }
  1877. advice.ExecutionStaff = executionStaff
  1878. advice.ExecutionTime = theTime.Unix()
  1879. c.ServeSuccessJSON(map[string]interface{}{
  1880. "msg": "ok",
  1881. "advice": advice,
  1882. })
  1883. return
  1884. }
  1885. func (c *PatientApiController) ExecDoctorAdvice() {
  1886. origin, _ := c.GetInt64("origin", 0)
  1887. patient, _ := c.GetInt64("patient", 0)
  1888. id, _ := c.GetInt64("id", 0)
  1889. executionTime := c.GetString("execution_time")
  1890. if origin != 2 {
  1891. if id <= 0 || patient <= 0 {
  1892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1893. return
  1894. }
  1895. if len(executionTime) <= 0 {
  1896. utils.ErrorLog("execution_time")
  1897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1898. return
  1899. }
  1900. adminUserInfo := c.GetAdminUserInfo()
  1901. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1902. if advice.ID == 0 || advice.PatientId != patient {
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1904. return
  1905. }
  1906. //医嘱已执行
  1907. if advice.ExecutionState == 1 {
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1909. return
  1910. }
  1911. executionStaff := adminUserInfo.AdminUser.Id
  1912. timeLayout := "2006-01-02 15:04:05"
  1913. loc, _ := time.LoadLocation("Local")
  1914. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1915. if err != nil {
  1916. utils.ErrorLog(err.Error())
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1918. return
  1919. }
  1920. if advice.StartTime > theTime.Unix() {
  1921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1922. return
  1923. }
  1924. exceAdvice := models.DoctorAdvice{
  1925. ExecutionStaff: executionStaff,
  1926. ExecutionTime: theTime.Unix(),
  1927. UpdatedTime: time.Now().Unix(),
  1928. }
  1929. // 查询信息规挡的设置天数
  1930. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1931. if infor.ID > 0 && infor.WeekDay > 0 {
  1932. var cha_time int64
  1933. timeNowStr := time.Now().Format("2006-01-02")
  1934. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1935. //今日的日期减去设置的日期
  1936. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1937. if cha_time >= advice.AdviceDate {
  1938. //查询审核是否允许
  1939. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  1940. //申请状态不允许的情况 拒绝修改
  1941. if infor.ApplicationStatus != 1 {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1943. return
  1944. }
  1945. }
  1946. }
  1947. if advice.ParentId > 0 {
  1948. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1949. //记录日志
  1950. byterequest, _ := json.Marshal(exceAdvice)
  1951. doctorAdviceLog := models.XtDoctorAdviceLog{
  1952. UserOrgId: exceAdvice.UserOrgId,
  1953. PatientId: exceAdvice.PatientId,
  1954. AdminUserId: adminUserInfo.AdminUser.Id,
  1955. Module: 2,
  1956. ErrLog: string(byterequest),
  1957. Status: 1,
  1958. Ctime: time.Now().Unix(),
  1959. Mtime: 0,
  1960. Source: "电脑端执行医嘱",
  1961. RecordDate: exceAdvice.RecordDate,
  1962. }
  1963. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1964. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1965. redis := service.RedisClient()
  1966. //清空key 值
  1967. redis.Set(key, "", time.Second)
  1968. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1969. redis.Set(keyTwo, "", time.Second)
  1970. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1971. redis.Set(keyThree, "", time.Second)
  1972. theTimes := theTime.Format("2006-01-02")
  1973. fmt.Println("theTIME", theTime)
  1974. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1975. redis.Set(keyFour, "", time.Second)
  1976. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1977. redis.Set(keyFive, "", time.Second)
  1978. defer redis.Close()
  1979. } else {
  1980. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1981. //记录日志
  1982. byterequest, _ := json.Marshal(exceAdvice)
  1983. doctorAdviceLog := models.XtDoctorAdviceLog{
  1984. UserOrgId: exceAdvice.UserOrgId,
  1985. PatientId: exceAdvice.PatientId,
  1986. AdminUserId: adminUserInfo.AdminUser.Id,
  1987. Module: 2,
  1988. ErrLog: string(byterequest),
  1989. Status: 1,
  1990. Ctime: time.Now().Unix(),
  1991. Mtime: 0,
  1992. Source: "电脑端执行医嘱",
  1993. RecordDate: exceAdvice.RecordDate,
  1994. }
  1995. service.CreateDoctorAdviceLog(doctorAdviceLog)
  1996. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1997. redis := service.RedisClient()
  1998. //清空key 值
  1999. redis.Set(key, "", time.Second)
  2000. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2001. redis.Set(keyTwo, "", time.Second)
  2002. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2003. redis.Set(keyThree, "", time.Second)
  2004. theTimes := theTime.Format("2006-01-02")
  2005. fmt.Println("theTIME", theTime)
  2006. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2007. redis.Set(keyFour, "", time.Second)
  2008. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2009. redis.Set(keyFive, "", time.Second)
  2010. defer redis.Close()
  2011. }
  2012. if err != nil {
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2014. return
  2015. }
  2016. advice.ExecutionStaff = executionStaff
  2017. advice.ExecutionTime = theTime.Unix()
  2018. //处理出库相关逻辑
  2019. //1.判断是否启用药品管理和自备药出库功能
  2020. //药品管理信息
  2021. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2022. //自备药信息
  2023. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  2024. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2025. if drugStockConfig.IsOpen == 1 {
  2026. var total int64
  2027. var prescribing_number_total int64
  2028. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2029. for _, item := range advices {
  2030. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2031. //查询该药品是否有库存
  2032. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  2033. //查询改药品信息
  2034. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  2035. //判断单位是否相等
  2036. if medical.MaxUnit == item.PrescribingNumberUnit {
  2037. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2038. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2039. //转化为最小单位
  2040. total = list.Count*medical.MinNumber + list.StockMinNumber
  2041. prescribing_number_total = count * medical.MinNumber
  2042. }
  2043. if medical.MinUnit == item.PrescribingNumberUnit {
  2044. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2045. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2046. total = list.Count*medical.MinNumber + list.StockMinNumber
  2047. prescribing_number_total = count
  2048. }
  2049. if medical.IsUse != 1 {
  2050. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2051. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2052. advice.ExecutionState = 2
  2053. advice.ExecutionStaff = 0
  2054. advice.ExecutionTime = 0
  2055. c.ServeSuccessJSON(map[string]interface{}{
  2056. "msg": "3",
  2057. "advice": advice,
  2058. })
  2059. return
  2060. }
  2061. if prescribing_number_total > total {
  2062. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  2063. advice.ExecutionState = 2
  2064. advice.ExecutionStaff = 0
  2065. advice.ExecutionTime = 0
  2066. c.ServeSuccessJSON(map[string]interface{}{
  2067. "msg": "2",
  2068. "advice": advice,
  2069. })
  2070. return
  2071. }
  2072. }
  2073. if medical.IsUse == 1 {
  2074. c.ServeSuccessJSON(map[string]interface{}{
  2075. "msg": "1",
  2076. "advice": advice,
  2077. })
  2078. return
  2079. }
  2080. if prescribing_number_total <= total {
  2081. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  2082. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  2083. if adviceSetting.IsAdviceOpen == 1 {
  2084. //查询是否出库按钮开启
  2085. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  2086. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2087. if prescriptionConfig.IsOpen == 1 {
  2088. if medical.IsUse == 2 {
  2089. //是通过药房发药
  2090. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2091. //执行出库
  2092. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2093. if drugOutInfo.ID == 0 {
  2094. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2095. }
  2096. }
  2097. //不通过药房发药
  2098. if pharmacyConfig.IsOpen != 1 {
  2099. //执行出库
  2100. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2101. if drugOutInfo.ID == 0 {
  2102. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2103. }
  2104. }
  2105. //查询默认仓库
  2106. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2107. //查询默认仓库剩余多少库存
  2108. var sum_count int64
  2109. //更新字典里面的库存
  2110. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2111. for _, its := range stockInfo {
  2112. if its.MaxUnit == medical.MaxUnit {
  2113. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2114. }
  2115. sum_count += its.StockMaxNumber + its.StockMinNumber
  2116. }
  2117. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2118. //剩余库存
  2119. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2120. break
  2121. c.ServeSuccessJSON(map[string]interface{}{
  2122. "msg": "1",
  2123. "advice": advice,
  2124. })
  2125. return
  2126. }
  2127. if medical.IsUse == 1 {
  2128. c.ServeSuccessJSON(map[string]interface{}{
  2129. "msg": "1",
  2130. "advice": advice,
  2131. })
  2132. return
  2133. }
  2134. } else {
  2135. if medical.IsUse == 1 {
  2136. c.ServeSuccessJSON(map[string]interface{}{
  2137. "msg": "1",
  2138. "advice": advice,
  2139. })
  2140. return
  2141. }
  2142. }
  2143. } else {
  2144. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2145. if medical.IsUse == 2 {
  2146. //是通过药房发药
  2147. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2148. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2149. if drugOutInfo.ID == 0 {
  2150. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2151. }
  2152. }
  2153. //不通过药房发药
  2154. if pharmacyConfig.IsOpen != 1 {
  2155. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  2156. if drugOutInfo.ID == 0 {
  2157. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2158. }
  2159. }
  2160. //更新字典里面的库存
  2161. var sum_count int64
  2162. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2163. for _, its := range stockInfo {
  2164. if its.MaxUnit == medical.MaxUnit {
  2165. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2166. }
  2167. sum_count += its.StockMaxNumber + its.StockMinNumber
  2168. }
  2169. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2170. //剩余库存
  2171. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2172. break
  2173. c.ServeSuccessJSON(map[string]interface{}{
  2174. "msg": "1",
  2175. "advice": advice,
  2176. })
  2177. return
  2178. }
  2179. if medical.IsUse == 1 {
  2180. c.ServeSuccessJSON(map[string]interface{}{
  2181. "msg": "1",
  2182. "advice": advice,
  2183. })
  2184. return
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  2191. for _, item := range advices {
  2192. if item.Way == 2 {
  2193. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  2194. if item.ExecutionState == 1 {
  2195. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  2196. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2197. timeStr := time.Now().Format("2006-01-02")
  2198. timeArr := strings.Split(timeStr, "-")
  2199. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  2200. total = total + 1
  2201. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2202. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2203. number = number + total
  2204. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2205. //插入自备药出库单
  2206. outStock := models.XtSelfOutStock{
  2207. DrugName: item.AdviceName,
  2208. DrugNameId: item.DrugId,
  2209. DrugSpec: item.AdviceDesc,
  2210. OutstoreNumber: count,
  2211. AdminUserId: adminUserInfo.AdminUser.Id,
  2212. StorckTime: item.RecordDate,
  2213. UserOrgId: adminUserInfo.CurrentOrgId,
  2214. CreatedTime: time.Now().Unix(),
  2215. Status: 1,
  2216. PatientId: item.PatientId,
  2217. ExitMode: 2,
  2218. MedicId: item.DrugId,
  2219. StockOutNumber: warehousing_out_order,
  2220. }
  2221. service.CreateOutStock(&outStock)
  2222. }
  2223. }
  2224. }
  2225. }
  2226. c.ServeSuccessJSON(map[string]interface{}{
  2227. "msg": "1",
  2228. "advice": advice,
  2229. })
  2230. return
  2231. } else {
  2232. if id <= 0 || patient <= 0 {
  2233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2234. return
  2235. }
  2236. if len(executionTime) <= 0 {
  2237. utils.ErrorLog("execution_time")
  2238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. adminUserInfo := c.GetAdminUserInfo()
  2242. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2243. if advice.ID == 0 || advice.PatientId != patient {
  2244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2245. return
  2246. }
  2247. //医嘱已执行
  2248. if advice.ExecutionState == 1 {
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2250. return
  2251. }
  2252. executionStaff := adminUserInfo.AdminUser.Id
  2253. timeLayout := "2006-01-02 15:04:05"
  2254. loc, _ := time.LoadLocation("Local")
  2255. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2256. if err != nil {
  2257. utils.ErrorLog(err.Error())
  2258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2259. return
  2260. }
  2261. if advice.StartTime > theTime.Unix() {
  2262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2263. return
  2264. }
  2265. exceAdvice := models.HisDoctorAdviceInfo{
  2266. ExecutionStaff: executionStaff,
  2267. ExecutionTime: theTime.Unix(),
  2268. UpdatedTime: time.Now().Unix(),
  2269. }
  2270. if advice.ParentId > 0 {
  2271. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2272. //记录日志
  2273. byterequest, _ := json.Marshal(exceAdvice)
  2274. doctorAdviceLog := models.XtDoctorAdviceLog{
  2275. UserOrgId: exceAdvice.UserOrgId,
  2276. PatientId: exceAdvice.PatientId,
  2277. AdminUserId: adminUserInfo.AdminUser.Id,
  2278. Module: 2,
  2279. ErrLog: string(byterequest),
  2280. Status: 1,
  2281. Ctime: time.Now().Unix(),
  2282. Mtime: 0,
  2283. Source: "电脑端执行His医嘱",
  2284. RecordDate: exceAdvice.RecordDate,
  2285. }
  2286. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2287. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2288. redis := service.RedisClient()
  2289. //清空key 值
  2290. redis.Set(key, "", time.Second)
  2291. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2292. redis.Set(keyTwo, "", time.Second)
  2293. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2294. redis.Set(keyThree, "", time.Second)
  2295. theTimes := theTime.Format("2006-01-02")
  2296. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2297. redis.Set(keyFour, "", time.Second)
  2298. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2299. redis.Set(keyFive, "", time.Second)
  2300. defer redis.Close()
  2301. } else {
  2302. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  2303. //记录日志
  2304. byterequest, _ := json.Marshal(exceAdvice)
  2305. doctorAdviceLog := models.XtDoctorAdviceLog{
  2306. UserOrgId: exceAdvice.UserOrgId,
  2307. PatientId: exceAdvice.PatientId,
  2308. AdminUserId: adminUserInfo.AdminUser.Id,
  2309. Module: 2,
  2310. ErrLog: string(byterequest),
  2311. Status: 1,
  2312. Ctime: time.Now().Unix(),
  2313. Mtime: 0,
  2314. Source: "电脑端执行His医嘱",
  2315. RecordDate: exceAdvice.RecordDate,
  2316. }
  2317. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2318. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2319. redis := service.RedisClient()
  2320. //清空key 值
  2321. redis.Set(key, "", time.Second)
  2322. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2323. redis.Set(keyTwo, "", time.Second)
  2324. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2325. redis.Set(keyThree, "", time.Second)
  2326. theTimes := theTime.Format("2006-01-02")
  2327. fmt.Println("theTIME", theTime)
  2328. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2329. redis.Set(keyFour, "", time.Second)
  2330. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2331. redis.Set(keyFive, "", time.Second)
  2332. defer redis.Close()
  2333. }
  2334. if err != nil {
  2335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2336. return
  2337. }
  2338. advice.ExecutionStaff = executionStaff
  2339. advice.ExecutionTime = theTime.Unix()
  2340. //处理出库相关逻辑
  2341. //1.判断是否启用药品管理和自备药出库功能
  2342. //药品管理信息
  2343. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  2344. if drugStockConfig.IsOpen == 1 {
  2345. //查询已经执行的医嘱
  2346. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  2347. for _, item := range advices {
  2348. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  2349. //查询这个患者这个患者这个药已经出库的所有数量
  2350. //advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2351. //drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  2352. //var total_count int64 // 现在出库的
  2353. //var drug_count int64 // 已经出库的
  2354. //for _, it := range advicelist {
  2355. // if it.PrescribingNumberUnit == medical.MaxUnit {
  2356. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2357. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2358. // total_count += prenumber * medical.MinNumber
  2359. // }
  2360. // if it.PrescribingNumberUnit == medical.MinUnit {
  2361. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  2362. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2363. // total_count += prenumber
  2364. // }
  2365. //
  2366. //}
  2367. //
  2368. //
  2369. //for _, its := range drugoutlist {
  2370. // if its.CountUnit == medical.MaxUnit {
  2371. // drug_count += its.Count * medical.MinNumber
  2372. // }
  2373. // if its.CountUnit == medical.MinUnit {
  2374. // drug_count += its.Count
  2375. // }
  2376. //}
  2377. //fmt.Println("total_count23232323232323232wode",total_count)
  2378. //fmt.Println("total_count23232323232323232wode",drug_count)
  2379. //if total_count == drug_count {
  2380. // c.ServeSuccessJSON(map[string]interface{}{
  2381. // "msg": "1",
  2382. // "advice": advice,
  2383. // })
  2384. // return
  2385. //}
  2386. var total int64
  2387. var prescribing_number_total int64
  2388. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2389. if config.IsOpen != 1 {
  2390. //查询默认出库仓库
  2391. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2392. //查询该药品在默认仓库是否有库存
  2393. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2394. //判断单位是否相等
  2395. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2396. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2397. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2398. //转化为最小单位
  2399. total = list.Count*medical.MinNumber + list.StockMinNumber
  2400. prescribing_number_total = count * medical.MinNumber
  2401. }
  2402. if medical.MinUnit == advice.PrescribingNumberUnit {
  2403. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2404. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2405. total = list.Count*medical.MinNumber + list.StockMinNumber
  2406. prescribing_number_total = count
  2407. }
  2408. if medical.IsUse == 1 {
  2409. drugError := models.XtDrugError{
  2410. UserOrgId: item.UserOrgId,
  2411. DrugId: item.DrugId,
  2412. RecordDate: item.AdviceDate,
  2413. PatientId: item.PatientId,
  2414. Remark: "电脑端零用药品",
  2415. Status: 1,
  2416. Ctime: time.Now().Unix(),
  2417. Mtime: 0,
  2418. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2419. Prescribingnumber: item.PrescribingNumber,
  2420. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2421. }
  2422. service.CreateDrugError(drugError)
  2423. c.ServeSuccessJSON(map[string]interface{}{
  2424. "msg": "1",
  2425. "advice": advice,
  2426. })
  2427. return
  2428. }
  2429. if medical.IsUse != 1 {
  2430. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2431. drugError := models.XtDrugError{
  2432. UserOrgId: item.UserOrgId,
  2433. DrugId: item.DrugId,
  2434. RecordDate: item.AdviceDate,
  2435. PatientId: item.PatientId,
  2436. Remark: "电脑端药品库存不足",
  2437. Status: 1,
  2438. Ctime: time.Now().Unix(),
  2439. Mtime: 0,
  2440. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2441. Prescribingnumber: item.PrescribingNumber,
  2442. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2443. }
  2444. service.CreateDrugError(drugError)
  2445. c.ServeSuccessJSON(map[string]interface{}{
  2446. "msg": "3",
  2447. "advice": advice,
  2448. })
  2449. return
  2450. }
  2451. if prescribing_number_total > total {
  2452. drugError := models.XtDrugError{
  2453. UserOrgId: item.UserOrgId,
  2454. DrugId: item.DrugId,
  2455. RecordDate: item.AdviceDate,
  2456. PatientId: item.PatientId,
  2457. Remark: "电脑端出库数量大于总库存",
  2458. Status: 1,
  2459. Ctime: time.Now().Unix(),
  2460. Mtime: 0,
  2461. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2462. Prescribingnumber: item.PrescribingNumber,
  2463. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2464. }
  2465. service.CreateDrugError(drugError)
  2466. c.ServeSuccessJSON(map[string]interface{}{
  2467. "msg": "2",
  2468. "advice": advice,
  2469. })
  2470. return
  2471. }
  2472. }
  2473. if prescribing_number_total <= total {
  2474. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2475. if medical.IsUse == 2 {
  2476. if config.IsOpen != 1 {
  2477. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2478. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2479. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2480. //查询该药品是否有出库记录
  2481. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2482. if len(flowMap) == 0 {
  2483. errs := service.UpdateHisAdviceById(item.ID)
  2484. if errs != nil {
  2485. drugError := models.XtDrugError{
  2486. UserOrgId: item.UserOrgId,
  2487. DrugId: item.DrugId,
  2488. RecordDate: item.AdviceDate,
  2489. PatientId: item.PatientId,
  2490. Remark: "出库记录为空,更新执行人失败",
  2491. Status: 1,
  2492. Ctime: time.Now().Unix(),
  2493. Mtime: 0,
  2494. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2495. Prescribingnumber: item.PrescribingNumber,
  2496. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2497. }
  2498. service.CreateDrugError(drugError)
  2499. }
  2500. c.ServeSuccessJSON(map[string]interface{}{
  2501. "msg": "6",
  2502. "advice": advice,
  2503. })
  2504. return
  2505. }
  2506. }
  2507. }
  2508. //不通过药房发药
  2509. if pharmacyConfig.IsOpen != 1 {
  2510. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2511. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2512. //查询该药品是否有出库记录
  2513. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2514. if len(flowMap) == 0 {
  2515. errs := service.UpdateHisAdviceById(item.ID)
  2516. if errs != nil {
  2517. drugError := models.XtDrugError{
  2518. UserOrgId: item.UserOrgId,
  2519. DrugId: item.DrugId,
  2520. RecordDate: item.AdviceDate,
  2521. PatientId: item.PatientId,
  2522. Remark: "出库记录为空,更新执行人失败",
  2523. Status: 1,
  2524. Ctime: time.Now().Unix(),
  2525. Mtime: 0,
  2526. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2527. Prescribingnumber: item.PrescribingNumber,
  2528. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2529. }
  2530. service.CreateDrugError(drugError)
  2531. }
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "msg": "6",
  2534. "advice": advice,
  2535. })
  2536. return
  2537. }
  2538. }
  2539. }
  2540. //查询默认仓库
  2541. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2542. //查询默认仓库剩余多少库存
  2543. var sum_count int64
  2544. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2545. for _, its := range stockInfo {
  2546. if its.MaxUnit == medical.MaxUnit {
  2547. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2548. }
  2549. sum_count += its.StockMaxNumber + its.StockMinNumber
  2550. }
  2551. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2552. //出库数量累加
  2553. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2554. //剩余库存
  2555. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2556. break
  2557. c.ServeSuccessJSON(map[string]interface{}{
  2558. "msg": "1",
  2559. "advice": advice,
  2560. })
  2561. return
  2562. }
  2563. }
  2564. if medical.IsUse == 1 {
  2565. c.ServeSuccessJSON(map[string]interface{}{
  2566. "msg": "1",
  2567. "advice": advice,
  2568. })
  2569. return
  2570. }
  2571. }
  2572. }
  2573. }
  2574. }
  2575. c.ServeSuccessJSON(map[string]interface{}{
  2576. "msg": "1",
  2577. "advice": advice,
  2578. })
  2579. return
  2580. }
  2581. }
  2582. func (c *PatientApiController) CheckGroupAdvice() {
  2583. groupno, _ := c.GetInt64("groupno", 0)
  2584. if groupno <= 0 {
  2585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2586. return
  2587. }
  2588. adminUserInfo := c.GetAdminUserInfo()
  2589. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2590. if advice.ID == 0 {
  2591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2592. return
  2593. }
  2594. if advice.CheckState == 1 {
  2595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2596. return
  2597. }
  2598. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2600. return
  2601. }
  2602. checker := adminUserInfo.AdminUser.Id
  2603. theTime := time.Now()
  2604. exceAdvice := models.DoctorAdvice{
  2605. Checker: checker,
  2606. CheckTime: theTime.Unix(),
  2607. UpdatedTime: time.Now().Unix(),
  2608. }
  2609. var err error
  2610. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2611. if err != nil {
  2612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2613. return
  2614. }
  2615. advice.Checker = checker
  2616. advice.CheckTime = theTime.Unix()
  2617. c.ServeSuccessJSON(map[string]interface{}{
  2618. "msg": "ok",
  2619. "advice": advice,
  2620. })
  2621. return
  2622. }
  2623. func (c *PatientApiController) CheckDoctorAdvice() {
  2624. patient, _ := c.GetInt64("patient", 0)
  2625. id, _ := c.GetInt64("id", 0)
  2626. origin, _ := c.GetInt64("origin", 0)
  2627. if origin != 2 {
  2628. // executionTime := c.GetString("execution_time")
  2629. if id <= 0 || patient <= 0 {
  2630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2631. return
  2632. }
  2633. adminUserInfo := c.GetAdminUserInfo()
  2634. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2635. if advice.ID == 0 || advice.PatientId != patient {
  2636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2637. return
  2638. }
  2639. if advice.CheckState == 1 {
  2640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2641. return
  2642. }
  2643. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2645. return
  2646. }
  2647. // executionStaff := adminUserInfo.AdminUser.Id
  2648. checker := adminUserInfo.AdminUser.Id
  2649. // timeLayout := "2006-01-02 15:04:05"
  2650. // loc, _ := time.LoadLocation("Local")
  2651. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2652. // if err != nil {
  2653. // utils.ErrorLog(err.Error())
  2654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2655. // return
  2656. // }
  2657. theTime := time.Now()
  2658. if advice.ExecutionTime > theTime.Unix() {
  2659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2660. return
  2661. }
  2662. exceAdvice := models.DoctorAdvice{
  2663. Checker: checker,
  2664. CheckTime: theTime.Unix(),
  2665. UpdatedTime: time.Now().Unix(),
  2666. }
  2667. var err error
  2668. // 查询信息规挡的设置天数
  2669. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2670. if infor.ID > 0 && infor.WeekDay > 0 {
  2671. var cha_time int64
  2672. timeNowStr := time.Now().Format("2006-01-02")
  2673. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2674. //今日的日期减去设置的日期
  2675. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2676. if cha_time >= advice.AdviceDate {
  2677. //查询审核是否允许
  2678. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2679. //申请状态不允许的情况 拒绝修改
  2680. if infor.ApplicationStatus != 1 {
  2681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2682. return
  2683. }
  2684. }
  2685. }
  2686. if advice.ParentId > 0 {
  2687. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2688. //记录日志
  2689. byterequest, _ := json.Marshal(exceAdvice)
  2690. adviceLog := models.XtDoctorAdviceLog{
  2691. UserOrgId: exceAdvice.UserOrgId,
  2692. PatientId: exceAdvice.PatientId,
  2693. AdminUserId: adminUserInfo.AdminUser.Id,
  2694. Module: 3,
  2695. ErrLog: string(byterequest),
  2696. Status: 1,
  2697. Ctime: time.Now().Unix(),
  2698. Mtime: 0,
  2699. Source: "核对医嘱",
  2700. RecordDate: exceAdvice.AdviceDate,
  2701. }
  2702. service.CreateDoctorAdviceLog(adviceLog)
  2703. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2704. redis := service.RedisClient()
  2705. //清空key 值
  2706. redis.Set(key, "", time.Second)
  2707. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2708. redis.Set(keyTwo, "", time.Second)
  2709. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2710. redis.Set(keyThree, "", time.Second)
  2711. recordDate := theTime.Format("2006-01-02")
  2712. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2713. redis.Set(keyFour, "", time.Second)
  2714. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2715. redis.Set(keyFive, "", time.Second)
  2716. } else {
  2717. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2718. //记录日志
  2719. byterequest, _ := json.Marshal(exceAdvice)
  2720. adviceLog := models.XtDoctorAdviceLog{
  2721. UserOrgId: exceAdvice.UserOrgId,
  2722. PatientId: exceAdvice.PatientId,
  2723. AdminUserId: adminUserInfo.AdminUser.Id,
  2724. Module: 3,
  2725. ErrLog: string(byterequest),
  2726. Status: 1,
  2727. Ctime: time.Now().Unix(),
  2728. Mtime: 0,
  2729. Source: "核对医嘱",
  2730. RecordDate: exceAdvice.AdviceDate,
  2731. }
  2732. service.CreateDoctorAdviceLog(adviceLog)
  2733. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2734. redis := service.RedisClient()
  2735. //清空key 值
  2736. redis.Set(key, "", time.Second)
  2737. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2738. redis.Set(keyTwo, "", time.Second)
  2739. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2740. redis.Set(keyThree, "", time.Second)
  2741. recordDate := theTime.Format("2006-01-02")
  2742. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2743. redis.Set(keyFour, "", time.Second)
  2744. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2745. redis.Set(keyFive, "", time.Second)
  2746. }
  2747. if err != nil {
  2748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2749. return
  2750. }
  2751. // advice.ExecutionStaff = executionStaff
  2752. // advice.ExecutionTime = theTime.Unix()
  2753. advice.Checker = checker
  2754. advice.CheckTime = theTime.Unix()
  2755. c.ServeSuccessJSON(map[string]interface{}{
  2756. "msg": "ok",
  2757. "advice": advice,
  2758. })
  2759. return
  2760. } else {
  2761. if id <= 0 || patient <= 0 {
  2762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2763. return
  2764. }
  2765. adminUserInfo := c.GetAdminUserInfo()
  2766. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2767. if advice.ID == 0 || advice.PatientId != patient {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2769. return
  2770. }
  2771. if advice.CheckState == 1 {
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2773. return
  2774. }
  2775. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2777. return
  2778. }
  2779. checker := adminUserInfo.AdminUser.Id
  2780. theTime := time.Now()
  2781. if advice.ExecutionTime > theTime.Unix() {
  2782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2783. return
  2784. }
  2785. exceAdvice := models.HisDoctorAdviceInfo{
  2786. Checker: checker,
  2787. CheckTime: theTime.Unix(),
  2788. UpdatedTime: time.Now().Unix(),
  2789. }
  2790. var err error
  2791. if advice.ParentId > 0 {
  2792. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2793. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2794. redis := service.RedisClient()
  2795. //清空key 值
  2796. redis.Set(key, "", time.Second)
  2797. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2798. redis.Set(keyTwo, "", time.Second)
  2799. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2800. redis.Set(keyThree, "", time.Second)
  2801. recordDate := theTime.Format("2006-01-02")
  2802. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2803. redis.Set(keyFour, "", time.Second)
  2804. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2805. redis.Set(keyFive, "", time.Second)
  2806. } else {
  2807. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2808. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2809. redis := service.RedisClient()
  2810. //清空key 值
  2811. redis.Set(key, "", time.Second)
  2812. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2813. redis.Set(keyTwo, "", time.Second)
  2814. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2815. redis.Set(keyThree, "", time.Second)
  2816. recordDate := theTime.Format("2006-01-02")
  2817. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2818. redis.Set(keyFour, "", time.Second)
  2819. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2820. redis.Set(keyFive, "", time.Second)
  2821. }
  2822. if err != nil {
  2823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2824. return
  2825. }
  2826. // advice.ExecutionStaff = executionStaff
  2827. // advice.ExecutionTime = theTime.Unix()
  2828. advice.Checker = checker
  2829. advice.CheckTime = theTime.Unix()
  2830. c.ServeSuccessJSON(map[string]interface{}{
  2831. "msg": "ok",
  2832. "advice": advice,
  2833. })
  2834. return
  2835. }
  2836. }
  2837. func (c *PatientApiController) UpdateDoctorAdvice() {
  2838. patient, _ := c.GetInt64("patient", 0)
  2839. id, _ := c.GetInt64("id", 0)
  2840. if id <= 0 || patient <= 0 {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2842. return
  2843. }
  2844. adminUserInfo := c.GetAdminUserInfo()
  2845. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2846. if advice.ID == 0 || advice.PatientId != patient {
  2847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2848. return
  2849. }
  2850. //if advice.AdviceType == 1 {
  2851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2852. // return
  2853. //}
  2854. if adminUserInfo.CurrentOrgId != 10612 && adminUserInfo.CurrentOrgId != 10460 {
  2855. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2857. return
  2858. }
  2859. }
  2860. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2861. //if appRole.UserType == 3 {
  2862. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2863. // if getPermissionErr != nil {
  2864. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2865. // return
  2866. // } else if headNursePermission == nil {
  2867. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2868. // return
  2869. // }
  2870. //}
  2871. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2873. // return
  2874. //}
  2875. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2876. if code > 0 {
  2877. c.ServeFailJSONWithSGJErrorCode(code)
  2878. return
  2879. }
  2880. advice.UpdatedTime = time.Now().Unix()
  2881. advice.Modifier = adminUserInfo.AdminUser.Id
  2882. // 查询信息规挡的设置天数
  2883. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2884. if infor.ID > 0 && infor.WeekDay > 0 {
  2885. var cha_time int64
  2886. timeNowStr := time.Now().Format("2006-01-02")
  2887. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2888. //今日的日期减去设置的日期
  2889. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2890. if cha_time >= advice.AdviceDate {
  2891. //查询审核是否允许
  2892. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  2893. //申请状态不允许的情况 拒绝修改
  2894. if infor.ApplicationStatus != 1 {
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2896. return
  2897. }
  2898. }
  2899. }
  2900. err := service.UpdateDoctorAdvice(&advice)
  2901. //记录日志
  2902. byterequest, _ := json.Marshal(advice)
  2903. doctorAdviceLog := models.XtDoctorAdviceLog{
  2904. UserOrgId: advice.UserOrgId,
  2905. PatientId: advice.PatientId,
  2906. AdminUserId: adminUserInfo.AdminUser.Id,
  2907. Module: 1,
  2908. ErrLog: string(byterequest),
  2909. Status: 1,
  2910. Ctime: time.Now().Unix(),
  2911. Mtime: 0,
  2912. Source: "电脑端修改医嘱",
  2913. RecordDate: advice.AdviceDate,
  2914. }
  2915. service.CreateDoctorAdviceLog(doctorAdviceLog)
  2916. redis := service.RedisClient()
  2917. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2918. redis.Set(key, "", time.Second)
  2919. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2920. redis.Set(keyOne, "", time.Second)
  2921. defer redis.Close()
  2922. if err != nil {
  2923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2924. return
  2925. }
  2926. c.ServeSuccessJSON(map[string]interface{}{
  2927. "msg": "ok",
  2928. "advice": advice,
  2929. })
  2930. return
  2931. }
  2932. func (c *PatientApiController) StopGroupAdvice() {
  2933. groupNo, _ := c.GetInt64("groupno", 0)
  2934. if groupNo <= 0 {
  2935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. return
  2937. }
  2938. adminUserInfo := c.GetAdminUserInfo()
  2939. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2940. if advice.ID == 0 {
  2941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2942. return
  2943. }
  2944. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2946. return
  2947. }
  2948. dataBody := make(map[string]interface{}, 0)
  2949. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2950. if err != nil {
  2951. utils.ErrorLog(err.Error())
  2952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2953. return
  2954. }
  2955. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2956. utils.ErrorLog("stop_time")
  2957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2958. return
  2959. }
  2960. stopTime, _ := dataBody["stop_time"].(string)
  2961. if len(stopTime) == 0 {
  2962. utils.ErrorLog("len(stop_time) == 0")
  2963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2964. return
  2965. }
  2966. timeLayout := "2006-01-02"
  2967. loc, _ := time.LoadLocation("Local")
  2968. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2969. if err != nil {
  2970. utils.ErrorLog(err.Error())
  2971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2972. return
  2973. }
  2974. advice.StopTime = theTime.Unix()
  2975. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2976. stopReason, _ := dataBody["stop_reason"].(string)
  2977. advice.StopReason = stopReason
  2978. }
  2979. advice.UpdatedTime = time.Now().Unix()
  2980. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2981. advice.StopState = 1
  2982. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2983. if err != nil {
  2984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2985. return
  2986. }
  2987. c.ServeSuccessJSON(map[string]interface{}{
  2988. "msg": "ok",
  2989. })
  2990. return
  2991. }
  2992. func (c *PatientApiController) StopDoctorAdvice() {
  2993. id, _ := c.GetInt64("id", 0)
  2994. if id <= 0 {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2996. return
  2997. }
  2998. adminUserInfo := c.GetAdminUserInfo()
  2999. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3000. //
  3001. //if appRole.UserType == 3 {
  3002. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3003. // if getPermissionErr != nil {
  3004. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3005. // return
  3006. // } else if headNursePermission == nil {
  3007. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3008. // return
  3009. // }
  3010. //}
  3011. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3012. if advice.ID == 0 {
  3013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3014. return
  3015. }
  3016. if advice.StopState == 1 || advice.ExecutionState == 1 {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3018. return
  3019. }
  3020. dataBody := make(map[string]interface{}, 0)
  3021. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3022. if err != nil {
  3023. utils.ErrorLog(err.Error())
  3024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3025. return
  3026. }
  3027. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  3028. utils.ErrorLog("stop_time")
  3029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3030. return
  3031. }
  3032. stopTime, _ := dataBody["stop_time"].(string)
  3033. if len(stopTime) == 0 {
  3034. utils.ErrorLog("len(stop_time) == 0")
  3035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3036. return
  3037. }
  3038. timeLayout := "2006-01-02"
  3039. loc, _ := time.LoadLocation("Local")
  3040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  3041. if err != nil {
  3042. utils.ErrorLog(err.Error())
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. advice.StopTime = theTime.Unix()
  3047. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  3048. stopReason, _ := dataBody["stop_reason"].(string)
  3049. advice.StopReason = stopReason
  3050. }
  3051. advice.UpdatedTime = time.Now().Unix()
  3052. advice.StopDoctor = adminUserInfo.AdminUser.Id
  3053. advice.StopState = 1
  3054. err = service.StopDoctorAdvice(&advice)
  3055. if err != nil {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  3057. return
  3058. }
  3059. c.ServeSuccessJSON(map[string]interface{}{
  3060. "msg": "ok",
  3061. "advice": advice,
  3062. })
  3063. return
  3064. }
  3065. func (c *PatientApiController) DeleteDoctorAdvice() {
  3066. id, _ := c.GetInt64("id", 0)
  3067. if id <= 0 {
  3068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3069. return
  3070. }
  3071. adminUserInfo := c.GetAdminUserInfo()
  3072. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3073. if advice.ID == 0 {
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3075. return
  3076. }
  3077. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3079. // return
  3080. //}
  3081. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3082. //
  3083. //if appRole.UserType == 3 {
  3084. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3085. // if getPermissionErr != nil {
  3086. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3087. // return
  3088. // } else if headNursePermission == nil {
  3089. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3090. // return
  3091. // }
  3092. //}
  3093. advice.UpdatedTime = time.Now().Unix()
  3094. advice.Status = 0
  3095. advice.Modifier = adminUserInfo.AdminUser.Id
  3096. // 查询信息规挡的设置天数
  3097. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3098. if infor.ID > 0 && infor.WeekDay > 0 {
  3099. var cha_time int64
  3100. timeNowStr := time.Now().Format("2006-01-02")
  3101. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3102. //今日的日期减去设置的日期
  3103. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3104. if cha_time >= advice.AdviceDate {
  3105. //查询审核是否允许
  3106. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3107. //申请状态不允许的情况 拒绝修改
  3108. if infor.ApplicationStatus != 1 {
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3110. return
  3111. }
  3112. }
  3113. }
  3114. err := service.DeleteDoctorAdvice(&advice)
  3115. //记录日志
  3116. byterequest, _ := json.Marshal(advice)
  3117. doctorAdviceLog := models.XtDoctorAdviceLog{
  3118. UserOrgId: advice.UserOrgId,
  3119. PatientId: advice.PatientId,
  3120. AdminUserId: adminUserInfo.AdminUser.Id,
  3121. Module: 4,
  3122. ErrLog: string(byterequest),
  3123. Status: 1,
  3124. Ctime: time.Now().Unix(),
  3125. Mtime: 0,
  3126. Source: "电脑端删除医嘱",
  3127. RecordDate: advice.RecordDate,
  3128. }
  3129. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3130. redis := service.RedisClient()
  3131. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3132. redis.Set(keyOne, "", time.Second)
  3133. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3134. redis.Set(key, "", time.Second)
  3135. redis.Close()
  3136. if err != nil {
  3137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3138. return
  3139. }
  3140. c.ServeSuccessJSON(map[string]interface{}{
  3141. "msg": "ok",
  3142. })
  3143. return
  3144. }
  3145. func (c *PatientApiController) DeleteGroupAdvice() {
  3146. groupNo, _ := c.GetInt64("groupno", 0)
  3147. if groupNo <= 0 {
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3149. return
  3150. }
  3151. adminUserInfo := c.GetAdminUserInfo()
  3152. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  3153. if advice.ID == 0 {
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3155. return
  3156. }
  3157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3158. //if appRole.UserType == 3 {
  3159. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3160. // if getPermissionErr != nil {
  3161. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3162. // return
  3163. // } else if headNursePermission == nil {
  3164. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3165. // return
  3166. // }
  3167. //}
  3168. // 查询信息规挡的设置天数
  3169. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3170. if infor.ID > 0 && infor.WeekDay > 0 {
  3171. var cha_time int64
  3172. timeNowStr := time.Now().Format("2006-01-02")
  3173. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3174. //今日的日期减去设置的日期
  3175. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3176. if cha_time >= advice.AdviceDate {
  3177. //查询审核是否允许
  3178. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.CurrentOrgId, 4)
  3179. //申请状态不允许的情况 拒绝修改
  3180. if infor.ApplicationStatus != 1 {
  3181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3182. return
  3183. }
  3184. }
  3185. }
  3186. err := service.DeleteGroupAdviceOne(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  3187. byterequest, _ := json.Marshal(advice)
  3188. doctorAdviceLog := models.XtDoctorAdviceLog{
  3189. UserOrgId: advice.UserOrgId,
  3190. PatientId: advice.PatientId,
  3191. AdminUserId: adminUserInfo.AdminUser.Id,
  3192. Module: 4,
  3193. ErrLog: string(byterequest),
  3194. Status: 1,
  3195. Ctime: time.Now().Unix(),
  3196. Mtime: 0,
  3197. Source: "电脑端批量删除医嘱",
  3198. RecordDate: advice.RecordDate,
  3199. }
  3200. service.CreateDoctorAdviceLog(doctorAdviceLog)
  3201. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3202. redis := service.RedisClient()
  3203. redis.Set(key, "", time.Second)
  3204. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3205. redis.Set(keyOne, "", time.Second)
  3206. defer redis.Close()
  3207. if err != nil {
  3208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3209. return
  3210. }
  3211. c.ServeSuccessJSON(map[string]interface{}{
  3212. "msg": "ok",
  3213. })
  3214. return
  3215. }
  3216. // GetDoctorAdvices 医嘱列表
  3217. func (c *PatientApiController) GetDoctorAdvices() {
  3218. id, _ := c.GetInt64("id", 0)
  3219. adviceType, _ := c.GetInt64("advice_type", 0)
  3220. stopType, _ := c.GetInt64("stop_state", 0)
  3221. startTime := c.GetString("start_time", "")
  3222. endTime := c.GetString("end_time", "")
  3223. keywords := c.GetString("keywords", "")
  3224. page, _ := c.GetInt64("page")
  3225. fmt.Println("page", page)
  3226. limit, _ := c.GetInt64("limit")
  3227. fmt.Println("limit", limit)
  3228. adminUserInfo := c.GetAdminUserInfo()
  3229. operatorIDs := make([]int64, 0)
  3230. timeLayout := "2006-01-02"
  3231. loc, _ := time.LoadLocation("Local")
  3232. var theStartTIme int64
  3233. if len(startTime) > 0 {
  3234. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3235. if err != nil {
  3236. utils.ErrorLog(err.Error())
  3237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3238. return
  3239. }
  3240. theStartTIme = theTime.Unix()
  3241. }
  3242. var theEndtTIme int64
  3243. if len(endTime) > 0 {
  3244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3245. if err != nil {
  3246. utils.ErrorLog(err.Error())
  3247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3248. return
  3249. }
  3250. theEndtTIme = theTime.Unix()
  3251. }
  3252. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3253. if hisconfig.IsOpen == 1 {
  3254. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3255. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3256. if len(advices) > 0 {
  3257. for _, item := range advices {
  3258. if item.AdviceDoctor > 0 {
  3259. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3260. }
  3261. if item.ExecutionStaff > 0 {
  3262. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3263. }
  3264. if item.Checker > 0 {
  3265. operatorIDs = append(operatorIDs, item.Checker)
  3266. }
  3267. if item.StopDoctor > 0 {
  3268. operatorIDs = append(operatorIDs, item.StopDoctor)
  3269. }
  3270. }
  3271. }
  3272. //相关操作对应的操作人
  3273. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3274. //获取长期医嘱
  3275. longAdvice, _, _ := service.GetLongDoctorAdviceList(adminUserInfo.CurrentOrgId, id, 1, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3276. c.ServeSuccessJSON(map[string]interface{}{
  3277. "advices": advices,
  3278. "operators": operators,
  3279. "total": total,
  3280. "advicetwo": advicestwo,
  3281. "longAdvice": longAdvice,
  3282. "is_open": hisconfig.IsOpen,
  3283. })
  3284. return
  3285. } else {
  3286. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  3287. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  3288. if len(advices) > 0 {
  3289. for _, item := range advices {
  3290. if item.AdviceDoctor > 0 {
  3291. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3292. }
  3293. if item.ExecutionStaff > 0 {
  3294. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3295. }
  3296. if item.Checker > 0 {
  3297. operatorIDs = append(operatorIDs, item.Checker)
  3298. }
  3299. if item.StopDoctor > 0 {
  3300. operatorIDs = append(operatorIDs, item.StopDoctor)
  3301. }
  3302. }
  3303. }
  3304. //相关操作对应的操作人
  3305. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3306. c.ServeSuccessJSON(map[string]interface{}{
  3307. "advices": advices,
  3308. "operators": operators,
  3309. "total": total,
  3310. "advicetwo": advicestwo,
  3311. "is_open": hisconfig.IsOpen,
  3312. })
  3313. return
  3314. }
  3315. }
  3316. func (c *PatientApiController) GetPatientSchedules() {
  3317. id, _ := c.GetInt64("id", 0)
  3318. if id <= 0 {
  3319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3320. return
  3321. }
  3322. adminUserInfo := c.GetAdminUserInfo()
  3323. todayTime := time.Now().Format("2006-01-02")
  3324. timeLayout := "2006-01-02 15:04:05"
  3325. loc, _ := time.LoadLocation("Local")
  3326. var theStartTime int64
  3327. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3328. theStartTime = theTime.Unix()
  3329. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  3330. if len(schedules) > 0 {
  3331. for index, item := range schedules {
  3332. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3333. schedules[index].Week = int64(week)
  3334. }
  3335. }
  3336. c.ServeSuccessJSON(map[string]interface{}{
  3337. "schedules": schedules,
  3338. })
  3339. return
  3340. }
  3341. func (c *PatientApiController) GetPatientDialysisRecords() {
  3342. patientID, _ := c.GetInt64("patient_id", 0)
  3343. page, _ := c.GetInt64("page", 0)
  3344. limit, _ := c.GetInt64("limit", 0)
  3345. startTime := c.GetString("start_time", "")
  3346. endTime := c.GetString("end_time", "")
  3347. mode_id, _ := c.GetInt64("mode_id", 0)
  3348. if page <= 0 {
  3349. page = 1
  3350. }
  3351. if limit <= 0 {
  3352. limit = 10
  3353. }
  3354. if patientID <= 0 {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3356. return
  3357. }
  3358. timeLayout := "2006-01-02"
  3359. loc, _ := time.LoadLocation("Local")
  3360. var theStartTIme int64
  3361. if len(startTime) > 0 {
  3362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3363. if err != nil {
  3364. theStartTIme = 0
  3365. }
  3366. theStartTIme = theTime.Unix()
  3367. }
  3368. var theEndtTIme int64
  3369. if len(endTime) > 0 {
  3370. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3371. if err != nil {
  3372. theEndtTIme = 0
  3373. }
  3374. theEndtTIme = theTime.Unix()
  3375. }
  3376. adminInfo := c.GetAdminUserInfo()
  3377. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3378. c.ServeSuccessJSON(map[string]interface{}{
  3379. "total": total,
  3380. "records": records,
  3381. })
  3382. return
  3383. }
  3384. func (c *PatientApiController) ProEducation() {
  3385. patientID, _ := c.GetInt64("patient_id", 0)
  3386. page, _ := c.GetInt64("page", 0)
  3387. limit, _ := c.GetInt64("limit", 0)
  3388. startTime := c.GetString("start_time", "")
  3389. endTime := c.GetString("end_time", "")
  3390. if page <= 0 {
  3391. page = 1
  3392. }
  3393. if limit <= 0 {
  3394. limit = 10
  3395. }
  3396. if patientID <= 0 {
  3397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3398. return
  3399. }
  3400. timeLayout := "2006-01-02"
  3401. loc, _ := time.LoadLocation("Local")
  3402. var theStartTIme int64
  3403. if len(startTime) > 0 {
  3404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3405. if err != nil {
  3406. theStartTIme = 0
  3407. }
  3408. theStartTIme = theTime.Unix()
  3409. }
  3410. var theEndtTIme int64
  3411. if len(endTime) > 0 {
  3412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3413. if err != nil {
  3414. theEndtTIme = 0
  3415. }
  3416. theEndtTIme = theTime.Unix()
  3417. }
  3418. adminInfo := c.GetAdminUserInfo()
  3419. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  3420. c.ServeSuccessJSON(map[string]interface{}{
  3421. "total": total,
  3422. "edus": edus,
  3423. })
  3424. return
  3425. }
  3426. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3427. dataBody := make(map[string]interface{}, 0)
  3428. err := json.Unmarshal(data, &dataBody)
  3429. if err != nil {
  3430. utils.ErrorLog(err.Error())
  3431. code = enums.ErrorCodeParamWrong
  3432. return
  3433. }
  3434. timeLayout := "2006-01-02"
  3435. loc, _ := time.LoadLocation("Local")
  3436. isChild := false
  3437. if action == "create" {
  3438. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3439. utils.ErrorLog("advice_type")
  3440. code = enums.ErrorCodeParamWrong
  3441. return
  3442. }
  3443. adviceType := int64(dataBody["advice_type"].(float64))
  3444. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  3445. utils.ErrorLog("advice_type != 1&&2")
  3446. code = enums.ErrorCodeParamWrong
  3447. return
  3448. }
  3449. advice.AdviceType = adviceType
  3450. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3451. utils.ErrorLog("advice_date")
  3452. code = enums.ErrorCodeParamWrong
  3453. return
  3454. }
  3455. adviceDate, _ := dataBody["advice_date"].(string)
  3456. if len(adviceDate) == 0 {
  3457. utils.ErrorLog("len(adviceDate) == 0")
  3458. code = enums.ErrorCodeParamWrong
  3459. return
  3460. }
  3461. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3462. if err != nil {
  3463. utils.ErrorLog(err.Error())
  3464. code = enums.ErrorCodeParamWrong
  3465. return
  3466. }
  3467. advice.AdviceDate = theTime.Unix()
  3468. advice.RecordDate = theTime.Unix()
  3469. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3470. parentId := int64(dataBody["parent_id"].(float64))
  3471. advice.ParentId = parentId
  3472. if parentId > 0 {
  3473. isChild = true
  3474. }
  3475. }
  3476. }
  3477. if !isChild {
  3478. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3479. utils.ErrorLog("start_time")
  3480. code = enums.ErrorCodeParamWrong
  3481. return
  3482. }
  3483. startTime, _ := dataBody["start_time"].(string)
  3484. if len(startTime) == 0 {
  3485. utils.ErrorLog("len(start_time) == 0")
  3486. code = enums.ErrorCodeParamWrong
  3487. return
  3488. }
  3489. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  3490. if err != nil {
  3491. utils.ErrorLog(err.Error())
  3492. code = enums.ErrorCodeParamWrong
  3493. return
  3494. }
  3495. advice.StartTime = theTime.Unix()
  3496. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  3497. // utils.ErrorLog("advice_doctor")
  3498. // code = enums.ErrorCodeParamWrong
  3499. // return
  3500. // }
  3501. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  3502. // if adviceDoctor <= 0 {
  3503. // utils.ErrorLog("advice_doctor <=0")
  3504. // code = enums.ErrorCodeParamWrong
  3505. // return
  3506. // }
  3507. // advice.AdviceDoctor = adviceDoctor
  3508. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3509. deliveryWay, _ := dataBody["delivery_way"].(string)
  3510. advice.DeliveryWay = deliveryWay
  3511. }
  3512. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3513. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3514. advice.ExecutionFrequency = executionFrequency
  3515. }
  3516. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3517. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3518. frequency_type := int64(dataBody["frequency_type"].(float64))
  3519. advice.FrequencyType = frequency_type
  3520. }
  3521. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3522. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3523. advice.DayCount = day_count
  3524. }
  3525. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3526. week_day, _ := dataBody["week_days"].(string)
  3527. advice.WeekDay = week_day
  3528. }
  3529. }
  3530. }
  3531. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3532. utils.ErrorLog("advice_name")
  3533. code = enums.ErrorCodeParamWrong
  3534. return
  3535. }
  3536. adviceName, _ := dataBody["advice_name"].(string)
  3537. if len(adviceName) == 0 {
  3538. utils.ErrorLog("len(advice_name) == 0")
  3539. code = enums.ErrorCodeParamWrong
  3540. return
  3541. }
  3542. advice.AdviceName = adviceName
  3543. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3544. adviceDsc, _ := dataBody["advice_desc"].(string)
  3545. advice.AdviceDesc = adviceDsc
  3546. }
  3547. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3548. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3549. advice.DialysisOrderId = int64(dialysisOrderId)
  3550. }
  3551. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3552. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3553. advice.SingleDose = singleDose
  3554. }
  3555. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3556. singleDose := dataBody["single_dose"].(float64)
  3557. advice.SingleDose = singleDose
  3558. }
  3559. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3560. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3561. advice.SingleDoseUnit = singleDoseUnit
  3562. }
  3563. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3564. tmp := dataBody["single_dose_unit"].(float64)
  3565. singleDoseUnit := service.TypeConversion(tmp)
  3566. advice.SingleDoseUnit = singleDoseUnit
  3567. }
  3568. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3569. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3570. advice.DrugSpec = drugSpec
  3571. }
  3572. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3573. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3574. advice.DrugSpecUnit = drugSpecUnit
  3575. }
  3576. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3577. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3578. advice.PrescribingNumber = prescribingNumber
  3579. }
  3580. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3581. prescribingNumber := dataBody["prescribing_number"].(float64)
  3582. advice.PrescribingNumber = prescribingNumber
  3583. }
  3584. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3585. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3586. advice.PrescribingNumberUnit = prescribingNumberUnit
  3587. }
  3588. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3589. remark, _ := dataBody["remark"].(string)
  3590. advice.Remark = remark
  3591. }
  3592. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3593. drug_id, _ := dataBody["drug_id"].(string)
  3594. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3595. advice.DrugId = tmpDrugId
  3596. }
  3597. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3598. drug_id, _ := dataBody["drug_id"].(float64)
  3599. advice.DrugId = int64(drug_id)
  3600. }
  3601. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3602. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3603. advice.DrugNameId = int64(drug_name_id)
  3604. }
  3605. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3606. way, _ := dataBody["way"].(float64)
  3607. advice.Way = int64(way)
  3608. }
  3609. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3610. push_start_time, _ := dataBody["push_start_time"].(string)
  3611. var startTime int64
  3612. if len(push_start_time) > 0 {
  3613. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3614. startTime = theTime.Unix()
  3615. }
  3616. advice.PushStartTime = startTime
  3617. }
  3618. return
  3619. }
  3620. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3621. dataBody := make(map[string]interface{}, 0)
  3622. err := json.Unmarshal(data, &dataBody)
  3623. utils.InfoLog(string(data))
  3624. if err != nil {
  3625. utils.ErrorLog(err.Error())
  3626. code = enums.ErrorCodeParamWrong
  3627. return
  3628. }
  3629. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3630. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3631. solution.DialysisDuration = dialysisDuration
  3632. }
  3633. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3634. replacementWay := int64(dataBody["replacement_way"].(float64))
  3635. solution.ReplacementWay = replacementWay
  3636. }
  3637. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3638. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3639. solution.BloodFlowVolume = bloodFlowVolume
  3640. }
  3641. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3642. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3643. solution.HemodialysisMachine = hemodialysisMachine
  3644. }
  3645. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3646. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3647. solution.BloodFilter = bloodFilter
  3648. }
  3649. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3650. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3651. solution.PerfusionApparatus = perfusionApparatus
  3652. }
  3653. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3654. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3655. solution.DialysateFlow = dialysateFlow
  3656. }
  3657. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3658. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3659. solution.Kalium = kalium
  3660. }
  3661. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3662. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3663. solution.Sodium = sodium
  3664. }
  3665. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3666. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3667. solution.Calcium = calcium
  3668. }
  3669. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3670. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3671. solution.Bicarbonate = bicarbonate
  3672. }
  3673. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3674. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3675. solution.Anticoagulant = anticoagulant
  3676. }
  3677. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3678. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3679. solution.AnticoagulantShouji = anticoagulantShouji
  3680. }
  3681. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3682. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3683. solution.AnticoagulantWeichi = anticoagulantWeichi
  3684. }
  3685. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3686. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3687. solution.AnticoagulantZongliang = anticoagulantZongliang
  3688. }
  3689. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3690. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3691. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3692. }
  3693. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3694. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3695. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3696. }
  3697. return
  3698. }
  3699. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3700. dataBody := make(map[string]interface{}, 0)
  3701. err := json.Unmarshal(data, &dataBody)
  3702. utils.InfoLog(string(data))
  3703. if err != nil {
  3704. utils.ErrorLog(err.Error())
  3705. code = enums.ErrorCodeParamWrong
  3706. return
  3707. }
  3708. if method == "create" {
  3709. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3710. utils.ErrorLog("mode")
  3711. code = enums.ErrorCodeParamWrong
  3712. return
  3713. }
  3714. mode := int64(dataBody["mode"].(float64))
  3715. if mode <= 0 {
  3716. utils.ErrorLog("mode <= 0")
  3717. code = enums.ErrorCodeParamWrong
  3718. return
  3719. }
  3720. solution.ModeId = mode
  3721. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3722. utils.ErrorLog("mode_name")
  3723. code = enums.ErrorCodeParamWrong
  3724. return
  3725. }
  3726. modeName, _ := dataBody["mode_name"].(string)
  3727. if len(modeName) == 0 {
  3728. utils.ErrorLog("len(mode_name) == 0")
  3729. code = enums.ErrorCodeParamWrong
  3730. return
  3731. }
  3732. solution.ModeName = modeName
  3733. solution.Name = modeName
  3734. }
  3735. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3736. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3737. solution.DialysisDuration = dialysisDuration
  3738. }
  3739. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3740. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3741. solution.TargetUltrafiltration = targetUltrafiltration
  3742. }
  3743. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3744. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3745. solution.DialysateFormulation = dialysateFormulation
  3746. }
  3747. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3748. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3749. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3750. }
  3751. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3752. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3753. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3754. }
  3755. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3756. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3757. solution.HemodialysisMachine = hemodialysisMachine
  3758. }
  3759. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3760. dialyzer := int64(dataBody["dialyzer"].(float64))
  3761. solution.Dialyzer = dialyzer
  3762. }
  3763. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3764. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3765. solution.PerfusionApparatus = perfusionApparatus
  3766. }
  3767. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3768. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3769. solution.BloodFlowVolume = bloodFlowVolume
  3770. }
  3771. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3772. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3773. solution.Dewater = dewater
  3774. }
  3775. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3776. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3777. solution.DisplaceLiqui = displaceLiqui
  3778. }
  3779. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3780. replacementWay := int64(dataBody["replacement_way"].(float64))
  3781. solution.ReplacementWay = replacementWay
  3782. }
  3783. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3784. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3785. solution.Anticoagulant = anticoagulant
  3786. }
  3787. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3788. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3789. solution.AnticoagulantShouji = anticoagulantShouji
  3790. }
  3791. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3792. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3793. solution.AnticoagulantWeichi = anticoagulantWeichi
  3794. }
  3795. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3796. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3797. solution.AnticoagulantZongliang = anticoagulantZongliang
  3798. }
  3799. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3800. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3801. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3802. }
  3803. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3804. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3805. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3806. }
  3807. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3808. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3809. solution.Kalium = kalium
  3810. }
  3811. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3812. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3813. solution.Sodium = sodium
  3814. }
  3815. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3816. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3817. solution.Calcium = calcium
  3818. }
  3819. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3820. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3821. solution.Bicarbonate = bicarbonate
  3822. }
  3823. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3824. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3825. solution.Glucose = glucose
  3826. }
  3827. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3828. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3829. // solution.DryWeight = dryWeight
  3830. // }
  3831. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3832. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3833. solution.DialysateFlow = dialysateFlow
  3834. }
  3835. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3836. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3837. solution.DialysateTemperature = dialysateTemperature
  3838. }
  3839. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3840. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3841. solution.Conductivity = conductivity
  3842. }
  3843. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3844. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3845. solution.ReplacementTotal = replacementTotal
  3846. }
  3847. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3848. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3849. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3850. }
  3851. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3852. body_fluid := int64(dataBody["body_fluid"].(float64))
  3853. solution.BodyFluid = body_fluid
  3854. }
  3855. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3856. body_fluid_other := dataBody["body_fluid_other"].(string)
  3857. solution.BodyFluidOther = body_fluid_other
  3858. }
  3859. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3860. special_medicine := int64(dataBody["special_medicine"].(float64))
  3861. solution.SpecialMedicine = special_medicine
  3862. }
  3863. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3864. special_medicine_other := dataBody["special_medicine_other"].(string)
  3865. solution.SpecialMedicineOther = special_medicine_other
  3866. }
  3867. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3868. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3869. solution.DisplaceLiquiPart = displace_liqui_part
  3870. }
  3871. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3872. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3873. solution.DisplaceLiquiValue = displace_liqui_value
  3874. }
  3875. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3876. blood_access := int64(dataBody["blood_access"].(float64))
  3877. solution.BloodAccess = blood_access
  3878. }
  3879. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3880. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3881. solution.Ultrafiltration = ultrafiltration
  3882. }
  3883. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3884. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3885. solution.TargetKtv = target_ktv
  3886. }
  3887. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3888. remark := dataBody["remark"].(string)
  3889. solution.Remark = remark
  3890. }
  3891. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3892. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3893. solution.HemodialysisPipelines = hemodialysis_pipelines
  3894. }
  3895. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3896. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3897. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3898. }
  3899. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3900. puncture_needle := dataBody["puncture_needle"].(string)
  3901. solution.PunctureNeedle = puncture_needle
  3902. }
  3903. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3904. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3905. solution.PunctureNeedleCount = puncture_needle_count
  3906. }
  3907. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3908. epo := dataBody["epo"].(string)
  3909. solution.Epo = epo
  3910. }
  3911. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3912. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3913. solution.EpoCount = epo_count
  3914. }
  3915. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3916. created_time := int64(dataBody["created_time"].(float64))
  3917. solution.CreatedTime = created_time
  3918. }
  3919. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3920. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3921. solution.DialysisDialyszers = dialysisDialyszers
  3922. }
  3923. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3924. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3925. solution.DialysisIrrigation = dialysisIrrigation
  3926. }
  3927. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3928. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3929. solution.DialysisStrainer = dialysis_strainer
  3930. }
  3931. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3932. plasmaSeparator := dataBody["plasma_separator"].(string)
  3933. solution.PlasmaSeparator = plasmaSeparator
  3934. }
  3935. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3936. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3937. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3938. }
  3939. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3940. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3941. solution.OxygenUptake = oxygen_uptake
  3942. }
  3943. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3944. oxygen_flow := dataBody["oxygen_flow"].(string)
  3945. solution.OxygenFlow = oxygen_flow
  3946. }
  3947. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3948. oxygen_time := dataBody["oxygen_time"].(string)
  3949. solution.OxygenTime = oxygen_time
  3950. }
  3951. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3952. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3953. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3954. }
  3955. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3956. amylaceum := dataBody["amylaceum"].(string)
  3957. solution.Amylaceum = amylaceum
  3958. }
  3959. if dataBody["chaptalization"] != nil && reflect.TypeOf(dataBody["chaptalization"]).String() == "string" {
  3960. chaptalization := dataBody["chaptalization"].(string)
  3961. solution.Chaptalization = chaptalization
  3962. }
  3963. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3964. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3965. solution.BloodAccessPartId = blood_access_part_id
  3966. }
  3967. return
  3968. }
  3969. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3970. dataBody := make(map[string]interface{}, 0)
  3971. err := json.Unmarshal(data, &dataBody)
  3972. utils.InfoLog(string(data))
  3973. if err != nil {
  3974. utils.ErrorLog(err.Error())
  3975. code = enums.ErrorCodeParamWrong
  3976. return
  3977. }
  3978. if method == "create" {
  3979. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3980. utils.ErrorLog("parent_id")
  3981. code = enums.ErrorCodeParamWrong
  3982. return
  3983. }
  3984. parentID := int64(dataBody["parent_id"].(float64))
  3985. if parentID <= 0 {
  3986. utils.ErrorLog("parentID <= 0")
  3987. code = enums.ErrorCodeParamWrong
  3988. return
  3989. }
  3990. solution.ParentId = parentID
  3991. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3992. utils.ErrorLog("sub_name")
  3993. code = enums.ErrorCodeParamWrong
  3994. return
  3995. }
  3996. subName, _ := dataBody["sub_name"].(string)
  3997. if len(subName) == 0 {
  3998. utils.ErrorLog("len(sub_name) == 0")
  3999. code = enums.ErrorCodeParamWrong
  4000. return
  4001. }
  4002. solution.SubName = subName
  4003. }
  4004. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  4005. utils.ErrorLog("initiate_mode")
  4006. code = enums.ErrorCodeParamWrong
  4007. return
  4008. }
  4009. initiateMode := int64(dataBody["initiate_mode"].(float64))
  4010. if initiateMode != 1 && initiateMode != 2 {
  4011. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  4012. code = enums.ErrorCodeParamWrong
  4013. return
  4014. }
  4015. solution.InitiateMode = initiateMode
  4016. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  4017. utils.ErrorLog("doctor")
  4018. code = enums.ErrorCodeParamWrong
  4019. return
  4020. }
  4021. doctor := int64(dataBody["doctor"].(float64))
  4022. if doctor <= 0 {
  4023. utils.ErrorLog("doctor <= 0")
  4024. code = enums.ErrorCodeParamWrong
  4025. return
  4026. }
  4027. solution.Doctor = doctor
  4028. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  4029. blood_access_part_id, _ := dataBody["blood_access_part_id"].(string)
  4030. solution.BloodAccessPartId = blood_access_part_id
  4031. }
  4032. return
  4033. }
  4034. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  4035. patientBody := make(map[string]interface{}, 0)
  4036. err := json.Unmarshal(data, &patientBody)
  4037. if err != nil {
  4038. utils.ErrorLog(err.Error())
  4039. code = enums.ErrorCodeParamWrong
  4040. return
  4041. }
  4042. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  4043. formItem, _ := patientBody["formItem"].([]interface{})
  4044. if len(formItem) > 0 {
  4045. for _, item := range formItem {
  4046. items := item.(map[string]interface{})
  4047. project_name, _ := items["project_name"].(string)
  4048. fmt.Println(project_name)
  4049. range_type := int64(items["range_type"].(float64))
  4050. fmt.Println(range_type)
  4051. project_id := int64(items["project_id"].(float64))
  4052. fmt.Println(project_id)
  4053. item_id := int64(items["item_id"].(float64))
  4054. fmt.Println(item_id)
  4055. item, _ := items["item"].(string)
  4056. fmt.Println(items["item"].(string))
  4057. item_name, _ := items["item_name"].(string)
  4058. fmt.Println(item_name)
  4059. value, _ := items["value"].(string)
  4060. fmt.Println(items["value"].(string))
  4061. var form models.FormItem
  4062. form.ProjectName = project_name
  4063. form.RangeType = range_type
  4064. form.ProjectId = project_id
  4065. form.ItemId = item_id
  4066. form.Item = item
  4067. form.ItemName = item_name
  4068. form.Value = value
  4069. formItems = append(formItems, &form)
  4070. }
  4071. }
  4072. }
  4073. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  4074. utils.ErrorLog("avatar")
  4075. code = enums.ErrorCodeParamWrong
  4076. return
  4077. }
  4078. avatar, _ := patientBody["avatar"].(string)
  4079. if len(avatar) == 0 {
  4080. utils.ErrorLog("len(avatar) == 0")
  4081. code = enums.ErrorCodeParamWrong
  4082. return
  4083. }
  4084. patient.Avatar = avatar
  4085. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  4086. utils.ErrorLog("name")
  4087. code = enums.ErrorCodeParamWrong
  4088. return
  4089. }
  4090. name, _ := patientBody["name"].(string)
  4091. if len(name) == 0 {
  4092. utils.ErrorLog("len(name) == 0")
  4093. code = enums.ErrorCodeParamWrong
  4094. return
  4095. }
  4096. patient.Name = name
  4097. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  4098. alias := patientBody["alias"].(string)
  4099. patient.Alias = alias
  4100. }
  4101. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  4102. nation := patientBody["nation"].(string)
  4103. patient.Nation = nation
  4104. }
  4105. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  4106. native_place := patientBody["native_place"].(string)
  4107. patient.NativePlace = native_place
  4108. }
  4109. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  4110. utils.ErrorLog("idCardNo")
  4111. code = enums.ErrorCodeParamWrong
  4112. return
  4113. }
  4114. idCardNo, _ := patientBody["idCardNo"].(string)
  4115. if len(idCardNo) == 0 {
  4116. utils.ErrorLog("len(idCardNo) == 0")
  4117. code = enums.ErrorCodeParamWrong
  4118. return
  4119. }
  4120. patient.IdCardNo = idCardNo
  4121. patient.PatientType = 1
  4122. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  4123. utils.ErrorLog("dialysisNo")
  4124. code = enums.ErrorCodeParamWrong
  4125. return
  4126. }
  4127. dialysisNo, _ := patientBody["dialysisNo"].(string)
  4128. if len(dialysisNo) == 0 {
  4129. utils.ErrorLog("len(dialysisNo) == 0")
  4130. code = enums.ErrorCodeParamWrong
  4131. return
  4132. }
  4133. patient.DialysisNo = dialysisNo
  4134. // }
  4135. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  4136. utils.ErrorLog("lapseto")
  4137. code = enums.ErrorCodeParamWrong
  4138. return
  4139. }
  4140. lapseto := int64(patientBody["lapseto"].(float64))
  4141. if lapseto <= 0 {
  4142. utils.ErrorLog("lapseto == 0")
  4143. code = enums.ErrorCodeParamWrong
  4144. return
  4145. }
  4146. patient.Lapseto = lapseto
  4147. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  4148. utils.ErrorLog("gender")
  4149. code = enums.ErrorCodeParamWrong
  4150. return
  4151. }
  4152. gender := int64(patientBody["gender"].(float64))
  4153. if gender <= 0 {
  4154. utils.ErrorLog("gender <= 0")
  4155. code = enums.ErrorCodeParamWrong
  4156. return
  4157. }
  4158. patient.Gender = gender
  4159. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  4160. response_result := patientBody["response_result"].(string)
  4161. patient.ResponseResult = response_result
  4162. }
  4163. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  4164. utils.ErrorLog("age")
  4165. code = enums.ErrorCodeParamWrong
  4166. return
  4167. }
  4168. age := int64(patientBody["age"].(float64))
  4169. patient.Age = age
  4170. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  4171. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  4172. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  4173. patient.UserSysBeforeCount = count
  4174. }
  4175. timeLayout := "2006-01-02"
  4176. loc, _ := time.LoadLocation("Local")
  4177. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  4178. utils.ErrorLog("birth")
  4179. code = enums.ErrorCodeParamWrong
  4180. return
  4181. }
  4182. birth, _ := patientBody["birth"].(string)
  4183. if len(birth) == 0 {
  4184. utils.ErrorLog("len(birth) == 0")
  4185. code = enums.ErrorCodeParamWrong
  4186. return
  4187. }
  4188. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  4189. if err != nil {
  4190. utils.ErrorLog("birthTime")
  4191. code = enums.ErrorCodeParamWrong
  4192. return
  4193. }
  4194. patient.Birthday = birthTime.Unix()
  4195. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  4196. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  4197. patient.Height = height
  4198. }
  4199. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  4200. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  4201. patient.MaritalStatus = maritalStatus
  4202. }
  4203. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  4204. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  4205. patient.Children = children
  4206. }
  4207. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  4208. admissionNumber, _ := patientBody["admissionNumber"].(string)
  4209. patient.AdmissionNumber = admissionNumber
  4210. }
  4211. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  4212. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  4213. patient.ReimbursementWayId = reimbursementWayID
  4214. }
  4215. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  4216. healthCareNo := patientBody["healthCareNo"].(string)
  4217. patient.HealthCareNo = healthCareNo
  4218. }
  4219. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  4220. utils.ErrorLog("phone")
  4221. code = enums.ErrorCodeParamWrong
  4222. return
  4223. }
  4224. phone := patientBody["phone"].(string)
  4225. if len(phone) == 0 {
  4226. utils.ErrorLog("len(phone) == 0")
  4227. code = enums.ErrorCodeParamWrong
  4228. return
  4229. }
  4230. if !utils.CheckMobile(phone) {
  4231. utils.ErrorLog("!phone")
  4232. code = enums.ErrorCodeMobileFormat
  4233. return
  4234. }
  4235. patient.Phone = phone
  4236. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  4237. homeTelephone := patientBody["homeTelephone"].(string)
  4238. patient.HomeTelephone = homeTelephone
  4239. }
  4240. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  4241. relativePhone := patientBody["relative_phone"].(string)
  4242. patient.RelativePhone = relativePhone
  4243. }
  4244. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  4245. relativeRelations := patientBody["relative_relations"].(string)
  4246. patient.RelativeRelations = relativeRelations
  4247. }
  4248. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  4249. homeAddress := patientBody["homeAddress"].(string)
  4250. patient.HomeAddress = homeAddress
  4251. }
  4252. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  4253. work := patientBody["work"].(string)
  4254. patient.WorkUnit = work
  4255. }
  4256. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  4257. unitAddress := patientBody["unit_address"].(string)
  4258. patient.UnitAddress = unitAddress
  4259. }
  4260. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  4261. profession := int64(patientBody["profession"].(float64))
  4262. patient.Profession = profession
  4263. }
  4264. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  4265. education := int64(patientBody["education"].(float64))
  4266. patient.EducationLevel = education
  4267. }
  4268. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  4269. utils.ErrorLog("source")
  4270. code = enums.ErrorCodeParamWrong
  4271. return
  4272. }
  4273. source := int64(patientBody["source"].(float64))
  4274. if source <= 0 {
  4275. utils.ErrorLog("source <= 0")
  4276. code = enums.ErrorCodeParamWrong
  4277. return
  4278. }
  4279. patient.Source = source
  4280. zb_patient_id := patientBody["zb_patient_id"].(string)
  4281. patient.ZbPatientId = zb_patient_id
  4282. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  4283. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  4284. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  4285. }
  4286. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  4287. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  4288. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  4289. if err == nil {
  4290. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  4291. }
  4292. }
  4293. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  4294. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  4295. patient.FirstDialysisHospital = firstDialysisHospital
  4296. }
  4297. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  4298. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  4299. if len(thePredialysisCondition) > 0 {
  4300. conditions := make([]string, 0)
  4301. for _, item := range thePredialysisCondition {
  4302. if reflect.TypeOf(item).String() != "string" {
  4303. continue
  4304. }
  4305. condition := item.(string)
  4306. if len(condition) > 0 {
  4307. conditions = append(conditions, condition)
  4308. }
  4309. }
  4310. patient.PredialysisCondition = strings.Join(conditions, ",")
  4311. }
  4312. }
  4313. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  4314. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  4315. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  4316. }
  4317. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  4318. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  4319. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  4320. }
  4321. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  4322. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  4323. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  4324. if err == nil {
  4325. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  4326. }
  4327. }
  4328. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  4329. partition := int64(patientBody["partition"].(float64))
  4330. patient.PartitionId = partition
  4331. }
  4332. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  4333. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  4334. patient.BedId = bed
  4335. }
  4336. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  4337. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  4338. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  4339. if err == nil {
  4340. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  4341. }
  4342. }
  4343. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  4344. blood := int64(patientBody["blood"].(float64))
  4345. patient.BloodType = blood
  4346. }
  4347. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  4348. rh := int64(patientBody["rh"].(float64))
  4349. patient.Rh = rh
  4350. }
  4351. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  4352. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  4353. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  4354. if err == nil {
  4355. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  4356. }
  4357. }
  4358. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  4359. receivingDate := patientBody["receivingDate"].(string)
  4360. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  4361. if err == nil {
  4362. patient.ReceivingDate = receivingDateTime.Unix()
  4363. }
  4364. }
  4365. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  4366. induction := int64(patientBody["induction"].(float64))
  4367. patient.InductionPeriod = induction
  4368. }
  4369. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  4370. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  4371. patient.InitialDialysis = initial
  4372. }
  4373. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  4374. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  4375. patient.TotalDialysis = dialysisTotal
  4376. }
  4377. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  4378. thisContagions, _ := patientBody["contagions"].([]interface{})
  4379. if len(thisContagions) > 0 {
  4380. for _, item := range thisContagions {
  4381. if reflect.TypeOf(item).String() != "float64" {
  4382. continue
  4383. }
  4384. contagion := int64(item.(float64))
  4385. if contagion > 0 {
  4386. contagions = append(contagions, contagion)
  4387. }
  4388. }
  4389. }
  4390. }
  4391. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4392. doctor := int64(patientBody["doctor"].(float64))
  4393. patient.AttendingDoctorId = doctor
  4394. }
  4395. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  4396. nurse := int64(patientBody["nurse"].(float64))
  4397. patient.HeadNurseId = nurse
  4398. }
  4399. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  4400. assessment := patientBody["assessment"].(string)
  4401. patient.Evaluate = assessment
  4402. }
  4403. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  4404. thisDiseases, _ := patientBody["diseases"].([]interface{})
  4405. if len(thisDiseases) > 0 {
  4406. for _, item := range thisDiseases {
  4407. if reflect.TypeOf(item).String() != "float64" {
  4408. continue
  4409. }
  4410. disease := int64(item.(float64))
  4411. if disease > 0 {
  4412. diseases = append(diseases, disease)
  4413. }
  4414. }
  4415. }
  4416. }
  4417. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  4418. diagnose := patientBody["diagnose"].(string)
  4419. patient.Diagnose = diagnose
  4420. }
  4421. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  4422. remark := patientBody["remark"].(string)
  4423. patient.Remark = remark
  4424. }
  4425. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  4426. sch_remark := patientBody["sch_remark"].(string)
  4427. patient.SchRemark = sch_remark
  4428. }
  4429. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  4430. patient_complains := patientBody["patient_complains"].(string)
  4431. patient.PatientComplains = patient_complains
  4432. }
  4433. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  4434. present_history := patientBody["present_history"].(string)
  4435. patient.PresentHistory = present_history
  4436. }
  4437. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  4438. past_history := patientBody["past_history"].(string)
  4439. patient.PastHistory = past_history
  4440. }
  4441. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  4442. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  4443. patient.Temperature = temperature
  4444. }
  4445. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  4446. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  4447. patient.Pulse = pulse
  4448. }
  4449. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  4450. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  4451. patient.Respiratory = respiratory
  4452. }
  4453. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  4454. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  4455. patient.SBP = sbp
  4456. }
  4457. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  4458. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  4459. patient.DBP = dbp
  4460. }
  4461. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  4462. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  4463. patient.DialysisAge = dialysis_age
  4464. }
  4465. fmt.Println(patient.DialysisAge)
  4466. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  4467. first_treatment_date := patientBody["first_treatment_date"].(string)
  4468. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4469. if err == nil {
  4470. patient.FirstTreatmentDate = first_treatment_time.Unix()
  4471. }
  4472. }
  4473. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  4474. expense_kind := int64(patientBody["expense_kind"].(float64))
  4475. patient.ExpenseKind = expense_kind
  4476. }
  4477. fmt.Println(patient.ExpenseKind)
  4478. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  4479. tell_phone := patientBody["tell_phone"].(string)
  4480. patient.TellPhone = tell_phone
  4481. }
  4482. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  4483. contact_name := patientBody["contact_name"].(string)
  4484. patient.ContactName = contact_name
  4485. }
  4486. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  4487. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  4488. patient.TrobleShoot = troble_shoot
  4489. }
  4490. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  4491. treatment_plan := patientBody["treatment_plan"].(string)
  4492. patient.TreatmentPlan = treatment_plan
  4493. }
  4494. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  4495. doctor := int64(patientBody["doctor"].(float64))
  4496. patient.Doctor = doctor
  4497. }
  4498. if patientBody["record_number"] != nil && reflect.TypeOf(patientBody["record_number"]).String() == "string" {
  4499. record_number := patientBody["record_number"].(string)
  4500. patient.RecordNumber = record_number
  4501. }
  4502. patient_source := int64(patientBody["patient_source"].(float64))
  4503. if patient_source <= 0 {
  4504. utils.ErrorLog("patient_source <= 0")
  4505. code = enums.ErrorCodeParamWrong
  4506. return
  4507. }
  4508. patient.PatientSource = patient_source
  4509. if patientBody["patient_start_time"] != nil && reflect.TypeOf(patientBody["patient_start_time"]).String() == "string" {
  4510. patient_start_time := patientBody["patient_start_time"].(string)
  4511. var startTime int64
  4512. if len(patient_start_time) > 0 {
  4513. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_start_time+" 00:00:00", loc)
  4514. startTime = theTime.Unix()
  4515. }
  4516. patient.PatientStartTime = startTime
  4517. }
  4518. if patientBody["patient_end_time"] != nil && reflect.TypeOf(patientBody["patient_end_time"]).String() == "string" {
  4519. patient_end_time := patientBody["patient_end_time"].(string)
  4520. var endTime int64
  4521. if len(patient_end_time) > 0 {
  4522. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", patient_end_time+" 00:00:00", loc)
  4523. endTime = theTime.Unix()
  4524. }
  4525. patient.PatientEndTime = endTime
  4526. }
  4527. if patientBody["infectious_remark"] != nil && reflect.TypeOf(patientBody["infectious_remark"]).String() == "string" {
  4528. record_number := patientBody["infectious_remark"].(string)
  4529. patient.InfectiousRemark = record_number
  4530. }
  4531. if patientBody["allergic_history"] != nil && reflect.TypeOf(patientBody["allergic_history"]).String() == "string" {
  4532. allergic_history := patientBody["allergic_history"].(string)
  4533. patient.AllergicHistory = allergic_history
  4534. }
  4535. if patientBody["patient_address"] != nil && reflect.TypeOf(patientBody["patient_address"]).String() == "string" {
  4536. patient_address := patientBody["patient_address"].(string)
  4537. patient.PatientAddress = patient_address
  4538. }
  4539. return
  4540. }
  4541. func (c *PatientApiController) GetPatientsByKeyWord() {
  4542. keyWord := c.GetString("keyword")
  4543. adminUserInfo := c.GetAdminUserInfo()
  4544. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  4545. if err != nil {
  4546. utils.ErrorLog(err.Error())
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4548. return
  4549. }
  4550. c.ServeSuccessJSON(map[string]interface{}{
  4551. "patient": patient,
  4552. })
  4553. }
  4554. func (c *PatientApiController) QueryPatientById() {
  4555. id, _ := c.GetInt64("id")
  4556. fmt.Println(id)
  4557. patientInfo := service.QueryPatientById(id)
  4558. c.ServeSuccessJSON(map[string]interface{}{
  4559. "patient": patientInfo,
  4560. })
  4561. return
  4562. }
  4563. func (c *PatientApiController) GetRemindPatientList() {
  4564. page, _ := c.GetInt64("page", 1)
  4565. limit, _ := c.GetInt64("limit", 10)
  4566. adminUserInfo := c.GetAdminUserInfo()
  4567. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4568. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4569. if errcode == gorm.ErrRecordNotFound {
  4570. information, err := service.GetAdminUserRoleInformation(0)
  4571. if err != nil {
  4572. utils.ErrorLog(err.Error())
  4573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4574. return
  4575. }
  4576. c.ServeSuccessJSON(map[string]interface{}{
  4577. "total": total,
  4578. "patients": patients,
  4579. "information": information,
  4580. })
  4581. } else if errcode == nil {
  4582. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4583. if err != nil {
  4584. utils.ErrorLog(err.Error())
  4585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4586. return
  4587. }
  4588. c.ServeSuccessJSON(map[string]interface{}{
  4589. "total": total,
  4590. "patients": patients,
  4591. "information": information,
  4592. })
  4593. }
  4594. }
  4595. func (c *PatientApiController) PostIsOpenRemind() {
  4596. patient_id, _ := c.GetInt64("id", 1)
  4597. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4598. adminUserInfo := c.GetAdminUserInfo()
  4599. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4600. if err == nil {
  4601. c.ServeSuccessJSON(map[string]interface{}{
  4602. "msg": "成功",
  4603. "is_open_remind": is_open_remind,
  4604. })
  4605. } else if err != nil {
  4606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4607. }
  4608. }
  4609. func (c *PatientApiController) GetPatientScheduleOne() {
  4610. id, _ := c.GetInt64("id")
  4611. //查询该病人是否当天是排班
  4612. nowDateTime := time.Now()
  4613. nowDate := nowDateTime.Format("2006-01-02")
  4614. nowDate += " 00:00:00"
  4615. timeLayout := "2006-01-02"
  4616. loc, _ := time.LoadLocation("Local")
  4617. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4618. nowdate := theTime.Unix()
  4619. fmt.Println("nowdate", nowdate)
  4620. adminUser := c.GetAdminUserInfo()
  4621. orgId := adminUser.CurrentOrgId
  4622. fmt.Println("orgid", orgId)
  4623. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4624. if err != nil {
  4625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4626. return
  4627. }
  4628. c.ServeSuccessJSON(map[string]interface{}{
  4629. "scheduls": scheduls,
  4630. })
  4631. }
  4632. func (c *PatientApiController) ExportPatients() {
  4633. dataBody := make(map[string]interface{}, 0)
  4634. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4635. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4636. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4637. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4638. if err != nil {
  4639. utils.ErrorLog(err.Error())
  4640. return
  4641. }
  4642. utils.ErrorLog("%v", dataBody)
  4643. export_time := time.Now().Unix()
  4644. var patients []*models.Patients
  4645. var total_patients []interface{}
  4646. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4647. tempPatients := dataBody["patients"].([]interface{})
  4648. total_patients = tempPatients
  4649. for index, patientMap := range tempPatients {
  4650. patientNameM := patientMap.(map[string]interface{})
  4651. var patient models.Patients
  4652. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4653. utils.ErrorLog("name")
  4654. return
  4655. }
  4656. name, _ := patientNameM["name"].(string)
  4657. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4658. err_log := models.ExportErrLog{
  4659. LogType: 1,
  4660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4661. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4662. Status: 1,
  4663. CreateTime: time.Now().Unix(),
  4664. UpdateTime: time.Now().Unix(),
  4665. ExportTime: export_time,
  4666. }
  4667. service.CreateExportErrLog(&err_log)
  4668. continue
  4669. }
  4670. patient.Name = name
  4671. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4672. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4673. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4674. err_log := models.ExportErrLog{
  4675. LogType: 1,
  4676. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4677. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4678. Status: 1,
  4679. CreateTime: time.Now().Unix(),
  4680. UpdateTime: time.Now().Unix(),
  4681. ExportTime: export_time,
  4682. }
  4683. service.CreateExportErrLog(&err_log)
  4684. continue
  4685. } else {
  4686. patient.Gender = gender
  4687. }
  4688. }
  4689. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4690. phone, _ := patientNameM["phone"].(string)
  4691. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4692. if len(phone) == 0 {
  4693. err_log := models.ExportErrLog{
  4694. LogType: 1,
  4695. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4696. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4697. Status: 1,
  4698. CreateTime: time.Now().Unix(),
  4699. UpdateTime: time.Now().Unix(),
  4700. ExportTime: export_time,
  4701. }
  4702. service.CreateExportErrLog(&err_log)
  4703. continue
  4704. } else {
  4705. err_log := models.ExportErrLog{
  4706. LogType: 1,
  4707. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4708. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4709. Status: 1,
  4710. CreateTime: time.Now().Unix(),
  4711. UpdateTime: time.Now().Unix(),
  4712. ExportTime: export_time,
  4713. }
  4714. service.CreateExportErrLog(&err_log)
  4715. continue
  4716. }
  4717. } else {
  4718. //var tempPatient *models.Patients
  4719. //for _, item := range all_patient {
  4720. // if item.Phone == phone {
  4721. // tempPatient = item
  4722. // }
  4723. //}
  4724. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4725. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4726. if count >= 1 {
  4727. err_log := models.ExportErrLog{
  4728. LogType: 1,
  4729. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4730. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4731. Status: 1,
  4732. CreateTime: time.Now().Unix(),
  4733. UpdateTime: time.Now().Unix(),
  4734. ExportTime: export_time,
  4735. }
  4736. service.CreateExportErrLog(&err_log)
  4737. continue
  4738. }
  4739. patient.Phone = phone
  4740. }
  4741. }
  4742. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4743. id_card_no, _ := patientNameM["id_card_no"].(string)
  4744. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4745. if len(id_card_no) == 0 {
  4746. err_log := models.ExportErrLog{
  4747. LogType: 1,
  4748. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4749. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4750. Status: 1,
  4751. CreateTime: time.Now().Unix(),
  4752. UpdateTime: time.Now().Unix(),
  4753. ExportTime: export_time,
  4754. }
  4755. service.CreateExportErrLog(&err_log)
  4756. continue
  4757. } else {
  4758. err_log := models.ExportErrLog{
  4759. LogType: 1,
  4760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4761. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4762. Status: 1,
  4763. CreateTime: time.Now().Unix(),
  4764. UpdateTime: time.Now().Unix(),
  4765. ExportTime: export_time,
  4766. }
  4767. service.CreateExportErrLog(&err_log)
  4768. continue
  4769. }
  4770. } else {
  4771. //var tempPatient *models.Patients
  4772. //for _, item := range all_patient {
  4773. // if item.IdCardNo == id_card_no {
  4774. // tempPatient = item
  4775. // }
  4776. //}
  4777. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4778. if count >= 1 {
  4779. //if tempPatient != nil && tempPatient.ID > 0 {
  4780. err_log := models.ExportErrLog{
  4781. LogType: 1,
  4782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4783. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4784. Status: 1,
  4785. CreateTime: time.Now().Unix(),
  4786. UpdateTime: time.Now().Unix(),
  4787. ExportTime: export_time,
  4788. }
  4789. service.CreateExportErrLog(&err_log)
  4790. continue
  4791. }
  4792. //}
  4793. patient.IdCardNo = id_card_no
  4794. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4795. if GetBirthDay(id_card_no) == nil {
  4796. patient.Birthday = 0
  4797. } else {
  4798. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4799. }
  4800. }
  4801. }
  4802. fmt.Println("111112222")
  4803. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4804. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4805. timeLayout := "2006/01/02"
  4806. loc, _ := time.LoadLocation("Local")
  4807. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4808. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4809. if len(first_treatment_date) == 0 {
  4810. err_log := models.ExportErrLog{
  4811. LogType: 1,
  4812. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4813. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4814. Status: 1,
  4815. CreateTime: time.Now().Unix(),
  4816. UpdateTime: time.Now().Unix(),
  4817. ExportTime: export_time,
  4818. }
  4819. service.CreateExportErrLog(&err_log)
  4820. continue
  4821. } else {
  4822. err_log := models.ExportErrLog{
  4823. LogType: 1,
  4824. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4825. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4826. Status: 1,
  4827. CreateTime: time.Now().Unix(),
  4828. UpdateTime: time.Now().Unix(),
  4829. ExportTime: export_time,
  4830. }
  4831. service.CreateExportErrLog(&err_log)
  4832. continue
  4833. }
  4834. } else {
  4835. if len(first_treatment_date) == 0 {
  4836. err_log := models.ExportErrLog{
  4837. LogType: 1,
  4838. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4839. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4840. Status: 1,
  4841. CreateTime: time.Now().Unix(),
  4842. UpdateTime: time.Now().Unix(),
  4843. ExportTime: export_time,
  4844. }
  4845. service.CreateExportErrLog(&err_log)
  4846. continue
  4847. } else {
  4848. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4849. err_log := models.ExportErrLog{
  4850. LogType: 1,
  4851. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4852. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4853. Status: 1,
  4854. CreateTime: time.Now().Unix(),
  4855. UpdateTime: time.Now().Unix(),
  4856. ExportTime: export_time,
  4857. }
  4858. service.CreateExportErrLog(&err_log)
  4859. continue
  4860. } else {
  4861. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4862. }
  4863. }
  4864. }
  4865. }
  4866. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4867. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4868. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4869. err_log := models.ExportErrLog{
  4870. LogType: 1,
  4871. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4872. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4873. Status: 1,
  4874. CreateTime: time.Now().Unix(),
  4875. UpdateTime: time.Now().Unix(),
  4876. ExportTime: export_time,
  4877. }
  4878. service.CreateExportErrLog(&err_log)
  4879. continue
  4880. } else if source == 3 {
  4881. err_log := models.ExportErrLog{
  4882. LogType: 1,
  4883. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4884. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4885. Status: 1,
  4886. CreateTime: time.Now().Unix(),
  4887. UpdateTime: time.Now().Unix(),
  4888. ExportTime: export_time,
  4889. }
  4890. service.CreateExportErrLog(&err_log)
  4891. continue
  4892. } else {
  4893. patient.Source = source
  4894. }
  4895. }
  4896. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4897. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4898. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4899. err_log := models.ExportErrLog{
  4900. LogType: 1,
  4901. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4902. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4903. Status: 1,
  4904. CreateTime: time.Now().Unix(),
  4905. UpdateTime: time.Now().Unix(),
  4906. ExportTime: export_time,
  4907. }
  4908. service.CreateExportErrLog(&err_log)
  4909. continue
  4910. } else if lapseto == 3 {
  4911. err_log := models.ExportErrLog{
  4912. LogType: 1,
  4913. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4914. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4915. Status: 1,
  4916. CreateTime: time.Now().Unix(),
  4917. UpdateTime: time.Now().Unix(),
  4918. ExportTime: export_time,
  4919. }
  4920. service.CreateExportErrLog(&err_log)
  4921. continue
  4922. } else {
  4923. patient.Lapseto = lapseto
  4924. }
  4925. }
  4926. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4927. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4928. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4929. err_log := models.ExportErrLog{
  4930. LogType: 1,
  4931. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4932. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4933. Status: 1,
  4934. CreateTime: time.Now().Unix(),
  4935. UpdateTime: time.Now().Unix(),
  4936. ExportTime: export_time,
  4937. }
  4938. service.CreateExportErrLog(&err_log)
  4939. continue
  4940. } else if is_infectious == 3 {
  4941. err_log := models.ExportErrLog{
  4942. LogType: 1,
  4943. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4944. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4945. Status: 1,
  4946. CreateTime: time.Now().Unix(),
  4947. UpdateTime: time.Now().Unix(),
  4948. ExportTime: export_time,
  4949. }
  4950. service.CreateExportErrLog(&err_log)
  4951. continue
  4952. } else {
  4953. patient.IsInfectious = is_infectious
  4954. }
  4955. }
  4956. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4957. var contagions []int64
  4958. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4959. if len(thisContagions) > 0 {
  4960. for _, item := range thisContagions {
  4961. if reflect.TypeOf(item).String() != "float64" {
  4962. continue
  4963. }
  4964. contagion := int64(item.(float64))
  4965. if contagion > 0 {
  4966. contagions = append(contagions, contagion)
  4967. }
  4968. }
  4969. }
  4970. patient.ContagionIds = contagions
  4971. }
  4972. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4973. diagnose, _ := patientNameM["diagnose"].(string)
  4974. patient.Diagnose = diagnose
  4975. }
  4976. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4977. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4978. var tempPatient *models.Patients
  4979. for _, item := range all_patient {
  4980. if item.DialysisNo == dialysis_no {
  4981. tempPatient = item
  4982. }
  4983. }
  4984. if tempPatient != nil && tempPatient.ID > 0 {
  4985. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4986. } else {
  4987. patient.DialysisNo = dialysis_no
  4988. }
  4989. }
  4990. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4991. height, _ := patientNameM["height"].(string)
  4992. heights, _ := strconv.ParseFloat(height, 64)
  4993. patient.Height = int64(heights)
  4994. }
  4995. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4996. home_address, _ := patientNameM["home_address"].(string)
  4997. patient.HomeAddress = home_address
  4998. }
  4999. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  5000. dry_weight, _ := patientNameM["dry_weight"].(string)
  5001. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  5002. patient.DryWeight = dry_weights
  5003. }
  5004. patient.CreatedTime = time.Now().Unix()
  5005. patient.UpdatedTime = time.Now().Unix()
  5006. patient.Status = 1
  5007. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  5008. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  5009. patient.IsExcelExport = 1
  5010. patient.PatientType = 1
  5011. patients = append(patients, &patient)
  5012. }
  5013. }
  5014. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5015. if len(patients) > 0 {
  5016. for _, item := range patients {
  5017. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  5018. }
  5019. log := models.ExportLog{
  5020. LogType: 1,
  5021. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5022. TotalNum: int64(len(total_patients)),
  5023. FailNum: int64(len(errLogs)),
  5024. SuccessNum: int64(len(patients)),
  5025. CreateTime: time.Now().Unix(),
  5026. UpdateTime: time.Now().Unix(),
  5027. ExportTime: export_time,
  5028. Status: 1,
  5029. }
  5030. service.CreateExportLog(&log)
  5031. c.ServeSuccessJSON(map[string]interface{}{
  5032. "msg": "导入成功",
  5033. "total_num": len(total_patients),
  5034. "success_num": len(patients),
  5035. "fail_num": int64(len(errLogs)),
  5036. })
  5037. } else {
  5038. log := models.ExportLog{
  5039. LogType: 1,
  5040. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5041. TotalNum: int64(len(total_patients)),
  5042. FailNum: int64(len(errLogs)),
  5043. SuccessNum: int64(len(patients)),
  5044. CreateTime: time.Now().Unix(),
  5045. UpdateTime: time.Now().Unix(),
  5046. ExportTime: export_time,
  5047. Status: 1,
  5048. }
  5049. service.CreateExportLog(&log)
  5050. c.ServeSuccessJSON(map[string]interface{}{
  5051. "msg": "导入成功",
  5052. "total_num": len(total_patients),
  5053. "success_num": len(patients),
  5054. "fail_num": int64(len(errLogs)),
  5055. })
  5056. }
  5057. }
  5058. func GetBirthDay(IDCardNo string) *time.Time {
  5059. dayStr := IDCardNo[6:14]
  5060. birthDay, err := time.Parse("20060102", dayStr)
  5061. if err != nil {
  5062. fmt.Println(err)
  5063. return nil
  5064. }
  5065. return &birthDay
  5066. }
  5067. func IsIdCard(id string) (res bool) {
  5068. id = strings.ToUpper(id)
  5069. if len(id) != 15 && len(id) != 18 {
  5070. fmt.Println("1111111")
  5071. return false
  5072. }
  5073. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  5074. if !r.MatchString(id) {
  5075. fmt.Println("222222")
  5076. return false
  5077. }
  5078. if len(id) == 15 {
  5079. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  5080. if tm2.Unix() == 0 {
  5081. fmt.Println("44444443333")
  5082. return false
  5083. }
  5084. return true
  5085. } else {
  5086. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  5087. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  5088. fmt.Println(tm2.Unix())
  5089. if tm2.Unix() == 0 {
  5090. fmt.Println("44445555555")
  5091. return false
  5092. }
  5093. //检验18位身份证的校验码是否正确。
  5094. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  5095. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  5096. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  5097. sign := 0
  5098. for k, v := range arr_int {
  5099. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  5100. sign += int_temp * v
  5101. }
  5102. n := sign % 11
  5103. val_num := arr_ch[n]
  5104. if val_num != string([]byte(id)[17:18]) {
  5105. fmt.Println("5556666666")
  5106. return false
  5107. }
  5108. return true
  5109. }
  5110. }
  5111. func (c *PatientApiController) SaveEditAdvices() {
  5112. adminInfo := c.GetAdminUserInfo()
  5113. orgid := adminInfo.CurrentOrgId
  5114. startTime := c.GetString("start_time")
  5115. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  5116. groupno, _ := c.GetInt64("groupno")
  5117. fmt.Println("组", groupno)
  5118. date, _ := c.GetInt64("date")
  5119. fmt.Println("date", date)
  5120. patient_id, _ := c.GetInt64("patient_id")
  5121. fmt.Println("paitent_id", patient_id)
  5122. advice := models.XtDoctorAdvice{
  5123. StartTime: theTime.Unix(),
  5124. }
  5125. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  5126. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  5127. redis := service.RedisClient()
  5128. redis.Set(key, "", time.Second)
  5129. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  5130. redis.Set(keyOne, "", time.Second)
  5131. scheduleTime := theTime.Format("2006-01-02")
  5132. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  5133. fmt.Println("keyFour323223323232323232", keyFour)
  5134. redis.Set(keyFour, "", time.Second)
  5135. defer redis.Close()
  5136. if err != nil {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5138. return
  5139. }
  5140. c.ServeSuccessJSON(map[string]interface{}{
  5141. "advice": advice,
  5142. })
  5143. }
  5144. func (c *PatientApiController) GetMaxDialysisNo() {
  5145. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  5146. c.ServeSuccessJSON(map[string]interface{}{
  5147. "dialysis_no": dialysisNo,
  5148. })
  5149. }
  5150. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  5151. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  5152. var tempPatient *models.Patients
  5153. for _, item := range patients {
  5154. if item.DialysisNo == dialysisNo2 {
  5155. tempPatient = item
  5156. }
  5157. }
  5158. if tempPatient == nil || tempPatient.ID == 0 {
  5159. return dialysisNo2
  5160. }
  5161. return GenerateDialysisNoTwo(patients)
  5162. }
  5163. func (c *PatientApiController) GetBanner() {
  5164. orgId := c.GetAdminUserInfo().CurrentOrgId
  5165. _, errcodes := service.GetOrgFollowIsExist(orgId)
  5166. if errcodes == gorm.ErrRecordNotFound {
  5167. information, err := service.GetAdminUserRoleInformation(0)
  5168. if err != nil {
  5169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5170. return
  5171. }
  5172. c.ServeSuccessJSON(map[string]interface{}{
  5173. "information": information,
  5174. })
  5175. } else if errcodes == nil {
  5176. information, err := service.GetAdminUserRoleInformation(orgId)
  5177. if err != nil {
  5178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5179. return
  5180. }
  5181. c.ServeSuccessJSON(map[string]interface{}{
  5182. "information": information,
  5183. })
  5184. }
  5185. }
  5186. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  5187. patient_id, _ := c.GetInt64("id", 0)
  5188. page, _ := c.GetInt64("page", 0)
  5189. limit, _ := c.GetInt64("limit", 0)
  5190. if patient_id <= 0 {
  5191. c.ServeSuccessJSON(map[string]interface{}{
  5192. "solutions": nil,
  5193. })
  5194. return
  5195. }
  5196. if page <= 0 {
  5197. page = 1
  5198. }
  5199. if limit <= 0 {
  5200. limit = 10
  5201. }
  5202. adminUserInfo := c.GetAdminUserInfo()
  5203. //获取该患者分组的透析模式
  5204. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  5205. for _, item := range list {
  5206. //获取该模式最新的1条数据
  5207. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  5208. //更新状态值
  5209. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  5210. }
  5211. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  5212. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  5213. if err != nil {
  5214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5215. return
  5216. }
  5217. c.ServeSuccessJSON(map[string]interface{}{
  5218. "solutions": solution,
  5219. "total": total,
  5220. "stockType": stockType,
  5221. })
  5222. }
  5223. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  5224. patient_id, _ := c.GetInt64("patient_id")
  5225. mode_id, _ := c.GetInt64("mode_id")
  5226. page, _ := c.GetInt64("page")
  5227. limit, _ := c.GetInt64("limit")
  5228. orgId := c.GetAdminUserInfo().CurrentOrgId
  5229. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  5230. if err != nil {
  5231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5232. return
  5233. }
  5234. c.ServeSuccessJSON(map[string]interface{}{
  5235. "list": list,
  5236. "total": total,
  5237. })
  5238. }
  5239. func (c *PatientApiController) SaveFallOutBedPrint() {
  5240. adminInfo := c.GetAdminUserInfo()
  5241. orgid := adminInfo.CurrentOrgId
  5242. dataBody := make(map[string]interface{}, 0)
  5243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5244. fmt.Println("err", err)
  5245. content := dataBody["content"].(string)
  5246. outPrint := models.XtFallOutPrint{
  5247. UserOrgId: orgid,
  5248. Content: content,
  5249. Status: 1,
  5250. Ctime: time.Now().Unix(),
  5251. Mtime: time.Now().Unix(),
  5252. }
  5253. //查询该机构是否存在
  5254. list, err := service.GetOutPrintList(orgid)
  5255. if list.ID == 0 {
  5256. service.CreateFallOutBedPrint(outPrint)
  5257. }
  5258. if list.ID > 0 {
  5259. service.UpdateFallOutBedPrint(list.ID, content)
  5260. }
  5261. c.ServeSuccessJSON(map[string]interface{}{
  5262. "list": list,
  5263. })
  5264. }
  5265. func (c *PatientApiController) GetFallOutBedPrintList() {
  5266. adminInfo := c.GetAdminUserInfo()
  5267. orgid := adminInfo.CurrentOrgId
  5268. list, _ := service.GetFallOutBedPrintList(orgid)
  5269. c.ServeSuccessJSON(map[string]interface{}{
  5270. "list": list,
  5271. })
  5272. }
  5273. func (c *PatientApiController) SaveFilterInformed() {
  5274. adminInfo := c.GetAdminUserInfo()
  5275. orgid := adminInfo.CurrentOrgId
  5276. dataBody := make(map[string]interface{}, 0)
  5277. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5278. fmt.Println("err", err)
  5279. content := dataBody["content"].(string)
  5280. informed := models.XtFilterInformed{
  5281. UserOrgId: orgid,
  5282. Content: content,
  5283. Status: 1,
  5284. Ctime: time.Now().Unix(),
  5285. Mtime: time.Now().Unix(),
  5286. }
  5287. filterInformed, _ := service.GetFilterInformed(orgid)
  5288. if filterInformed.ID == 0 {
  5289. service.CreateFilterInformed(informed)
  5290. }
  5291. if filterInformed.ID > 0 {
  5292. service.UpdateFilterInformed(filterInformed.ID, content)
  5293. }
  5294. c.ServeSuccessJSON(map[string]interface{}{
  5295. "informed": informed,
  5296. })
  5297. }
  5298. func (c *PatientApiController) GetFilterInformed() {
  5299. adminInfo := c.GetAdminUserInfo()
  5300. orgid := adminInfo.CurrentOrgId
  5301. filterInformed, _ := service.GetFilterInformed(orgid)
  5302. c.ServeSuccessJSON(map[string]interface{}{
  5303. "list": filterInformed,
  5304. })
  5305. }
  5306. func (c *PatientApiController) SaveProfundaInformed() {
  5307. adminInfo := c.GetAdminUserInfo()
  5308. orgid := adminInfo.CurrentOrgId
  5309. dataBody := make(map[string]interface{}, 0)
  5310. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5311. fmt.Println("err", err)
  5312. content := dataBody["content"].(string)
  5313. informed := models.XtProfundaInformed{
  5314. UserOrgId: orgid,
  5315. Content: content,
  5316. Status: 1,
  5317. Ctime: time.Now().Unix(),
  5318. Mtime: time.Now().Unix(),
  5319. }
  5320. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5321. if profundaInformed.ID == 0 {
  5322. service.CreateProfundaInformed(informed)
  5323. }
  5324. if profundaInformed.ID > 0 {
  5325. service.UpdateProfundaInformed(profundaInformed.ID, content)
  5326. }
  5327. c.ServeSuccessJSON(map[string]interface{}{
  5328. "list": profundaInformed,
  5329. })
  5330. }
  5331. func (c *PatientApiController) GetProfundaInformed() {
  5332. adminInfo := c.GetAdminUserInfo()
  5333. orgid := adminInfo.CurrentOrgId
  5334. profundaInformed, _ := service.GetProfundaInformed(orgid)
  5335. c.ServeSuccessJSON(map[string]interface{}{
  5336. "list": profundaInformed,
  5337. })
  5338. }
  5339. func (c *PatientApiController) SaveArterOvenous() {
  5340. adminInfo := c.GetAdminUserInfo()
  5341. orgid := adminInfo.CurrentOrgId
  5342. dataBody := make(map[string]interface{}, 0)
  5343. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5344. fmt.Println("err", err)
  5345. content := dataBody["content"].(string)
  5346. arterOvenous := models.XtArterOvenous{
  5347. UserOrgId: orgid,
  5348. Content: content,
  5349. Status: 1,
  5350. Ctime: time.Now().Unix(),
  5351. Mtime: time.Now().Unix(),
  5352. }
  5353. list, _ := service.GetArterOvenousList(orgid)
  5354. if list.ID == 0 {
  5355. service.CreateArterOvernous(arterOvenous)
  5356. }
  5357. if list.ID > 0 {
  5358. service.UpdateArterOvernous(list.ID, content)
  5359. }
  5360. c.ServeSuccessJSON(map[string]interface{}{
  5361. "list": list,
  5362. })
  5363. }
  5364. func (c *PatientApiController) GetArterOverNous() {
  5365. adminInfo := c.GetAdminUserInfo()
  5366. orgid := adminInfo.CurrentOrgId
  5367. list, _ := service.GetArterOvenousList(orgid)
  5368. c.ServeSuccessJSON(map[string]interface{}{
  5369. "list": list,
  5370. })
  5371. }
  5372. func (c *PatientApiController) SaveHighRikInformed() {
  5373. adminInfo := c.GetAdminUserInfo()
  5374. orgid := adminInfo.CurrentOrgId
  5375. dataBody := make(map[string]interface{}, 0)
  5376. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5377. fmt.Println("err", err)
  5378. content := dataBody["content"].(string)
  5379. risk := models.XtHightRisk{
  5380. UserOrgId: orgid,
  5381. Content: content,
  5382. Status: 1,
  5383. Ctime: time.Now().Unix(),
  5384. Mtime: time.Now().Unix(),
  5385. }
  5386. highRik, _ := service.GetHightRikInformed(orgid)
  5387. if highRik.ID == 0 {
  5388. service.CreateHighRik(risk)
  5389. }
  5390. if highRik.ID > 0 {
  5391. service.UpdateHighRik(highRik.ID, content)
  5392. }
  5393. c.ServeSuccessJSON(map[string]interface{}{
  5394. "list": risk,
  5395. })
  5396. }
  5397. func (c *PatientApiController) GetHighRiskInformed() {
  5398. orgId := c.GetAdminUserInfo().CurrentOrgId
  5399. rikInformed, _ := service.GetHightRikInformed(orgId)
  5400. c.ServeSuccessJSON(map[string]interface{}{
  5401. "list": rikInformed,
  5402. })
  5403. }
  5404. func (c *PatientApiController) SaveAnticoagulation() {
  5405. orgId := c.GetAdminUserInfo().CurrentOrgId
  5406. dataBody := make(map[string]interface{}, 0)
  5407. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5408. fmt.Println("err", err)
  5409. content := dataBody["content"].(string)
  5410. auticoagutionPrint := models.XtAuticoagutionPrint{
  5411. Content: content,
  5412. UserOrgId: orgId,
  5413. Status: 1,
  5414. Ctime: time.Now().Unix(),
  5415. Mtime: time.Now().Unix(),
  5416. }
  5417. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5418. if anticoagulation.ID == 0 {
  5419. service.CreateAnticoagulation(auticoagutionPrint)
  5420. }
  5421. if anticoagulation.ID > 0 {
  5422. service.UpdateAnticoagulation(anticoagulation.ID, content)
  5423. }
  5424. c.ServeSuccessJSON(map[string]interface{}{
  5425. "list": auticoagutionPrint,
  5426. })
  5427. }
  5428. func (c *PatientApiController) GetAnticoagulationInformed() {
  5429. orgId := c.GetAdminUserInfo().CurrentOrgId
  5430. anticoagulation, _ := service.GetAnticoagulation(orgId)
  5431. c.ServeSuccessJSON(map[string]interface{}{
  5432. "list": anticoagulation,
  5433. })
  5434. }
  5435. func (c *PatientApiController) SaveCriticalInfomed() {
  5436. orgId := c.GetAdminUserInfo().CurrentOrgId
  5437. dataBody := make(map[string]interface{}, 0)
  5438. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5439. fmt.Println("err", err)
  5440. content := dataBody["content"].(string)
  5441. criticalinfomedPrint := models.XtCriticalinfomedPrint{
  5442. UserOrgId: orgId,
  5443. Content: content,
  5444. Status: 1,
  5445. Ctime: time.Now().Unix(),
  5446. Mtime: time.Now().Unix(),
  5447. }
  5448. infomed, _ := service.GetCriticalInfomed(orgId)
  5449. if infomed.ID == 0 {
  5450. service.CreatedCriticalInfomed(criticalinfomedPrint)
  5451. }
  5452. if infomed.ID > 0 {
  5453. service.UpdateCriticalInfomed(infomed.ID, content)
  5454. }
  5455. c.ServeSuccessJSON(map[string]interface{}{
  5456. "list": criticalinfomedPrint,
  5457. })
  5458. }
  5459. func (c *PatientApiController) GetCriticalInformed() {
  5460. orgId := c.GetAdminUserInfo().CurrentOrgId
  5461. infomed, _ := service.GetCriticalInfomed(orgId)
  5462. c.ServeSuccessJSON(map[string]interface{}{
  5463. "list": infomed,
  5464. })
  5465. }
  5466. func (c *PatientApiController) SaveHemoperfusionInformed() {
  5467. orgId := c.GetAdminUserInfo().CurrentOrgId
  5468. dataBody := make(map[string]interface{}, 0)
  5469. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5470. fmt.Println("err", err)
  5471. content := dataBody["content"].(string)
  5472. hemoperfusionmedPrint := models.XtHemoperfusionmedPrint{
  5473. UserOrgId: orgId,
  5474. Content: content,
  5475. Status: 1,
  5476. Ctime: time.Now().Unix(),
  5477. Mtime: time.Now().Unix(),
  5478. }
  5479. informed, _ := service.GetHemoperfusionInformed(orgId)
  5480. if informed.ID == 0 {
  5481. service.CreateHemoperfusionInformed(hemoperfusionmedPrint)
  5482. }
  5483. if informed.ID > 0 {
  5484. service.UpdateHemoperfusionInformed(informed.ID, content)
  5485. }
  5486. c.ServeSuccessJSON(map[string]interface{}{
  5487. "list": hemoperfusionmedPrint,
  5488. })
  5489. }
  5490. func (c *PatientApiController) GetHemoperfusionInformed() {
  5491. orgId := c.GetAdminUserInfo().CurrentOrgId
  5492. informed, _ := service.GetHemoperfusionInformed(orgId)
  5493. c.ServeSuccessJSON(map[string]interface{}{
  5494. "list": informed,
  5495. })
  5496. }
  5497. func (c *PatientApiController) SaveBringInformed() {
  5498. orgId := c.GetAdminUserInfo().CurrentOrgId
  5499. dataBody := make(map[string]interface{}, 0)
  5500. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5501. fmt.Println("err", err)
  5502. content := dataBody["content"].(string)
  5503. bringinformedPrint := models.XtBringinformedPrint{
  5504. Content: content,
  5505. UserOrgId: orgId,
  5506. Ctime: time.Now().Unix(),
  5507. Mtime: time.Now().Unix(),
  5508. Status: 1,
  5509. }
  5510. informed, _ := service.GetBringInformed(orgId)
  5511. if informed.ID == 0 {
  5512. service.CreateBringInformed(bringinformedPrint)
  5513. }
  5514. if informed.ID > 0 {
  5515. service.UpdateBringInformed(informed.ID, content)
  5516. }
  5517. c.ServeSuccessJSON(map[string]interface{}{
  5518. "list": bringinformedPrint,
  5519. })
  5520. }
  5521. func (c *PatientApiController) GetInformedContsent() {
  5522. orgId := c.GetAdminUserInfo().CurrentOrgId
  5523. informed, _ := service.GetBringInformed(orgId)
  5524. c.ServeSuccessJSON(map[string]interface{}{
  5525. "list": informed,
  5526. })
  5527. }
  5528. func (c *PatientApiController) SaveCatheterization() {
  5529. orgId := c.GetAdminUserInfo().CurrentOrgId
  5530. dataBody := make(map[string]interface{}, 0)
  5531. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5532. fmt.Println("err", err)
  5533. content := dataBody["content"].(string)
  5534. cathetercationPrint := models.XtCathetercationPrint{
  5535. UserOrgId: orgId,
  5536. Content: content,
  5537. Status: 1,
  5538. Ctime: time.Now().Unix(),
  5539. Mtime: time.Now().Unix(),
  5540. }
  5541. catheterization, _ := service.GetCatheterization(orgId)
  5542. if cathetercationPrint.ID == 0 {
  5543. service.CreateCatheteriztion(cathetercationPrint)
  5544. }
  5545. if cathetercationPrint.ID > 0 {
  5546. service.UpdateCatheterization(catheterization.ID, content)
  5547. }
  5548. c.ServeSuccessJSON(map[string]interface{}{
  5549. "list": catheterization,
  5550. })
  5551. }
  5552. func (c *PatientApiController) GetCatheterization() {
  5553. orgId := c.GetAdminUserInfo().CurrentOrgId
  5554. catheterization, _ := service.GetCatheterization(orgId)
  5555. c.ServeSuccessJSON(map[string]interface{}{
  5556. "list": catheterization,
  5557. })
  5558. }
  5559. func (c *PatientApiController) SaveDialyzerInformed() {
  5560. orgId := c.GetAdminUserInfo().CurrentOrgId
  5561. dataBody := make(map[string]interface{}, 0)
  5562. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5563. fmt.Println("err", err)
  5564. content := dataBody["content"].(string)
  5565. dialyszerinformedPrint := models.XtDialyszerinformedPrint{
  5566. UserOrgId: orgId,
  5567. Content: content,
  5568. Status: 1,
  5569. Ctime: time.Now().Unix(),
  5570. Mtime: time.Now().Unix(),
  5571. }
  5572. informed, _ := service.GetDialyzerInformed(orgId)
  5573. if informed.ID == 0 {
  5574. service.CreateDialyzerInformed(dialyszerinformedPrint)
  5575. }
  5576. if informed.ID > 0 {
  5577. service.UpdateDialyszerInformed(informed.ID, content)
  5578. }
  5579. c.ServeSuccessJSON(map[string]interface{}{
  5580. "list": dialyszerinformedPrint,
  5581. })
  5582. }
  5583. func (c *PatientApiController) GetDialyzerInformed() {
  5584. orgId := c.GetAdminUserInfo().CurrentOrgId
  5585. informed, _ := service.GetDialyzerInformed(orgId)
  5586. c.ServeSuccessJSON(map[string]interface{}{
  5587. "list": informed,
  5588. })
  5589. }
  5590. func (c *PatientApiController) SaveTheapyInformed() {
  5591. orgId := c.GetAdminUserInfo().CurrentOrgId
  5592. dataBody := make(map[string]interface{}, 0)
  5593. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5594. fmt.Println("err", err)
  5595. content := dataBody["content"].(string)
  5596. theapyinformedPrint := models.XtTheapyinformedPrint{
  5597. Content: content,
  5598. UserOrgId: orgId,
  5599. Status: 1,
  5600. Ctime: time.Now().Unix(),
  5601. Mtime: time.Now().Unix(),
  5602. }
  5603. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5604. if theapyInformed.ID == 0 {
  5605. service.CreateTheapyInformed(theapyinformedPrint)
  5606. }
  5607. if theapyInformed.ID > 0 {
  5608. service.UpdateTheaphInformed(theapyInformed.ID, content)
  5609. }
  5610. c.ServeSuccessJSON(map[string]interface{}{
  5611. "list": theapyinformedPrint,
  5612. })
  5613. }
  5614. func (c *PatientApiController) GetTherapyInformed() {
  5615. orgId := c.GetAdminUserInfo().CurrentOrgId
  5616. theapyInformed, _ := service.GetTheapyInformed(orgId)
  5617. c.ServeSuccessJSON(map[string]interface{}{
  5618. "list": theapyInformed,
  5619. })
  5620. }