patient_api_controller.go 317KB

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