patient_api_controller.go 287KB

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