patient_api_controller.go 262KB

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