patient_api_controller.go 265KB

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