patient_api_controller.go 209KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 && infor.WeekDay > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id, 4)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. record_date, _ := c.GetInt64("record_date")
  530. if origin != 2 {
  531. adminUserInfo := c.GetMobileAdminUserInfo()
  532. execution_staff := adminUserInfo.AdminUser.Id
  533. var ids []string
  534. advice_ids := c.GetString("advice_id")
  535. if groupno == 0 {
  536. ids = strings.Split(advice_ids, ",")
  537. }
  538. if groupno < 0 {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if len(execution_time) <= 0 {
  543. utils.ErrorLog("execution_time")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeLayout2 := "2006-01-02 15:04:05"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  550. if errs != nil {
  551. utils.ErrorLog(errs.Error())
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. var advice models.DoctorAdvice
  556. if groupno > 0 {
  557. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  558. for _, item := range advices {
  559. //恒泰中医院
  560. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  561. if item.DrugId == 0 || item.DrugNameId == 0 {
  562. //从字典里面查找
  563. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  564. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  565. }
  566. }
  567. if item.ExecutionState == 2 {
  568. advice = item
  569. }
  570. //记录日志
  571. byterequest, _ := json.Marshal(item)
  572. adviceLog := models.XtDoctorAdviceLog{
  573. UserOrgId: item.UserOrgId,
  574. PatientId: item.PatientId,
  575. AdminUserId: adminUserInfo.AdminUser.Id,
  576. Module: 2,
  577. ErrLog: string(byterequest),
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. Source: "手机端执行医嘱",
  582. RecordDate: item.AdviceDate,
  583. }
  584. service.CreateDoctorAdviceLog(adviceLog)
  585. }
  586. } else {
  587. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  588. for _, item := range advices {
  589. //恒泰中医院
  590. if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
  591. if item.DrugId == 0 || item.DrugNameId == 0 {
  592. //从字典里面查找
  593. drug, _ := service.GetBaseDrugByName(item.AdviceName, item.UserOrgId)
  594. service.UpdateDoctorAdviceByGoroupNo(item.ID, drug.ID)
  595. }
  596. }
  597. if item.ExecutionState == 2 {
  598. advice = item
  599. }
  600. }
  601. }
  602. if advice.ExecutionState == 1 {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  604. return
  605. }
  606. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  608. return
  609. }
  610. //针对普宁
  611. if adminUserInfo.Org.Id != 10599 {
  612. if advice.StartTime > theTime.Unix() {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  614. return
  615. }
  616. }
  617. advices := models.DoctorAdvice{
  618. ExecutionStaff: execution_staff,
  619. ExecutionTime: theTime.Unix(),
  620. UpdatedTime: time.Now().Unix(),
  621. }
  622. var err error
  623. if groupno > 0 {
  624. // 查询信息规挡的设置天数
  625. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  626. if infor.ID > 0 && infor.WeekDay > 0 {
  627. var cha_time int64
  628. timeNowStr := time.Now().Format("2006-01-02")
  629. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  630. //今日的日期减去设置的日期
  631. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  632. if cha_time >= record_date {
  633. //查询审核是否允许
  634. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  635. //申请状态不允许的情况 拒绝修改
  636. if infor.ApplicationStatus != 1 {
  637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  638. return
  639. }
  640. }
  641. }
  642. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  643. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  644. redis := service.RedisClient()
  645. //清空key 值
  646. redis.Set(key, "", time.Second)
  647. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  648. redis.Set(keyTwo, "", time.Second)
  649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  650. redis.Set(keyThree, "", time.Second)
  651. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  652. theTime := toTime.Format("2006-01-02")
  653. fmt.Println("theTIME", theTime)
  654. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  655. redis.Set(keyFour, "", time.Second)
  656. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  657. redis.Set(keyFive, "", time.Second)
  658. defer redis.Close()
  659. } else {
  660. // 查询信息规挡的设置天数
  661. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  662. if infor.ID > 0 {
  663. var cha_time int64
  664. timeNowStr := time.Now().Format("2006-01-02")
  665. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  666. //今日的日期减去设置的日期
  667. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  668. if cha_time >= record_date {
  669. //查询审核是否允许
  670. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  671. //申请状态不允许的情况 拒绝修改
  672. if infor.ApplicationStatus != 1 {
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  674. return
  675. }
  676. }
  677. }
  678. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  679. //记录日志
  680. byterequest, _ := json.Marshal(advice)
  681. adviceLog := models.XtDoctorAdviceLog{
  682. UserOrgId: advice.UserOrgId,
  683. PatientId: advice.PatientId,
  684. AdminUserId: adminUserInfo.AdminUser.Id,
  685. Module: 2,
  686. ErrLog: string(byterequest),
  687. Status: 1,
  688. Ctime: time.Now().Unix(),
  689. Mtime: 0,
  690. Source: "手机端执行医嘱",
  691. RecordDate: advices.RecordDate,
  692. }
  693. service.CreateDoctorAdviceLog(adviceLog)
  694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  695. redis := service.RedisClient()
  696. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  697. redis.Set(keyTwo, "", time.Second)
  698. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  699. redis.Set(keyThree, "", time.Second)
  700. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  701. theTime := toTime.Format("2006-01-02")
  702. fmt.Println("theTIME", theTime)
  703. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  704. redis.Set(keyFour, "", time.Second)
  705. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  706. redis.Set(keySix, "", time.Second)
  707. defer redis.Close()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. }
  711. if err != nil {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  713. return
  714. }
  715. advice.ExecutionStaff = execution_staff
  716. advice.ExecutionTime = theTime.Unix()
  717. advice.ExecutionState = 1
  718. advice.Modifier = adminUserInfo.AdminUser.Id
  719. //处理出库相关逻辑
  720. //1.判断是否启用药品管理和自备药出库功能
  721. //药品管理信息
  722. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  723. //自备药信息
  724. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  725. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  726. if drugStockConfig.IsOpen == 1 {
  727. if groupno > 0 {
  728. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  729. if len(advices) > 0 {
  730. var total int64
  731. var prescribing_number_total int64
  732. //出库
  733. for _, item := range advices {
  734. if item.Way == 1 {
  735. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  736. //查询该药品的剩余库存
  737. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  738. //查询改药品信息
  739. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  740. //判断单位是否相等
  741. if medical.MaxUnit == item.PrescribingNumberUnit {
  742. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  743. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  744. //转化为最小单位
  745. total = list.Count * medical.MinNumber
  746. prescribing_number_total = count * medical.MinNumber
  747. }
  748. if medical.MinUnit == item.PrescribingNumberUnit {
  749. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  750. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  751. total = list.Count*medical.MinNumber + list.StockMinNumber
  752. prescribing_number_total = count
  753. }
  754. if medical.IsUse == 1 {
  755. c.ServeSuccessJSON(map[string]interface{}{
  756. "msg": "1",
  757. "advice": advice,
  758. "ids": ids,
  759. })
  760. return
  761. }
  762. if medical.IsUse != 1 {
  763. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  764. if advice.UserOrgId != 10278 {
  765. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  766. advice.ExecutionTime = 0
  767. advice.ExecutionState = 2
  768. advice.ExecutionStaff = 0
  769. }
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "msg": "3",
  772. "advice": advice,
  773. "ids": ids,
  774. })
  775. return
  776. }
  777. if prescribing_number_total > total {
  778. if advice.UserOrgId != 10278 {
  779. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  780. advice.ExecutionTime = 0
  781. advice.ExecutionState = 2
  782. advice.ExecutionStaff = 0
  783. }
  784. c.ServeSuccessJSON(map[string]interface{}{
  785. "msg": "2",
  786. "advice": advice,
  787. "ids": ids,
  788. })
  789. return
  790. }
  791. }
  792. //查询是否出库按钮开启
  793. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  794. if adviceSetting.IsAdviceOpen == 1 {
  795. //查询是否出库按钮开启
  796. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  797. //患者发药
  798. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  799. if prescriptionConfig.IsOpen == 1 {
  800. if medical.IsUse == 2 {
  801. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  802. //查询今日是否出库
  803. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  804. if drugOutInfo.ID == 0 {
  805. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  806. }
  807. }
  808. if pharmacyConfig.IsOpen != 1 {
  809. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  810. if drugOutInfo.ID == 0 {
  811. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  812. }
  813. }
  814. //更新字典里面的库存
  815. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  816. var sum_count int64
  817. for _, its := range stockInfo {
  818. if its.MaxUnit == medical.MaxUnit {
  819. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  820. }
  821. sum_count += its.StockMaxNumber + its.StockMinNumber
  822. }
  823. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  824. //剩余库存
  825. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  826. }
  827. }
  828. } else {
  829. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  830. if medical.IsUse == 2 {
  831. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  832. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  833. if drugOutInfo.ID == 0 {
  834. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  835. }
  836. }
  837. if pharmacyConfig.IsOpen != 1 {
  838. drugError := models.XtDrugError{
  839. ID: 0,
  840. UserOrgId: item.UserOrgId,
  841. DrugId: item.DrugId,
  842. RecordDate: item.AdviceDate,
  843. PatientId: item.PatientId,
  844. Remark: "恒泰中医院出库开始",
  845. Status: 1,
  846. Ctime: time.Now().Unix(),
  847. Mtime: 0,
  848. Prescribingnumber: item.PrescribingNumber,
  849. PrescribingNumberUnit: item.PrescribingNumberUnit,
  850. SumCount: 0,
  851. }
  852. service.CreateDrugError(drugError)
  853. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  854. if drugOutInfo.ID == 0 {
  855. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  856. }
  857. }
  858. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  859. var sum_count int64
  860. for _, its := range stockInfo {
  861. if its.MaxUnit == medical.MaxUnit {
  862. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  863. }
  864. sum_count += its.StockMaxNumber + its.StockMinNumber
  865. }
  866. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  867. //剩余库存
  868. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  869. }
  870. }
  871. }
  872. }
  873. }
  874. c.ServeSuccessJSON(map[string]interface{}{
  875. "msg": "1",
  876. "advice": advice,
  877. "ids": ids,
  878. })
  879. return
  880. } else {
  881. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  882. if len(advices) > 0 {
  883. var total int64
  884. var prescribing_number_total int64
  885. for _, item := range advices {
  886. if item.Way == 1 {
  887. //查询改药品信息
  888. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  889. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  890. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  891. //查询该药品的剩余库存
  892. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  893. //判断单位是否相等
  894. if medical.MaxUnit == item.PrescribingNumberUnit {
  895. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  896. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  897. //转化为最小单位
  898. total = list.Count*medical.MinNumber + list.StockMinNumber
  899. prescribing_number_total = count * medical.MinNumber
  900. }
  901. if medical.MinUnit == item.PrescribingNumberUnit {
  902. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  903. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  904. total = list.Count*medical.MinNumber + list.StockMinNumber
  905. prescribing_number_total = count
  906. }
  907. if medical.IsUse == 1 {
  908. c.ServeSuccessJSON(map[string]interface{}{
  909. "msg": "1",
  910. "advice": advice,
  911. "ids": ids,
  912. })
  913. return
  914. }
  915. if medical.IsUse != 1 {
  916. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  917. if advice.UserOrgId != 10278 {
  918. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  919. advice.ExecutionTime = 0
  920. advice.ExecutionState = 2
  921. advice.ExecutionStaff = 0
  922. }
  923. c.ServeSuccessJSON(map[string]interface{}{
  924. "msg": "3",
  925. "advice": advice,
  926. "ids": ids,
  927. })
  928. return
  929. }
  930. if prescribing_number_total > total {
  931. if advice.UserOrgId != 10278 {
  932. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  933. advice.ExecutionTime = 0
  934. advice.ExecutionState = 2
  935. advice.ExecutionStaff = 0
  936. }
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "msg": "2",
  939. "advice": advice,
  940. "ids": ids,
  941. })
  942. return
  943. }
  944. }
  945. if medical.IsUse == 2 {
  946. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  947. //查询今日是否出库
  948. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  949. if drugOutInfo.ID == 0 {
  950. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  951. }
  952. }
  953. if pharmacyConfig.IsOpen != 1 {
  954. //查询今日是否出库
  955. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  956. if drugOutInfo.ID == 0 {
  957. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  958. }
  959. }
  960. //更新字典里面的库存
  961. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  962. var sum_count int64
  963. for _, its := range stockInfo {
  964. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  965. if its.MaxUnit == baseDrug.MaxUnit {
  966. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  967. }
  968. sum_count += its.StockMaxNumber + its.StockMinNumber
  969. }
  970. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  971. //剩余库存
  972. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  973. }
  974. if medical.IsUse == 1 {
  975. c.ServeSuccessJSON(map[string]interface{}{
  976. "msg": "1",
  977. "advice": advice,
  978. "ids": ids,
  979. })
  980. return
  981. }
  982. }
  983. }
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "msg": "1",
  987. "advice": advice,
  988. "ids": ids,
  989. })
  990. return
  991. }
  992. }
  993. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  994. if groupno > 0 {
  995. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  996. for _, item := range advices {
  997. if item.ExecutionState == 1 && item.Way == 2 {
  998. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  999. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1000. timeStr := time.Now().Format("2006-01-02")
  1001. timeArr := strings.Split(timeStr, "-")
  1002. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1003. total = total + 1
  1004. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1005. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1006. number = number + total
  1007. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1008. //插入自备药出库单
  1009. outStock := models.XtSelfOutStock{
  1010. DrugName: item.AdviceName,
  1011. DrugNameId: item.DrugNameId,
  1012. DrugSpec: item.AdviceDesc,
  1013. OutstoreNumber: count,
  1014. AdminUserId: adminUserInfo.AdminUser.Id,
  1015. StorckTime: item.AdviceDate,
  1016. UserOrgId: adminUserInfo.Org.Id,
  1017. CreatedTime: time.Now().Unix(),
  1018. Status: 1,
  1019. PatientId: item.PatientId,
  1020. ExitMode: 2,
  1021. MedicId: item.DrugId,
  1022. StockOutNumber: warehousing_out_order,
  1023. }
  1024. //查询 该患者是否已出库
  1025. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1026. if errcode == gorm.ErrRecordNotFound {
  1027. service.CreateOutStock(&outStock)
  1028. } else if errcode == nil {
  1029. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1030. fmt.Println("err", err)
  1031. }
  1032. }
  1033. }
  1034. } else {
  1035. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1036. for _, item := range advices {
  1037. if item.ExecutionState == 1 && item.Way == 2 {
  1038. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1039. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1040. timeStr := time.Now().Format("2006-01-02")
  1041. timeArr := strings.Split(timeStr, "-")
  1042. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  1043. total = total + 1
  1044. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1045. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1046. number = number + total
  1047. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1048. //插入自备药出库单
  1049. outStock := models.XtSelfOutStock{
  1050. DrugName: item.AdviceName,
  1051. DrugNameId: item.DrugNameId,
  1052. DrugSpec: item.AdviceDesc,
  1053. OutstoreNumber: count,
  1054. AdminUserId: adminUserInfo.AdminUser.Id,
  1055. StorckTime: item.AdviceDate,
  1056. UserOrgId: adminUserInfo.Org.Id,
  1057. CreatedTime: time.Now().Unix(),
  1058. Status: 1,
  1059. PatientId: item.PatientId,
  1060. ExitMode: 2,
  1061. MedicId: item.DrugId,
  1062. StockOutNumber: warehousing_out_order,
  1063. }
  1064. //查询 该患者是否已出库
  1065. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1066. if errcode == gorm.ErrRecordNotFound {
  1067. service.CreateOutStock(&outStock)
  1068. } else if errcode == nil {
  1069. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1070. fmt.Println("err", err)
  1071. }
  1072. }
  1073. }
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "msg": "1",
  1076. "advice": advice,
  1077. "ids": ids,
  1078. })
  1079. return
  1080. }
  1081. }
  1082. c.ServeSuccessJSON(map[string]interface{}{
  1083. "msg": "1",
  1084. "advice": advice,
  1085. "ids": ids,
  1086. })
  1087. return
  1088. } else if origin == 2 {
  1089. adminInfo := c.GetMobileAdminUserInfo()
  1090. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1091. var ids []string
  1092. advice_ids := c.GetString("advice_id")
  1093. ids = strings.Split(advice_ids, ",")
  1094. if len(execution_time) <= 0 {
  1095. utils.ErrorLog("execution_time")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. timeLayout2 := "2006-01-02 15:04:05"
  1100. loc, _ := time.LoadLocation("Local")
  1101. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1102. if errs != nil {
  1103. utils.ErrorLog(errs.Error())
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1108. var err error
  1109. for _, item := range advices {
  1110. if item.ExecutionState == 1 {
  1111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1112. return
  1113. }
  1114. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1116. return
  1117. }
  1118. if item.StartTime > theTime.Unix() {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1120. return
  1121. }
  1122. item.ExecutionState = 1
  1123. item.ExecutionStaff = adminInfo.AdminUser.Id
  1124. item.ExecutionTime = theTime.Unix()
  1125. item.IsMobile = 1
  1126. // 查询信息规挡的设置天数
  1127. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1128. if infor.ID > 0 {
  1129. var cha_time int64
  1130. timeNowStr := time.Now().Format("2006-01-02")
  1131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1132. //今日的日期减去设置的日期
  1133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1134. if cha_time >= item.AdviceDate {
  1135. //查询审核是否允许
  1136. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId, 4)
  1137. //申请状态不允许的情况 拒绝修改
  1138. if infor.ApplicationStatus != 1 {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1140. return
  1141. }
  1142. }
  1143. }
  1144. err = service.SaveHisDoctorAdvice(item)
  1145. //记录日志
  1146. byterequest, _ := json.Marshal(item)
  1147. adviceLog := models.XtDoctorAdviceLog{
  1148. UserOrgId: item.UserOrgId,
  1149. PatientId: item.PatientId,
  1150. AdminUserId: item.ExecutionStaff,
  1151. Module: 2,
  1152. ErrLog: string(byterequest),
  1153. Status: 1,
  1154. Ctime: time.Now().Unix(),
  1155. Mtime: 0,
  1156. Source: "手机端执行his医嘱",
  1157. RecordDate: item.AdviceDate,
  1158. }
  1159. service.CreateDoctorAdviceLog(adviceLog)
  1160. if err == nil {
  1161. drugError := models.XtDrugError{
  1162. UserOrgId: adminInfo.Org.Id,
  1163. DrugId: item.DrugId,
  1164. RecordDate: item.AdviceDate,
  1165. PatientId: item.PatientId,
  1166. Remark: "执行成功",
  1167. Status: 1,
  1168. Ctime: time.Now().Unix(),
  1169. Mtime: 0,
  1170. SumCount: 0,
  1171. Prescribingnumber: item.PrescribingNumber,
  1172. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1173. }
  1174. service.CreateDrugError(drugError)
  1175. }
  1176. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1177. redis := service.RedisClient()
  1178. //清空key 值
  1179. redis.Set(key, "", time.Second)
  1180. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1181. redis.Set(keyTwo, "", time.Second)
  1182. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1183. redis.Set(keyThree, "", time.Second)
  1184. recordDate := theTime.Format("2006-01-02")
  1185. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1186. redis.Set(keyFour, "", time.Second)
  1187. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1188. redis.Set(keyFive, "", time.Second)
  1189. defer redis.Close()
  1190. }
  1191. //药品管理信息
  1192. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1193. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1194. if drugStockConfig.IsOpen == 1 {
  1195. for _, item := range advices {
  1196. //查询改药品信息
  1197. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1198. //判断单位是否合格
  1199. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1200. //查询该药品是否有出库记录
  1201. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  1202. if len(flowMap) == 0 {
  1203. errs := service.UpdateHisAdviceById(item.ID)
  1204. if errs != nil {
  1205. drugError := models.XtDrugError{
  1206. UserOrgId: adminInfo.Org.Id,
  1207. DrugId: item.DrugId,
  1208. RecordDate: item.AdviceDate,
  1209. PatientId: item.PatientId,
  1210. Remark: "单位不统一,执行失败",
  1211. Status: 1,
  1212. Ctime: time.Now().Unix(),
  1213. Mtime: 0,
  1214. SumCount: 0,
  1215. Prescribingnumber: item.PrescribingNumber,
  1216. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1217. }
  1218. service.CreateDrugError(drugError)
  1219. }
  1220. }
  1221. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "msg": "7",
  1224. "advice": advice,
  1225. "ids": ids,
  1226. })
  1227. return
  1228. }
  1229. //查询这个患者这个患者这个药已经出库的所有数量
  1230. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1231. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1232. var total_count int64
  1233. var drug_count int64
  1234. for _, it := range advicelist {
  1235. if it.PrescribingNumberUnit == medical.MaxUnit {
  1236. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1237. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1238. total_count += prenumber * medical.MinNumber
  1239. }
  1240. if it.PrescribingNumberUnit == medical.MinUnit {
  1241. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1242. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1243. total_count += prenumber
  1244. }
  1245. }
  1246. for _, its := range drugoutlist {
  1247. if its.CountUnit == medical.MaxUnit {
  1248. drug_count += its.Count * medical.MinNumber
  1249. }
  1250. if its.CountUnit == medical.MinUnit {
  1251. drug_count += its.Count
  1252. }
  1253. }
  1254. if total_count == drug_count {
  1255. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "msg": "1",
  1258. "advice": advice,
  1259. "ids": ids,
  1260. })
  1261. return
  1262. }
  1263. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1264. var total int64
  1265. var prescribing_number_total int64
  1266. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1267. if config.IsOpen != 1 {
  1268. //查询该药品是否有库存
  1269. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1270. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1271. //判断单位是否相等
  1272. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1273. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1274. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1275. //转化为最小单位
  1276. total = list.Count*medical.MinNumber + list.StockMinNumber
  1277. prescribing_number_total = count * medical.MinNumber
  1278. }
  1279. //fmt.Println("医嘱开的数量", total)
  1280. if medical.MinUnit == advice.PrescribingNumberUnit {
  1281. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1282. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1283. total = list.Count*medical.MinNumber + list.StockMinNumber
  1284. prescribing_number_total = count
  1285. }
  1286. if medical.IsUse == 1 {
  1287. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1288. drugError := models.XtDrugError{
  1289. UserOrgId: adminInfo.Org.Id,
  1290. DrugId: item.DrugId,
  1291. RecordDate: item.AdviceDate,
  1292. PatientId: item.PatientId,
  1293. Remark: "零用药品库存不足",
  1294. Status: 1,
  1295. Ctime: time.Now().Unix(),
  1296. Mtime: 0,
  1297. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1298. Prescribingnumber: advice.PrescribingNumber,
  1299. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1300. }
  1301. service.CreateDrugError(drugError)
  1302. c.ServeSuccessJSON(map[string]interface{}{
  1303. "msg": "1",
  1304. "advice": advice,
  1305. "ids": ids,
  1306. })
  1307. return
  1308. }
  1309. }
  1310. if medical.IsUse != 1 {
  1311. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1312. drugError := models.XtDrugError{
  1313. UserOrgId: adminInfo.Org.Id,
  1314. DrugId: item.DrugId,
  1315. RecordDate: item.AdviceDate,
  1316. PatientId: item.PatientId,
  1317. Remark: "药品库存不足",
  1318. Status: 1,
  1319. Ctime: time.Now().Unix(),
  1320. Mtime: 0,
  1321. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1322. Prescribingnumber: advice.PrescribingNumber,
  1323. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1324. }
  1325. service.CreateDrugError(drugError)
  1326. c.ServeSuccessJSON(map[string]interface{}{
  1327. "msg": "3",
  1328. "advice": advice,
  1329. "ids": ids,
  1330. })
  1331. return
  1332. }
  1333. if prescribing_number_total > total {
  1334. drugError := models.XtDrugError{
  1335. UserOrgId: adminInfo.Org.Id,
  1336. DrugId: item.DrugId,
  1337. RecordDate: item.AdviceDate,
  1338. PatientId: item.PatientId,
  1339. Remark: "出库数量大于库存",
  1340. Status: 1,
  1341. Ctime: time.Now().Unix(),
  1342. Mtime: 0,
  1343. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1344. Prescribingnumber: advice.PrescribingNumber,
  1345. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1346. }
  1347. service.CreateDrugError(drugError)
  1348. c.ServeSuccessJSON(map[string]interface{}{
  1349. "msg": "2",
  1350. "advice": advice,
  1351. "ids": ids,
  1352. })
  1353. return
  1354. }
  1355. }
  1356. if prescribing_number_total <= total {
  1357. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1358. //判断药品是否零用
  1359. if medical.IsUse == 2 {
  1360. if config.IsOpen != 1 {
  1361. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1362. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1363. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1364. //查询该药品是否有出库记录
  1365. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1366. if len(flowMap) == 0 {
  1367. errs := service.UpdateHisAdviceById(advice.ID)
  1368. if errs != nil {
  1369. drugError := models.XtDrugError{
  1370. UserOrgId: adminInfo.Org.Id,
  1371. DrugId: item.DrugId,
  1372. RecordDate: item.AdviceDate,
  1373. PatientId: item.PatientId,
  1374. Remark: "出库记录为空,更新执行人失败",
  1375. Status: 1,
  1376. Ctime: time.Now().Unix(),
  1377. Mtime: 0,
  1378. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1379. Prescribingnumber: advice.PrescribingNumber,
  1380. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1381. }
  1382. service.CreateDrugError(drugError)
  1383. }
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "msg": "6",
  1386. "advice": advice,
  1387. "ids": ids,
  1388. })
  1389. return
  1390. }
  1391. }
  1392. }
  1393. if pharmacyConfig.IsOpen != 1 {
  1394. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1395. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1396. //查询该药品是否有出库记录
  1397. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1398. if len(flowMap) == 0 {
  1399. errs := service.UpdateHisAdviceById(advice.ID)
  1400. if errs != nil {
  1401. drugError := models.XtDrugError{
  1402. UserOrgId: adminInfo.Org.Id,
  1403. DrugId: item.DrugId,
  1404. RecordDate: item.AdviceDate,
  1405. PatientId: item.PatientId,
  1406. Remark: "出库记录为空,更新执行人失败",
  1407. Status: 1,
  1408. Ctime: time.Now().Unix(),
  1409. Mtime: 0,
  1410. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1411. Prescribingnumber: advice.PrescribingNumber,
  1412. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1413. }
  1414. service.CreateDrugError(drugError)
  1415. }
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "msg": "6",
  1418. "advice": advice,
  1419. "ids": ids,
  1420. })
  1421. return
  1422. }
  1423. }
  1424. }
  1425. //更新字典里面的库存
  1426. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1427. var sum_count int64
  1428. for _, its := range stockInfo {
  1429. if its.MaxUnit == medical.MaxUnit {
  1430. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1431. }
  1432. sum_count += its.StockMaxNumber + its.StockMinNumber
  1433. }
  1434. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1435. //剩余库存
  1436. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1437. }
  1438. }
  1439. }
  1440. }
  1441. //
  1442. //if config.IsOpen == 1 && item.UserOrgId == 10210 {
  1443. //
  1444. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1445. // //更新字典里面的库存
  1446. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1447. // var sum_count int64
  1448. // for _, its := range stockInfo {
  1449. // if its.MaxUnit == medical.MaxUnit {
  1450. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1451. // }
  1452. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1453. // }
  1454. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1455. // //剩余库存
  1456. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1457. //}
  1458. }
  1459. }
  1460. for _, item := range advices {
  1461. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1462. c.ServeSuccessJSON(map[string]interface{}{
  1463. "msg": "1",
  1464. "advice": advice,
  1465. "ids": ids,
  1466. })
  1467. }
  1468. }
  1469. }
  1470. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1471. execution_time := c.GetString("execution_time")
  1472. fmt.Println("execution_time", execution_time)
  1473. groupno, _ := c.GetInt64("groupno", -1)
  1474. //patient_id, _ := c.GetInt64("patient_id")
  1475. advice_date, _ := c.GetInt64("advice_date")
  1476. var ids []string
  1477. if groupno == 0 {
  1478. advice_ids := c.GetString("advice_id")
  1479. ids = strings.Split(advice_ids, ",")
  1480. }
  1481. if groupno < 0 {
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. if len(execution_time) <= 0 {
  1486. utils.ErrorLog("execution_time")
  1487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1488. return
  1489. }
  1490. timeLayout2 := "2006-01-02 15:04:05"
  1491. loc, _ := time.LoadLocation("Local")
  1492. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1493. if errs != nil {
  1494. utils.ErrorLog(errs.Error())
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1496. return
  1497. }
  1498. adminUserInfo := c.GetMobileAdminUserInfo()
  1499. var advice models.DoctorAdvice
  1500. if groupno > 0 {
  1501. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1502. for _, item := range advices {
  1503. if item.ExecutionState == 1 {
  1504. advice = item
  1505. }
  1506. }
  1507. } else {
  1508. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1509. for _, item := range advices {
  1510. if item.ExecutionState == 1 {
  1511. advice = item
  1512. }
  1513. }
  1514. }
  1515. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1516. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1517. // if getPermissionErr != nil {
  1518. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1519. // return
  1520. // } else if headNursePermission == nil {
  1521. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1522. // return
  1523. // }
  1524. //}
  1525. if advice.StartTime > theTime.Unix() {
  1526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1527. return
  1528. }
  1529. advices := models.DoctorAdvice{
  1530. ExecutionTime: theTime.Unix(),
  1531. UpdatedTime: time.Now().Unix(),
  1532. }
  1533. var err error
  1534. if groupno > 0 {
  1535. // 查询信息规挡的设置天数
  1536. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1537. if infor.ID > 0 {
  1538. var cha_time int64
  1539. timeNowStr := time.Now().Format("2006-01-02")
  1540. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1541. //今日的日期减去设置的日期
  1542. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1543. if cha_time >= advices.AdviceDate {
  1544. //查询审核是否允许
  1545. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1546. //申请状态不允许的情况 拒绝修改
  1547. if infor.ApplicationStatus != 1 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1549. return
  1550. }
  1551. }
  1552. }
  1553. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1554. //记录日志
  1555. byterequest, _ := json.Marshal(advices)
  1556. adviceLog := models.XtDoctorAdviceLog{
  1557. UserOrgId: adminUserInfo.Org.Id,
  1558. PatientId: advices.PatientId,
  1559. AdminUserId: adminUserInfo.AdminUser.Id,
  1560. Module: 1,
  1561. ErrLog: string(byterequest),
  1562. Status: 1,
  1563. Ctime: time.Now().Unix(),
  1564. Mtime: 0,
  1565. Source: "手机端编辑医嘱",
  1566. RecordDate: advices.AdviceDate,
  1567. }
  1568. service.CreateDoctorAdviceLog(adviceLog)
  1569. redis := service.RedisClient()
  1570. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1571. redis.Set(key, "", time.Second)
  1572. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1573. redis.Set(keyOne, "", time.Second)
  1574. defer redis.Close()
  1575. } else {
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= advices.AdviceDate {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1594. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1595. //记录日志
  1596. byterequest, _ := json.Marshal(advices)
  1597. adviceLog := models.XtDoctorAdviceLog{
  1598. UserOrgId: adminUserInfo.Org.Id,
  1599. PatientId: advices.PatientId,
  1600. AdminUserId: adminUserInfo.AdminUser.Id,
  1601. Module: 1,
  1602. ErrLog: string(byterequest),
  1603. Status: 1,
  1604. Ctime: time.Now().Unix(),
  1605. Mtime: 0,
  1606. Source: "手机端编辑执行医嘱",
  1607. RecordDate: advices.AdviceDate,
  1608. }
  1609. service.CreateDoctorAdviceLog(adviceLog)
  1610. redis := service.RedisClient()
  1611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1612. redis.Set(key, "", time.Second)
  1613. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1614. redis.Set(keyOne, "", time.Second)
  1615. defer redis.Close()
  1616. }
  1617. //判断是否开启his
  1618. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1619. //如果开启去修改执行时间
  1620. if config.IsOpen == 1 {
  1621. advicesinfo := models.HisDoctorAdviceInfo{
  1622. ExecutionTime: theTime.Unix(),
  1623. UpdatedTime: time.Now().Unix(),
  1624. }
  1625. var advicehis models.HisDoctorAdviceInfo
  1626. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1627. //记录日志
  1628. byterequest, _ := json.Marshal(advicesinfo)
  1629. adviceLog := models.XtDoctorAdviceLog{
  1630. UserOrgId: adminUserInfo.Org.Id,
  1631. PatientId: advices.PatientId,
  1632. AdminUserId: adminUserInfo.AdminUser.Id,
  1633. Module: 1,
  1634. ErrLog: string(byterequest),
  1635. Status: 1,
  1636. Ctime: time.Now().Unix(),
  1637. Mtime: 0,
  1638. Source: "手机端his编辑医嘱",
  1639. RecordDate: advices.AdviceDate,
  1640. }
  1641. service.CreateDoctorAdviceLog(adviceLog)
  1642. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1643. for _, item := range his_advices {
  1644. if item.ExecutionState == 1 {
  1645. advicehis = item
  1646. }
  1647. }
  1648. redis := service.RedisClient()
  1649. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1650. redis.Set(keyThree, "", time.Second)
  1651. recordDate := theTime.Format("2006-01-02")
  1652. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1653. redis.Set(keyFour, "", time.Second)
  1654. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1655. redis.Set(keyFive, "", time.Second)
  1656. defer redis.Close()
  1657. project := models.HisPrescriptionProject{
  1658. ExecutionTime: theTime.Unix(),
  1659. Mtime: time.Now().Unix(),
  1660. }
  1661. service.ModifyHisPrescriptionProject(&project, ids)
  1662. //记录日志
  1663. projectquerst, _ := json.Marshal(project)
  1664. projectLog := models.XtDoctorAdviceLog{
  1665. UserOrgId: adminUserInfo.Org.Id,
  1666. PatientId: advices.PatientId,
  1667. AdminUserId: adminUserInfo.AdminUser.Id,
  1668. Module: 1,
  1669. ErrLog: string(projectquerst),
  1670. Status: 1,
  1671. Ctime: time.Now().Unix(),
  1672. Mtime: 0,
  1673. Source: "手机端his编辑项目医嘱",
  1674. RecordDate: advices.AdviceDate,
  1675. }
  1676. service.CreateDoctorAdviceLog(projectLog)
  1677. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1678. redis.Set(keyEnd, "", time.Second)
  1679. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1680. redis.Set(keyFours, "", time.Second)
  1681. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1682. redis.Set(keyFives, "", time.Second)
  1683. defer redis.Close()
  1684. }
  1685. if err != nil {
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1687. return
  1688. }
  1689. advice.ExecutionTime = theTime.Unix()
  1690. c.ServeSuccessJSON(map[string]interface{}{
  1691. "msg": "ok",
  1692. "advice": advice,
  1693. "ids": ids,
  1694. })
  1695. return
  1696. }
  1697. func (c *PatientApiController) CheckMobileDoctorAdvice() {
  1698. origin, _ := c.GetInt64("origin", 0)
  1699. record_date, _ := c.GetInt64("record_date")
  1700. patient_id, _ := c.GetInt64("patient_id")
  1701. check_time := c.GetString("check_time")
  1702. if len(check_time) <= 0 {
  1703. utils.ErrorLog("check_time")
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. timeLayout2 := "2006-01-02 15:04:05"
  1708. loc, _ := time.LoadLocation("Local")
  1709. theTime, errs := time.ParseInLocation(timeLayout2, check_time, loc)
  1710. fmt.Println("theTimewowowow", theTime)
  1711. if errs != nil {
  1712. utils.ErrorLog(errs.Error())
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1714. return
  1715. }
  1716. if origin != 2 {
  1717. groupno, _ := c.GetInt64("groupno", -1)
  1718. var ids []string
  1719. if groupno == 0 {
  1720. advice_ids := c.GetString("advice_id")
  1721. if advice_ids == "" {
  1722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1723. return
  1724. } else {
  1725. ids = strings.Split(advice_ids, ",")
  1726. if len(ids) <= 0 {
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1728. return
  1729. }
  1730. }
  1731. }
  1732. if groupno < 0 {
  1733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1734. return
  1735. }
  1736. adminUserInfo := c.GetMobileAdminUserInfo()
  1737. var advice models.DoctorAdvice
  1738. if groupno > 0 {
  1739. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1740. for _, item := range advices {
  1741. if item.CheckState == 0 {
  1742. advice = item
  1743. }
  1744. //记录日志
  1745. byterequest, _ := json.Marshal(advices)
  1746. adviceLog := models.XtDoctorAdviceLog{
  1747. UserOrgId: adminUserInfo.Org.Id,
  1748. PatientId: item.PatientId,
  1749. AdminUserId: adminUserInfo.AdminUser.Id,
  1750. Module: 3,
  1751. ErrLog: string(byterequest),
  1752. Status: 1,
  1753. Ctime: time.Now().Unix(),
  1754. Mtime: 0,
  1755. Source: "手机端核对医嘱",
  1756. RecordDate: item.AdviceDate,
  1757. }
  1758. service.CreateDoctorAdviceLog(adviceLog)
  1759. }
  1760. if advice.CheckState == 1 {
  1761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1762. return
  1763. }
  1764. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1766. return
  1767. }
  1768. } else {
  1769. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1770. for _, item := range advices {
  1771. if item.CheckState == 0 {
  1772. advice = item
  1773. }
  1774. //记录日志
  1775. byterequest, _ := json.Marshal(advices)
  1776. adviceLog := models.XtDoctorAdviceLog{
  1777. UserOrgId: adminUserInfo.Org.Id,
  1778. PatientId: item.PatientId,
  1779. AdminUserId: adminUserInfo.AdminUser.Id,
  1780. Module: 3,
  1781. ErrLog: string(byterequest),
  1782. Status: 1,
  1783. Ctime: time.Now().Unix(),
  1784. Mtime: 0,
  1785. Source: "手机端核对医嘱",
  1786. RecordDate: item.AdviceDate,
  1787. }
  1788. service.CreateDoctorAdviceLog(adviceLog)
  1789. }
  1790. if advice.CheckState == 1 {
  1791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1792. return
  1793. }
  1794. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1796. return
  1797. }
  1798. }
  1799. checker := adminUserInfo.AdminUser.Id
  1800. advices := models.DoctorAdvice{
  1801. CheckTime: theTime.Unix(),
  1802. Checker: checker,
  1803. UpdatedTime: time.Now().Unix(),
  1804. }
  1805. fmt.Println("groupnowowowowoowowow", groupno)
  1806. var err error
  1807. if groupno > 0 {
  1808. // 查询信息规挡的设置天数
  1809. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1810. if infor.ID > 0 && infor.WeekDay > 0 {
  1811. var cha_time int64
  1812. timeNowStr := time.Now().Format("2006-01-02")
  1813. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1814. //今日的日期减去设置的日期
  1815. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1816. if cha_time >= record_date {
  1817. //查询审核是否允许
  1818. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  1819. //申请状态不允许的情况 拒绝修改
  1820. if infor.ApplicationStatus != 1 {
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1822. return
  1823. }
  1824. }
  1825. }
  1826. err = service.CheckDoctorAdviceByGroupNoOne(&advices, groupno, adminUserInfo.Org.Id)
  1827. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1828. redis := service.RedisClient()
  1829. //清空key 值
  1830. redis.Set(key, "", time.Second)
  1831. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1832. redis.Set(keyTwo, "", time.Second)
  1833. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1834. redis.Set(keyThree, "", time.Second)
  1835. recordDate := theTime.Format("2006-01-02")
  1836. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1837. redis.Set(keyFour, "", time.Second)
  1838. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1839. redis.Set(keyFive, "", time.Second)
  1840. defer redis.Close()
  1841. } else {
  1842. if len(ids[0]) <= 0 {
  1843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1844. return
  1845. } else {
  1846. //t := time.Now().Format("2006-01-02")/**/
  1847. //timeLayout2 := "2006-01-02"
  1848. //loc, _ := time.LoadLocation("Local")
  1849. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1850. // 查询信息规挡的设置天数
  1851. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1852. if infor.ID > 0 {
  1853. var cha_time int64
  1854. timeNowStr := time.Now().Format("2006-01-02")
  1855. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1856. //今日的日期减去设置的日期
  1857. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1858. if cha_time >= advices.AdviceDate {
  1859. //查询审核是否允许
  1860. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  1861. //申请状态不允许的情况 拒绝修改
  1862. if infor.ApplicationStatus != 1 {
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1864. return
  1865. }
  1866. }
  1867. }
  1868. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1869. //记录日志
  1870. byterequest, _ := json.Marshal(advices)
  1871. adviceLog := models.XtDoctorAdviceLog{
  1872. UserOrgId: adminUserInfo.Org.Id,
  1873. PatientId: advices.PatientId,
  1874. AdminUserId: advices.Checker,
  1875. Module: 3,
  1876. ErrLog: string(byterequest),
  1877. Status: 1,
  1878. Ctime: time.Now().Unix(),
  1879. Mtime: 0,
  1880. Source: "手机端核对医嘱",
  1881. RecordDate: advices.AdviceDate,
  1882. }
  1883. service.CreateDoctorAdviceLog(adviceLog)
  1884. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1885. redis := service.RedisClient()
  1886. //清空key 值
  1887. redis.Set(key, "", time.Second)
  1888. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1889. redis.Set(keyTwo, "", time.Second)
  1890. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1891. redis.Set(keyThree, "", time.Second)
  1892. recordDate := theTime.Format("2006-01-02")
  1893. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1894. redis.Set(keyFour, "", time.Second)
  1895. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1896. redis.Set(keyFive, "", time.Second)
  1897. defer redis.Close()
  1898. }
  1899. }
  1900. if err != nil {
  1901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1902. return
  1903. }
  1904. advice.Checker = checker
  1905. advice.CheckTime = theTime.Unix()
  1906. advice.CheckState = 1
  1907. c.ServeSuccessJSON(map[string]interface{}{
  1908. "msg": "ok",
  1909. "advice": advice,
  1910. })
  1911. }
  1912. return
  1913. }
  1914. func (c *PatientApiController) CheckDoctorAdvice() {
  1915. origin, _ := c.GetInt64("origin", 0)
  1916. record_date, _ := c.GetInt64("record_date")
  1917. patient_id, _ := c.GetInt64("patient_id")
  1918. if origin != 2 {
  1919. groupno, _ := c.GetInt64("groupno", -1)
  1920. var ids []string
  1921. if groupno == 0 {
  1922. advice_ids := c.GetString("advice_id")
  1923. if advice_ids == "" {
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. } else {
  1927. ids = strings.Split(advice_ids, ",")
  1928. if len(ids) <= 0 {
  1929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1930. return
  1931. }
  1932. }
  1933. }
  1934. if groupno < 0 {
  1935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1936. return
  1937. }
  1938. adminUserInfo := c.GetMobileAdminUserInfo()
  1939. var advice models.DoctorAdvice
  1940. if groupno > 0 {
  1941. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1942. for _, item := range advices {
  1943. if item.CheckState == 0 {
  1944. advice = item
  1945. }
  1946. //记录日志
  1947. byterequest, _ := json.Marshal(advices)
  1948. adviceLog := models.XtDoctorAdviceLog{
  1949. UserOrgId: adminUserInfo.Org.Id,
  1950. PatientId: item.PatientId,
  1951. AdminUserId: adminUserInfo.AdminUser.Id,
  1952. Module: 3,
  1953. ErrLog: string(byterequest),
  1954. Status: 1,
  1955. Ctime: time.Now().Unix(),
  1956. Mtime: 0,
  1957. Source: "手机端核对医嘱",
  1958. RecordDate: item.AdviceDate,
  1959. }
  1960. service.CreateDoctorAdviceLog(adviceLog)
  1961. }
  1962. if advice.CheckState == 1 {
  1963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1964. return
  1965. }
  1966. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1968. return
  1969. }
  1970. } else {
  1971. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1972. for _, item := range advices {
  1973. if item.CheckState == 0 {
  1974. advice = item
  1975. }
  1976. //记录日志
  1977. byterequest, _ := json.Marshal(advices)
  1978. adviceLog := models.XtDoctorAdviceLog{
  1979. UserOrgId: adminUserInfo.Org.Id,
  1980. PatientId: item.PatientId,
  1981. AdminUserId: adminUserInfo.AdminUser.Id,
  1982. Module: 3,
  1983. ErrLog: string(byterequest),
  1984. Status: 1,
  1985. Ctime: time.Now().Unix(),
  1986. Mtime: 0,
  1987. Source: "手机端核对医嘱",
  1988. RecordDate: item.AdviceDate,
  1989. }
  1990. service.CreateDoctorAdviceLog(adviceLog)
  1991. }
  1992. if advice.CheckState == 1 {
  1993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1994. return
  1995. }
  1996. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1998. return
  1999. }
  2000. }
  2001. checker := adminUserInfo.AdminUser.Id
  2002. theTime := time.Now()
  2003. advices := models.DoctorAdvice{
  2004. CheckTime: theTime.Unix(),
  2005. Checker: checker,
  2006. UpdatedTime: time.Now().Unix(),
  2007. }
  2008. var err error
  2009. if groupno > 0 {
  2010. // 查询信息规挡的设置天数
  2011. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2012. if infor.ID > 0 && infor.WeekDay > 0 {
  2013. var cha_time int64
  2014. timeNowStr := time.Now().Format("2006-01-02")
  2015. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2016. //今日的日期减去设置的日期
  2017. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2018. if cha_time >= record_date {
  2019. //查询审核是否允许
  2020. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id, 4)
  2021. //申请状态不允许的情况 拒绝修改
  2022. if infor.ApplicationStatus != 1 {
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2024. return
  2025. }
  2026. }
  2027. }
  2028. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  2029. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2030. redis := service.RedisClient()
  2031. //清空key 值
  2032. redis.Set(key, "", time.Second)
  2033. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2034. redis.Set(keyTwo, "", time.Second)
  2035. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2036. redis.Set(keyThree, "", time.Second)
  2037. recordDate := theTime.Format("2006-01-02")
  2038. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2039. redis.Set(keyFour, "", time.Second)
  2040. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2041. redis.Set(keyFive, "", time.Second)
  2042. defer redis.Close()
  2043. } else {
  2044. if len(ids[0]) <= 0 {
  2045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2046. return
  2047. } else {
  2048. //t := time.Now().Format("2006-01-02")/**/
  2049. //timeLayout2 := "2006-01-02"
  2050. //loc, _ := time.LoadLocation("Local")
  2051. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  2052. // 查询信息规挡的设置天数
  2053. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2054. if infor.ID > 0 {
  2055. var cha_time int64
  2056. timeNowStr := time.Now().Format("2006-01-02")
  2057. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2058. //今日的日期减去设置的日期
  2059. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2060. if cha_time >= advices.AdviceDate {
  2061. //查询审核是否允许
  2062. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id, 4)
  2063. //申请状态不允许的情况 拒绝修改
  2064. if infor.ApplicationStatus != 1 {
  2065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2066. return
  2067. }
  2068. }
  2069. }
  2070. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  2071. //记录日志
  2072. byterequest, _ := json.Marshal(advices)
  2073. adviceLog := models.XtDoctorAdviceLog{
  2074. UserOrgId: adminUserInfo.Org.Id,
  2075. PatientId: advices.PatientId,
  2076. AdminUserId: advices.Checker,
  2077. Module: 3,
  2078. ErrLog: string(byterequest),
  2079. Status: 1,
  2080. Ctime: time.Now().Unix(),
  2081. Mtime: 0,
  2082. Source: "手机端核对医嘱",
  2083. RecordDate: advices.AdviceDate,
  2084. }
  2085. service.CreateDoctorAdviceLog(adviceLog)
  2086. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2087. redis := service.RedisClient()
  2088. //清空key 值
  2089. redis.Set(key, "", time.Second)
  2090. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2091. redis.Set(keyTwo, "", time.Second)
  2092. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2093. redis.Set(keyThree, "", time.Second)
  2094. recordDate := theTime.Format("2006-01-02")
  2095. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2096. redis.Set(keyFour, "", time.Second)
  2097. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2098. redis.Set(keyFive, "", time.Second)
  2099. defer redis.Close()
  2100. }
  2101. }
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2104. return
  2105. }
  2106. advice.Checker = checker
  2107. advice.CheckTime = theTime.Unix()
  2108. advice.CheckState = 1
  2109. c.ServeSuccessJSON(map[string]interface{}{
  2110. "msg": "ok",
  2111. "advice": advice,
  2112. })
  2113. } else if origin == 2 {
  2114. adminInfo := c.GetMobileAdminUserInfo()
  2115. var ids []string
  2116. advice_ids := c.GetString("advice_id")
  2117. ids = strings.Split(advice_ids, ",")
  2118. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  2119. var err error
  2120. for _, item := range advices {
  2121. if item.CheckState == 1 {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2123. return
  2124. }
  2125. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2127. return
  2128. }
  2129. item.Checker = adminInfo.AdminUser.Id
  2130. item.CheckTime = time.Now().Unix()
  2131. item.CheckState = 1
  2132. // 查询信息规挡的设置天数
  2133. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  2134. if infor.ID > 0 {
  2135. var cha_time int64
  2136. timeNowStr := time.Now().Format("2006-01-02")
  2137. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2138. //今日的日期减去设置的日期
  2139. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2140. if cha_time >= record_date {
  2141. //查询审核是否允许
  2142. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id, 4)
  2143. //申请状态不允许的情况 拒绝修改
  2144. if infor.ApplicationStatus != 1 {
  2145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2146. return
  2147. }
  2148. }
  2149. }
  2150. err = service.SaveHisDoctorAdvice(item)
  2151. //记录日志
  2152. byterequest, _ := json.Marshal(advices)
  2153. adviceLog := models.XtDoctorAdviceLog{
  2154. UserOrgId: adminInfo.Org.Id,
  2155. PatientId: item.PatientId,
  2156. AdminUserId: item.Checker,
  2157. Module: 3,
  2158. ErrLog: string(byterequest),
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Source: "手机端核对His医嘱",
  2163. RecordDate: item.AdviceDate,
  2164. }
  2165. service.CreateDoctorAdviceLog(adviceLog)
  2166. redis := service.RedisClient()
  2167. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2168. //清空key 值
  2169. redis.Set(key, "", time.Second)
  2170. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2171. redis.Set(keyTwo, "", time.Second)
  2172. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2173. redis.Set(keyThree, "", time.Second)
  2174. theTime := time.Now()
  2175. recordDate := theTime.Format("2006-01-02")
  2176. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  2177. redis.Set(keyFour, "", time.Second)
  2178. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2179. redis.Set(keyFive, "", time.Second)
  2180. defer redis.Close()
  2181. }
  2182. if err == nil {
  2183. c.ServeSuccessJSON(map[string]interface{}{
  2184. "msg": "ok",
  2185. "advice": advices,
  2186. })
  2187. } else {
  2188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2189. return
  2190. }
  2191. }
  2192. return
  2193. }
  2194. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  2195. id, _ := c.GetInt64("patient", 0)
  2196. assessmentDate := c.GetString("assessment_date", "")
  2197. if id <= 0 || len(assessmentDate) != 10 {
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2199. return
  2200. }
  2201. timeLayout := "2006-01-02"
  2202. loc, _ := time.LoadLocation("Local")
  2203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  2204. if err != nil {
  2205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2206. return
  2207. }
  2208. theAssessmentDateTime := theTime.Unix()
  2209. adminUserInfo := c.GetMobileAdminUserInfo()
  2210. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2211. if patient.ID == 0 {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2213. return
  2214. }
  2215. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2216. if getPEErr != nil {
  2217. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  2218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2219. return
  2220. }
  2221. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2222. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2223. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2224. var evaluation models.PredialysisEvaluation
  2225. if theEvaluation != nil {
  2226. evaluation = *theEvaluation
  2227. }
  2228. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  2229. if code > 0 {
  2230. c.ServeFailJSONWithSGJErrorCode(code)
  2231. return
  2232. }
  2233. if theEvaluation == nil {
  2234. evaluation.CreatedTime = time.Now().Unix()
  2235. evaluation.Status = 1
  2236. evaluation.AssessmentDate = theAssessmentDateTime
  2237. evaluation.PatientId = id
  2238. evaluation.UserOrgId = adminUserInfo.Org.Id
  2239. if appRole.UserType == 2 || appRole.UserType == 1 {
  2240. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2241. evaluation.AssessmentTime = time.Now().Unix()
  2242. } else {
  2243. evaluation.Creater = adminUserInfo.AdminUser.Id
  2244. }
  2245. } else {
  2246. evaluation.UpdatedTime = time.Now().Unix()
  2247. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  2248. if appRole.UserType == 2 || appRole.UserType == 1 {
  2249. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2250. evaluation.AssessmentTime = time.Now().Unix()
  2251. } else {
  2252. evaluation.Modifier = adminUserInfo.AdminUser.Id
  2253. if evaluation.Creater == 0 {
  2254. evaluation.Creater = adminUserInfo.AdminUser.Id
  2255. }
  2256. }
  2257. }
  2258. //新增逻辑
  2259. var dewater_amount float64
  2260. dewater_amount = 0
  2261. if evaluation.DryWeight > 0 {
  2262. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2263. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10551 || adminUserInfo.Org.Id == 10579 || adminUserInfo.Org.Id == 10580 || adminUserInfo.Org.Id == 10585 {
  2264. if adminUserInfo.Org.Id != 10551 && adminUserInfo.Org.Id != 10579 && adminUserInfo.Org.Id != 10580 && adminUserInfo.Org.Id != 10585 {
  2265. dewater_amount = dewater_amount * 1000
  2266. }
  2267. }
  2268. if dewater_amount <= 0 {
  2269. dewater_amount = 0
  2270. }
  2271. } else {
  2272. dewater_amount = 0
  2273. }
  2274. // 计算透析处方的相关超滤量
  2275. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  2276. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  2277. var lastDialysisPrescribe *models.DialysisPrescription
  2278. var dialysisSolution *models.DialysisSolution
  2279. var dialysisPrescribe *models.DialysisPrescription
  2280. var system_dialysisPrescribe *models.SystemPrescription
  2281. var mode_id int64
  2282. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  2283. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2284. if schedual != nil {
  2285. // 获取透析模版
  2286. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  2287. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  2288. mode_id = schedual.ModeId
  2289. } else {
  2290. // 获取透析模版
  2291. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  2292. if dialysisPrescribe == nil && dialysisSolution != nil {
  2293. mode_id = dialysisSolution.ModeId
  2294. }
  2295. if dialysisPrescribe == nil && dialysisSolution == nil {
  2296. mode_id = 0
  2297. }
  2298. }
  2299. // 插入透析处方
  2300. if dialysisPrescribe == nil && dialysisSolution != nil {
  2301. var newprescribe models.DialysisPrescription
  2302. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2303. newprescribe.PatientId = id
  2304. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2305. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2306. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2307. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2308. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2309. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2310. newprescribe.ModeId = dialysisSolution.ModeId
  2311. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2312. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2313. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2314. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2315. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2316. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2317. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2318. newprescribe.Glucose = dialysisSolution.Glucose
  2319. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2320. newprescribe.Kalium = dialysisSolution.Kalium
  2321. newprescribe.Sodium = dialysisSolution.Sodium
  2322. newprescribe.Calcium = dialysisSolution.Calcium
  2323. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2324. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2325. newprescribe.Conductivity = dialysisSolution.Conductivity
  2326. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2327. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2328. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2329. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2330. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2331. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2332. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2333. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2334. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2335. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2336. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2337. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2338. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2339. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2340. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2341. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2342. newprescribe.CreatedTime = time.Now().Unix()
  2343. newprescribe.UpdatedTime = time.Now().Unix()
  2344. newprescribe.RecordDate = theAssessmentDateTime
  2345. newprescribe.DewaterAmount = dewater_amount
  2346. newprescribe.TargetUltrafiltration = dewater_amount
  2347. newprescribe.Status = 1
  2348. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2349. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2350. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2351. newprescribe.Remark = lastDialysisPrescription.Remark
  2352. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2353. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2354. newprescribe.ID = dialysisPrescription.ID
  2355. if dialysisPrescription.ID == 0 {
  2356. if adminUserInfo.Org.Id == 10340 {
  2357. newprescribe.Sodium = 138
  2358. newprescribe.Bicarbonate = 31.1
  2359. newprescribe.DialysateFlow = 500
  2360. newprescribe.PrescribingNumber = 1
  2361. }
  2362. err := service.AddSigleRecord(&newprescribe)
  2363. //记录日志
  2364. byterequest, _ := json.Marshal(newprescribe)
  2365. prescriptionLog := models.XtDialysisPrescriptionLog{
  2366. UserOrgId: adminUserInfo.Org.Id,
  2367. Ctime: time.Now().Unix(),
  2368. Mtime: 0,
  2369. ErrLog: string(byterequest),
  2370. AdminUserId: adminUserInfo.AdminUser.Id,
  2371. RecordDate: newprescribe.RecordDate,
  2372. PatientId: id,
  2373. Source: "手机端新增透前评估插入处方",
  2374. Status: 1,
  2375. }
  2376. service.CreatePrescriptionLog(prescriptionLog)
  2377. //获取key,清空redis
  2378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2379. redis := service.RedisClient()
  2380. //清空key 值
  2381. redis.Set(key, "", time.Second)
  2382. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2383. //清空key 值
  2384. redis.Set(keyOne, "", time.Second)
  2385. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2386. //清空key 值
  2387. redis.Set(keyTwo, "", time.Second)
  2388. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2389. redis.Set(keySix, "", time.Second)
  2390. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2391. redis.Set(keySeven, "", time.Second)
  2392. if err != nil {
  2393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2394. }
  2395. } else {
  2396. if adminUserInfo.Org.Id == 10340 {
  2397. newprescribe.Sodium = 138
  2398. newprescribe.Bicarbonate = 31.1
  2399. newprescribe.DialysateFlow = 500
  2400. }
  2401. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2402. //
  2403. if appRole.UserType == 2 || appRole.UserType == 1 {
  2404. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2405. if adminUserInfo.Org.Id == 9882 {
  2406. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2407. }
  2408. }
  2409. err := service.UpDateDialysisPrescription(&newprescribe)
  2410. //记录日志
  2411. byterequest, _ := json.Marshal(newprescribe)
  2412. prescriptionLog := models.XtDialysisPrescriptionLog{
  2413. UserOrgId: adminUserInfo.Org.Id,
  2414. Ctime: time.Now().Unix(),
  2415. Mtime: 0,
  2416. ErrLog: string(byterequest),
  2417. AdminUserId: adminUserInfo.AdminUser.Id,
  2418. RecordDate: newprescribe.RecordDate,
  2419. PatientId: id,
  2420. Source: "手机端新增透前评估插入处方",
  2421. Status: 1,
  2422. }
  2423. service.CreatePrescriptionLog(prescriptionLog)
  2424. //获取key,清空redis
  2425. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2426. redis := service.RedisClient()
  2427. //清空key 值
  2428. redis.Set(key, "", time.Second)
  2429. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2430. //清空key 值
  2431. redis.Set(keyOne, "", time.Second)
  2432. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2433. //清空key 值
  2434. redis.Set(keyTwo, "", time.Second)
  2435. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2436. redis.Set(keySix, "", time.Second)
  2437. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2438. redis.Set(keySeven, "", time.Second)
  2439. if err != nil {
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2441. }
  2442. }
  2443. }
  2444. if dialysisPrescribe == nil && dialysisSolution == nil {
  2445. if lastDialysisPrescribe != nil {
  2446. var newprescribe models.DialysisPrescription
  2447. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2448. newprescribe.PatientId = id
  2449. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2450. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2451. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2452. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2453. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2454. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2455. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2456. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2457. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2458. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2459. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2460. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2461. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2462. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2463. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2464. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2465. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2466. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2467. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2468. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2469. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2470. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2471. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2472. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2473. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2474. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2475. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2476. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2477. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2478. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2479. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2480. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2481. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2482. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2483. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2484. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2485. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2486. newprescribe.CreatedTime = time.Now().Unix()
  2487. newprescribe.UpdatedTime = time.Now().Unix()
  2488. newprescribe.RecordDate = theAssessmentDateTime
  2489. newprescribe.DewaterAmount = dewater_amount
  2490. newprescribe.TargetUltrafiltration = dewater_amount
  2491. newprescribe.Status = 1
  2492. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2493. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2494. if dialysisSolution != nil && dialysisSolution.DialysisStrainer != "" {
  2495. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2496. }
  2497. newprescribe.Remark = lastDialysisPrescription.Remark
  2498. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2499. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2500. newprescribe.ID = dialysisPrescription.ID
  2501. if dialysisPrescription.ID == 0 {
  2502. if adminUserInfo.Org.Id == 10340 {
  2503. newprescribe.Sodium = 138
  2504. newprescribe.Bicarbonate = 31.1
  2505. newprescribe.DialysateFlow = 500
  2506. }
  2507. err := service.AddSigleRecord(&newprescribe)
  2508. //记录日志
  2509. byterequest, _ := json.Marshal(newprescribe)
  2510. prescriptionLog := models.XtDialysisPrescriptionLog{
  2511. UserOrgId: adminUserInfo.Org.Id,
  2512. Ctime: time.Now().Unix(),
  2513. Mtime: 0,
  2514. ErrLog: string(byterequest),
  2515. AdminUserId: adminUserInfo.AdminUser.Id,
  2516. RecordDate: newprescribe.RecordDate,
  2517. PatientId: id,
  2518. Source: "手机端新增透前评估插入处方",
  2519. Status: 1,
  2520. }
  2521. service.CreatePrescriptionLog(prescriptionLog)
  2522. //获取key,清空redis
  2523. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2524. redis := service.RedisClient()
  2525. //清空key 值
  2526. redis.Set(key, "", time.Second)
  2527. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2528. //清空key 值
  2529. redis.Set(keyOne, "", time.Second)
  2530. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2531. //清空key 值
  2532. redis.Set(keyTwo, "", time.Second)
  2533. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2534. redis.Set(keySix, "", time.Second)
  2535. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2536. redis.Set(keySeven, "", time.Second)
  2537. if err != nil {
  2538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2539. }
  2540. } else {
  2541. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2542. //
  2543. if appRole.UserType == 2 || appRole.UserType == 1 {
  2544. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2545. if adminUserInfo.Org.Id == 9882 {
  2546. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2547. }
  2548. }
  2549. err := service.UpDateDialysisPrescription(&newprescribe)
  2550. //记录日志
  2551. byterequest, _ := json.Marshal(newprescribe)
  2552. prescriptionLog := models.XtDialysisPrescriptionLog{
  2553. UserOrgId: adminUserInfo.Org.Id,
  2554. Ctime: time.Now().Unix(),
  2555. Mtime: 0,
  2556. ErrLog: string(byterequest),
  2557. AdminUserId: adminUserInfo.AdminUser.Id,
  2558. RecordDate: newprescribe.RecordDate,
  2559. PatientId: id,
  2560. Source: "手机端新增透前评估插入处方",
  2561. Status: 1,
  2562. }
  2563. service.CreatePrescriptionLog(prescriptionLog)
  2564. //获取key,清空redis
  2565. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2566. redis := service.RedisClient()
  2567. //清空key 值
  2568. redis.Set(key, "", time.Second)
  2569. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2570. //清空key 值
  2571. redis.Set(keyOne, "", time.Second)
  2572. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2573. //清空key 值
  2574. redis.Set(keyTwo, "", time.Second)
  2575. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2576. redis.Set(keySix, "", time.Second)
  2577. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2578. redis.Set(keySeven, "", time.Second)
  2579. if err != nil {
  2580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2581. }
  2582. }
  2583. if err != nil {
  2584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2585. }
  2586. } else if system_dialysisPrescribe != nil {
  2587. var newprescribe models.DialysisPrescription
  2588. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2589. newprescribe.PatientId = id
  2590. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2591. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2592. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2593. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2594. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2595. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2596. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2597. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2598. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2599. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2600. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2601. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2602. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2603. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2604. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2605. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2606. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2607. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2608. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2609. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2610. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2611. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2612. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2613. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2614. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2615. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2616. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2617. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2618. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2619. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2620. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2621. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2622. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2623. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2624. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2625. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2626. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2627. newprescribe.CreatedTime = time.Now().Unix()
  2628. newprescribe.UpdatedTime = time.Now().Unix()
  2629. newprescribe.RecordDate = theAssessmentDateTime
  2630. newprescribe.DewaterAmount = dewater_amount
  2631. newprescribe.TargetUltrafiltration = dewater_amount
  2632. newprescribe.Status = 1
  2633. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2634. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2635. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2636. newprescribe.Remark = lastDialysisPrescription.Remark
  2637. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2638. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2639. newprescribe.ID = dialysisPrescription.ID
  2640. if dialysisPrescription.ID == 0 {
  2641. if adminUserInfo.Org.Id == 10340 {
  2642. newprescribe.Sodium = 138
  2643. newprescribe.Bicarbonate = 31.1
  2644. newprescribe.DialysateFlow = 500
  2645. }
  2646. err := service.AddSigleRecord(&newprescribe)
  2647. //记录日志
  2648. byterequest, _ := json.Marshal(newprescribe)
  2649. prescriptionLog := models.XtDialysisPrescriptionLog{
  2650. UserOrgId: adminUserInfo.Org.Id,
  2651. Ctime: time.Now().Unix(),
  2652. Mtime: 0,
  2653. ErrLog: string(byterequest),
  2654. AdminUserId: adminUserInfo.AdminUser.Id,
  2655. RecordDate: newprescribe.RecordDate,
  2656. PatientId: id,
  2657. Source: "手机端新增透前评估插入处方",
  2658. Status: 1,
  2659. }
  2660. service.CreatePrescriptionLog(prescriptionLog)
  2661. //获取key,清空redis
  2662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2663. redis := service.RedisClient()
  2664. //清空key 值
  2665. redis.Set(key, "", time.Second)
  2666. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2667. //清空key 值
  2668. redis.Set(keyOne, "", time.Second)
  2669. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2670. //清空key 值
  2671. redis.Set(keyTwo, "", time.Second)
  2672. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2673. redis.Set(keySix, "", time.Second)
  2674. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2675. redis.Set(keySeven, "", time.Second)
  2676. if err != nil {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2678. }
  2679. } else {
  2680. if adminUserInfo.Org.Id == 10340 {
  2681. newprescribe.Sodium = 138
  2682. newprescribe.Bicarbonate = 31.1
  2683. newprescribe.DialysateFlow = 500
  2684. }
  2685. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2686. //
  2687. if appRole.UserType == 2 || appRole.UserType == 1 {
  2688. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2689. if adminUserInfo.Org.Id == 9882 {
  2690. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2691. }
  2692. }
  2693. err := service.UpDateDialysisPrescription(&newprescribe)
  2694. //记录日志
  2695. byterequest, _ := json.Marshal(newprescribe)
  2696. prescriptionLog := models.XtDialysisPrescriptionLog{
  2697. UserOrgId: adminUserInfo.Org.Id,
  2698. Ctime: time.Now().Unix(),
  2699. Mtime: 0,
  2700. ErrLog: string(byterequest),
  2701. AdminUserId: adminUserInfo.AdminUser.Id,
  2702. RecordDate: newprescribe.RecordDate,
  2703. PatientId: id,
  2704. Source: "手机端新增透前评估插入处方",
  2705. Status: 1,
  2706. }
  2707. service.CreatePrescriptionLog(prescriptionLog)
  2708. //获取key,清空redis
  2709. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2710. redis := service.RedisClient()
  2711. //清空key 值
  2712. redis.Set(key, "", time.Second)
  2713. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2714. //清空key 值
  2715. redis.Set(keyOne, "", time.Second)
  2716. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2717. //清空key 值
  2718. redis.Set(keyTwo, "", time.Second)
  2719. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2720. redis.Set(keySix, "", time.Second)
  2721. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2722. redis.Set(keySeven, "", time.Second)
  2723. if err != nil {
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2725. }
  2726. }
  2727. if err != nil {
  2728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2729. }
  2730. } else {
  2731. var newprescribe models.DialysisPrescription
  2732. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2733. newprescribe.PatientId = id
  2734. newprescribe.ModeId = mode_id
  2735. newprescribe.CreatedTime = time.Now().Unix()
  2736. newprescribe.UpdatedTime = time.Now().Unix()
  2737. newprescribe.RecordDate = theAssessmentDateTime
  2738. newprescribe.DewaterAmount = dewater_amount
  2739. newprescribe.TargetUltrafiltration = dewater_amount
  2740. newprescribe.Status = 1
  2741. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2742. if dialysisPrescription.ID > 0 {
  2743. newprescribe.ID = dialysisPrescription.ID
  2744. }
  2745. if dialysisPrescription.ID == 0 {
  2746. if adminUserInfo.Org.Id == 10340 {
  2747. newprescribe.Sodium = 138
  2748. newprescribe.Bicarbonate = 31.1
  2749. newprescribe.DialysateFlow = 500
  2750. }
  2751. err := service.AddSigleRecord(&newprescribe)
  2752. //获取key,清空redis
  2753. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2754. redis := service.RedisClient()
  2755. //清空key 值
  2756. redis.Set(key, "", time.Second)
  2757. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2758. //清空key 值
  2759. redis.Set(keyOne, "", time.Second)
  2760. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2761. //清空key 值
  2762. redis.Set(keyTwo, "", time.Second)
  2763. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2764. redis.Set(keySix, "", time.Second)
  2765. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2766. redis.Set(keySeven, "", time.Second)
  2767. if err != nil {
  2768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2769. }
  2770. } else {
  2771. if adminUserInfo.Org.Id == 10340 {
  2772. newprescribe.Sodium = 138
  2773. newprescribe.Bicarbonate = 31.1
  2774. newprescribe.DialysateFlow = 500
  2775. }
  2776. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2777. //
  2778. if appRole.UserType == 2 || appRole.UserType == 1 {
  2779. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2780. if adminUserInfo.Org.Id == 9882 {
  2781. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2782. }
  2783. }
  2784. err := service.UpDateDialysisPrescription(&newprescribe)
  2785. //记录日志
  2786. byterequest, _ := json.Marshal(newprescribe)
  2787. prescriptionLog := models.XtDialysisPrescriptionLog{
  2788. UserOrgId: adminUserInfo.Org.Id,
  2789. Ctime: time.Now().Unix(),
  2790. Mtime: 0,
  2791. ErrLog: string(byterequest),
  2792. AdminUserId: adminUserInfo.AdminUser.Id,
  2793. RecordDate: newprescribe.RecordDate,
  2794. PatientId: id,
  2795. Source: "手机端新增透前评估插入处方",
  2796. Status: 1,
  2797. }
  2798. service.CreatePrescriptionLog(prescriptionLog)
  2799. //获取key,清空redis
  2800. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2801. redis := service.RedisClient()
  2802. //清空key 值
  2803. redis.Set(key, "", time.Second)
  2804. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2805. //清空key 值
  2806. redis.Set(keyOne, "", time.Second)
  2807. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2808. //清空key 值
  2809. redis.Set(keyTwo, "", time.Second)
  2810. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2811. redis.Set(keySix, "", time.Second)
  2812. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2813. redis.Set(keySeven, "", time.Second)
  2814. if err != nil {
  2815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2816. }
  2817. }
  2818. if err != nil {
  2819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2820. }
  2821. }
  2822. }
  2823. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2824. // if dialysisPrescribe != nil {
  2825. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2826. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2827. // dialysisPrescribe.DewaterAmount = dewater_amount
  2828. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2829. // dialysisPrescribe.Status = 1
  2830. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2831. // if updateErr != nil {
  2832. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2833. // }
  2834. // }
  2835. // 查询信息规挡的设置天数
  2836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2837. if infor.ID > 0 && infor.WeekDay > 0 {
  2838. var cha_time int64
  2839. timeNowStr := time.Now().Format("2006-01-02")
  2840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2841. //今日的日期减去设置的日期
  2842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2843. if cha_time >= evaluation.AssessmentDate {
  2844. //查询审核是否允许
  2845. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id, 3)
  2846. //申请状态不允许的情况 拒绝修改
  2847. if infor.ApplicationStatus != 1 {
  2848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2849. return
  2850. }
  2851. }
  2852. }
  2853. err = service.UpadatePredialysisEvaluation(&evaluation)
  2854. //记录日志
  2855. byterequest, _ := json.Marshal(evaluation)
  2856. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2857. UserOrgId: evaluation.UserOrgId,
  2858. AdminUserId: adminUserInfo.AdminUser.Id,
  2859. ErrLog: string(byterequest),
  2860. PatientId: evaluation.PatientId,
  2861. RecordDate: evaluation.AssessmentDate,
  2862. Ctime: time.Now().Unix(),
  2863. Mtime: 0,
  2864. Status: 1,
  2865. Source: "手机端保存透前评估",
  2866. }
  2867. service.CreateBeforLog(beforeDislysisLog)
  2868. finish := models.XtDialysisFinish{
  2869. IsFinish: 1,
  2870. UserOrgId: adminUserInfo.Org.Id,
  2871. Status: 1,
  2872. Ctime: time.Now().Unix(),
  2873. Mtime: 0,
  2874. Module: 3,
  2875. RecordDate: evaluation.AssessmentDate,
  2876. Sourse: 1,
  2877. PatientId: id,
  2878. }
  2879. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2880. if dialysisFinish.ID == 0 {
  2881. service.CreateDialysisFinish(finish)
  2882. }
  2883. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2884. redis := service.RedisClient()
  2885. defer redis.Close()
  2886. //清空key 值
  2887. redis.Set(key, "", time.Second)
  2888. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2889. redis.Set(keyOne, "", time.Second)
  2890. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2891. redis.Set(keyTwo, "", time.Second)
  2892. if err != nil {
  2893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2894. return
  2895. }
  2896. c.ServeSuccessJSON(map[string]interface{}{
  2897. "msg": "ok",
  2898. "evaluation": evaluation,
  2899. })
  2900. return
  2901. }
  2902. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2903. dataBody := make(map[string]interface{}, 0)
  2904. err := json.Unmarshal(data, &dataBody)
  2905. utils.InfoLog(string(data))
  2906. if err != nil {
  2907. utils.ErrorLog(err.Error())
  2908. code = enums.ErrorCodeParamWrong
  2909. return
  2910. }
  2911. // if method == "create" {
  2912. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2913. utils.ErrorLog("mode")
  2914. code = enums.ErrorCodeParamWrong
  2915. return
  2916. }
  2917. mode := int64(dataBody["mode"].(float64))
  2918. if mode <= 0 {
  2919. utils.ErrorLog("mode <= 0")
  2920. code = enums.ErrorCodeParamWrong
  2921. return
  2922. }
  2923. solution.ModeId = mode
  2924. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2925. utils.ErrorLog("mode_name")
  2926. code = enums.ErrorCodeParamWrong
  2927. return
  2928. }
  2929. modeName, _ := dataBody["mode_name"].(string)
  2930. if len(modeName) == 0 {
  2931. utils.ErrorLog("len(mode_name) == 0")
  2932. code = enums.ErrorCodeParamWrong
  2933. return
  2934. }
  2935. solution.ModeName = modeName
  2936. solution.Name = modeName
  2937. // }
  2938. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2939. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2940. solution.DialysisDuration = dialysisDuration
  2941. }
  2942. if dataBody["dialysis_duration"] != nil {
  2943. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2944. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2945. solution.DialysisDuration = dialysisDuration
  2946. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2947. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2948. solution.DialysisDuration = dialysisDuration
  2949. }
  2950. }
  2951. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2952. dialyzer := int64(dataBody["dialyzer"].(float64))
  2953. solution.Dialyzer = dialyzer
  2954. }
  2955. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2956. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2957. solution.PerfusionApparatus = perfusionApparatus
  2958. }
  2959. if dataBody["blood_flow_volume"] != nil {
  2960. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2961. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2962. solution.BloodFlowVolume = bloodFlowVolume
  2963. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2964. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2965. solution.BloodFlowVolume = bloodFlowVolume
  2966. }
  2967. }
  2968. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2969. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2970. solution.HemodialysisMachine = hemodialysisMachine
  2971. }
  2972. if dataBody["dewater"] != nil {
  2973. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2974. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2975. solution.Dewater = dewater
  2976. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  2977. dewater := dataBody["dewater"].(float64)
  2978. solution.Dewater = dewater
  2979. }
  2980. }
  2981. if dataBody["replacement_total"] != nil {
  2982. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2983. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2984. solution.ReplacementTotal = replacementTotal
  2985. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2986. replacementTotal := dataBody["replacement_total"].(float64)
  2987. solution.ReplacementTotal = replacementTotal
  2988. }
  2989. }
  2990. if dataBody["displace_liqui"] != nil {
  2991. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2992. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2993. solution.DisplaceLiqui = displaceLiqui
  2994. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2995. displaceLiqui := dataBody["displace_liqui"].(float64)
  2996. solution.DisplaceLiqui = displaceLiqui
  2997. }
  2998. }
  2999. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3000. replacementWay := int64(dataBody["replacement_way"].(float64))
  3001. solution.ReplacementWay = replacementWay
  3002. }
  3003. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3004. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3005. solution.Anticoagulant = anticoagulant
  3006. }
  3007. if dataBody["anticoagulant_shouji"] != nil {
  3008. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3009. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3010. solution.AnticoagulantShouji = anticoagulantShouji
  3011. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  3012. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  3013. solution.AnticoagulantShouji = anticoagulantShouji
  3014. }
  3015. }
  3016. if dataBody["anticoagulant_weichi"] != nil {
  3017. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3018. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3019. solution.AnticoagulantWeichi = anticoagulantWeichi
  3020. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  3021. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  3022. solution.AnticoagulantWeichi = anticoagulantWeichi
  3023. }
  3024. }
  3025. if dataBody["anticoagulant_zongliang"] != nil {
  3026. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3027. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3028. solution.AnticoagulantZongliang = anticoagulantZongliang
  3029. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  3030. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  3031. solution.AnticoagulantZongliang = anticoagulantZongliang
  3032. }
  3033. }
  3034. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3035. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3036. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3037. }
  3038. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3039. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3040. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3041. }
  3042. if dataBody["kalium"] != nil {
  3043. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3044. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3045. solution.Kalium = kalium
  3046. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  3047. kalium := dataBody["kalium"].(float64)
  3048. solution.Kalium = kalium
  3049. }
  3050. }
  3051. if dataBody["sodium"] != nil {
  3052. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3053. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3054. solution.Sodium = sodium
  3055. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  3056. sodium := dataBody["sodium"].(float64)
  3057. solution.Sodium = sodium
  3058. }
  3059. }
  3060. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3061. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3062. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3063. solution.Calcium = calcium
  3064. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  3065. calcium := dataBody["calcium"].(float64)
  3066. solution.Calcium = calcium
  3067. }
  3068. }
  3069. if dataBody["bicarbonate"] != nil {
  3070. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3071. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3072. solution.Bicarbonate = bicarbonate
  3073. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  3074. bicarbonate := dataBody["bicarbonate"].(float64)
  3075. solution.Bicarbonate = bicarbonate
  3076. }
  3077. }
  3078. if dataBody["glucose"] != nil {
  3079. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3080. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3081. solution.Glucose = glucose
  3082. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  3083. glucose := dataBody["glucose"].(float64)
  3084. solution.Glucose = glucose
  3085. }
  3086. }
  3087. // if dataBody["dry_weight"] != nil {
  3088. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3089. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3090. // solution.DryWeight = dryWeight
  3091. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  3092. // dryWeight := dataBody["dry_weight"].(float64)
  3093. // solution.DryWeight = dryWeight
  3094. // }
  3095. // }
  3096. if dataBody["dialysate_flow"] != nil {
  3097. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3098. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3099. solution.DialysateFlow = dialysateFlow
  3100. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  3101. dialysateFlow := dataBody["dialysate_flow"].(float64)
  3102. solution.DialysateFlow = dialysateFlow
  3103. }
  3104. }
  3105. if dataBody["dialysate_temperature"] != nil {
  3106. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3107. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3108. solution.DialysateTemperature = dialysateTemperature
  3109. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  3110. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  3111. solution.DialysateTemperature = dialysateTemperature
  3112. }
  3113. }
  3114. if dataBody["conductivity"] != nil {
  3115. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3116. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3117. solution.Conductivity = conductivity
  3118. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  3119. conductivity := dataBody["conductivity"].(float64)
  3120. solution.Conductivity = conductivity
  3121. }
  3122. }
  3123. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3124. remark := dataBody["remark"].(string)
  3125. solution.Remark = remark
  3126. }
  3127. if dataBody["dialysis_duration_hour"] != nil {
  3128. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3129. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  3130. solution.DialysisDurationHour = dialysisDurationHour
  3131. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  3132. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  3133. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3134. }
  3135. }
  3136. if dataBody["dialysis_duration_minute"] != nil {
  3137. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3138. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  3139. solution.DialysisDurationMinute = dialysisDurationMinute
  3140. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  3141. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  3142. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3143. }
  3144. }
  3145. if dataBody["target_ultrafiltration"] != nil {
  3146. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3147. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3148. solution.TargetUltrafiltration = targetUltrafiltration
  3149. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  3150. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  3151. solution.TargetUltrafiltration = targetUltrafiltration
  3152. }
  3153. }
  3154. if dataBody["dialysate_formulation"] != nil {
  3155. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  3156. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  3157. solution.DialysateFormulation = dialysateFormulation
  3158. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3159. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  3160. solution.DialysateFormulation = int64(dialysateFormulation)
  3161. }
  3162. }
  3163. return
  3164. }
  3165. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  3166. dataBody := make(map[string]interface{}, 0)
  3167. err := json.Unmarshal(data, &dataBody)
  3168. utils.InfoLog(string(data))
  3169. if err != nil {
  3170. utils.ErrorLog(err.Error())
  3171. code = enums.ErrorCodeParamWrong
  3172. return
  3173. }
  3174. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  3175. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  3176. evaluation.WeightBefore = weightVefore
  3177. }
  3178. // fmt.Println(dataBody["dry_weight"])
  3179. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  3180. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3181. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3182. fmt.Println(additionalWeight)
  3183. evaluation.DryWeight = additionalWeight
  3184. }
  3185. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  3186. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  3187. fmt.Println(additionalWeight)
  3188. evaluation.AdditionalWeight = additionalWeight
  3189. }
  3190. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  3191. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  3192. evaluation.Temperature = Temperature
  3193. }
  3194. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  3195. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  3196. evaluation.SystolicBloodPressure = systolicBloodPressure
  3197. }
  3198. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  3199. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  3200. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  3201. }
  3202. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  3203. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  3204. evaluation.PulseFrequency = pulseFrequency
  3205. }
  3206. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  3207. breathingRate := dataBody["breathing_rate"].(string)
  3208. evaluation.BreathingRate = breathingRate
  3209. }
  3210. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  3211. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  3212. evaluation.LastPostDialysis = lastPostDialysis
  3213. }
  3214. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  3215. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  3216. evaluation.DialysisInterphase = dialysisInterphase
  3217. }
  3218. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  3219. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  3220. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  3221. }
  3222. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  3223. catheter, _ := dataBody["catheter"].(string)
  3224. evaluation.Catheter = catheter
  3225. }
  3226. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  3227. catheter_bend := int(dataBody["catheter_bend"].(float64))
  3228. evaluation.CatheterBend = catheter_bend
  3229. }
  3230. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  3231. Complication, _ := dataBody["complication"].(string)
  3232. evaluation.Complication = Complication
  3233. }
  3234. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3235. remark := dataBody["remark"].(string)
  3236. evaluation.Remark = remark
  3237. }
  3238. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  3239. machine_type := dataBody["machine_type"].(string)
  3240. evaluation.MachineType = machine_type
  3241. }
  3242. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  3243. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  3244. evaluation.BloodAccessPartId = blood_access_part_id
  3245. }
  3246. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  3247. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  3248. // evaluation.BloodAccessPartId = blood_access_part_id
  3249. //}
  3250. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  3251. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  3252. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  3253. }
  3254. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  3255. internal_fistula, _ := dataBody["internal_fistula"].(string)
  3256. evaluation.InternalFistula = internal_fistula
  3257. }
  3258. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  3259. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  3260. evaluation.InternalFistulaSkin = internal_fistula_skin
  3261. }
  3262. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  3263. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  3264. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  3265. evaluation.IsHemorrhage = is_hemorrhage
  3266. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  3267. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  3268. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  3269. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  3270. is_hemorrhage = 0
  3271. }
  3272. evaluation.IsHemorrhage = is_hemorrhage
  3273. if is_hemorrhage == 1 {
  3274. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  3275. hemorrhage, _ := dataBody["hemorrhage"].(string)
  3276. evaluation.Hemorrhage = hemorrhage
  3277. }
  3278. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  3279. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  3280. evaluation.HemorrhageOther = hemorrhage_other
  3281. }
  3282. }
  3283. } else {
  3284. evaluation.IsHemorrhage = 0
  3285. }
  3286. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  3287. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  3288. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  3289. }
  3290. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  3291. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  3292. evaluation.InternalFistulaOther = internal_fistula_other
  3293. }
  3294. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  3295. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  3296. evaluation.BloodAccessNoise = blood_access_noise
  3297. }
  3298. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  3299. //puncture_way := int64(dataBody["puncture_way"].(float64))
  3300. puncture_way := dataBody["puncture_way"].(string)
  3301. evaluation.PunctureWay = puncture_way
  3302. }
  3303. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  3304. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  3305. evaluation.VenousCatheterization = venous_catheterization
  3306. }
  3307. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  3308. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  3309. evaluation.VenousCatheterizationPart = venous_catheterization_part
  3310. }
  3311. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  3312. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  3313. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  3314. }
  3315. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  3316. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  3317. evaluation.DuctusArantii = ductus_arantii
  3318. }
  3319. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  3320. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  3321. evaluation.EmergencyTreatment = emergency_treatment
  3322. }
  3323. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  3324. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  3325. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  3326. }
  3327. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  3328. dialysis_count, _ := dataBody["dialysis_count"].(string)
  3329. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  3330. evaluation.DialysisCount = dialysis_count
  3331. }
  3332. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  3333. is_infect, _ := dataBody["is_infect"].(string)
  3334. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  3335. evaluation.IsInfect = infect
  3336. }
  3337. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  3338. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  3339. evaluation.Exposed = exposed
  3340. }
  3341. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  3342. skin, _ := dataBody["skin"].(string)
  3343. //skins, _ := strconv.ParseInt(skin, 10, 64)
  3344. evaluation.Skin = skin
  3345. }
  3346. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  3347. skin_other, _ := dataBody["skin_other"].(string)
  3348. evaluation.SkinOther = skin_other
  3349. }
  3350. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  3351. infect_other, _ := dataBody["infect_other"].(string)
  3352. evaluation.InfectOther = infect_other
  3353. }
  3354. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  3355. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  3356. evaluation.DuctusArantiiOther = ductus_arantii_other
  3357. }
  3358. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3359. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  3360. evaluation.PunctureNeedle = punctureNeedle
  3361. }
  3362. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  3363. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  3364. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  3365. }
  3366. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  3367. pinholing := dataBody["pinholing"].(string)
  3368. evaluation.Phinholing = pinholing
  3369. }
  3370. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  3371. catheter_suture := dataBody["catheter_suture"].(string)
  3372. evaluation.CatheterSuture = catheter_suture
  3373. }
  3374. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  3375. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  3376. evaluation.CatheterSutureOther = catheter_suture_other
  3377. }
  3378. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  3379. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  3380. evaluation.UrineVolume = urine_volume
  3381. }
  3382. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  3383. edema := dataBody["edema"].(string)
  3384. evaluation.Edema = edema
  3385. }
  3386. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  3387. specialTreatment := dataBody["special_treatment"].(string)
  3388. evaluation.SpecialTreatment = specialTreatment
  3389. }
  3390. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  3391. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  3392. evaluation.CatheterMaintenance = catheter_maintenance
  3393. }
  3394. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  3395. thromubusType := int64(dataBody["thromubus_type"].(float64))
  3396. evaluation.ThromubusType = thromubusType
  3397. }
  3398. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  3399. thrombus_av := dataBody["thrombus_av"].(string)
  3400. evaluation.ThrombusAv = thrombus_av
  3401. }
  3402. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  3403. thromubus_a := dataBody["thromubus_a"].(string)
  3404. evaluation.ThromubusA = thromubus_a
  3405. }
  3406. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  3407. thromubus_v := dataBody["thromubus_v"].(string)
  3408. evaluation.ThromubusV = thromubus_v
  3409. }
  3410. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  3411. dehydration := dataBody["dehydration"].(string)
  3412. evaluation.Dehydration = dehydration
  3413. }
  3414. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  3415. period := int64(dataBody["period"].(float64))
  3416. evaluation.Period = period
  3417. }
  3418. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  3419. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  3420. evaluation.EstimatedFoodIntake = estimated_food_intake
  3421. }
  3422. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  3423. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  3424. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  3425. }
  3426. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  3427. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  3428. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  3429. }
  3430. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  3431. urea_befor := dataBody["urea_befor"].(string)
  3432. evaluation.UreaBefor = urea_befor
  3433. }
  3434. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  3435. suction := dataBody["suction"].(string)
  3436. evaluation.Suction = suction
  3437. }
  3438. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  3439. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  3440. evaluation.WeightBeforRemake = weight_befor_remake
  3441. }
  3442. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  3443. height := dataBody["height"].(string)
  3444. evaluation.Height = height
  3445. }
  3446. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  3447. age := dataBody["age"].(string)
  3448. evaluation.Age = age
  3449. }
  3450. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  3451. his_department := dataBody["his_department"].(string)
  3452. evaluation.HisDepartment = his_department
  3453. }
  3454. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  3455. his_bed := dataBody["his_bed"].(string)
  3456. evaluation.HisBed = his_bed
  3457. }
  3458. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  3459. point_puncture := dataBody["point_puncture"].(string)
  3460. evaluation.PointPuncture = point_puncture
  3461. }
  3462. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  3463. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  3464. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  3465. }
  3466. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  3467. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  3468. evaluation.SkinSiteCatheterization = skin_site_catheterization
  3469. }
  3470. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  3471. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  3472. evaluation.WhetherUnobstructed = whether_unobstructed
  3473. }
  3474. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  3475. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  3476. evaluation.LienNecessary = lien_necessary
  3477. }
  3478. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  3479. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  3480. timeLayout := "2006-01-02"
  3481. loc, _ := time.LoadLocation("Local")
  3482. var startTime int64
  3483. if len(pathway_formation_time) > 0 {
  3484. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  3485. startTime = theTime.Unix()
  3486. }
  3487. evaluation.PathwayFormationTime = startTime
  3488. }
  3489. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  3490. befor_symptoms := dataBody["befor_symptoms"].(string)
  3491. evaluation.BeforSymptoms = befor_symptoms
  3492. }
  3493. if dataBody["washing_time"] != nil && reflect.TypeOf(dataBody["washing_time"]).String() == "string" {
  3494. washing_time, _ := dataBody["washing_time"].(string)
  3495. evaluation.WashingTime = washing_time
  3496. }
  3497. if dataBody["warsh_count"] != nil && reflect.TypeOf(dataBody["warsh_count"]).String() == "string" {
  3498. warsh_count, _ := dataBody["warsh_count"].(string)
  3499. evaluation.WarshCount = warsh_count
  3500. }
  3501. if dataBody["puncture_needle_direction"] != nil && reflect.TypeOf(dataBody["puncture_needle_direction"]).String() == "string" {
  3502. puncture_needle_direction, _ := dataBody["puncture_needle_direction"].(string)
  3503. evaluation.PunctureNeedleDirection = puncture_needle_direction
  3504. }
  3505. if dataBody["symptom_before_dialysis_other"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis_other"]).String() == "string" {
  3506. symptom_before_dialysis_other, _ := dataBody["symptom_before_dialysis_other"].(string)
  3507. evaluation.SymptomBeforeDialysisOther = symptom_before_dialysis_other
  3508. }
  3509. return
  3510. }
  3511. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  3512. dataBody := make(map[string]interface{}, 0)
  3513. err := json.Unmarshal(data, &dataBody)
  3514. if err != nil {
  3515. utils.ErrorLog(err.Error())
  3516. code = enums.ErrorCodeParamWrong
  3517. return
  3518. }
  3519. timeLayout := "2006-01-02"
  3520. loc, _ := time.LoadLocation("Local")
  3521. isChild := false
  3522. if action == "create" {
  3523. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3524. utils.ErrorLog("advice_type")
  3525. code = enums.ErrorCodeParamWrong
  3526. return
  3527. }
  3528. adviceType := int64(dataBody["advice_type"].(float64))
  3529. if adviceType != 1 && adviceType != 2 {
  3530. utils.ErrorLog("advice_type != 1&&2")
  3531. code = enums.ErrorCodeParamWrong
  3532. return
  3533. }
  3534. advice.AdviceType = adviceType
  3535. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3536. utils.ErrorLog("advice_date")
  3537. code = enums.ErrorCodeParamWrong
  3538. return
  3539. }
  3540. adviceDate, _ := dataBody["advice_date"].(string)
  3541. if len(adviceDate) == 0 {
  3542. utils.ErrorLog("len(adviceDate) == 0")
  3543. code = enums.ErrorCodeParamWrong
  3544. return
  3545. }
  3546. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3547. if err != nil {
  3548. utils.ErrorLog(err.Error())
  3549. code = enums.ErrorCodeParamWrong
  3550. return
  3551. }
  3552. advice.AdviceDate = theTime.Unix()
  3553. advice.RecordDate = theTime.Unix()
  3554. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  3555. parentId := int64(dataBody["parent_id"].(float64))
  3556. advice.ParentId = parentId
  3557. if parentId > 0 {
  3558. isChild = true
  3559. }
  3560. }
  3561. } else {
  3562. isChild = advice.ParentId > 0
  3563. }
  3564. if !isChild {
  3565. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3566. utils.ErrorLog("start_time")
  3567. code = enums.ErrorCodeParamWrong
  3568. return
  3569. }
  3570. startTime, _ := dataBody["start_time"].(string)
  3571. if len(startTime) == 0 {
  3572. utils.ErrorLog("len(start_time) == 0")
  3573. code = enums.ErrorCodeParamWrong
  3574. return
  3575. }
  3576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3577. if err != nil {
  3578. utils.ErrorLog(err.Error())
  3579. code = enums.ErrorCodeParamWrong
  3580. return
  3581. }
  3582. advice.StartTime = theTime.Unix()
  3583. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3584. deliveryWay, _ := dataBody["delivery_way"].(string)
  3585. advice.DeliveryWay = deliveryWay
  3586. }
  3587. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3588. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3589. advice.ExecutionFrequency = executionFrequency
  3590. }
  3591. }
  3592. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3593. deliveryWay, _ := dataBody["delivery_way"].(string)
  3594. advice.DeliveryWay = deliveryWay
  3595. }
  3596. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3597. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3598. advice.ExecutionFrequency = executionFrequency
  3599. }
  3600. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3601. utils.ErrorLog("advice_name")
  3602. code = enums.ErrorCodeParamWrong
  3603. return
  3604. }
  3605. adviceName, _ := dataBody["advice_name"].(string)
  3606. if len(adviceName) == 0 {
  3607. utils.ErrorLog("len(advice_name) == 0")
  3608. code = enums.ErrorCodeParamWrong
  3609. return
  3610. }
  3611. advice.AdviceName = adviceName
  3612. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3613. adviceDsc, _ := dataBody["advice_desc"].(string)
  3614. advice.AdviceDesc = adviceDsc
  3615. }
  3616. if dataBody["way"] == nil {
  3617. advice.Way = 0
  3618. } else {
  3619. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3620. way := int64(dataBody["way"].(float64))
  3621. advice.Way = way
  3622. }
  3623. }
  3624. if dataBody["drug_id"] == nil {
  3625. advice.DrugId = 0
  3626. } else {
  3627. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3628. drug_id := int64(dataBody["drug_id"].(float64))
  3629. advice.DrugId = drug_id
  3630. }
  3631. }
  3632. if dataBody["drug_name_id"] == nil {
  3633. advice.DrugNameId = 0
  3634. } else {
  3635. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3636. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3637. advice.DrugNameId = drug_name_id
  3638. }
  3639. }
  3640. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3641. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3642. advice.SingleDose = singleDose
  3643. }
  3644. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3645. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3646. advice.SingleDoseUnit = singleDoseUnit
  3647. }
  3648. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3649. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3650. advice.DrugSpec = drugSpec
  3651. }
  3652. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3653. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3654. advice.DrugSpecUnit = drugSpecUnit
  3655. }
  3656. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3657. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3658. advice.PrescribingNumber = prescribingNumber
  3659. }
  3660. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3661. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3662. advice.PrescribingNumberUnit = prescribingNumberUnit
  3663. }
  3664. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3665. remark, _ := dataBody["remark"].(string)
  3666. advice.Remark = remark
  3667. }
  3668. return
  3669. }
  3670. func (c *PatientApiController) GetPatientEducation() {
  3671. patientID, _ := c.GetInt64("patient_id", 0)
  3672. page, _ := c.GetInt64("page", 0)
  3673. limit, _ := c.GetInt64("limit", 0)
  3674. startTime := c.GetString("start_time", "")
  3675. endTime := c.GetString("end_time", "")
  3676. if page <= 0 {
  3677. page = 1
  3678. }
  3679. if limit <= 0 {
  3680. limit = 10
  3681. }
  3682. if patientID <= 0 {
  3683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3684. return
  3685. }
  3686. timeLayout := "2006-01-02"
  3687. loc, _ := time.LoadLocation("Local")
  3688. var theStartTIme int64
  3689. if len(startTime) > 0 {
  3690. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3691. if err != nil {
  3692. theStartTIme = 0
  3693. }
  3694. theStartTIme = theTime.Unix()
  3695. }
  3696. var theEndtTIme int64
  3697. if len(endTime) > 0 {
  3698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3699. if err != nil {
  3700. theEndtTIme = 0
  3701. }
  3702. theEndtTIme = theTime.Unix()
  3703. }
  3704. adminUserInfo := c.GetMobileAdminUserInfo()
  3705. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3706. c.ServeSuccessJSON(map[string]interface{}{
  3707. "total": total,
  3708. "edus": edus,
  3709. })
  3710. return
  3711. }
  3712. func (c *PatientApiController) GetPatientSchedulesList() {
  3713. patientID, _ := c.GetInt64("patient_id", 0)
  3714. page, _ := c.GetInt64("page", 0)
  3715. limit, _ := c.GetInt64("limit", 0)
  3716. if patientID <= 0 {
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3718. return
  3719. }
  3720. adminUserInfo := c.GetMobileAdminUserInfo()
  3721. todayTime := time.Now().Format("2006-01-02")
  3722. timeLayout := "2006-01-02 15:04:05"
  3723. loc, _ := time.LoadLocation("Local")
  3724. var theStartTime int64
  3725. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3726. theStartTime = theTime.Unix()
  3727. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3728. if len(schedules) > 0 {
  3729. for index, item := range schedules {
  3730. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3731. schedules[index].Week = int64(week)
  3732. }
  3733. }
  3734. c.ServeSuccessJSON(map[string]interface{}{
  3735. "schedules": schedules,
  3736. })
  3737. return
  3738. }
  3739. func (c *PatientApiController) GetRecords() {
  3740. patientID, _ := c.GetInt64("patient_id", 0)
  3741. page, _ := c.GetInt64("page", 0)
  3742. limit, _ := c.GetInt64("limit", 0)
  3743. startTime := c.GetString("start_time", "")
  3744. endTime := c.GetString("end_time", "")
  3745. mode_id, _ := c.GetInt64("mode_id", 0)
  3746. if page <= 0 {
  3747. page = 1
  3748. }
  3749. if limit <= 0 {
  3750. limit = 10
  3751. }
  3752. if patientID <= 0 {
  3753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3754. return
  3755. }
  3756. timeLayout := "2006-01-02"
  3757. loc, _ := time.LoadLocation("Local")
  3758. var theStartTIme int64
  3759. if len(startTime) > 0 {
  3760. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3761. if err != nil {
  3762. theStartTIme = 0
  3763. }
  3764. theStartTIme = theTime.Unix()
  3765. }
  3766. var theEndtTIme int64
  3767. if len(endTime) > 0 {
  3768. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3769. if err != nil {
  3770. theEndtTIme = 0
  3771. }
  3772. theEndtTIme = theTime.Unix()
  3773. }
  3774. adminUserInfo := c.GetMobileAdminUserInfo()
  3775. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3776. c.ServeSuccessJSON(map[string]interface{}{
  3777. "total": total,
  3778. "records": records,
  3779. })
  3780. return
  3781. }
  3782. func (c *PatientApiController) GetPatientMonitor() {
  3783. partition, _ := c.GetInt64("partition")
  3784. monitorDate := c.GetString("date")
  3785. patient_id, _ := c.GetInt64("patient_id")
  3786. timeLayout := "2006-01-02"
  3787. loc, _ := time.LoadLocation("Local")
  3788. var theStartTime int64
  3789. if len(monitorDate) > 0 {
  3790. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3791. if err != nil {
  3792. theStartTime = 0
  3793. }
  3794. theStartTime = theTime.Unix()
  3795. }
  3796. adminInfo := c.GetMobileAdminUserInfo()
  3797. orgID := adminInfo.Org.Id
  3798. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3799. if err != nil {
  3800. c.ErrorLog("获取排班信息失败:%v", err)
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3802. } else {
  3803. if len(monitor) > 0 {
  3804. //获取所有床位
  3805. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3806. //获取所有分区
  3807. zoneList, _ := service.GetAllZoneByList(orgID)
  3808. //获取透析处方
  3809. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3810. //获取透前评估
  3811. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3812. //获取上机
  3813. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3814. //获取透后
  3815. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3816. //获取透后监测
  3817. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3818. //获取所有的患者
  3819. patients, _ := service.GetAllPatientListByListOne(orgID)
  3820. for _, it := range patients {
  3821. if orgID == 10445 {
  3822. if theStartTime <= 1703952000 {
  3823. listOne, _ := service.GetDialysisOrderCountTwentyEight(orgID, it.ID, theStartTime)
  3824. it.TotalDialysis = listOne.Count
  3825. }
  3826. if theStartTime >= 1704038400 {
  3827. listOrder, _ := service.GetDialysisOrderCountTenEight(it.ID, theStartTime)
  3828. it.TotalDialysis = listOrder.Count
  3829. }
  3830. }
  3831. }
  3832. //获取所有透析模式
  3833. treatments, _ := service.GetAllTreatModeByList(orgID)
  3834. for key, item := range monitor {
  3835. // 获取床位信息
  3836. for _, it := range numberList {
  3837. if item.BedId == it.ID {
  3838. monitor[key].DeviceNumber = it
  3839. break
  3840. }
  3841. }
  3842. //获取分区信息
  3843. for _, it := range zoneList {
  3844. if item.PartitionId == it.ID {
  3845. monitor[key].DeviceZone = it
  3846. }
  3847. }
  3848. for _, prescription := range prescriptions {
  3849. if item.PatientId == prescription.PatientId {
  3850. monitor[key].Prescription = prescription
  3851. break
  3852. }
  3853. }
  3854. // 透前评估
  3855. for _, assessmentBefore := range assessmentBefores {
  3856. if item.PatientId == assessmentBefore.PatientId {
  3857. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3858. break
  3859. }
  3860. }
  3861. // 透析上下机
  3862. for _, dialysisOrder := range dialysisOrders {
  3863. if item.PatientId == dialysisOrder.PatientId {
  3864. monitor[key].DialysisOrder = dialysisOrder
  3865. break
  3866. }
  3867. }
  3868. // 治疗小节
  3869. for _, afterDislysis := range AssessmentAfterDislysis {
  3870. if item.PatientId == afterDislysis.PatientId {
  3871. monitor[key].AssessmentAfterDislysis = afterDislysis
  3872. break
  3873. }
  3874. }
  3875. for _, it := range monitorlist {
  3876. if item.PatientId == it.PatientId {
  3877. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3878. }
  3879. }
  3880. for _, patient := range patients {
  3881. if item.PatientId == patient.ID {
  3882. monitor[key].MonitorPatients = patient
  3883. break
  3884. }
  3885. }
  3886. for _, treatment := range treatments {
  3887. if item.ModeId == treatment.ID {
  3888. monitor[key].TreatmentMode = treatment
  3889. break
  3890. }
  3891. }
  3892. }
  3893. }
  3894. }
  3895. //获取患者的透析次数
  3896. //count, err := service.GetDialysisCount(orgID, partition)
  3897. patients, err := service.GetAllpatientFourty(orgID)
  3898. if err == nil {
  3899. c.ServeSuccessJSON(map[string]interface{}{
  3900. "monitor": monitor,
  3901. //"patientCount": count,
  3902. "patients": patients,
  3903. })
  3904. } else {
  3905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3906. }
  3907. }
  3908. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3909. // @param keyword:string 病人姓名或透析号
  3910. // @param page:int
  3911. func (this *PatientApiController) SearchMonitorPatient() {
  3912. keyword := this.GetString("keyword")
  3913. page, _ := this.GetInt("page")
  3914. if page <= 0 {
  3915. page = 1
  3916. }
  3917. if len(keyword) == 0 {
  3918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3919. return
  3920. }
  3921. adminUserInfo := this.GetMobileAdminUserInfo()
  3922. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3923. if getMonitorErr != nil {
  3924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3925. return
  3926. } else {
  3927. this.ServeSuccessJSON(map[string]interface{}{
  3928. "monitor": monitors,
  3929. })
  3930. }
  3931. }
  3932. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3933. id, _ := c.GetInt64("id", 0)
  3934. page, _ := c.GetInt64("page", 0)
  3935. limit, _ := c.GetInt64("limit", 0)
  3936. if id <= 0 {
  3937. c.ServeSuccessJSON(map[string]interface{}{
  3938. "solutions": nil,
  3939. })
  3940. return
  3941. }
  3942. if page <= 0 {
  3943. page = 1
  3944. }
  3945. if limit <= 0 {
  3946. limit = 10
  3947. }
  3948. adminInfo := c.GetMobileAdminUserInfo()
  3949. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3950. c.ServeSuccessJSON(map[string]interface{}{
  3951. "solutions": solutions,
  3952. "total": total,
  3953. })
  3954. return
  3955. }
  3956. // GetDoctorAdvices 医嘱列表
  3957. func (c *PatientApiController) GetDoctorAdvices() {
  3958. id, _ := c.GetInt64("id", 0)
  3959. adviceType, _ := c.GetInt64("advice_type", 0)
  3960. stopType, _ := c.GetInt64("stop_state", 0)
  3961. startTime := c.GetString("start_time", "")
  3962. endTime := c.GetString("end_time", "")
  3963. keywords := c.GetString("keywords", "")
  3964. need, _ := c.GetInt64("need_doctor", 0)
  3965. adminUserInfo := c.GetMobileAdminUserInfo()
  3966. timeLayout := "2006-01-02"
  3967. loc, _ := time.LoadLocation("Local")
  3968. var theStartTIme int64
  3969. if len(startTime) > 0 {
  3970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3971. if err != nil {
  3972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3973. return
  3974. }
  3975. theStartTIme = theTime.Unix()
  3976. }
  3977. var theEndtTIme int64
  3978. if len(endTime) > 0 {
  3979. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3980. if err != nil {
  3981. utils.ErrorLog(err.Error())
  3982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3983. return
  3984. }
  3985. theEndtTIme = theTime.Unix()
  3986. }
  3987. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  3988. if need == 1 {
  3989. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3990. c.ServeSuccessJSON(map[string]interface{}{
  3991. "advices": advices,
  3992. "total": total,
  3993. "users": users,
  3994. })
  3995. } else {
  3996. c.ServeSuccessJSON(map[string]interface{}{
  3997. "advices": advices,
  3998. "total": total,
  3999. "users": []string{},
  4000. })
  4001. }
  4002. return
  4003. }
  4004. func (c *PatientApiController) GetPrintDialysisOrder() {
  4005. xtno := c.GetString("xtno")
  4006. xtdate := c.GetString("xtdate")
  4007. timeLayout := "2006-01-02"
  4008. loc, _ := time.LoadLocation("Local")
  4009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4010. if err != nil {
  4011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4012. return
  4013. }
  4014. xttime := theTime.Unix()
  4015. //获取当前日期月份的第一天
  4016. firstmonth := service.GetFirstDateOfMonth(theTime)
  4017. firstMonthDate := firstmonth.Unix()
  4018. operatorIDs := make([]int64, 0)
  4019. adminUserInfo := c.GetMobileAdminUserInfo()
  4020. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  4021. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  4022. //透析单
  4023. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4024. if dialysisOrder != nil {
  4025. if dialysisOrder.FinishNurse > 0 {
  4026. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4027. }
  4028. if dialysisOrder.StartNurse > 0 {
  4029. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4030. }
  4031. }
  4032. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4033. //透前评估
  4034. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4035. //透后评估
  4036. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4037. if AssessmentAfterDislysis.Modifier > 0 {
  4038. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4039. }
  4040. //透析处方
  4041. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4042. if dialysisPrescription.PrescriptionDoctor > 0 {
  4043. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4044. }
  4045. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4046. patientInfo.TotalDialysis = dialysis_count
  4047. //临时医嘱
  4048. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4049. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4050. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  4051. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  4052. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4053. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4054. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4055. for _, item := range projects {
  4056. cnt, _ := strconv.ParseFloat(item.Count, 64)
  4057. var advice models.HisDoctorAdviceInfo
  4058. advice.ID = item.ID
  4059. advice.Checker = item.Checker
  4060. advice.CheckTime = item.CheckTime
  4061. advice.CheckState = item.CheckState
  4062. advice.ExecutionState = item.ExecutionState
  4063. advice.ExecutionStaff = item.ExecutionStaff
  4064. //advice.PrescribingNumber = float64(item.Count)
  4065. advice.PrescribingNumber = cnt
  4066. advice.PrescribingNumberUnit = item.Unit
  4067. advice.AdviceDoctor = item.Doctor
  4068. if item.Type == 3 {
  4069. advice.AdviceName = item.GoodInfo.GoodName
  4070. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  4071. } else if item.Type == 2 {
  4072. advice.AdviceName = item.HisProject.ProjectName
  4073. }
  4074. advice.StartTime = item.StartTime
  4075. hisAdvice = append(hisAdvice, &advice)
  4076. }
  4077. }
  4078. if len(DoctorAdvice) > 0 {
  4079. for _, item := range DoctorAdvice {
  4080. if item.AdviceDoctor > 0 {
  4081. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4082. }
  4083. if item.ExecutionStaff > 0 {
  4084. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4085. }
  4086. if item.Checker > 0 {
  4087. operatorIDs = append(operatorIDs, item.Checker)
  4088. }
  4089. }
  4090. }
  4091. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4092. //透析监测
  4093. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4094. //透析小结
  4095. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4096. //接诊评估
  4097. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4098. //相关操作对应的操作人
  4099. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  4100. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  4101. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4102. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4103. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  4104. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4105. if config.IsOpen == 1 {
  4106. c.ServeSuccessJSON(map[string]interface{}{
  4107. "users": adminUser,
  4108. "patientInfo": patientInfo,
  4109. "PredialysisEvaluation": PredialysisEvaluation,
  4110. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4111. "dialysisPrescription": dialysisPrescription,
  4112. "advices": hisAdvice,
  4113. "monitors": Record,
  4114. "summary": TreatmentSummary,
  4115. "receiverTreatmentAccess": receiverTreatmentAccess,
  4116. "dialysisOrder": dialysisOrder,
  4117. "operators": operators,
  4118. "org_template_info": templateInfo,
  4119. "check": check,
  4120. "dialysiscount": dialysiscount,
  4121. "last_order": last_order,
  4122. "projects": projects,
  4123. "project_config": project_config,
  4124. "lastWeight": lastWeight,
  4125. "lastSchedule": lastSchedule,
  4126. })
  4127. }
  4128. if config.IsOpen == 0 || config.IsOpen == 2 {
  4129. c.ServeSuccessJSON(map[string]interface{}{
  4130. "users": adminUser,
  4131. "patientInfo": patientInfo,
  4132. "PredialysisEvaluation": PredialysisEvaluation,
  4133. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4134. "dialysisPrescription": dialysisPrescription,
  4135. "advices": DoctorAdvice,
  4136. "monitors": Record,
  4137. "summary": TreatmentSummary,
  4138. "receiverTreatmentAccess": receiverTreatmentAccess,
  4139. "dialysisOrder": dialysisOrder,
  4140. "operators": operators,
  4141. "org_template_info": templateInfo,
  4142. "check": check,
  4143. "dialysiscount": dialysiscount,
  4144. "last_order": last_order,
  4145. "projects": projects,
  4146. "project_config": project_config,
  4147. "lastWeight": lastWeight,
  4148. "lastSchedule": lastSchedule,
  4149. })
  4150. }
  4151. }
  4152. func (c *PatientApiController) CreateGroupAdvice() {
  4153. is_child, _ := c.GetInt64("is_child", 0)
  4154. if is_child == 1 {
  4155. patient, _ := c.GetInt64("id", 0)
  4156. if patient <= 0 {
  4157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4158. return
  4159. }
  4160. adminUserInfo := c.GetMobileAdminUserInfo()
  4161. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4162. if patientInfo.ID == 0 {
  4163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4164. return
  4165. }
  4166. group_no, _ := c.GetInt64("group_no")
  4167. if group_no <= 0 {
  4168. group_no = 0
  4169. }
  4170. dataBody := make(map[string]interface{}, 0)
  4171. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4172. if err != nil {
  4173. utils.ErrorLog(err.Error())
  4174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4175. return
  4176. }
  4177. timeLayout := "2006-01-02"
  4178. loc, _ := time.LoadLocation("Local")
  4179. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4180. utils.ErrorLog("advice_type")
  4181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4182. return
  4183. }
  4184. adviceType := int64(dataBody["advice_type"].(float64))
  4185. if adviceType != 1 && adviceType != 2 {
  4186. utils.ErrorLog("advice_type != 1&&2")
  4187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4188. return
  4189. }
  4190. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4191. utils.ErrorLog("start_time")
  4192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4193. return
  4194. }
  4195. startTime2, _ := dataBody["start_time"].(string)
  4196. time_arr := strings.Split(startTime2, " ")
  4197. if len(time_arr) > 0 {
  4198. startTime2 = time_arr[0]
  4199. }
  4200. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4201. utils.ErrorLog("advice_date")
  4202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4203. return
  4204. }
  4205. advice_date, _ := dataBody["advice_date"].(string)
  4206. var advicedateunix int64
  4207. if len(advice_date) > 0 {
  4208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  4209. if err != nil {
  4210. fmt.Println(err)
  4211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4212. return
  4213. }
  4214. advicedateunix = theTime.Unix()
  4215. }
  4216. adviceDate := startTime2
  4217. if len(adviceDate) == 0 {
  4218. utils.ErrorLog("len(adviceDate) == 0")
  4219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4220. return
  4221. }
  4222. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4223. if err != nil {
  4224. utils.ErrorLog(err.Error())
  4225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. AdviceDate := advicedateunix
  4229. RecordDate := advicedateunix
  4230. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4231. utils.ErrorLog("start_time")
  4232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4233. return
  4234. }
  4235. startTime, _ := dataBody["start_time"].(string)
  4236. if len(startTime) == 0 {
  4237. utils.ErrorLog("len(start_time) == 0")
  4238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4239. return
  4240. }
  4241. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  4242. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  4243. if err != nil {
  4244. utils.ErrorLog(err.Error())
  4245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4246. return
  4247. }
  4248. StartTime := theTime.Unix()
  4249. Remark := ""
  4250. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4251. remark, _ := dataBody["remark"].(string)
  4252. Remark = remark
  4253. }
  4254. Startdate := int64(dataBody["record_date"].(float64))
  4255. var advices []*models.GroupAdvice
  4256. // utils.TraceLog("%+v", dataBody["adviceNames"])
  4257. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  4258. utils.ErrorLog("adviceNames")
  4259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4260. return
  4261. }
  4262. adviceNames := dataBody["adviceNames"].([]interface{})
  4263. for _, adviceNameMap := range adviceNames {
  4264. adviceNameM := adviceNameMap.(map[string]interface{})
  4265. var advice models.GroupAdvice
  4266. advice.Remark = Remark
  4267. advice.AdviceType = adviceType
  4268. advice.StartTime = StartTime
  4269. if adminUserInfo.Org.Id == 10340 {
  4270. advice.AdviceDate = AdviceDate
  4271. advice.RecordDate = RecordDate
  4272. }
  4273. if adminUserInfo.Org.Id != 10340 {
  4274. advice.AdviceDate = theTimeOne.Unix()
  4275. advice.RecordDate = theTimeOne.Unix()
  4276. }
  4277. advice.Status = 1
  4278. advice.CreatedTime = time.Now().Unix()
  4279. advice.UpdatedTime = time.Now().Unix()
  4280. advice.StopState = 2
  4281. advice.ExecutionState = 2
  4282. advice.UserOrgId = adminUserInfo.Org.Id
  4283. advice.PatientId = patientInfo.ID
  4284. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4285. advice.IsSettle = 2
  4286. //入口
  4287. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  4288. if errcode > 0 {
  4289. c.ServeFailJSONWithSGJErrorCode(errcode)
  4290. return
  4291. }
  4292. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  4293. subdrugs := adviceNameM["subdrugs"].([]interface{})
  4294. if len(subdrugs) > 0 {
  4295. for _, subdrug := range subdrugs {
  4296. var s models.GroupAdvice
  4297. s.Remark = Remark
  4298. s.AdviceType = adviceType
  4299. s.StartTime = StartTime
  4300. s.AdviceDate = AdviceDate
  4301. s.RecordDate = RecordDate
  4302. s.Status = 1
  4303. s.CreatedTime = time.Now().Unix()
  4304. s.UpdatedTime = time.Now().Unix()
  4305. s.StopState = 2
  4306. s.ExecutionState = 2
  4307. s.UserOrgId = adminUserInfo.Org.Id
  4308. s.PatientId = patientInfo.ID
  4309. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  4310. s.IsSettle = 2
  4311. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  4312. if errcode > 0 {
  4313. c.ServeFailJSONWithSGJErrorCode(errcode)
  4314. return
  4315. }
  4316. advice.Children = append(advice.Children, &s)
  4317. }
  4318. }
  4319. }
  4320. //长沙南雅
  4321. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4322. //查询该患者今日有没有双人核对
  4323. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  4324. if check.ID > 0 {
  4325. advice.Checker = check.Modifier
  4326. advice.CheckState = 1
  4327. advice.CheckTime = time.Now().Unix()
  4328. }
  4329. }
  4330. advices = append(advices, &advice)
  4331. }
  4332. // 查询信息规挡的设置天数
  4333. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4334. if infor.ID > 0 && infor.WeekDay > 0 {
  4335. var cha_time int64
  4336. timeNowStr := time.Now().Format("2006-01-02")
  4337. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4338. //今日的日期减去设置的日期
  4339. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4340. if cha_time >= Startdate {
  4341. //查询审核是否允许
  4342. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id, 5)
  4343. //申请状态不允许的情况 拒绝修改
  4344. if infor.ApplicationStatus != 1 {
  4345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4346. return
  4347. }
  4348. }
  4349. }
  4350. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  4351. for _, item := range advices {
  4352. //记录日志
  4353. byterequest, _ := json.Marshal(item)
  4354. adviceLog := models.XtDoctorAdviceLog{
  4355. UserOrgId: item.UserOrgId,
  4356. PatientId: item.PatientId,
  4357. AdminUserId: adminUserInfo.AdminUser.Id,
  4358. Module: 1,
  4359. ErrLog: string(byterequest),
  4360. Status: 1,
  4361. Ctime: time.Now().Unix(),
  4362. Mtime: 0,
  4363. Source: "手机端新增医嘱",
  4364. RecordDate: item.AdviceDate,
  4365. }
  4366. service.CreateDoctorAdviceLog(adviceLog)
  4367. }
  4368. finish := models.XtDialysisFinish{
  4369. IsFinish: 1,
  4370. UserOrgId: adminUserInfo.Org.Id,
  4371. Status: 1,
  4372. Ctime: time.Now().Unix(),
  4373. Mtime: 0,
  4374. Module: 4,
  4375. RecordDate: advicedateunix,
  4376. Sourse: 1,
  4377. PatientId: patient,
  4378. }
  4379. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  4380. if dialysisFinish.ID == 0 {
  4381. service.CreateDialysisFinish(finish)
  4382. }
  4383. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4384. redis := service.RedisClient()
  4385. //清空key 值
  4386. redis.Set(key, "", time.Second)
  4387. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4388. redis.Set(keyOne, "", time.Second)
  4389. defer redis.Close()
  4390. if createErr != nil {
  4391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4392. return
  4393. }
  4394. c.ServeSuccessJSON(map[string]interface{}{
  4395. "msg": "ok",
  4396. "advices": newAdvices,
  4397. })
  4398. return
  4399. } else if is_child == 2 {
  4400. patient, _ := c.GetInt64("id", 0)
  4401. if patient <= 0 {
  4402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4403. return
  4404. }
  4405. adminUserInfo := c.GetMobileAdminUserInfo()
  4406. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  4407. if patientInfo.ID == 0 {
  4408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4409. return
  4410. }
  4411. var advice models.DoctorAdvice
  4412. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  4413. if code > 0 {
  4414. c.ServeFailJSONWithSGJErrorCode(code)
  4415. return
  4416. }
  4417. if advice.ParentId > 0 {
  4418. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  4419. if old.ID == 0 || old.PatientId != patient {
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  4421. return
  4422. }
  4423. if old.StopState == 1 || old.ExecutionState == 1 {
  4424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  4425. return
  4426. }
  4427. if old.ParentId > 0 {
  4428. advice.ParentId = old.ParentId
  4429. }
  4430. advice.StartTime = old.StartTime
  4431. advice.AdviceDoctor = old.AdviceDoctor
  4432. advice.DeliveryWay = old.DeliveryWay
  4433. advice.ExecutionFrequency = old.ExecutionFrequency
  4434. advice.GroupNo = old.GroupNo
  4435. }
  4436. advice.Status = 1
  4437. advice.CreatedTime = time.Now().Unix()
  4438. advice.UpdatedTime = time.Now().Unix()
  4439. advice.StopState = 2
  4440. advice.ExecutionState = 2
  4441. advice.UserOrgId = adminUserInfo.Org.Id
  4442. advice.PatientId = patient
  4443. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4444. advice.IsSettle = 2
  4445. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  4446. if advice.PrescribingNumber == 0 {
  4447. advice.PrescribingNumber = 1
  4448. }
  4449. //查询该患者今日有没有双人核对
  4450. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  4451. if check.ID > 0 {
  4452. advice.Checker = check.Modifier
  4453. advice.CheckState = 1
  4454. advice.CheckTime = time.Now().Unix()
  4455. }
  4456. }
  4457. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4458. if infor.ID > 0 {
  4459. var cha_time int64
  4460. timeNowStr := time.Now().Format("2006-01-02")
  4461. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4462. //今日的日期减去设置的日期
  4463. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4464. if cha_time >= advice.RecordDate {
  4465. //查询审核是否允许
  4466. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id, 4)
  4467. //申请状态不允许的情况 拒绝修改
  4468. if infor.ApplicationStatus != 1 {
  4469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4470. return
  4471. }
  4472. }
  4473. }
  4474. err := service.CreateDoctorAdvice(&advice)
  4475. //记录日志
  4476. byterequest, _ := json.Marshal(advice)
  4477. adviceLog := models.XtDoctorAdviceLog{
  4478. UserOrgId: advice.UserOrgId,
  4479. PatientId: advice.PatientId,
  4480. AdminUserId: adminUserInfo.Org.Id,
  4481. Module: 1,
  4482. ErrLog: string(byterequest),
  4483. Status: 1,
  4484. Ctime: time.Now().Unix(),
  4485. Mtime: 0,
  4486. Source: "手机端新增医嘱",
  4487. RecordDate: advice.AdviceDate,
  4488. }
  4489. service.CreateDoctorAdviceLog(adviceLog)
  4490. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  4491. redis := service.RedisClient()
  4492. //清空key 值
  4493. redis.Set(key, "", time.Second)
  4494. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  4495. redis.Set(keyOne, "", time.Second)
  4496. defer redis.Close()
  4497. if err != nil {
  4498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4499. return
  4500. }
  4501. c.ServeSuccessJSON(map[string]interface{}{
  4502. "msg": "ok",
  4503. "advice": advice,
  4504. })
  4505. return
  4506. }
  4507. }
  4508. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  4509. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  4510. utils.ErrorLog("advice_name")
  4511. return enums.ErrorCodeParamWrong
  4512. }
  4513. adviceName, _ := json["advice_name"].(string)
  4514. if len(adviceName) == 0 {
  4515. utils.ErrorLog("len(advice_name) == 0")
  4516. return enums.ErrorCodeParamWrong
  4517. }
  4518. advice.AdviceName = adviceName
  4519. adviceDesc, _ := json["advice_desc"].(string)
  4520. advice.AdviceDesc = adviceDesc
  4521. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4522. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4523. advice.DrugSpec = drugSpec
  4524. }
  4525. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4526. remark, _ := json["remark"].(string)
  4527. advice.Remark = remark
  4528. }
  4529. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  4530. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  4531. // advice.Way = src_type
  4532. //}
  4533. if json["way"] == nil {
  4534. advice.Way = 0
  4535. } else {
  4536. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  4537. way := int64(json["way"].(float64))
  4538. advice.Way = way
  4539. }
  4540. }
  4541. if json["drug_id"] == nil {
  4542. advice.DrugId = 0
  4543. } else {
  4544. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  4545. drug_id := int64(json["drug_id"].(float64))
  4546. advice.DrugId = drug_id
  4547. }
  4548. }
  4549. if json["drug_name_id"] == nil {
  4550. advice.DrugNameId = 0
  4551. } else {
  4552. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  4553. drug_name_id := int64(json["drug_name_id"].(float64))
  4554. advice.DrugNameId = drug_name_id
  4555. }
  4556. }
  4557. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  4558. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  4559. advice.DrugSpecUnit = drugSpecUnit
  4560. }
  4561. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4562. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4563. advice.SingleDose = singleDose
  4564. }
  4565. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4566. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4567. advice.SingleDoseUnit = singleDoseUnit
  4568. }
  4569. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4570. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4571. advice.PrescribingNumber = prescribingNumber
  4572. }
  4573. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4574. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4575. advice.PrescribingNumberUnit = prescribingNumberUnit
  4576. }
  4577. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4578. deliveryWay, _ := json["delivery_way"].(string)
  4579. advice.DeliveryWay = deliveryWay
  4580. }
  4581. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4582. executionFrequency, _ := json["execution_frequency"].(string)
  4583. advice.ExecutionFrequency = executionFrequency
  4584. }
  4585. return 0
  4586. }
  4587. func (c *PatientApiController) DelDoctorAdvice() {
  4588. groupno, _ := c.GetInt64("groupno", -1)
  4589. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  4590. patient_id, _ := c.GetInt64("patient_id")
  4591. doc_advice_date, _ := c.GetInt64("advice_date")
  4592. redis := service.RedisClient()
  4593. if is_sub == 1 { //是
  4594. advice_id, _ := c.GetInt64("advice_id")
  4595. adminUserInfo := c.GetMobileAdminUserInfo()
  4596. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4597. if advice.ID == 0 {
  4598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4599. return
  4600. }
  4601. advice.Status = 0
  4602. advice.UpdatedTime = time.Now().Unix()
  4603. advice.Modifier = adminUserInfo.AdminUser.Id
  4604. // 查询信息规挡的设置天数
  4605. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4606. if infor.ID > 0 && infor.WeekDay > 0 {
  4607. var cha_time int64
  4608. timeNowStr := time.Now().Format("2006-01-02")
  4609. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4610. //今日的日期减去设置的日期
  4611. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4612. if cha_time >= advice.AdviceDate {
  4613. //查询审核是否允许
  4614. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4615. //申请状态不允许的情况 拒绝修改
  4616. if infor.ApplicationStatus != 1 {
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4618. return
  4619. }
  4620. }
  4621. }
  4622. err := service.DeleteDoctorAdvice(&advice)
  4623. //记录日志
  4624. byterequest, _ := json.Marshal(advice)
  4625. adviceLog := models.XtDoctorAdviceLog{
  4626. UserOrgId: advice.UserOrgId,
  4627. PatientId: advice.PatientId,
  4628. AdminUserId: adminUserInfo.AdminUser.Id,
  4629. Module: 4,
  4630. ErrLog: string(byterequest),
  4631. Status: 1,
  4632. Ctime: time.Now().Unix(),
  4633. Mtime: 0,
  4634. Source: "手机端删除医嘱",
  4635. RecordDate: advice.RecordDate,
  4636. }
  4637. service.CreateDoctorAdviceLog(adviceLog)
  4638. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4639. redis.Set(key, "", time.Second)
  4640. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4641. redis.Set(keyTwo, "", time.Second)
  4642. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4643. redis.Set(keyThree, "", time.Second)
  4644. redis.Close()
  4645. if err != nil {
  4646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4647. return
  4648. }
  4649. c.ServeSuccessJSON(map[string]interface{}{
  4650. "msg": "ok",
  4651. })
  4652. return
  4653. } else { //
  4654. var ids []string
  4655. if groupno == 0 {
  4656. advice_id := c.GetString("advice_id")
  4657. ids = strings.Split(advice_id, ",")
  4658. if len(ids) <= 0 {
  4659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4660. return
  4661. }
  4662. }
  4663. if groupno < 0 {
  4664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4665. return
  4666. }
  4667. adminUserInfo := c.GetMobileAdminUserInfo()
  4668. var advice models.DoctorAdvice
  4669. if groupno > 0 {
  4670. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4671. if advice.ID == 0 {
  4672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4673. return
  4674. }
  4675. } else {
  4676. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4677. for _, item := range advices {
  4678. if item.ID == 0 {
  4679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4680. return
  4681. }
  4682. }
  4683. }
  4684. advice.UpdatedTime = time.Now().Unix()
  4685. advice.Status = 0
  4686. advice.GroupNo = groupno
  4687. advice.Modifier = adminUserInfo.AdminUser.Id
  4688. var err error
  4689. if groupno > 0 {
  4690. // 查询信息规挡的设置天数
  4691. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4692. if infor.ID > 0 {
  4693. var cha_time int64
  4694. timeNowStr := time.Now().Format("2006-01-02")
  4695. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4696. //今日的日期减去设置的日期
  4697. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4698. if cha_time >= advice.AdviceDate {
  4699. //查询审核是否允许
  4700. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4701. //申请状态不允许的情况 拒绝修改
  4702. if infor.ApplicationStatus != 1 {
  4703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4704. return
  4705. }
  4706. }
  4707. }
  4708. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4709. //记录日志
  4710. byterequest, _ := json.Marshal(advice)
  4711. adviceLog := models.XtDoctorAdviceLog{
  4712. UserOrgId: advice.UserOrgId,
  4713. PatientId: advice.PatientId,
  4714. AdminUserId: adminUserInfo.AdminUser.Id,
  4715. Module: 4,
  4716. ErrLog: string(byterequest),
  4717. Status: 1,
  4718. Ctime: time.Now().Unix(),
  4719. Mtime: 0,
  4720. Source: "手机端删除医嘱",
  4721. RecordDate: advice.RecordDate,
  4722. }
  4723. service.CreateDoctorAdviceLog(adviceLog)
  4724. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4725. redis.Set(key, "", time.Second)
  4726. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4727. redis.Set(keyTwo, "", time.Second)
  4728. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4729. redis.Set(keyThree, "", time.Second)
  4730. } else {
  4731. // 查询信息规挡的设置天数
  4732. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4733. if infor.ID > 0 {
  4734. var cha_time int64
  4735. timeNowStr := time.Now().Format("2006-01-02")
  4736. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4737. //今日的日期减去设置的日期
  4738. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4739. if cha_time >= advice.AdviceDate {
  4740. //查询审核是否允许
  4741. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id, 4)
  4742. //申请状态不允许的情况 拒绝修改
  4743. if infor.ApplicationStatus != 1 {
  4744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4745. return
  4746. }
  4747. }
  4748. }
  4749. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4750. advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
  4751. for _, item := range advicelist {
  4752. //记录日志
  4753. byterequest, _ := json.Marshal(item)
  4754. adviceLog := models.XtDoctorAdviceLog{
  4755. UserOrgId: item.UserOrgId,
  4756. PatientId: item.PatientId,
  4757. AdminUserId: adminUserInfo.AdminUser.Id,
  4758. Module: 4,
  4759. ErrLog: string(byterequest),
  4760. Status: 1,
  4761. Ctime: time.Now().Unix(),
  4762. Mtime: 0,
  4763. Source: "手机端批量删除医嘱",
  4764. RecordDate: item.RecordDate,
  4765. }
  4766. service.CreateDoctorAdviceLog(adviceLog)
  4767. }
  4768. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4769. redis.Set(key, "", time.Second)
  4770. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4771. redis.Set(keyTwo, "", time.Second)
  4772. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4773. redis.Set(keyThree, "", time.Second)
  4774. redis.Close()
  4775. }
  4776. if err != nil {
  4777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4778. return
  4779. }
  4780. c.ServeSuccessJSON(map[string]interface{}{
  4781. "msg": "ok",
  4782. })
  4783. return
  4784. }
  4785. }
  4786. // /m/api/advice/group/modify_starttime [post]
  4787. // @param group_no:int
  4788. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4789. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4790. group_no, _ := this.GetInt64("group_no")
  4791. start_time_str := this.GetString("start_time")
  4792. if group_no <= 0 || len(start_time_str) == 0 {
  4793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4794. return
  4795. }
  4796. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4797. if parseTimeErr != nil {
  4798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4799. return
  4800. }
  4801. adminUserInfo := this.GetMobileAdminUserInfo()
  4802. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4803. if updateStartTimeErr != nil {
  4804. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4806. return
  4807. }
  4808. this.ServeSuccessJSON(map[string]interface{}{
  4809. "start_time": startTime.Unix(),
  4810. })
  4811. }
  4812. func (this *PatientApiController) DelSubDoctorAdvice() {
  4813. advice_id, _ := this.GetInt64("advice_id")
  4814. adminUserInfo := this.GetMobileAdminUserInfo()
  4815. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4816. if advice.ID == 0 {
  4817. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4818. return
  4819. }
  4820. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4821. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4822. // return
  4823. //}
  4824. advice.Status = 0
  4825. advice.UpdatedTime = time.Now().Unix()
  4826. advice.Modifier = adminUserInfo.AdminUser.Id
  4827. err := service.DeleteDoctorAdvice(&advice)
  4828. if err != nil {
  4829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4830. return
  4831. }
  4832. this.ServeSuccessJSON(map[string]interface{}{
  4833. "msg": "ok",
  4834. })
  4835. return
  4836. }
  4837. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4838. //adminUserInfo := this.GetMobileAdminUserInfo()
  4839. //service.FindUnReadDoctorAdviceMessage()
  4840. }
  4841. func (this *PatientApiController) GetPatientsByKeyWord() {
  4842. keyWord := this.GetString("keyword")
  4843. adminUserInfo := this.GetMobileAdminUserInfo()
  4844. today := utils.ZeroHourTimeOfDay(time.Now())
  4845. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4846. if err != nil {
  4847. utils.ErrorLog(err.Error())
  4848. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4849. return
  4850. }
  4851. this.ServeSuccessJSON(map[string]interface{}{
  4852. "patient": patient,
  4853. })
  4854. }
  4855. func (this *PatientApiController) GetSearchPatient() {
  4856. keyWord := this.GetString("keyword")
  4857. adminUserInfo := this.GetMobileAdminUserInfo()
  4858. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4859. if err != nil {
  4860. utils.ErrorLog(err.Error())
  4861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4862. return
  4863. }
  4864. this.ServeSuccessJSON(map[string]interface{}{
  4865. "patient": patient,
  4866. })
  4867. }
  4868. func (c *PatientApiController) ExecProject() {
  4869. execution_time := c.GetString("execution_time")
  4870. project_id, _ := c.GetInt64("project_id")
  4871. team_id, _ := c.GetInt64("team_id")
  4872. is_check_team, _ := c.GetInt64("is_check_team")
  4873. if len(execution_time) <= 0 {
  4874. utils.ErrorLog("execution_time")
  4875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4876. return
  4877. }
  4878. timeLayout2 := "2006-01-02 15:04:05"
  4879. loc, _ := time.LoadLocation("Local")
  4880. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4881. if errs != nil {
  4882. utils.ErrorLog(errs.Error())
  4883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4884. return
  4885. }
  4886. adminInfo := c.GetMobileAdminUserInfo()
  4887. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4888. if project.Type == 3 {
  4889. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4890. if good.IsUser != 1 {
  4891. //查询开关是否开启
  4892. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4893. //开关已经开启
  4894. if stockSetting.IsType == 1 {
  4895. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4896. scheduleDateStart := theTime.Format("2006-01-02")
  4897. timeLayout3 := "2006-01-02"
  4898. loc, _ := time.LoadLocation("Local")
  4899. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4900. //查询该耗材是否已经出库
  4901. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4902. if auto.ID == 0 {
  4903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4904. return
  4905. }
  4906. }
  4907. }
  4908. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4909. //查询开关是否开启
  4910. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4911. //开关已经开启
  4912. if stockSetting.IsType == 1 {
  4913. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4914. scheduleDateStart := theTime.Format("2006-01-02")
  4915. timeLayout3 := "2006-01-02"
  4916. loc, _ := time.LoadLocation("Local")
  4917. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4918. //查询该耗材是否已经出库
  4919. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4920. if auto.ID == 0 {
  4921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4922. return
  4923. }
  4924. }
  4925. }
  4926. }
  4927. if project.ExecutionState == 1 {
  4928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4929. return
  4930. }
  4931. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4933. return
  4934. }
  4935. project.ExecutionState = 1
  4936. project.ExecutionStaff = adminInfo.AdminUser.Id
  4937. project.ExecutionTime = theTime.Unix()
  4938. if team_id == 0 {
  4939. // 查询信息规挡的设置天数
  4940. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4941. if infor.ID > 0 {
  4942. var cha_time int64
  4943. timeNowStr := time.Now().Format("2006-01-02")
  4944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4945. //今日的日期减去设置的日期
  4946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4947. if cha_time >= project.RecordDate {
  4948. //查询审核是否允许
  4949. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4950. //申请状态不允许的情况 拒绝修改
  4951. if infor.ApplicationStatus != 1 {
  4952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4953. return
  4954. }
  4955. }
  4956. }
  4957. err := service.SaveHisProject(&project)
  4958. if err == nil {
  4959. c.ServeSuccessJSON(map[string]interface{}{
  4960. "project": project,
  4961. })
  4962. } else {
  4963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4964. return
  4965. }
  4966. } else {
  4967. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4968. // 查询信息规挡的设置天数
  4969. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4970. if infor.ID > 0 {
  4971. var cha_time int64
  4972. timeNowStr := time.Now().Format("2006-01-02")
  4973. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4974. //今日的日期减去设置的日期
  4975. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4976. if cha_time >= project.RecordDate {
  4977. //查询审核是否允许
  4978. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  4979. //申请状态不允许的情况 拒绝修改
  4980. if infor.ApplicationStatus != 1 {
  4981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4982. return
  4983. }
  4984. }
  4985. }
  4986. err := service.SaveHisProject(&project)
  4987. if err == nil {
  4988. c.ServeSuccessJSON(map[string]interface{}{
  4989. "project": project,
  4990. })
  4991. } else {
  4992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4993. return
  4994. }
  4995. } else {
  4996. // 查询信息规挡的设置天数
  4997. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4998. if infor.ID > 0 {
  4999. var cha_time int64
  5000. timeNowStr := time.Now().Format("2006-01-02")
  5001. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5002. //今日的日期减去设置的日期
  5003. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5004. if cha_time >= project.RecordDate {
  5005. //查询审核是否允许
  5006. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5007. //申请状态不允许的情况 拒绝修改
  5008. if infor.ApplicationStatus != 1 {
  5009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5010. return
  5011. }
  5012. }
  5013. }
  5014. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5015. var ids []int64
  5016. for _, items := range ps {
  5017. ids = append(ids, items.ID)
  5018. }
  5019. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  5020. if err == nil {
  5021. c.ServeSuccessJSON(map[string]interface{}{
  5022. "project": project,
  5023. })
  5024. } else {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5026. return
  5027. }
  5028. }
  5029. }
  5030. }
  5031. func (c *PatientApiController) CheckProject() {
  5032. adminInfo := c.GetMobileAdminUserInfo()
  5033. project_id, _ := c.GetInt64("project_id")
  5034. team_id, _ := c.GetInt64("team_id")
  5035. is_check_team, _ := c.GetInt64("is_check_team")
  5036. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  5037. if project.CheckState == 1 {
  5038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  5039. return
  5040. }
  5041. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  5042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  5043. return
  5044. }
  5045. project.Checker = adminInfo.AdminUser.Id
  5046. project.CheckTime = time.Now().Unix()
  5047. project.CheckState = 1
  5048. if team_id == 0 {
  5049. // 查询信息规挡的设置天数
  5050. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5051. if infor.ID > 0 {
  5052. var cha_time int64
  5053. timeNowStr := time.Now().Format("2006-01-02")
  5054. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5055. //今日的日期减去设置的日期
  5056. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5057. if cha_time >= project.RecordDate {
  5058. //查询审核是否允许
  5059. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5060. //申请状态不允许的情况 拒绝修改
  5061. if infor.ApplicationStatus != 1 {
  5062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5063. return
  5064. }
  5065. }
  5066. }
  5067. err := service.SaveHisProject(&project)
  5068. if err == nil {
  5069. c.ServeSuccessJSON(map[string]interface{}{
  5070. "msg": "ok",
  5071. "project": project,
  5072. })
  5073. } else {
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5075. return
  5076. }
  5077. } else {
  5078. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  5079. // 查询信息规挡的设置天数
  5080. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5081. if infor.ID > 0 {
  5082. var cha_time int64
  5083. timeNowStr := time.Now().Format("2006-01-02")
  5084. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5085. //今日的日期减去设置的日期
  5086. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5087. if cha_time >= project.RecordDate {
  5088. //查询审核是否允许
  5089. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5090. //申请状态不允许的情况 拒绝修改
  5091. if infor.ApplicationStatus != 1 {
  5092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5093. return
  5094. }
  5095. }
  5096. }
  5097. err := service.SaveHisProject(&project)
  5098. if err == nil {
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "msg": "ok",
  5101. "project": project,
  5102. })
  5103. } else {
  5104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5105. return
  5106. }
  5107. } else {
  5108. // 查询信息规挡的设置天数
  5109. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  5110. if infor.ID > 0 {
  5111. var cha_time int64
  5112. timeNowStr := time.Now().Format("2006-01-02")
  5113. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5114. //今日的日期减去设置的日期
  5115. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5116. if cha_time >= project.RecordDate {
  5117. //查询审核是否允许
  5118. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId, 4)
  5119. //申请状态不允许的情况 拒绝修改
  5120. if infor.ApplicationStatus != 1 {
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5122. return
  5123. }
  5124. }
  5125. }
  5126. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  5127. var ids []int64
  5128. for _, items := range ps {
  5129. ids = append(ids, items.ID)
  5130. }
  5131. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  5132. if err == nil {
  5133. c.ServeSuccessJSON(map[string]interface{}{
  5134. "project": project,
  5135. })
  5136. } else {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5138. return
  5139. }
  5140. }
  5141. }
  5142. }