patient_api_controller.go 226KB

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