patient_api_controller.go 269KB

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