patient_api_controller.go 298KB

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