patient_api_controller.go 199KB

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