patient_api_controller.go 277KB

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