patient_api_controller.go 209KB

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