patient_api_controller.go 186KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/jinzhu/gorm"
  9. //"github.com/jinzhu/gorm"
  10. "math"
  11. "math/rand"
  12. "reflect"
  13. "regexp"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "fmt"
  18. "github.com/astaxie/beego"
  19. )
  20. type PatientApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func PatientApiRegistRouters() {
  24. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  25. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  26. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  27. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  28. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  29. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  30. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  31. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  33. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  34. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  35. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  36. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  37. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  38. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  39. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  40. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  41. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  42. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  43. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  44. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  45. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  46. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  47. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  48. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  49. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  50. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  51. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  52. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  53. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  54. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  55. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  56. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  57. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  58. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  59. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  60. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  61. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  62. beego.Router("/api/patients/banner", &PatientApiController{}, "Get:GetBanner")
  63. //长期医嘱新接口
  64. beego.Router("/api/patient/findepatientdialysislongsolutions", &PatientApiController{}, "Get:GetPatientDialysisLongSolution")
  65. beego.Router("/api/patient/getdialysissolutiondetaillist", &PatientApiController{}, "Get:GetDialysisSolutionDetailList")
  66. }
  67. // GetPatientsList 取患者列表
  68. func (c *PatientApiController) GetPatientsList() {
  69. var err error
  70. defer func() {
  71. if rec := recover(); rec != nil {
  72. err = fmt.Errorf("程序异常:%v", rec)
  73. }
  74. if err != nil {
  75. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  76. }
  77. }()
  78. page, _ := c.GetInt64("page", 1)
  79. limit, _ := c.GetInt64("limit", 10)
  80. schedulType, _ := c.GetInt64("schedul_type", 0)
  81. bindingState, _ := c.GetInt64("binding_state", 0)
  82. lapseto, _ := c.GetInt64("lapseto", 0)
  83. source, _ := c.GetInt64("source", 0)
  84. startTime := c.GetString("start_time", "")
  85. endTime := c.GetString("end_time", "")
  86. keywords := c.GetString("keywords", "")
  87. contagion, _ := c.GetInt64("contagion", 0)
  88. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  89. isscheduling, _ := c.GetInt64("isscheduling", 0)
  90. isprescription, _ := c.GetInt64("isprescription", 0)
  91. if page <= 0 {
  92. page = 1
  93. }
  94. if limit <= 0 {
  95. limit = 10
  96. }
  97. adminUserInfo := c.GetAdminUserInfo()
  98. timeLayout := "2006-01-02"
  99. loc, _ := time.LoadLocation("Local")
  100. var isStartTime bool
  101. var theStartTIme int64
  102. if len(startTime) > 0 {
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. isStartTime = true
  109. theStartTIme = theTime.Unix()
  110. }
  111. var isEndTime bool
  112. var theEndtTIme int64
  113. if len(endTime) > 0 {
  114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  115. if err != nil {
  116. utils.ErrorLog(err.Error())
  117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  118. return
  119. }
  120. isEndTime = true
  121. theEndtTIme = theTime.Unix()
  122. }
  123. var patients []*models.Patients
  124. var total int64
  125. patients, total, err = service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
  126. c.ServeSuccessJSON(map[string]interface{}{
  127. "patients": patients,
  128. "total": total,
  129. })
  130. return
  131. }
  132. // GetPatientTotal
  133. func (c *PatientApiController) GetPatientTotal() {
  134. adminUserInfo := c.GetAdminUserInfo()
  135. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  136. c.ServeSuccessJSON(map[string]interface{}{
  137. "total": total,
  138. })
  139. return
  140. }
  141. func (c *PatientApiController) GetPatientsAllList() {
  142. adminUserInfo := c.GetAdminUserInfo()
  143. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  144. c.ServeSuccessJSON(map[string]interface{}{
  145. "patients": patients,
  146. "total": total,
  147. })
  148. return
  149. }
  150. // GenerateDialysisNo 生成透析号
  151. func (c *PatientApiController) GenerateDialysisNo() {
  152. adminUserInfo := c.GetAdminUserInfo()
  153. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  154. if dialysisNo == 0 {
  155. dialysisNo = 1
  156. } else {
  157. dialysisNo++
  158. }
  159. no := strconv.FormatInt(dialysisNo, 10)
  160. rep := 3 - len(no)
  161. if rep > 0 {
  162. no = strings.Repeat("0", rep) + no
  163. }
  164. c.ServeSuccessJSON(map[string]interface{}{
  165. "no": no,
  166. })
  167. return
  168. }
  169. // CreatePatient 创建患者
  170. func (c *PatientApiController) CreatePatient() {
  171. record_date := c.GetString("record_date")
  172. is_infectious, _ := c.GetInt64("is_infectious")
  173. remind_cycle, _ := c.GetInt64("remind_cycle")
  174. adminUserInfo := c.GetAdminUserInfo()
  175. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  176. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  177. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  178. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  179. // return
  180. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  181. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  182. // return
  183. //}
  184. var patient models.Patients
  185. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  186. fmt.Println(code)
  187. fmt.Println(patient)
  188. fmt.Println("contagions是什么", contagions)
  189. if code > 0 {
  190. c.ServeFailJSONWithSGJErrorCode(code)
  191. return
  192. }
  193. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  194. if thisPatient.ID > 0 {
  195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  196. return
  197. }
  198. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  199. if thisPatient.ID > 0 {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  201. return
  202. }
  203. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  204. if thisPatient.ID > 0 {
  205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  206. return
  207. }
  208. patient.RemindCycle = remind_cycle
  209. patient.IsInfectious = is_infectious
  210. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  211. patient.Status = 1
  212. patient.CreatedTime = time.Now().Unix()
  213. patient.UserOrgId = adminUserInfo.CurrentOrgId
  214. patient.UpdatedTime = time.Now().Unix()
  215. patient.BindingState = 2
  216. // patient.Lapseto = 1
  217. err := service.CreatePatient(&patient, contagions, diseases)
  218. fmt.Println("创建病人失败err")
  219. if err != nil {
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  221. return
  222. }
  223. //获取老表的最后一条数据
  224. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  225. patientsNew := models.XtPatientsNew{
  226. UserOrgId: adminUserInfo.CurrentOrgId,
  227. UserId: 0,
  228. Avatar: patients.Avatar,
  229. PatientType: patients.PatientType,
  230. DialysisNo: patients.DialysisNo,
  231. AdmissionNumber: patients.AdmissionNumber,
  232. Source: patients.Source,
  233. Lapseto: patients.Lapseto,
  234. PartitionId: patients.PartitionId,
  235. BedId: patients.BedId,
  236. Name: patients.Name,
  237. Alias: patients.Alias,
  238. Gender: patients.Gender,
  239. MaritalStatus: patients.MaritalStatus,
  240. IdCardNo: patients.IdCardNo,
  241. Birthday: patients.Birthday,
  242. ReimbursementWayId: patients.ReimbursementWayId,
  243. HealthCareType: patients.HealthCareType,
  244. HealthCareNo: patients.HealthCareNo,
  245. HealthCareDueDate: patients.HealthCareDueDate,
  246. Height: patients.Height,
  247. BloodType: patients.BloodType,
  248. Rh: patients.Rh,
  249. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  250. EducationLevel: patients.EducationLevel,
  251. Profession: patients.Profession,
  252. Phone: patients.Phone,
  253. HomeTelephone: patients.HomeTelephone,
  254. RelativePhone: patients.RelativePhone,
  255. RelativeRelations: patients.RelativeRelations,
  256. HomeAddress: patients.HomeAddress,
  257. WorkUnit: patients.WorkUnit,
  258. UnitAddress: patients.UnitAddress,
  259. Children: patients.Children,
  260. ReceivingDate: patients.ReceivingDate,
  261. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  262. FirstDialysisDate: patients.FirstDialysisDate,
  263. FirstDialysisHospital: patients.FirstDialysisHospital,
  264. PredialysisCondition: patients.PredialysisCondition,
  265. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  266. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  267. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  268. InductionPeriod: patients.InductionPeriod,
  269. InitialDialysis: patients.InitialDialysis,
  270. TotalDialysis: patients.TotalDialysis,
  271. AttendingDoctorId: patients.AttendingDoctorId,
  272. HeadNurseId: patients.HeadNurseId,
  273. Evaluate: patients.Evaluate,
  274. Diagnose: patients.Diagnose,
  275. Remark: patients.Remark,
  276. RegistrarsId: patients.RegistrarsId,
  277. Registrars: patients.Registrars,
  278. QrCode: patients.QrCode,
  279. BindingState: patients.BindingState,
  280. PatientComplains: patients.PatientComplains,
  281. PresentHistory: patients.PresentHistory,
  282. PastHistory: patients.PresentHistory,
  283. Temperature: patients.Temperature,
  284. Pulse: patients.Pulse,
  285. Respiratory: patients.Respiratory,
  286. Sbp: patients.SBP,
  287. Dbp: patients.DBP,
  288. Status: patients.Status,
  289. CreatedTime: patients.CreatedTime,
  290. UpdatedTime: patients.UpdatedTime,
  291. Nation: patients.Nation,
  292. NativePlace: patients.NativePlace,
  293. Age: patients.Age,
  294. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  295. IsInfectious: patients.IsInfectious,
  296. RemindCycle: patients.RemindCycle,
  297. ResponseResult: patients.ResponseResult,
  298. IsOpenRemind: patients.IsOpenRemind,
  299. FirstTreatmentDate: patients.FirstTreatmentDate,
  300. DialysisAge: patients.DialysisAge,
  301. ExpenseKind: patients.ExpenseKind,
  302. TellPhone: patients.TellPhone,
  303. ContactName: patients.ContactName,
  304. BloodPatients: 1,
  305. SlowPatients: 0,
  306. MemberPatients: 0,
  307. EcommerPatients: "",
  308. BloodId: patients.ID,
  309. SlowId: 0,
  310. MemberId: 0,
  311. MemberFistdate: 0,
  312. MemberPatienttype: 0,
  313. MemberTreatement: 0,
  314. EquitmentId: "",
  315. UserSysBeforeCount: patient.UserSysBeforeCount,
  316. TrobleShoot: patient.TrobleShoot,
  317. TreatmentPlan: patient.TreatmentPlan,
  318. Doctor: patient.Doctor,
  319. }
  320. err = service.CreatePatientsNew(&patientsNew)
  321. fmt.Print("创建失败", err)
  322. if len(record_date) > 0 {
  323. var recordTime int64
  324. timeLayout := "2006-01-02"
  325. loc, _ := time.LoadLocation("Local")
  326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  327. if err != nil {
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. recordTime = theTime.Unix()
  332. inspections := make([]models.Inspection, 0)
  333. for _, item := range formItems {
  334. var inspection models.Inspection
  335. inspection.OrgId = adminUserInfo.CurrentOrgId
  336. inspection.PatientId = patient.ID
  337. inspection.ProjectId = item.ProjectId
  338. inspection.ItemId = item.ItemId
  339. inspection.ItemName = item.ItemName
  340. inspection.ProjectName = item.ProjectName
  341. inspection.InspectType = item.RangeType
  342. inspection.InspectValue = item.Value
  343. inspection.InspectDate = recordTime
  344. inspection.Status = 1
  345. inspection.CreatedTime = time.Now().Unix()
  346. inspection.UpdatedTime = time.Now().Unix()
  347. inspections = append(inspections, inspection)
  348. }
  349. err = service.CreatePatientInspection(inspections)
  350. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  351. var record_time int64
  352. switch remind_cycle {
  353. case 1: //1个月
  354. ts := time.Unix(infectiousRecord.InspectDate, 0)
  355. record_time = ts.AddDate(0, 1, 0).Unix()
  356. break
  357. case 2: //2个月
  358. ts := time.Unix(infectiousRecord.InspectDate, 0)
  359. record_time = ts.AddDate(0, 2, 0).Unix()
  360. break
  361. case 3: //3个月
  362. ts := time.Unix(infectiousRecord.InspectDate, 0)
  363. record_time = ts.AddDate(0, 3, 0).Unix()
  364. break
  365. case 4: //6个月
  366. ts := time.Unix(infectiousRecord.InspectDate, 0)
  367. record_time = ts.AddDate(0, 6, 0).Unix()
  368. break
  369. case 5: //12个月
  370. ts := time.Unix(infectiousRecord.InspectDate, 0)
  371. record_time = ts.AddDate(0, 12, 0).Unix()
  372. break
  373. }
  374. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  375. if errs != nil {
  376. utils.ErrorLog("更新日期出错:%v", errs)
  377. }
  378. }
  379. redis := service.RedisClient()
  380. defer redis.Close()
  381. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  382. c.ServeSuccessJSON(map[string]interface{}{
  383. "msg": "ok",
  384. })
  385. return
  386. }
  387. // EditPatient 修改
  388. func (c *PatientApiController) EditPatient() {
  389. id, _ := c.GetInt64("id", 0)
  390. record_date := c.GetString("record_date")
  391. is_infectious, _ := c.GetInt64("is_infectious")
  392. remind_cycle, _ := c.GetInt64("remind_cycle")
  393. if id <= 0 {
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  395. return
  396. }
  397. adminUserInfo := c.GetAdminUserInfo()
  398. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  399. if patient.ID == 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  401. return
  402. }
  403. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  404. if code > 0 {
  405. c.ServeFailJSONWithSGJErrorCode(code)
  406. return
  407. }
  408. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  409. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  411. return
  412. }
  413. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  414. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  416. return
  417. }
  418. patient.UpdatedTime = time.Now().Unix()
  419. patient.IsInfectious = is_infectious
  420. patient.RemindCycle = remind_cycle
  421. err := service.UpdatePatient(&patient, contagions, diseases)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  424. return
  425. }
  426. ////更新转归状态
  427. //lapseto := models.PatientLapseto{
  428. // LapsetoType: patient.Lapseto,
  429. // LapsetoTime: time.Now().Unix(),
  430. // UpdatedTime: time.Now().Unix(),
  431. //}
  432. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  433. //fmt.Println("更新转归失败", err)
  434. if err != nil {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  436. return
  437. }
  438. patientsNew := models.XtPatientsNew{
  439. UserOrgId: patient.UserOrgId,
  440. UserId: patient.UserId,
  441. Avatar: patient.Avatar,
  442. PatientType: patient.PatientType,
  443. DialysisNo: patient.DialysisNo,
  444. AdmissionNumber: patient.AdmissionNumber,
  445. Source: patient.Source,
  446. PartitionId: patient.PartitionId,
  447. BedId: patient.BedId,
  448. Name: patient.Name,
  449. Alias: patient.Alias,
  450. Gender: patient.Gender,
  451. MaritalStatus: patient.MaritalStatus,
  452. IdCardNo: patient.IdCardNo,
  453. Birthday: patient.Birthday,
  454. ReimbursementWayId: patient.ReimbursementWayId,
  455. HealthCareType: patient.HealthCareType,
  456. HealthCareNo: patient.HealthCareNo,
  457. HealthCareDueDate: patient.HealthCareDueDate,
  458. Height: patient.Height,
  459. BloodType: patient.BloodType,
  460. Rh: patient.Rh,
  461. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  462. EducationLevel: patient.EducationLevel,
  463. Profession: patient.Profession,
  464. Phone: patient.Phone,
  465. HomeTelephone: patient.HomeTelephone,
  466. RelativePhone: patient.RelativePhone,
  467. RelativeRelations: patient.RelativeRelations,
  468. HomeAddress: patient.HomeAddress,
  469. WorkUnit: patient.WorkUnit,
  470. UnitAddress: patient.UnitAddress,
  471. Children: patient.Children,
  472. ReceivingDate: patient.ReceivingDate,
  473. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  474. FirstDialysisDate: patient.FirstDialysisDate,
  475. FirstDialysisHospital: patient.FirstDialysisHospital,
  476. PredialysisCondition: patient.PredialysisCondition,
  477. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  478. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  479. InductionPeriod: patient.InductionPeriod,
  480. InitialDialysis: patient.InitialDialysis,
  481. TotalDialysis: patient.TotalDialysis,
  482. AttendingDoctorId: patient.AttendingDoctorId,
  483. HeadNurseId: patient.HeadNurseId,
  484. Evaluate: patient.Evaluate,
  485. Diagnose: patient.Diagnose,
  486. Remark: patient.Remark,
  487. RegistrarsId: patient.RegistrarsId,
  488. Registrars: patient.Registrars,
  489. QrCode: patient.QrCode,
  490. BindingState: patient.BindingState,
  491. PatientComplains: patient.PatientComplains,
  492. PresentHistory: patient.PresentHistory,
  493. PastHistory: patient.PastHistory,
  494. Temperature: patient.Temperature,
  495. Pulse: patient.Pulse,
  496. Respiratory: patient.Respiratory,
  497. Sbp: patient.SBP,
  498. Dbp: patient.DBP,
  499. Nation: patient.Nation,
  500. NativePlace: patient.NativePlace,
  501. Age: patient.Age,
  502. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  503. IsInfectious: patient.IsInfectious,
  504. RemindCycle: patient.RemindCycle,
  505. ResponseResult: patient.ResponseResult,
  506. IsOpenRemind: patient.IsOpenRemind,
  507. FirstTreatmentDate: patient.FirstTreatmentDate,
  508. DialysisAge: patient.DialysisAge,
  509. ExpenseKind: patient.ExpenseKind,
  510. TellPhone: patient.TellPhone,
  511. ContactName: patient.ContactName,
  512. UpdatedTime: time.Now().Unix(),
  513. BloodPatients: 1,
  514. Lapseto: patient.Lapseto,
  515. TrobleShoot: patient.TrobleShoot,
  516. SchRemark: patient.SchRemark,
  517. TreatmentPlan: patient.TreatmentPlan,
  518. }
  519. // //更新病人ID获取新表病人ID
  520. err = service.UpdatepatientTwo(&patientsNew, id)
  521. nowTimeUinx := time.Now()
  522. today := nowTimeUinx.Format("2006-01-02")
  523. redis := service.RedisClient()
  524. defer redis.Close()
  525. key := "scheduals_" + today + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  526. redis.Set(key, "", time.Second*60*60*18)
  527. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":patient_info"
  528. redis.Set(keyOne, "", time.Second*60*60*18)
  529. if len(record_date) > 0 {
  530. var recordTime int64
  531. timeLayout := "2006-01-02"
  532. loc, _ := time.LoadLocation("Local")
  533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  534. if err != nil {
  535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  536. return
  537. }
  538. recordTime = theTime.Unix()
  539. inspections := make([]models.Inspection, 0)
  540. for _, item := range formItems {
  541. var inspection models.Inspection
  542. inspection.OrgId = adminUserInfo.CurrentOrgId
  543. inspection.PatientId = patient.ID
  544. inspection.ProjectId = item.ProjectId
  545. inspection.ItemId = item.ItemId
  546. inspection.ItemName = item.ItemName
  547. inspection.ProjectName = item.ProjectName
  548. inspection.InspectType = item.RangeType
  549. inspection.InspectValue = item.Value
  550. inspection.InspectDate = recordTime
  551. inspection.Status = 1
  552. inspection.CreatedTime = time.Now().Unix()
  553. inspection.UpdatedTime = time.Now().Unix()
  554. inspections = append(inspections, inspection)
  555. }
  556. err = service.CreatePatientInspection(inspections)
  557. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  558. var record_time int64
  559. switch remind_cycle {
  560. case 1: //1个月
  561. ts := time.Unix(infectiousRecord.InspectDate, 0)
  562. record_time = ts.AddDate(0, 1, 0).Unix()
  563. break
  564. case 2: //2个月
  565. ts := time.Unix(infectiousRecord.InspectDate, 0)
  566. record_time = ts.AddDate(0, 2, 0).Unix()
  567. break
  568. case 3: //3个月
  569. ts := time.Unix(infectiousRecord.InspectDate, 0)
  570. record_time = ts.AddDate(0, 3, 0).Unix()
  571. break
  572. case 4: //6个月
  573. ts := time.Unix(infectiousRecord.InspectDate, 0)
  574. record_time = ts.AddDate(0, 6, 0).Unix()
  575. break
  576. case 5: //12个月
  577. ts := time.Unix(infectiousRecord.InspectDate, 0)
  578. record_time = ts.AddDate(0, 12, 0).Unix()
  579. break
  580. }
  581. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  582. if errs != nil {
  583. utils.ErrorLog("更新日期出错:%v", errs)
  584. }
  585. }
  586. c.ServeSuccessJSON(map[string]interface{}{
  587. "msg": "ok",
  588. })
  589. return
  590. }
  591. func (c *PatientApiController) EditLapseto() {
  592. id, _ := c.GetInt64("id", 0)
  593. if id <= 0 {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  595. return
  596. }
  597. adminUserInfo := c.GetAdminUserInfo()
  598. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  599. if patient.ID == 0 {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  601. return
  602. }
  603. patientBody := make(map[string]interface{}, 0)
  604. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  605. if err != nil {
  606. utils.ErrorLog(err.Error())
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  608. return
  609. }
  610. var lapseto models.PatientLapseto
  611. lapseto.PatientId = patient.ID
  612. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  613. utils.ErrorLog("lapseto_type")
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  615. return
  616. }
  617. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  618. if lapsetoType <= 0 || lapsetoType > 3 {
  619. utils.ErrorLog("lapsetoType <= 0 || lapsetoType > 3")
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  621. return
  622. }
  623. lapseto.LapsetoType = lapsetoType
  624. timeLayout := "2006-01-02 15:04:05"
  625. loc, _ := time.LoadLocation("Local")
  626. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  627. utils.ErrorLog("lapseto_time")
  628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  629. return
  630. }
  631. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  632. if len(lapsetoTime) == 0 {
  633. utils.ErrorLog("len(lapsetoTime) == 0")
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  635. return
  636. }
  637. out_reason, _ := patientBody["out_reason"].(string)
  638. //if len(out_reason) == 0 {
  639. // utils.ErrorLog("len(out_reason) == 0")
  640. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  641. // return
  642. //}
  643. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  644. if err != nil {
  645. utils.ErrorLog("lapsetoTimeUnix")
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  647. return
  648. }
  649. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  650. lapseto.UpdatedTime = time.Now().Unix()
  651. lapseto.CreatedTime = time.Now().Unix()
  652. lapseto.Status = 1
  653. patient.Lapseto = lapseto.LapsetoType
  654. patient.OutReason = out_reason
  655. patient.DeathTime = lapsetoTimeUnix.Unix()
  656. //if patient.Lapseto == 1 {
  657. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  658. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  659. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  660. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  661. // return
  662. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  663. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  664. // return
  665. // }
  666. //}
  667. err = service.EditPatientLapseto(&patient, &lapseto)
  668. //if lapseto.LapsetoType == 3 || lapseto.LapsetoType == 2 {
  669. // timeStr := time.Now().Format("2006-01-02")
  670. // timeLayout := "2006-01-02 15:04:05"
  671. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  672. // timenow := timeStringToTime.Unix()
  673. // service.UpdateScheduleByDeathTime(id, timenow)
  674. // service.UpdateScheduleItemByPatientId(id)
  675. //}
  676. if err != nil {
  677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  678. return
  679. }
  680. c.ServeSuccessJSON(map[string]interface{}{
  681. "msg": "ok",
  682. })
  683. return
  684. }
  685. func (c *PatientApiController) GetPatient() {
  686. id, _ := c.GetInt64("id", 0)
  687. if id <= 0 {
  688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  689. return
  690. }
  691. adminUserInfo := c.GetAdminUserInfo()
  692. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  693. if patient.ID == 0 {
  694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  695. return
  696. }
  697. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  698. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  699. diseases := service.GetPatientDiseases(patient.ID)
  700. contagions := service.GetPatientContagions(patient.ID)
  701. c.ServeSuccessJSON(map[string]interface{}{
  702. "patient": patient,
  703. "diseases": diseases,
  704. "contagions": contagions,
  705. "infections": infections,
  706. })
  707. return
  708. }
  709. func (c *PatientApiController) CreateDialysisSolution() {
  710. id, _ := c.GetInt64("patient", 0)
  711. if id <= 0 {
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  713. return
  714. }
  715. adminUserInfo := c.GetAdminUserInfo()
  716. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  717. if patient.ID == 0 {
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  719. return
  720. }
  721. var solution models.DialysisSolution
  722. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  723. if code > 0 {
  724. c.ServeFailJSONWithSGJErrorCode(code)
  725. return
  726. }
  727. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  728. //if thisSolution.ID > 0 {
  729. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  730. // return
  731. //}
  732. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  733. solution.Doctor = adminUserInfo.AdminUser.Id
  734. solution.Status = 1
  735. solution.PatientId = id
  736. solution.CreatedTime = time.Now().Unix()
  737. solution.UserOrgId = adminUserInfo.CurrentOrgId
  738. solution.UpdatedTime = time.Now().Unix()
  739. solution.SubName = ""
  740. solution.ParentId = 0
  741. solution.SolutionStatus = 1
  742. //records, _ := service.GetAllSchedules()
  743. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  744. for _, sch := range schs {
  745. var DialysisMachineName string
  746. if len(solution.DialysisDialyszers) > 0 {
  747. DialysisMachineName = solution.DialysisDialyszers
  748. }
  749. if len(solution.DialyzerPerfusionApparatus) > 0 {
  750. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  751. }
  752. if len(solution.DialysisIrrigation) > 0 {
  753. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  754. }
  755. sch.DialysisMachineName = DialysisMachineName
  756. service.UpdateSch(sch)
  757. }
  758. err := service.CreatePatientDialysisSolution(&solution)
  759. //获取最新1条
  760. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.CurrentOrgId)
  761. //更新状态
  762. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  763. if err != nil {
  764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  765. return
  766. }
  767. c.ServeSuccessJSON(map[string]interface{}{
  768. "msg": "ok",
  769. "solution": solution,
  770. })
  771. return
  772. }
  773. func (c *PatientApiController) UpdateDialysisSolution() {
  774. patient, _ := c.GetInt64("patient", 0)
  775. id, _ := c.GetInt64("id", 0)
  776. if id <= 0 || patient <= 0 {
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  778. return
  779. }
  780. adminUserInfo := c.GetAdminUserInfo()
  781. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  782. if solution.ID == 0 || solution.PatientId != patient {
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  784. return
  785. }
  786. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  787. if code > 0 {
  788. c.ServeFailJSONWithSGJErrorCode(code)
  789. return
  790. }
  791. solution.UpdatedTime = time.Now().Unix()
  792. err := service.UpdatePatientDialysisSolution(&solution)
  793. nowTimeUinx := time.Now()
  794. today := nowTimeUinx.Format("2006-01-02")
  795. timeLayout := "2006-01-02"
  796. loc, _ := time.LoadLocation("Local")
  797. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  798. if adminUserInfo.CurrentOrgId == 9538 {
  799. prescription := models.DialysisPrescription{
  800. Dialyzer: solution.Dialyzer,
  801. Anticoagulant: solution.Anticoagulant,
  802. AnticoagulantShouji: solution.AnticoagulantShouji,
  803. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  804. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  805. ModeId: solution.ModeId,
  806. DialysisDurationHour: solution.DialysisDurationHour,
  807. Kalium: solution.Kalium,
  808. Sodium: solution.Sodium,
  809. Calcium: solution.Calcium,
  810. TargetUltrafiltration: solution.TargetUltrafiltration,
  811. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  812. BloodAccess: solution.BloodAccess,
  813. DialysateFlow: solution.DialysateFlow,
  814. DialysateTemperature: solution.DialysateTemperature,
  815. DialysisIrrigation: solution.DialysisIrrigation,
  816. DialysisDialyszers: solution.DialysisDialyszers,
  817. PlasmaSeparator: solution.PlasmaSeparator,
  818. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  819. OxygenUptake: solution.OxygenUptake,
  820. OxygenFlow: solution.OxygenFlow,
  821. OxygenTime: solution.OxygenTime,
  822. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  823. Amylaceum: solution.Amylaceum,
  824. DialysisStrainer: solution.DialysisStrainer,
  825. }
  826. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  827. }
  828. schs, _ := service.GetAllSchedulesByPatientInfo(adminUserInfo.CurrentOrgId, solution.PatientId, solution.ModeId)
  829. for _, sch := range schs {
  830. var DialysisMachineName string
  831. if len(solution.DialysisDialyszers) > 0 {
  832. DialysisMachineName = solution.DialysisDialyszers
  833. }
  834. if len(solution.DialyzerPerfusionApparatus) > 0 {
  835. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  836. }
  837. if len(solution.DialysisIrrigation) > 0 {
  838. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  839. }
  840. sch.DialysisMachineName = DialysisMachineName
  841. service.UpdateSch(sch)
  842. }
  843. if err != nil {
  844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  845. return
  846. }
  847. c.ServeSuccessJSON(map[string]interface{}{
  848. "msg": "ok",
  849. "solution": solution,
  850. })
  851. return
  852. }
  853. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  854. patient, _ := c.GetInt64("patient", 0)
  855. id, _ := c.GetInt64("id", 0)
  856. if id <= 0 || patient <= 0 {
  857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. return
  859. }
  860. adminUserInfo := c.GetAdminUserInfo()
  861. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  862. if solution.ID == 0 || solution.PatientId != patient {
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  864. return
  865. }
  866. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  867. if code > 0 {
  868. c.ServeFailJSONWithSGJErrorCode(code)
  869. return
  870. }
  871. solution.UpdatedTime = time.Now().Unix()
  872. solution.AffirmState = 1
  873. err := service.UpdatePatientDialysisSolution(&solution)
  874. if err != nil {
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  876. return
  877. }
  878. c.ServeSuccessJSON(map[string]interface{}{
  879. "msg": "ok",
  880. "solution": solution,
  881. })
  882. return
  883. }
  884. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  885. id, _ := c.GetInt64("id", 0)
  886. page, _ := c.GetInt64("page", 0)
  887. limit, _ := c.GetInt64("limit", 0)
  888. if id <= 0 {
  889. c.ServeSuccessJSON(map[string]interface{}{
  890. "solutions": nil,
  891. })
  892. return
  893. }
  894. if page <= 0 {
  895. page = 1
  896. }
  897. if limit <= 0 {
  898. limit = 10
  899. }
  900. adminUserInfo := c.GetAdminUserInfo()
  901. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  902. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  903. c.ServeSuccessJSON(map[string]interface{}{
  904. "solutions": solutions,
  905. "total": total,
  906. "stockType": stockType,
  907. })
  908. return
  909. }
  910. func (c *PatientApiController) DeleteDialysisSolution() {
  911. id, _ := c.GetInt64("id", 0)
  912. if id <= 0 {
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  914. return
  915. }
  916. adminUserInfo := c.GetAdminUserInfo()
  917. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  918. if solution.ID == 0 {
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  920. return
  921. }
  922. if solution.UseState == 1 {
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  924. return
  925. }
  926. solution.UpdatedTime = time.Now().Unix()
  927. solution.Status = 0
  928. err := service.DeleteSolution(&solution)
  929. if err != nil {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  931. return
  932. }
  933. c.ServeSuccessJSON(map[string]interface{}{
  934. "msg": "ok",
  935. })
  936. return
  937. }
  938. // GetDryWeights 取患者干体重调整铺
  939. func (c *PatientApiController) GetDryWeights() {
  940. page, _ := c.GetInt64("page", 1)
  941. limit, _ := c.GetInt64("limit", 10)
  942. id, _ := c.GetInt64("id", 0)
  943. if id <= 0 {
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. adminUserInfo := c.GetAdminUserInfo()
  948. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  949. c.ServeSuccessJSON(map[string]interface{}{
  950. "weights": weights,
  951. "total": total,
  952. })
  953. return
  954. }
  955. func (c *PatientApiController) CreateDryWeights() {
  956. patient, _ := c.GetInt64("id", 0)
  957. if patient <= 0 {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. adminUserInfo := c.GetAdminUserInfo()
  962. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  963. if patientInfo.ID == 0 {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  965. return
  966. }
  967. var theWeight models.DryWeightAdjust
  968. dataBody := make(map[string]interface{}, 0)
  969. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  970. if err != nil {
  971. utils.ErrorLog(err.Error())
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  980. theWeight.Weight = weight
  981. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  982. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. // return
  984. // }
  985. // doctor := int64(dataBody["doctor"].(float64))
  986. // theWeight.Doctor = doctor
  987. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  988. remark, _ := dataBody["remark"].(string)
  989. theWeight.Remark = remark
  990. }
  991. theWeight.CreatedTime = time.Now().Unix()
  992. theWeight.UpdatedTime = time.Now().Unix()
  993. theWeight.Status = 1
  994. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  995. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  996. theWeight.PatientId = patient
  997. theWeight.Doctor = adminUserInfo.AdminUser.Id
  998. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  999. if old.ID > 0 {
  1000. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  1001. }
  1002. err = service.CreateDryWeightAdjust(&theWeight)
  1003. if err != nil {
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  1005. return
  1006. }
  1007. c.ServeSuccessJSON(map[string]interface{}{
  1008. "msg": "ok",
  1009. "weight": theWeight,
  1010. })
  1011. return
  1012. }
  1013. func (c *PatientApiController) CreateGroupAdvice() {
  1014. var err error
  1015. defer func() {
  1016. if rec := recover(); rec != nil {
  1017. err = fmt.Errorf("程序异常:%v", rec)
  1018. }
  1019. if err != nil {
  1020. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1021. }
  1022. }()
  1023. patient, _ := c.GetInt64("id", 0)
  1024. groupNo, _ := c.GetInt64("groupno", 0)
  1025. if patient <= 0 {
  1026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. adminUserInfo := c.GetAdminUserInfo()
  1030. var patientInfo models.Patients
  1031. patientInfo, err = service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1032. if patientInfo.ID == 0 {
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1034. return
  1035. }
  1036. dataBody := make(map[string]interface{}, 0)
  1037. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1038. if err != nil {
  1039. utils.ErrorLog(err.Error())
  1040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1041. return
  1042. }
  1043. utils.ErrorLog("%v", dataBody)
  1044. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1045. if appRole.UserType == 3 {
  1046. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1047. if getPermissionErr != nil {
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1049. return
  1050. } else if headNursePermission == nil {
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1052. return
  1053. }
  1054. }
  1055. timeLayout := "2006-01-02"
  1056. loc, _ := time.LoadLocation("Local")
  1057. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1058. utils.ErrorLog("advice_type")
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. adviceType := int64(dataBody["advice_type"].(float64))
  1063. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  1064. utils.ErrorLog("advice_type != 1&&2")
  1065. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1066. return
  1067. }
  1068. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1069. utils.ErrorLog("advice_date")
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1071. return
  1072. }
  1073. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1074. utils.ErrorLog("start_time")
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1076. return
  1077. }
  1078. startTime2, _ := dataBody["start_time"].(string)
  1079. time_arr := strings.Split(startTime2, " ")
  1080. if len(time_arr) > 0 {
  1081. startTime2 = time_arr[0]
  1082. }
  1083. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1084. utils.ErrorLog("advice_date")
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1086. return
  1087. }
  1088. adviceDate := startTime2
  1089. if len(adviceDate) == 0 {
  1090. utils.ErrorLog("len(adviceDate) == 0")
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1092. return
  1093. }
  1094. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1095. if err != nil {
  1096. utils.ErrorLog(err.Error())
  1097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1098. return
  1099. }
  1100. AdviceDate := theTime.Unix()
  1101. RecordDate := theTime.Unix()
  1102. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1103. utils.ErrorLog("start_time")
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1105. return
  1106. }
  1107. startTime, _ := dataBody["start_time"].(string)
  1108. if len(startTime) == 0 {
  1109. utils.ErrorLog("len(start_time) == 0")
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1114. if err != nil {
  1115. utils.ErrorLog(err.Error())
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. StartTime := theTime.Unix()
  1120. Remark := ""
  1121. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1122. remark, _ := dataBody["remark"].(string)
  1123. Remark = remark
  1124. }
  1125. var advices []*models.GroupAdvice
  1126. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1127. utils.ErrorLog("adviceNames")
  1128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1129. return
  1130. }
  1131. adviceNames := dataBody["adviceNames"].([]interface{})
  1132. for _, adviceNameMap := range adviceNames {
  1133. adviceNameM := adviceNameMap.(map[string]interface{})
  1134. var advice models.GroupAdvice
  1135. advice.Remark = Remark
  1136. advice.AdviceType = adviceType
  1137. advice.StartTime = StartTime
  1138. advice.AdviceDate = AdviceDate
  1139. advice.RecordDate = RecordDate
  1140. advice.Status = 1
  1141. advice.CreatedTime = time.Now().Unix()
  1142. advice.UpdatedTime = time.Now().Unix()
  1143. advice.StopState = 2
  1144. advice.ExecutionState = 2
  1145. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1146. advice.PatientId = patientInfo.ID
  1147. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1148. advice.IsSettle = 2
  1149. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1150. utils.ErrorLog("advice_name")
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1152. return
  1153. }
  1154. adviceName, _ := adviceNameM["advice_name"].(string)
  1155. if len(adviceName) == 0 {
  1156. utils.ErrorLog("len(advice_name) == 0")
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. advice.AdviceName = adviceName
  1161. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1162. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1163. advice.DrugSpec = drugSpec
  1164. }
  1165. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1166. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1167. advice.AdviceDesc = adviceDesc
  1168. }
  1169. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1170. template_id, _ := adviceNameM["template_id"].(string)
  1171. advice.TemplateId = template_id
  1172. }
  1173. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1174. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1175. advice.DrugSpecUnit = drugSpecUnit
  1176. }
  1177. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1178. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1179. advice.SingleDose = singleDose
  1180. }
  1181. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  1182. singleDose := adviceNameM["single_dose"].(float64)
  1183. advice.SingleDose = singleDose
  1184. }
  1185. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1186. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1187. advice.SingleDoseUnit = singleDoseUnit
  1188. }
  1189. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  1190. tmp := adviceNameM["single_dose_unit"].(float64)
  1191. singleDoseUnit := service.TypeConversion(tmp)
  1192. advice.SingleDoseUnit = singleDoseUnit
  1193. }
  1194. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1195. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1196. advice.PrescribingNumber = prescribingNumber
  1197. }
  1198. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  1199. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  1200. advice.PrescribingNumber = prescribingNumber
  1201. }
  1202. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1203. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1204. advice.PrescribingNumberUnit = prescribingNumberUnit
  1205. }
  1206. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1207. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1208. advice.DeliveryWay = deliveryWay
  1209. }
  1210. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1211. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1212. advice.ExecutionFrequency = executionFrequency
  1213. }
  1214. if adviceNameM["way"] != nil && reflect.TypeOf(adviceNameM["way"]).String() == "string" {
  1215. way, _ := strconv.ParseFloat(adviceNameM["way"].(string), 64)
  1216. advice.Way = int64(way)
  1217. }
  1218. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1219. way := int64(adviceNameM["way"].(float64))
  1220. advice.Way = way
  1221. }
  1222. if adviceNameM["drug_id"] != nil && reflect.TypeOf(adviceNameM["drug_id"]).String() == "string" {
  1223. drug_id, _ := strconv.ParseFloat(adviceNameM["drug_id"].(string), 64)
  1224. advice.DrugId = int64(drug_id)
  1225. }
  1226. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1227. drug_id := int64(adviceNameM["drug_id"].(float64))
  1228. advice.DrugId = drug_id
  1229. }
  1230. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1231. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1232. advice.DrugNameId = drug_name_id
  1233. }
  1234. remark, _ := adviceNameM["remark"].(string)
  1235. advice.Remark = remark
  1236. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1237. if advice.PrescribingNumber == 0 {
  1238. advice.PrescribingNumber = 1
  1239. }
  1240. //查询该患者今日有没有双人核对
  1241. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, advice.AdviceDate)
  1242. fmt.Println("chek", check)
  1243. if check.ID > 0 {
  1244. advice.Checker = check.Modifier
  1245. advice.CheckState = 1
  1246. advice.CheckTime = time.Now().Unix()
  1247. }
  1248. }
  1249. if adviceType == 1 {
  1250. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1251. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1252. advice.FrequencyType = frequency_type
  1253. }
  1254. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1255. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1256. advice.DayCount = day_count
  1257. }
  1258. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1259. week_day, _ := adviceNameM["week_days"].(string)
  1260. advice.WeekDay = week_day
  1261. }
  1262. if adviceNameM["push_start_time"] != nil && reflect.TypeOf(adviceNameM["push_start_time"]).String() == "string" {
  1263. push_start_time, _ := adviceNameM["push_start_time"].(string)
  1264. var startTime int64
  1265. if len(push_start_time) > 0 {
  1266. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  1267. startTime = theTime.Unix()
  1268. }
  1269. advice.PushStartTime = startTime
  1270. }
  1271. }
  1272. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1273. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1274. advice.ExecutionFrequency = executionFrequency
  1275. }
  1276. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1277. children := adviceNameM["children"].([]interface{})
  1278. if len(children) > 0 {
  1279. for _, childrenMap := range children {
  1280. childMap := childrenMap.(map[string]interface{})
  1281. var child models.GroupAdvice
  1282. child.Remark = Remark
  1283. child.AdviceType = adviceType
  1284. child.StartTime = StartTime
  1285. child.AdviceDate = AdviceDate
  1286. child.RecordDate = RecordDate
  1287. child.Status = 1
  1288. child.CreatedTime = time.Now().Unix()
  1289. child.UpdatedTime = time.Now().Unix()
  1290. child.StopState = 2
  1291. child.ExecutionState = 2
  1292. child.UserOrgId = adminUserInfo.CurrentOrgId
  1293. child.PatientId = patientInfo.ID
  1294. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1295. child.IsSettle = 2
  1296. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1297. utils.ErrorLog("child advice_name")
  1298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1299. return
  1300. }
  1301. childAdviceName, _ := childMap["advice_name"].(string)
  1302. if len(childAdviceName) == 0 {
  1303. utils.ErrorLog("len(child advice_name) == 0")
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1305. return
  1306. }
  1307. child.AdviceName = childAdviceName
  1308. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1309. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1310. child.AdviceDesc = childAdviceDesc
  1311. }
  1312. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1313. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1314. child.DrugSpec = childDrugSpec
  1315. }
  1316. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1317. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1318. child.DrugSpecUnit = childDrugSpecUnit
  1319. }
  1320. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1321. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1322. child.SingleDose = childSingleDose
  1323. }
  1324. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1325. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1326. child.SingleDoseUnit = childSingleDoseUnit
  1327. }
  1328. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1329. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1330. child.PrescribingNumber = childPrescribingNumber
  1331. }
  1332. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1333. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1334. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1335. }
  1336. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1337. drug_id := int64(childMap["drug_id"].(float64))
  1338. child.DrugId = drug_id
  1339. }
  1340. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1341. way := int64(childMap["way"].(float64))
  1342. child.Way = way
  1343. }
  1344. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1345. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1346. child.DrugNameId = drug_name_id
  1347. }
  1348. child.DeliveryWay = advice.DeliveryWay
  1349. child.ExecutionFrequency = advice.ExecutionFrequency
  1350. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
  1351. if child.PrescribingNumber == 0 {
  1352. child.PrescribingNumber = 1
  1353. }
  1354. //查询该患者今日有没有双人核对
  1355. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
  1356. if check.ID > 0 {
  1357. child.Checker = check.Modifier
  1358. child.CheckState = 1
  1359. child.CheckTime = time.Now().Unix()
  1360. }
  1361. }
  1362. advice.Children = append(advice.Children, &child)
  1363. }
  1364. }
  1365. }
  1366. advices = append(advices, &advice)
  1367. }
  1368. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1369. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  1370. redis := service.RedisClient()
  1371. defer redis.Close()
  1372. redis.Set(key, "", time.Second)
  1373. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  1374. redis.Set(keyOne, "", time.Second)
  1375. if err != nil {
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1377. return
  1378. }
  1379. c.ServeSuccessJSON(map[string]interface{}{
  1380. "msg": "ok",
  1381. "advices": list,
  1382. })
  1383. return
  1384. }
  1385. func (c *PatientApiController) CreateDoctorAdvice() {
  1386. patient, _ := c.GetInt64("id", 0)
  1387. if patient <= 0 {
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. adminUserInfo := c.GetAdminUserInfo()
  1392. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1393. if patientInfo.ID == 0 {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1395. return
  1396. }
  1397. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1398. if appRole.UserType == 3 {
  1399. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1400. if getPermissionErr != nil {
  1401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1402. return
  1403. } else if headNursePermission == nil {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1405. return
  1406. }
  1407. }
  1408. var advice models.DoctorAdvice
  1409. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1410. if code > 0 {
  1411. c.ServeFailJSONWithSGJErrorCode(code)
  1412. return
  1413. }
  1414. if advice.ParentId > 0 {
  1415. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1416. if old.ID == 0 || old.PatientId != patient {
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1418. return
  1419. }
  1420. if old.StopState == 1 || old.ExecutionState == 1 {
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1422. return
  1423. }
  1424. if old.ParentId > 0 {
  1425. advice.ParentId = old.ParentId
  1426. }
  1427. advice.StartTime = old.StartTime
  1428. advice.AdviceDoctor = old.AdviceDoctor
  1429. advice.DeliveryWay = old.DeliveryWay
  1430. advice.ExecutionFrequency = old.ExecutionFrequency
  1431. advice.GroupNo = old.GroupNo
  1432. }
  1433. advice.Status = 1
  1434. advice.CreatedTime = time.Now().Unix()
  1435. advice.UpdatedTime = time.Now().Unix()
  1436. advice.StopState = 2
  1437. advice.ExecutionState = 2
  1438. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1439. advice.PatientId = patient
  1440. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1441. err := service.CreateDoctorAdvice(&advice)
  1442. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1443. redis := service.RedisClient()
  1444. defer redis.Close()
  1445. redis.Set(key, "", time.Second)
  1446. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1447. redis.Set(keyOne, "", time.Second)
  1448. if err != nil {
  1449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1450. return
  1451. }
  1452. c.ServeSuccessJSON(map[string]interface{}{
  1453. "msg": "ok",
  1454. "advice": advice,
  1455. })
  1456. return
  1457. }
  1458. func (c *PatientApiController) ExecGroupAdvice() {
  1459. groupNo, _ := c.GetInt64("groupno", 0)
  1460. executionTime := c.GetString("execution_time")
  1461. if groupNo <= 0 {
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1463. return
  1464. }
  1465. if len(executionTime) <= 0 {
  1466. utils.ErrorLog("execution_time")
  1467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1468. return
  1469. }
  1470. adminUserInfo := c.GetAdminUserInfo()
  1471. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1472. if advice.ID == 0 {
  1473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1474. return
  1475. }
  1476. if advice.ExecutionState == 1 {
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1478. return
  1479. }
  1480. executionStaff := adminUserInfo.AdminUser.Id
  1481. // checker := adminUserInfo.AdminUser.Id
  1482. timeLayout := "2006-01-02 15:04:05"
  1483. loc, _ := time.LoadLocation("Local")
  1484. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1485. if err != nil {
  1486. utils.ErrorLog(err.Error())
  1487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1488. return
  1489. }
  1490. if advice.StartTime > theTime.Unix() {
  1491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1492. return
  1493. }
  1494. exceAdvice := models.DoctorAdvice{
  1495. ExecutionStaff: executionStaff,
  1496. ExecutionTime: theTime.Unix(),
  1497. UpdatedTime: time.Now().Unix(),
  1498. }
  1499. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1500. if err != nil {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1502. return
  1503. }
  1504. //查询自动扣减是否开启
  1505. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1506. //查询已经执行的医嘱
  1507. advicelist, _ := service.GetExceDoctorAdviceGroupNo(groupNo, adminUserInfo.CurrentOrgId)
  1508. if drugStockConfig.IsOpen == 1 {
  1509. for _, item := range advicelist {
  1510. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1511. //查询这个患者这个患者这个药已经出库的所有数量
  1512. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1513. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1514. var total_count int64
  1515. var drug_count int64
  1516. for _, it := range advicelist {
  1517. if it.PrescribingNumberUnit == medical.MaxUnit {
  1518. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1519. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1520. total_count += prenumber * medical.MinNumber
  1521. }
  1522. if it.PrescribingNumberUnit == medical.MinUnit {
  1523. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1524. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1525. total_count += prenumber
  1526. }
  1527. }
  1528. for _, its := range drugoutlist {
  1529. if its.CountUnit == medical.MaxUnit {
  1530. drug_count += its.Count * medical.MinNumber
  1531. }
  1532. if its.CountUnit == medical.MinUnit {
  1533. drug_count += its.Count
  1534. }
  1535. }
  1536. if total_count == drug_count {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "msg": "1",
  1539. "advice": advice,
  1540. })
  1541. return
  1542. }
  1543. var total int64
  1544. var prescribing_number_total int64
  1545. //查询默认出库仓库
  1546. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1547. //查询该药品在默认仓库是否有库存
  1548. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1549. //判断单位是否相等
  1550. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1551. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1552. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1553. //转化为最小单位
  1554. total = list.Count*medical.MinNumber + list.StockMinNumber
  1555. prescribing_number_total = count * medical.MinNumber
  1556. }
  1557. if medical.MinUnit == advice.PrescribingNumberUnit {
  1558. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1559. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1560. total = list.Count*medical.MinNumber + list.StockMinNumber
  1561. prescribing_number_total = count
  1562. }
  1563. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1564. c.ServeSuccessJSON(map[string]interface{}{
  1565. "msg": "3",
  1566. "advice": advice,
  1567. })
  1568. return
  1569. }
  1570. if prescribing_number_total > total {
  1571. c.ServeSuccessJSON(map[string]interface{}{
  1572. "msg": "2",
  1573. "advice": advice,
  1574. })
  1575. return
  1576. }
  1577. if prescribing_number_total <= total {
  1578. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1579. if medical.IsUse == 2 {
  1580. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1581. service.DrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
  1582. }
  1583. if pharmacyConfig.IsOpen != 1 {
  1584. service.DrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
  1585. }
  1586. //查询默认仓库
  1587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1588. //查询默认仓库剩余多少库存
  1589. var sum_count int64
  1590. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1591. for _, its := range stockInfo {
  1592. if its.MaxUnit == medical.MaxUnit {
  1593. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1594. }
  1595. sum_count += its.StockMaxNumber + its.StockMinNumber
  1596. }
  1597. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1598. break
  1599. c.ServeSuccessJSON(map[string]interface{}{
  1600. "msg": "1",
  1601. "advice": advice,
  1602. })
  1603. return
  1604. }
  1605. if medical.IsUse == 1 {
  1606. c.ServeSuccessJSON(map[string]interface{}{
  1607. "msg": "1",
  1608. "advice": advice,
  1609. })
  1610. return
  1611. }
  1612. }
  1613. }
  1614. }
  1615. advice.ExecutionStaff = executionStaff
  1616. advice.ExecutionTime = theTime.Unix()
  1617. c.ServeSuccessJSON(map[string]interface{}{
  1618. "msg": "ok",
  1619. "advice": advice,
  1620. })
  1621. return
  1622. }
  1623. func (c *PatientApiController) ExecDoctorAdvice() {
  1624. origin, _ := c.GetInt64("origin", 0)
  1625. patient, _ := c.GetInt64("patient", 0)
  1626. id, _ := c.GetInt64("id", 0)
  1627. executionTime := c.GetString("execution_time")
  1628. if origin != 2 {
  1629. if id <= 0 || patient <= 0 {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1631. return
  1632. }
  1633. if len(executionTime) <= 0 {
  1634. utils.ErrorLog("execution_time")
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1636. return
  1637. }
  1638. adminUserInfo := c.GetAdminUserInfo()
  1639. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1640. if advice.ID == 0 || advice.PatientId != patient {
  1641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1642. return
  1643. }
  1644. //医嘱已执行
  1645. if advice.ExecutionState == 1 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1647. return
  1648. }
  1649. executionStaff := adminUserInfo.AdminUser.Id
  1650. timeLayout := "2006-01-02 15:04:05"
  1651. loc, _ := time.LoadLocation("Local")
  1652. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1653. if err != nil {
  1654. utils.ErrorLog(err.Error())
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. if advice.StartTime > theTime.Unix() {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1660. return
  1661. }
  1662. exceAdvice := models.DoctorAdvice{
  1663. ExecutionStaff: executionStaff,
  1664. ExecutionTime: theTime.Unix(),
  1665. UpdatedTime: time.Now().Unix(),
  1666. }
  1667. if advice.ParentId > 0 {
  1668. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1669. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1670. redis := service.RedisClient()
  1671. //清空key 值
  1672. redis.Set(key, "", time.Second)
  1673. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1674. redis.Set(keyTwo, "", time.Second)
  1675. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1676. redis.Set(keyThree, "", time.Second)
  1677. theTimes := theTime.Format("2006-01-02")
  1678. fmt.Println("theTIME", theTime)
  1679. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1680. redis.Set(keyFour, "", time.Second)
  1681. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1682. redis.Set(keyFive, "", time.Second)
  1683. defer redis.Close()
  1684. } else {
  1685. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1686. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1687. redis := service.RedisClient()
  1688. //清空key 值
  1689. redis.Set(key, "", time.Second)
  1690. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1691. redis.Set(keyTwo, "", time.Second)
  1692. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1693. redis.Set(keyThree, "", time.Second)
  1694. theTimes := theTime.Format("2006-01-02")
  1695. fmt.Println("theTIME", theTime)
  1696. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1697. redis.Set(keyFour, "", time.Second)
  1698. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1699. redis.Set(keyFive, "", time.Second)
  1700. defer redis.Close()
  1701. }
  1702. if err != nil {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1704. return
  1705. }
  1706. advice.ExecutionStaff = executionStaff
  1707. advice.ExecutionTime = theTime.Unix()
  1708. //处理出库相关逻辑
  1709. //1.判断是否启用药品管理和自备药出库功能
  1710. //药品管理信息
  1711. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1712. //自备药信息
  1713. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  1714. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  1715. if drugStockConfig.IsOpen == 1 {
  1716. var total int64
  1717. var prescribing_number_total int64
  1718. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1719. for _, item := range advices {
  1720. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  1721. //查询该药品是否有库存
  1722. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  1723. //查询改药品信息
  1724. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1725. //判断单位是否相等
  1726. if medical.MaxUnit == item.PrescribingNumberUnit {
  1727. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1728. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1729. //转化为最小单位
  1730. total = list.Count*medical.MinNumber + list.StockMinNumber
  1731. prescribing_number_total = count * medical.MinNumber
  1732. }
  1733. if medical.MinUnit == item.PrescribingNumberUnit {
  1734. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1735. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1736. total = list.Count*medical.MinNumber + list.StockMinNumber
  1737. prescribing_number_total = count
  1738. }
  1739. if medical.IsUse != 1 {
  1740. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1741. c.ServeSuccessJSON(map[string]interface{}{
  1742. "msg": "3",
  1743. "advice": advice,
  1744. })
  1745. return
  1746. }
  1747. if prescribing_number_total > total {
  1748. c.ServeSuccessJSON(map[string]interface{}{
  1749. "msg": "2",
  1750. "advice": advice,
  1751. })
  1752. return
  1753. }
  1754. }
  1755. if medical.IsUse == 1 {
  1756. c.ServeSuccessJSON(map[string]interface{}{
  1757. "msg": "1",
  1758. "advice": advice,
  1759. })
  1760. return
  1761. }
  1762. if prescribing_number_total <= total {
  1763. //查询是否门诊处方和临时医嘱同步到透析医嘱的开关是否开启
  1764. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  1765. if adviceSetting.IsAdviceOpen == 1 {
  1766. //查询是否出库按钮开启
  1767. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  1768. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1769. if prescriptionConfig.IsOpen == 1 {
  1770. if medical.IsUse == 2 {
  1771. //是通过药房发药
  1772. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1773. //执行出库
  1774. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1775. }
  1776. //不通过药房发药
  1777. if pharmacyConfig.IsOpen != 1 {
  1778. //执行出库
  1779. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1780. }
  1781. //查询默认仓库
  1782. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1783. //查询默认仓库剩余多少库存
  1784. var sum_count int64
  1785. //更新字典里面的库存
  1786. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1787. for _, its := range stockInfo {
  1788. if its.MaxUnit == medical.MaxUnit {
  1789. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1790. }
  1791. sum_count += its.StockMaxNumber + its.StockMinNumber
  1792. }
  1793. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1794. break
  1795. c.ServeSuccessJSON(map[string]interface{}{
  1796. "msg": "1",
  1797. "advice": advice,
  1798. })
  1799. return
  1800. }
  1801. if medical.IsUse == 1 {
  1802. c.ServeSuccessJSON(map[string]interface{}{
  1803. "msg": "1",
  1804. "advice": advice,
  1805. })
  1806. return
  1807. }
  1808. } else {
  1809. if medical.IsUse == 1 {
  1810. c.ServeSuccessJSON(map[string]interface{}{
  1811. "msg": "1",
  1812. "advice": advice,
  1813. })
  1814. return
  1815. }
  1816. }
  1817. } else {
  1818. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  1819. if medical.IsUse == 2 {
  1820. //是通过药房发药
  1821. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1822. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1823. }
  1824. //不通过药房发药
  1825. if pharmacyConfig.IsOpen != 1 {
  1826. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1827. }
  1828. //更新字典里面的库存
  1829. var sum_count int64
  1830. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1831. for _, its := range stockInfo {
  1832. if its.MaxUnit == medical.MaxUnit {
  1833. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1834. }
  1835. sum_count += its.StockMaxNumber + its.StockMinNumber
  1836. }
  1837. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1838. break
  1839. c.ServeSuccessJSON(map[string]interface{}{
  1840. "msg": "1",
  1841. "advice": advice,
  1842. })
  1843. return
  1844. }
  1845. if medical.IsUse == 1 {
  1846. c.ServeSuccessJSON(map[string]interface{}{
  1847. "msg": "1",
  1848. "advice": advice,
  1849. })
  1850. return
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1857. for _, item := range advices {
  1858. if item.Way == 2 {
  1859. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1860. if item.ExecutionState == 1 {
  1861. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1862. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. timeStr := time.Now().Format("2006-01-02")
  1864. timeArr := strings.Split(timeStr, "-")
  1865. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1866. total = total + 1
  1867. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1868. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1869. number = number + total
  1870. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1871. //插入自备药出库单
  1872. outStock := models.XtSelfOutStock{
  1873. DrugName: item.AdviceName,
  1874. DrugNameId: item.DrugId,
  1875. DrugSpec: item.AdviceDesc,
  1876. OutstoreNumber: count,
  1877. AdminUserId: adminUserInfo.AdminUser.Id,
  1878. StorckTime: item.RecordDate,
  1879. UserOrgId: adminUserInfo.CurrentOrgId,
  1880. CreatedTime: time.Now().Unix(),
  1881. Status: 1,
  1882. PatientId: item.PatientId,
  1883. ExitMode: 2,
  1884. MedicId: item.DrugId,
  1885. StockOutNumber: warehousing_out_order,
  1886. }
  1887. service.CreateOutStock(&outStock)
  1888. }
  1889. }
  1890. }
  1891. }
  1892. c.ServeSuccessJSON(map[string]interface{}{
  1893. "msg": "1",
  1894. "advice": advice,
  1895. })
  1896. return
  1897. } else {
  1898. if id <= 0 || patient <= 0 {
  1899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1900. return
  1901. }
  1902. if len(executionTime) <= 0 {
  1903. utils.ErrorLog("execution_time")
  1904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1905. return
  1906. }
  1907. adminUserInfo := c.GetAdminUserInfo()
  1908. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1909. if advice.ID == 0 || advice.PatientId != patient {
  1910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1911. return
  1912. }
  1913. //医嘱已执行
  1914. if advice.ExecutionState == 1 {
  1915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1916. return
  1917. }
  1918. executionStaff := adminUserInfo.AdminUser.Id
  1919. timeLayout := "2006-01-02 15:04:05"
  1920. loc, _ := time.LoadLocation("Local")
  1921. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1922. if err != nil {
  1923. utils.ErrorLog(err.Error())
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. }
  1927. if advice.StartTime > theTime.Unix() {
  1928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1929. return
  1930. }
  1931. exceAdvice := models.HisDoctorAdviceInfo{
  1932. ExecutionStaff: executionStaff,
  1933. ExecutionTime: theTime.Unix(),
  1934. UpdatedTime: time.Now().Unix(),
  1935. }
  1936. if advice.ParentId > 0 {
  1937. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1938. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1943. redis.Set(keyTwo, "", time.Second)
  1944. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1945. redis.Set(keyThree, "", time.Second)
  1946. theTimes := theTime.Format("2006-01-02")
  1947. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1948. redis.Set(keyFour, "", time.Second)
  1949. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1950. redis.Set(keyFive, "", time.Second)
  1951. defer redis.Close()
  1952. } else {
  1953. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1954. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1955. redis := service.RedisClient()
  1956. //清空key 值
  1957. redis.Set(key, "", time.Second)
  1958. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1959. redis.Set(keyTwo, "", time.Second)
  1960. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1961. redis.Set(keyThree, "", time.Second)
  1962. theTimes := theTime.Format("2006-01-02")
  1963. fmt.Println("theTIME", theTime)
  1964. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1965. redis.Set(keyFour, "", time.Second)
  1966. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1967. redis.Set(keyFive, "", time.Second)
  1968. defer redis.Close()
  1969. }
  1970. if err != nil {
  1971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1972. return
  1973. }
  1974. advice.ExecutionStaff = executionStaff
  1975. advice.ExecutionTime = theTime.Unix()
  1976. //处理出库相关逻辑
  1977. //1.判断是否启用药品管理和自备药出库功能
  1978. //药品管理信息
  1979. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1980. if drugStockConfig.IsOpen == 1 {
  1981. //查询已经执行的医嘱
  1982. advices, _ := service.GetHisExecutionDoctorsTwo(adminUserInfo.CurrentOrgId, patient, id)
  1983. for _, item := range advices {
  1984. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1985. //查询这个患者这个患者这个药已经出库的所有数量
  1986. //advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1987. //drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1988. //var total_count int64 // 现在出库的
  1989. //var drug_count int64 // 已经出库的
  1990. //for _, it := range advicelist {
  1991. // if it.PrescribingNumberUnit == medical.MaxUnit {
  1992. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1993. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1994. // total_count += prenumber * medical.MinNumber
  1995. // }
  1996. // if it.PrescribingNumberUnit == medical.MinUnit {
  1997. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1998. // prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1999. // total_count += prenumber
  2000. // }
  2001. //
  2002. //}
  2003. //
  2004. //
  2005. //for _, its := range drugoutlist {
  2006. // if its.CountUnit == medical.MaxUnit {
  2007. // drug_count += its.Count * medical.MinNumber
  2008. // }
  2009. // if its.CountUnit == medical.MinUnit {
  2010. // drug_count += its.Count
  2011. // }
  2012. //}
  2013. //fmt.Println("total_count23232323232323232wode",total_count)
  2014. //fmt.Println("total_count23232323232323232wode",drug_count)
  2015. //if total_count == drug_count {
  2016. // c.ServeSuccessJSON(map[string]interface{}{
  2017. // "msg": "1",
  2018. // "advice": advice,
  2019. // })
  2020. // return
  2021. //}
  2022. var total int64
  2023. var prescribing_number_total int64
  2024. config, _ := service.GetDrugOpenConfigOne(adminUserInfo.CurrentOrgId)
  2025. if config.IsOpen != 1 {
  2026. //查询默认出库仓库
  2027. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2028. //查询该药品在默认仓库是否有库存
  2029. list, _ := service.GetDrugTotalCountTwenty(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  2030. //判断单位是否相等
  2031. if medical.MaxUnit == advice.PrescribingNumberUnit {
  2032. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2033. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2034. //转化为最小单位
  2035. total = list.Count*medical.MinNumber + list.StockMinNumber
  2036. prescribing_number_total = count * medical.MinNumber
  2037. }
  2038. if medical.MinUnit == advice.PrescribingNumberUnit {
  2039. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  2040. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  2041. total = list.Count*medical.MinNumber + list.StockMinNumber
  2042. prescribing_number_total = count
  2043. }
  2044. if medical.IsUse == 1 {
  2045. drugError := models.XtDrugError{
  2046. UserOrgId: item.UserOrgId,
  2047. DrugId: item.DrugId,
  2048. RecordDate: item.AdviceDate,
  2049. PatientId: item.PatientId,
  2050. Remark: "电脑端零用药品",
  2051. Status: 1,
  2052. Ctime: time.Now().Unix(),
  2053. Mtime: 0,
  2054. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2055. Prescribingnumber: item.PrescribingNumber,
  2056. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2057. }
  2058. service.CreateDrugError(drugError)
  2059. c.ServeSuccessJSON(map[string]interface{}{
  2060. "msg": "1",
  2061. "advice": advice,
  2062. })
  2063. return
  2064. }
  2065. if medical.IsUse != 1 {
  2066. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  2067. drugError := models.XtDrugError{
  2068. UserOrgId: item.UserOrgId,
  2069. DrugId: item.DrugId,
  2070. RecordDate: item.AdviceDate,
  2071. PatientId: item.PatientId,
  2072. Remark: "电脑端药品库存不足",
  2073. Status: 1,
  2074. Ctime: time.Now().Unix(),
  2075. Mtime: 0,
  2076. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2077. Prescribingnumber: item.PrescribingNumber,
  2078. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2079. }
  2080. service.CreateDrugError(drugError)
  2081. c.ServeSuccessJSON(map[string]interface{}{
  2082. "msg": "3",
  2083. "advice": advice,
  2084. })
  2085. return
  2086. }
  2087. if prescribing_number_total > total {
  2088. drugError := models.XtDrugError{
  2089. UserOrgId: item.UserOrgId,
  2090. DrugId: item.DrugId,
  2091. RecordDate: item.AdviceDate,
  2092. PatientId: item.PatientId,
  2093. Remark: "电脑端出库数量大于总库存",
  2094. Status: 1,
  2095. Ctime: time.Now().Unix(),
  2096. Mtime: 0,
  2097. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2098. Prescribingnumber: item.PrescribingNumber,
  2099. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2100. }
  2101. service.CreateDrugError(drugError)
  2102. c.ServeSuccessJSON(map[string]interface{}{
  2103. "msg": "2",
  2104. "advice": advice,
  2105. })
  2106. return
  2107. }
  2108. }
  2109. if prescribing_number_total <= total {
  2110. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  2111. if medical.IsUse == 2 {
  2112. if config.IsOpen != 1 {
  2113. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  2114. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2115. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2116. //查询该药品是否有出库记录
  2117. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2118. if len(flowMap) == 0 {
  2119. errs := service.UpdateHisAdviceById(item.ID)
  2120. if errs != nil {
  2121. drugError := models.XtDrugError{
  2122. UserOrgId: item.UserOrgId,
  2123. DrugId: item.DrugId,
  2124. RecordDate: item.AdviceDate,
  2125. PatientId: item.PatientId,
  2126. Remark: "出库记录为空,更新执行人失败",
  2127. Status: 1,
  2128. Ctime: time.Now().Unix(),
  2129. Mtime: 0,
  2130. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2131. Prescribingnumber: item.PrescribingNumber,
  2132. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2133. }
  2134. service.CreateDrugError(drugError)
  2135. }
  2136. c.ServeSuccessJSON(map[string]interface{}{
  2137. "msg": "6",
  2138. "advice": advice,
  2139. })
  2140. return
  2141. }
  2142. }
  2143. }
  2144. //不通过药房发药
  2145. if pharmacyConfig.IsOpen != 1 {
  2146. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  2147. if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
  2148. //查询该药品是否有出库记录
  2149. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  2150. if len(flowMap) == 0 {
  2151. errs := service.UpdateHisAdviceById(item.ID)
  2152. if errs != nil {
  2153. drugError := models.XtDrugError{
  2154. UserOrgId: item.UserOrgId,
  2155. DrugId: item.DrugId,
  2156. RecordDate: item.AdviceDate,
  2157. PatientId: item.PatientId,
  2158. Remark: "出库记录为空,更新执行人失败",
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  2163. Prescribingnumber: item.PrescribingNumber,
  2164. PrescribingNumberUnit: item.PrescribingNumberUnit,
  2165. }
  2166. service.CreateDrugError(drugError)
  2167. }
  2168. c.ServeSuccessJSON(map[string]interface{}{
  2169. "msg": "6",
  2170. "advice": advice,
  2171. })
  2172. return
  2173. }
  2174. }
  2175. }
  2176. //查询默认仓库
  2177. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2178. //查询默认仓库剩余多少库存
  2179. var sum_count int64
  2180. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2181. for _, its := range stockInfo {
  2182. if its.MaxUnit == medical.MaxUnit {
  2183. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  2184. }
  2185. sum_count += its.StockMaxNumber + its.StockMinNumber
  2186. }
  2187. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2188. //出库数量累加
  2189. //service.AddDrugCount(item.DrugId,item.UserOrgId,storeHouseConfig.DrugStorehouseOut,prescribing_number_total)
  2190. //剩余库存
  2191. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  2192. break
  2193. c.ServeSuccessJSON(map[string]interface{}{
  2194. "msg": "1",
  2195. "advice": advice,
  2196. })
  2197. return
  2198. }
  2199. }
  2200. if medical.IsUse == 1 {
  2201. c.ServeSuccessJSON(map[string]interface{}{
  2202. "msg": "1",
  2203. "advice": advice,
  2204. })
  2205. return
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. c.ServeSuccessJSON(map[string]interface{}{
  2212. "msg": "1",
  2213. "advice": advice,
  2214. })
  2215. return
  2216. }
  2217. }
  2218. func (c *PatientApiController) CheckGroupAdvice() {
  2219. groupno, _ := c.GetInt64("groupno", 0)
  2220. if groupno <= 0 {
  2221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2222. return
  2223. }
  2224. adminUserInfo := c.GetAdminUserInfo()
  2225. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  2226. if advice.ID == 0 {
  2227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2228. return
  2229. }
  2230. if advice.CheckState == 1 {
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2232. return
  2233. }
  2234. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2236. return
  2237. }
  2238. checker := adminUserInfo.AdminUser.Id
  2239. theTime := time.Now()
  2240. exceAdvice := models.DoctorAdvice{
  2241. Checker: checker,
  2242. CheckTime: theTime.Unix(),
  2243. UpdatedTime: time.Now().Unix(),
  2244. }
  2245. var err error
  2246. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  2247. if err != nil {
  2248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2249. return
  2250. }
  2251. advice.Checker = checker
  2252. advice.CheckTime = theTime.Unix()
  2253. c.ServeSuccessJSON(map[string]interface{}{
  2254. "msg": "ok",
  2255. "advice": advice,
  2256. })
  2257. return
  2258. }
  2259. func (c *PatientApiController) CheckDoctorAdvice() {
  2260. patient, _ := c.GetInt64("patient", 0)
  2261. id, _ := c.GetInt64("id", 0)
  2262. origin, _ := c.GetInt64("origin", 0)
  2263. if origin != 2 {
  2264. // executionTime := c.GetString("execution_time")
  2265. if id <= 0 || patient <= 0 {
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2267. return
  2268. }
  2269. adminUserInfo := c.GetAdminUserInfo()
  2270. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2271. if advice.ID == 0 || advice.PatientId != patient {
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2273. return
  2274. }
  2275. if advice.CheckState == 1 {
  2276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2277. return
  2278. }
  2279. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2281. return
  2282. }
  2283. // executionStaff := adminUserInfo.AdminUser.Id
  2284. checker := adminUserInfo.AdminUser.Id
  2285. // timeLayout := "2006-01-02 15:04:05"
  2286. // loc, _ := time.LoadLocation("Local")
  2287. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  2288. // if err != nil {
  2289. // utils.ErrorLog(err.Error())
  2290. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2291. // return
  2292. // }
  2293. theTime := time.Now()
  2294. if advice.ExecutionTime > theTime.Unix() {
  2295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2296. return
  2297. }
  2298. exceAdvice := models.DoctorAdvice{
  2299. Checker: checker,
  2300. CheckTime: theTime.Unix(),
  2301. UpdatedTime: time.Now().Unix(),
  2302. }
  2303. var err error
  2304. if advice.ParentId > 0 {
  2305. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2306. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2307. redis := service.RedisClient()
  2308. //清空key 值
  2309. redis.Set(key, "", time.Second)
  2310. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2311. redis.Set(keyTwo, "", time.Second)
  2312. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2313. redis.Set(keyThree, "", time.Second)
  2314. recordDate := theTime.Format("2006-01-02")
  2315. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2316. redis.Set(keyFour, "", time.Second)
  2317. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2318. redis.Set(keyFive, "", time.Second)
  2319. } else {
  2320. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  2321. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2322. redis := service.RedisClient()
  2323. //清空key 值
  2324. redis.Set(key, "", time.Second)
  2325. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2326. redis.Set(keyTwo, "", time.Second)
  2327. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2328. redis.Set(keyThree, "", time.Second)
  2329. recordDate := theTime.Format("2006-01-02")
  2330. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2331. redis.Set(keyFour, "", time.Second)
  2332. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2333. redis.Set(keyFive, "", time.Second)
  2334. }
  2335. if err != nil {
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2337. return
  2338. }
  2339. // advice.ExecutionStaff = executionStaff
  2340. // advice.ExecutionTime = theTime.Unix()
  2341. advice.Checker = checker
  2342. advice.CheckTime = theTime.Unix()
  2343. c.ServeSuccessJSON(map[string]interface{}{
  2344. "msg": "ok",
  2345. "advice": advice,
  2346. })
  2347. return
  2348. } else {
  2349. if id <= 0 || patient <= 0 {
  2350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2351. return
  2352. }
  2353. adminUserInfo := c.GetAdminUserInfo()
  2354. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2355. if advice.ID == 0 || advice.PatientId != patient {
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2357. return
  2358. }
  2359. if advice.CheckState == 1 {
  2360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2361. return
  2362. }
  2363. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  2364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2365. return
  2366. }
  2367. checker := adminUserInfo.AdminUser.Id
  2368. theTime := time.Now()
  2369. if advice.ExecutionTime > theTime.Unix() {
  2370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  2371. return
  2372. }
  2373. exceAdvice := models.HisDoctorAdviceInfo{
  2374. Checker: checker,
  2375. CheckTime: theTime.Unix(),
  2376. UpdatedTime: time.Now().Unix(),
  2377. }
  2378. var err error
  2379. if advice.ParentId > 0 {
  2380. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  2381. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2382. redis := service.RedisClient()
  2383. //清空key 值
  2384. redis.Set(key, "", time.Second)
  2385. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2386. redis.Set(keyTwo, "", time.Second)
  2387. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2388. redis.Set(keyThree, "", time.Second)
  2389. recordDate := theTime.Format("2006-01-02")
  2390. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2391. redis.Set(keyFour, "", time.Second)
  2392. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2393. redis.Set(keyFive, "", time.Second)
  2394. } else {
  2395. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  2396. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2397. redis := service.RedisClient()
  2398. //清空key 值
  2399. redis.Set(key, "", time.Second)
  2400. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2401. redis.Set(keyTwo, "", time.Second)
  2402. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2403. redis.Set(keyThree, "", time.Second)
  2404. recordDate := theTime.Format("2006-01-02")
  2405. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2406. redis.Set(keyFour, "", time.Second)
  2407. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2408. redis.Set(keyFive, "", time.Second)
  2409. }
  2410. if err != nil {
  2411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2412. return
  2413. }
  2414. // advice.ExecutionStaff = executionStaff
  2415. // advice.ExecutionTime = theTime.Unix()
  2416. advice.Checker = checker
  2417. advice.CheckTime = theTime.Unix()
  2418. c.ServeSuccessJSON(map[string]interface{}{
  2419. "msg": "ok",
  2420. "advice": advice,
  2421. })
  2422. return
  2423. }
  2424. }
  2425. func (c *PatientApiController) UpdateDoctorAdvice() {
  2426. patient, _ := c.GetInt64("patient", 0)
  2427. id, _ := c.GetInt64("id", 0)
  2428. if id <= 0 || patient <= 0 {
  2429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2430. return
  2431. }
  2432. adminUserInfo := c.GetAdminUserInfo()
  2433. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2434. if advice.ID == 0 || advice.PatientId != patient {
  2435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2436. return
  2437. }
  2438. //if advice.AdviceType == 1 {
  2439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  2440. // return
  2441. //}
  2442. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2444. return
  2445. }
  2446. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2447. //if appRole.UserType == 3 {
  2448. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2449. // if getPermissionErr != nil {
  2450. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2451. // return
  2452. // } else if headNursePermission == nil {
  2453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2454. // return
  2455. // }
  2456. //}
  2457. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2458. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  2459. // return
  2460. //}
  2461. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  2462. if code > 0 {
  2463. c.ServeFailJSONWithSGJErrorCode(code)
  2464. return
  2465. }
  2466. advice.UpdatedTime = time.Now().Unix()
  2467. advice.Modifier = adminUserInfo.AdminUser.Id
  2468. err := service.UpdateDoctorAdvice(&advice)
  2469. redis := service.RedisClient()
  2470. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2471. redis.Set(key, "", time.Second)
  2472. fmt.Println("key2332233232322332", key)
  2473. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2474. redis.Set(keyOne, "", time.Second)
  2475. fmt.Println("key3333333333333333", keyOne)
  2476. defer redis.Close()
  2477. if err != nil {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2479. return
  2480. }
  2481. c.ServeSuccessJSON(map[string]interface{}{
  2482. "msg": "ok",
  2483. "advice": advice,
  2484. })
  2485. return
  2486. }
  2487. func (c *PatientApiController) StopGroupAdvice() {
  2488. groupNo, _ := c.GetInt64("groupno", 0)
  2489. if groupNo <= 0 {
  2490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2491. return
  2492. }
  2493. adminUserInfo := c.GetAdminUserInfo()
  2494. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2495. if advice.ID == 0 {
  2496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2497. return
  2498. }
  2499. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2501. return
  2502. }
  2503. dataBody := make(map[string]interface{}, 0)
  2504. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2505. if err != nil {
  2506. utils.ErrorLog(err.Error())
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2508. return
  2509. }
  2510. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2511. utils.ErrorLog("stop_time")
  2512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2513. return
  2514. }
  2515. stopTime, _ := dataBody["stop_time"].(string)
  2516. if len(stopTime) == 0 {
  2517. utils.ErrorLog("len(stop_time) == 0")
  2518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2519. return
  2520. }
  2521. timeLayout := "2006-01-02"
  2522. loc, _ := time.LoadLocation("Local")
  2523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2524. if err != nil {
  2525. utils.ErrorLog(err.Error())
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2527. return
  2528. }
  2529. advice.StopTime = theTime.Unix()
  2530. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2531. stopReason, _ := dataBody["stop_reason"].(string)
  2532. advice.StopReason = stopReason
  2533. }
  2534. advice.UpdatedTime = time.Now().Unix()
  2535. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2536. advice.StopState = 1
  2537. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2538. if err != nil {
  2539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2540. return
  2541. }
  2542. c.ServeSuccessJSON(map[string]interface{}{
  2543. "msg": "ok",
  2544. })
  2545. return
  2546. }
  2547. func (c *PatientApiController) StopDoctorAdvice() {
  2548. id, _ := c.GetInt64("id", 0)
  2549. if id <= 0 {
  2550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2551. return
  2552. }
  2553. adminUserInfo := c.GetAdminUserInfo()
  2554. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2555. //
  2556. //if appRole.UserType == 3 {
  2557. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2558. // if getPermissionErr != nil {
  2559. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2560. // return
  2561. // } else if headNursePermission == nil {
  2562. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2563. // return
  2564. // }
  2565. //}
  2566. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2567. if advice.ID == 0 {
  2568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2569. return
  2570. }
  2571. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2573. return
  2574. }
  2575. dataBody := make(map[string]interface{}, 0)
  2576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2577. if err != nil {
  2578. utils.ErrorLog(err.Error())
  2579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2580. return
  2581. }
  2582. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2583. utils.ErrorLog("stop_time")
  2584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2585. return
  2586. }
  2587. stopTime, _ := dataBody["stop_time"].(string)
  2588. if len(stopTime) == 0 {
  2589. utils.ErrorLog("len(stop_time) == 0")
  2590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2591. return
  2592. }
  2593. timeLayout := "2006-01-02"
  2594. loc, _ := time.LoadLocation("Local")
  2595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2596. if err != nil {
  2597. utils.ErrorLog(err.Error())
  2598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2599. return
  2600. }
  2601. advice.StopTime = theTime.Unix()
  2602. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2603. stopReason, _ := dataBody["stop_reason"].(string)
  2604. advice.StopReason = stopReason
  2605. }
  2606. advice.UpdatedTime = time.Now().Unix()
  2607. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2608. advice.StopState = 1
  2609. err = service.StopDoctorAdvice(&advice)
  2610. if err != nil {
  2611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2612. return
  2613. }
  2614. c.ServeSuccessJSON(map[string]interface{}{
  2615. "msg": "ok",
  2616. "advice": advice,
  2617. })
  2618. return
  2619. }
  2620. func (c *PatientApiController) DeleteDoctorAdvice() {
  2621. id, _ := c.GetInt64("id", 0)
  2622. if id <= 0 {
  2623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2624. return
  2625. }
  2626. adminUserInfo := c.GetAdminUserInfo()
  2627. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2628. if advice.ID == 0 {
  2629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2630. return
  2631. }
  2632. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2634. // return
  2635. //}
  2636. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2637. //
  2638. //if appRole.UserType == 3 {
  2639. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2640. // if getPermissionErr != nil {
  2641. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2642. // return
  2643. // } else if headNursePermission == nil {
  2644. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2645. // return
  2646. // }
  2647. //}
  2648. advice.UpdatedTime = time.Now().Unix()
  2649. advice.Status = 0
  2650. advice.Modifier = adminUserInfo.AdminUser.Id
  2651. err := service.DeleteDoctorAdvice(&advice)
  2652. redis := service.RedisClient()
  2653. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2654. redis.Set(keyOne, "", time.Second)
  2655. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2656. redis.Set(key, "", time.Second)
  2657. redis.Close()
  2658. if err != nil {
  2659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2660. return
  2661. }
  2662. c.ServeSuccessJSON(map[string]interface{}{
  2663. "msg": "ok",
  2664. })
  2665. return
  2666. }
  2667. func (c *PatientApiController) DeleteGroupAdvice() {
  2668. groupNo, _ := c.GetInt64("groupno", 0)
  2669. if groupNo <= 0 {
  2670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2671. return
  2672. }
  2673. adminUserInfo := c.GetAdminUserInfo()
  2674. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2675. if advice.ID == 0 {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2677. return
  2678. }
  2679. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2680. //if appRole.UserType == 3 {
  2681. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2682. // if getPermissionErr != nil {
  2683. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2684. // return
  2685. // } else if headNursePermission == nil {
  2686. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2687. // return
  2688. // }
  2689. //}
  2690. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2691. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2692. redis := service.RedisClient()
  2693. redis.Set(key, "", time.Second)
  2694. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2695. redis.Set(keyOne, "", time.Second)
  2696. defer redis.Close()
  2697. if err != nil {
  2698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2699. return
  2700. }
  2701. c.ServeSuccessJSON(map[string]interface{}{
  2702. "msg": "ok",
  2703. })
  2704. return
  2705. }
  2706. // GetDoctorAdvices 医嘱列表
  2707. func (c *PatientApiController) GetDoctorAdvices() {
  2708. id, _ := c.GetInt64("id", 0)
  2709. adviceType, _ := c.GetInt64("advice_type", 0)
  2710. stopType, _ := c.GetInt64("stop_state", 0)
  2711. startTime := c.GetString("start_time", "")
  2712. endTime := c.GetString("end_time", "")
  2713. keywords := c.GetString("keywords", "")
  2714. page, _ := c.GetInt64("page")
  2715. fmt.Println("page", page)
  2716. limit, _ := c.GetInt64("limit")
  2717. fmt.Println("limit", limit)
  2718. adminUserInfo := c.GetAdminUserInfo()
  2719. operatorIDs := make([]int64, 0)
  2720. timeLayout := "2006-01-02"
  2721. loc, _ := time.LoadLocation("Local")
  2722. var theStartTIme int64
  2723. if len(startTime) > 0 {
  2724. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2725. if err != nil {
  2726. utils.ErrorLog(err.Error())
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2728. return
  2729. }
  2730. theStartTIme = theTime.Unix()
  2731. }
  2732. var theEndtTIme int64
  2733. if len(endTime) > 0 {
  2734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2735. if err != nil {
  2736. utils.ErrorLog(err.Error())
  2737. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2738. return
  2739. }
  2740. theEndtTIme = theTime.Unix()
  2741. }
  2742. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2743. if hisconfig.IsOpen == 1 {
  2744. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2745. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2746. if len(advices) > 0 {
  2747. for _, item := range advices {
  2748. if item.AdviceDoctor > 0 {
  2749. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2750. }
  2751. if item.ExecutionStaff > 0 {
  2752. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2753. }
  2754. if item.Checker > 0 {
  2755. operatorIDs = append(operatorIDs, item.Checker)
  2756. }
  2757. if item.StopDoctor > 0 {
  2758. operatorIDs = append(operatorIDs, item.StopDoctor)
  2759. }
  2760. }
  2761. }
  2762. //相关操作对应的操作人
  2763. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2764. c.ServeSuccessJSON(map[string]interface{}{
  2765. "advices": advices,
  2766. "operators": operators,
  2767. "total": total,
  2768. "advicetwo": advicestwo,
  2769. })
  2770. return
  2771. } else {
  2772. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2773. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2774. if len(advices) > 0 {
  2775. for _, item := range advices {
  2776. if item.AdviceDoctor > 0 {
  2777. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2778. }
  2779. if item.ExecutionStaff > 0 {
  2780. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2781. }
  2782. if item.Checker > 0 {
  2783. operatorIDs = append(operatorIDs, item.Checker)
  2784. }
  2785. if item.StopDoctor > 0 {
  2786. operatorIDs = append(operatorIDs, item.StopDoctor)
  2787. }
  2788. }
  2789. }
  2790. //相关操作对应的操作人
  2791. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2792. c.ServeSuccessJSON(map[string]interface{}{
  2793. "advices": advices,
  2794. "operators": operators,
  2795. "total": total,
  2796. "advicetwo": advicestwo,
  2797. })
  2798. return
  2799. }
  2800. }
  2801. func (c *PatientApiController) GetPatientSchedules() {
  2802. id, _ := c.GetInt64("id", 0)
  2803. if id <= 0 {
  2804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2805. return
  2806. }
  2807. adminUserInfo := c.GetAdminUserInfo()
  2808. todayTime := time.Now().Format("2006-01-02")
  2809. timeLayout := "2006-01-02 15:04:05"
  2810. loc, _ := time.LoadLocation("Local")
  2811. var theStartTime int64
  2812. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2813. theStartTime = theTime.Unix()
  2814. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2815. if len(schedules) > 0 {
  2816. for index, item := range schedules {
  2817. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2818. schedules[index].Week = int64(week)
  2819. }
  2820. }
  2821. c.ServeSuccessJSON(map[string]interface{}{
  2822. "schedules": schedules,
  2823. })
  2824. return
  2825. }
  2826. func (c *PatientApiController) GetPatientDialysisRecords() {
  2827. patientID, _ := c.GetInt64("patient_id", 0)
  2828. page, _ := c.GetInt64("page", 0)
  2829. limit, _ := c.GetInt64("limit", 0)
  2830. startTime := c.GetString("start_time", "")
  2831. endTime := c.GetString("end_time", "")
  2832. mode_id, _ := c.GetInt64("mode_id", 0)
  2833. if page <= 0 {
  2834. page = 1
  2835. }
  2836. if limit <= 0 {
  2837. limit = 10
  2838. }
  2839. if patientID <= 0 {
  2840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2841. return
  2842. }
  2843. timeLayout := "2006-01-02"
  2844. loc, _ := time.LoadLocation("Local")
  2845. var theStartTIme int64
  2846. if len(startTime) > 0 {
  2847. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2848. if err != nil {
  2849. theStartTIme = 0
  2850. }
  2851. theStartTIme = theTime.Unix()
  2852. }
  2853. var theEndtTIme int64
  2854. if len(endTime) > 0 {
  2855. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2856. if err != nil {
  2857. theEndtTIme = 0
  2858. }
  2859. theEndtTIme = theTime.Unix()
  2860. }
  2861. adminInfo := c.GetAdminUserInfo()
  2862. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2863. c.ServeSuccessJSON(map[string]interface{}{
  2864. "total": total,
  2865. "records": records,
  2866. })
  2867. return
  2868. }
  2869. func (c *PatientApiController) ProEducation() {
  2870. patientID, _ := c.GetInt64("patient_id", 0)
  2871. page, _ := c.GetInt64("page", 0)
  2872. limit, _ := c.GetInt64("limit", 0)
  2873. startTime := c.GetString("start_time", "")
  2874. endTime := c.GetString("end_time", "")
  2875. if page <= 0 {
  2876. page = 1
  2877. }
  2878. if limit <= 0 {
  2879. limit = 10
  2880. }
  2881. if patientID <= 0 {
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2883. return
  2884. }
  2885. timeLayout := "2006-01-02"
  2886. loc, _ := time.LoadLocation("Local")
  2887. var theStartTIme int64
  2888. if len(startTime) > 0 {
  2889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2890. if err != nil {
  2891. theStartTIme = 0
  2892. }
  2893. theStartTIme = theTime.Unix()
  2894. }
  2895. var theEndtTIme int64
  2896. if len(endTime) > 0 {
  2897. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2898. if err != nil {
  2899. theEndtTIme = 0
  2900. }
  2901. theEndtTIme = theTime.Unix()
  2902. }
  2903. adminInfo := c.GetAdminUserInfo()
  2904. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2905. c.ServeSuccessJSON(map[string]interface{}{
  2906. "total": total,
  2907. "edus": edus,
  2908. })
  2909. return
  2910. }
  2911. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2912. dataBody := make(map[string]interface{}, 0)
  2913. err := json.Unmarshal(data, &dataBody)
  2914. if err != nil {
  2915. utils.ErrorLog(err.Error())
  2916. code = enums.ErrorCodeParamWrong
  2917. return
  2918. }
  2919. timeLayout := "2006-01-02"
  2920. loc, _ := time.LoadLocation("Local")
  2921. isChild := false
  2922. if action == "create" {
  2923. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2924. utils.ErrorLog("advice_type")
  2925. code = enums.ErrorCodeParamWrong
  2926. return
  2927. }
  2928. adviceType := int64(dataBody["advice_type"].(float64))
  2929. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2930. utils.ErrorLog("advice_type != 1&&2")
  2931. code = enums.ErrorCodeParamWrong
  2932. return
  2933. }
  2934. advice.AdviceType = adviceType
  2935. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2936. utils.ErrorLog("advice_date")
  2937. code = enums.ErrorCodeParamWrong
  2938. return
  2939. }
  2940. adviceDate, _ := dataBody["advice_date"].(string)
  2941. if len(adviceDate) == 0 {
  2942. utils.ErrorLog("len(adviceDate) == 0")
  2943. code = enums.ErrorCodeParamWrong
  2944. return
  2945. }
  2946. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2947. if err != nil {
  2948. utils.ErrorLog(err.Error())
  2949. code = enums.ErrorCodeParamWrong
  2950. return
  2951. }
  2952. advice.AdviceDate = theTime.Unix()
  2953. advice.RecordDate = theTime.Unix()
  2954. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2955. parentId := int64(dataBody["parent_id"].(float64))
  2956. advice.ParentId = parentId
  2957. if parentId > 0 {
  2958. isChild = true
  2959. }
  2960. }
  2961. }
  2962. if !isChild {
  2963. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2964. utils.ErrorLog("start_time")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. startTime, _ := dataBody["start_time"].(string)
  2969. if len(startTime) == 0 {
  2970. utils.ErrorLog("len(start_time) == 0")
  2971. code = enums.ErrorCodeParamWrong
  2972. return
  2973. }
  2974. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2975. if err != nil {
  2976. utils.ErrorLog(err.Error())
  2977. code = enums.ErrorCodeParamWrong
  2978. return
  2979. }
  2980. advice.StartTime = theTime.Unix()
  2981. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2982. // utils.ErrorLog("advice_doctor")
  2983. // code = enums.ErrorCodeParamWrong
  2984. // return
  2985. // }
  2986. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2987. // if adviceDoctor <= 0 {
  2988. // utils.ErrorLog("advice_doctor <=0")
  2989. // code = enums.ErrorCodeParamWrong
  2990. // return
  2991. // }
  2992. // advice.AdviceDoctor = adviceDoctor
  2993. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2994. deliveryWay, _ := dataBody["delivery_way"].(string)
  2995. advice.DeliveryWay = deliveryWay
  2996. }
  2997. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2998. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2999. advice.ExecutionFrequency = executionFrequency
  3000. }
  3001. if advice.AdviceType == 1 && advice.ParentId == 0 {
  3002. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  3003. frequency_type := int64(dataBody["frequency_type"].(float64))
  3004. advice.FrequencyType = frequency_type
  3005. }
  3006. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  3007. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  3008. advice.DayCount = day_count
  3009. }
  3010. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  3011. week_day, _ := dataBody["week_days"].(string)
  3012. advice.WeekDay = week_day
  3013. }
  3014. }
  3015. }
  3016. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3017. utils.ErrorLog("advice_name")
  3018. code = enums.ErrorCodeParamWrong
  3019. return
  3020. }
  3021. adviceName, _ := dataBody["advice_name"].(string)
  3022. if len(adviceName) == 0 {
  3023. utils.ErrorLog("len(advice_name) == 0")
  3024. code = enums.ErrorCodeParamWrong
  3025. return
  3026. }
  3027. advice.AdviceName = adviceName
  3028. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3029. adviceDsc, _ := dataBody["advice_desc"].(string)
  3030. advice.AdviceDesc = adviceDsc
  3031. }
  3032. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  3033. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  3034. advice.DialysisOrderId = int64(dialysisOrderId)
  3035. }
  3036. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3037. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3038. advice.SingleDose = singleDose
  3039. }
  3040. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "float64" {
  3041. singleDose := dataBody["single_dose"].(float64)
  3042. advice.SingleDose = singleDose
  3043. }
  3044. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3045. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3046. advice.SingleDoseUnit = singleDoseUnit
  3047. }
  3048. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "float64" {
  3049. tmp := dataBody["single_dose_unit"].(float64)
  3050. singleDoseUnit := service.TypeConversion(tmp)
  3051. advice.SingleDoseUnit = singleDoseUnit
  3052. }
  3053. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3054. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3055. advice.DrugSpec = drugSpec
  3056. }
  3057. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3058. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3059. advice.DrugSpecUnit = drugSpecUnit
  3060. }
  3061. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3062. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3063. advice.PrescribingNumber = prescribingNumber
  3064. }
  3065. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "float64" {
  3066. prescribingNumber := dataBody["prescribing_number"].(float64)
  3067. advice.PrescribingNumber = prescribingNumber
  3068. }
  3069. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3070. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3071. advice.PrescribingNumberUnit = prescribingNumberUnit
  3072. }
  3073. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3074. remark, _ := dataBody["remark"].(string)
  3075. advice.Remark = remark
  3076. }
  3077. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "string" {
  3078. drug_id, _ := dataBody["drug_id"].(string)
  3079. tmpDrugId, _ := strconv.ParseInt(drug_id, 10, 64)
  3080. advice.DrugId = tmpDrugId
  3081. }
  3082. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3083. drug_id, _ := dataBody["drug_id"].(float64)
  3084. advice.DrugId = int64(drug_id)
  3085. }
  3086. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3087. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  3088. advice.DrugNameId = int64(drug_name_id)
  3089. }
  3090. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3091. way, _ := dataBody["way"].(float64)
  3092. advice.Way = int64(way)
  3093. }
  3094. if dataBody["push_start_time"] != nil && reflect.TypeOf(dataBody["push_start_time"]).String() == "string" {
  3095. push_start_time, _ := dataBody["push_start_time"].(string)
  3096. var startTime int64
  3097. if len(push_start_time) > 0 {
  3098. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", push_start_time+" 00:00:00", loc)
  3099. startTime = theTime.Unix()
  3100. }
  3101. advice.PushStartTime = startTime
  3102. }
  3103. return
  3104. }
  3105. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  3106. dataBody := make(map[string]interface{}, 0)
  3107. err := json.Unmarshal(data, &dataBody)
  3108. utils.InfoLog(string(data))
  3109. if err != nil {
  3110. utils.ErrorLog(err.Error())
  3111. code = enums.ErrorCodeParamWrong
  3112. return
  3113. }
  3114. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3115. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3116. solution.DialysisDuration = dialysisDuration
  3117. }
  3118. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3119. replacementWay := int64(dataBody["replacement_way"].(float64))
  3120. solution.ReplacementWay = replacementWay
  3121. }
  3122. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3123. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3124. solution.BloodFlowVolume = bloodFlowVolume
  3125. }
  3126. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3127. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3128. solution.HemodialysisMachine = hemodialysisMachine
  3129. }
  3130. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  3131. bloodFilter := int64(dataBody["blood_filter"].(float64))
  3132. solution.BloodFilter = bloodFilter
  3133. }
  3134. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3135. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3136. solution.PerfusionApparatus = perfusionApparatus
  3137. }
  3138. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3139. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3140. solution.DialysateFlow = dialysateFlow
  3141. }
  3142. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3143. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3144. solution.Kalium = kalium
  3145. }
  3146. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3147. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3148. solution.Sodium = sodium
  3149. }
  3150. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3151. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3152. solution.Calcium = calcium
  3153. }
  3154. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3155. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3156. solution.Bicarbonate = bicarbonate
  3157. }
  3158. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3159. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3160. solution.Anticoagulant = anticoagulant
  3161. }
  3162. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3163. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3164. solution.AnticoagulantShouji = anticoagulantShouji
  3165. }
  3166. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3167. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3168. solution.AnticoagulantWeichi = anticoagulantWeichi
  3169. }
  3170. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3171. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3172. solution.AnticoagulantZongliang = anticoagulantZongliang
  3173. }
  3174. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3175. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3176. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3177. }
  3178. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3179. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3180. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3181. }
  3182. return
  3183. }
  3184. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3185. dataBody := make(map[string]interface{}, 0)
  3186. err := json.Unmarshal(data, &dataBody)
  3187. utils.InfoLog(string(data))
  3188. if err != nil {
  3189. utils.ErrorLog(err.Error())
  3190. code = enums.ErrorCodeParamWrong
  3191. return
  3192. }
  3193. if method == "create" {
  3194. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  3195. utils.ErrorLog("mode")
  3196. code = enums.ErrorCodeParamWrong
  3197. return
  3198. }
  3199. mode := int64(dataBody["mode"].(float64))
  3200. if mode <= 0 {
  3201. utils.ErrorLog("mode <= 0")
  3202. code = enums.ErrorCodeParamWrong
  3203. return
  3204. }
  3205. solution.ModeId = mode
  3206. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  3207. utils.ErrorLog("mode_name")
  3208. code = enums.ErrorCodeParamWrong
  3209. return
  3210. }
  3211. modeName, _ := dataBody["mode_name"].(string)
  3212. if len(modeName) == 0 {
  3213. utils.ErrorLog("len(mode_name) == 0")
  3214. code = enums.ErrorCodeParamWrong
  3215. return
  3216. }
  3217. solution.ModeName = modeName
  3218. solution.Name = modeName
  3219. }
  3220. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  3221. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  3222. solution.DialysisDuration = dialysisDuration
  3223. }
  3224. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  3225. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  3226. solution.TargetUltrafiltration = targetUltrafiltration
  3227. }
  3228. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  3229. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  3230. solution.DialysateFormulation = dialysateFormulation
  3231. }
  3232. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  3233. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  3234. solution.DialysisDurationHour = int64(dialysisDurationHour)
  3235. }
  3236. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  3237. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  3238. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  3239. }
  3240. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  3241. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  3242. solution.HemodialysisMachine = hemodialysisMachine
  3243. }
  3244. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  3245. dialyzer := int64(dataBody["dialyzer"].(float64))
  3246. solution.Dialyzer = dialyzer
  3247. }
  3248. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  3249. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  3250. solution.PerfusionApparatus = perfusionApparatus
  3251. }
  3252. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  3253. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  3254. solution.BloodFlowVolume = bloodFlowVolume
  3255. }
  3256. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  3257. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  3258. solution.Dewater = dewater
  3259. }
  3260. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  3261. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  3262. solution.DisplaceLiqui = displaceLiqui
  3263. }
  3264. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  3265. replacementWay := int64(dataBody["replacement_way"].(float64))
  3266. solution.ReplacementWay = replacementWay
  3267. }
  3268. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  3269. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  3270. solution.Anticoagulant = anticoagulant
  3271. }
  3272. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  3273. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  3274. solution.AnticoagulantShouji = anticoagulantShouji
  3275. }
  3276. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  3277. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  3278. solution.AnticoagulantWeichi = anticoagulantWeichi
  3279. }
  3280. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  3281. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  3282. solution.AnticoagulantZongliang = anticoagulantZongliang
  3283. }
  3284. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  3285. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  3286. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  3287. }
  3288. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  3289. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  3290. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  3291. }
  3292. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  3293. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  3294. solution.Kalium = kalium
  3295. }
  3296. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  3297. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  3298. solution.Sodium = sodium
  3299. }
  3300. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  3301. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  3302. solution.Calcium = calcium
  3303. }
  3304. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  3305. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  3306. solution.Bicarbonate = bicarbonate
  3307. }
  3308. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  3309. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  3310. solution.Glucose = glucose
  3311. }
  3312. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  3313. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  3314. // solution.DryWeight = dryWeight
  3315. // }
  3316. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  3317. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  3318. solution.DialysateFlow = dialysateFlow
  3319. }
  3320. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  3321. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  3322. solution.DialysateTemperature = dialysateTemperature
  3323. }
  3324. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  3325. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  3326. solution.Conductivity = conductivity
  3327. }
  3328. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  3329. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  3330. solution.ReplacementTotal = replacementTotal
  3331. }
  3332. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  3333. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  3334. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  3335. }
  3336. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  3337. body_fluid := int64(dataBody["body_fluid"].(float64))
  3338. solution.BodyFluid = body_fluid
  3339. }
  3340. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  3341. body_fluid_other := dataBody["body_fluid_other"].(string)
  3342. solution.BodyFluidOther = body_fluid_other
  3343. }
  3344. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  3345. special_medicine := int64(dataBody["special_medicine"].(float64))
  3346. solution.SpecialMedicine = special_medicine
  3347. }
  3348. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  3349. special_medicine_other := dataBody["special_medicine_other"].(string)
  3350. solution.SpecialMedicineOther = special_medicine_other
  3351. }
  3352. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  3353. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  3354. solution.DisplaceLiquiPart = displace_liqui_part
  3355. }
  3356. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  3357. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  3358. solution.DisplaceLiquiValue = displace_liqui_value
  3359. }
  3360. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  3361. blood_access := int64(dataBody["blood_access"].(float64))
  3362. solution.BloodAccess = blood_access
  3363. }
  3364. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  3365. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  3366. solution.Ultrafiltration = ultrafiltration
  3367. }
  3368. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  3369. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  3370. solution.TargetKtv = target_ktv
  3371. }
  3372. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3373. remark := dataBody["remark"].(string)
  3374. solution.Remark = remark
  3375. }
  3376. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  3377. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  3378. solution.HemodialysisPipelines = hemodialysis_pipelines
  3379. }
  3380. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  3381. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  3382. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  3383. }
  3384. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  3385. puncture_needle := dataBody["puncture_needle"].(string)
  3386. solution.PunctureNeedle = puncture_needle
  3387. }
  3388. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  3389. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  3390. solution.PunctureNeedleCount = puncture_needle_count
  3391. }
  3392. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  3393. epo := dataBody["epo"].(string)
  3394. solution.Epo = epo
  3395. }
  3396. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  3397. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  3398. solution.EpoCount = epo_count
  3399. }
  3400. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  3401. created_time := int64(dataBody["created_time"].(float64))
  3402. solution.CreatedTime = created_time
  3403. }
  3404. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  3405. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  3406. solution.DialysisDialyszers = dialysisDialyszers
  3407. }
  3408. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  3409. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  3410. solution.DialysisIrrigation = dialysisIrrigation
  3411. }
  3412. if dataBody["dialysis_strainer"] != nil && reflect.TypeOf(dataBody["dialysis_strainer"]).String() == "string" {
  3413. dialysis_strainer := dataBody["dialysis_strainer"].(string)
  3414. solution.DialysisStrainer = dialysis_strainer
  3415. }
  3416. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  3417. plasmaSeparator := dataBody["plasma_separator"].(string)
  3418. solution.PlasmaSeparator = plasmaSeparator
  3419. }
  3420. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  3421. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  3422. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  3423. }
  3424. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  3425. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  3426. solution.OxygenUptake = oxygen_uptake
  3427. }
  3428. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  3429. oxygen_flow := dataBody["oxygen_flow"].(string)
  3430. solution.OxygenFlow = oxygen_flow
  3431. }
  3432. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  3433. oxygen_time := dataBody["oxygen_time"].(string)
  3434. solution.OxygenTime = oxygen_time
  3435. }
  3436. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  3437. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  3438. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  3439. }
  3440. if dataBody["amylaceum"] != nil && reflect.TypeOf(dataBody["amylaceum"]).String() == "string" {
  3441. amylaceum := dataBody["amylaceum"].(string)
  3442. solution.Amylaceum = amylaceum
  3443. }
  3444. return
  3445. }
  3446. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  3447. dataBody := make(map[string]interface{}, 0)
  3448. err := json.Unmarshal(data, &dataBody)
  3449. utils.InfoLog(string(data))
  3450. if err != nil {
  3451. utils.ErrorLog(err.Error())
  3452. code = enums.ErrorCodeParamWrong
  3453. return
  3454. }
  3455. if method == "create" {
  3456. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  3457. utils.ErrorLog("parent_id")
  3458. code = enums.ErrorCodeParamWrong
  3459. return
  3460. }
  3461. parentID := int64(dataBody["parent_id"].(float64))
  3462. if parentID <= 0 {
  3463. utils.ErrorLog("parentID <= 0")
  3464. code = enums.ErrorCodeParamWrong
  3465. return
  3466. }
  3467. solution.ParentId = parentID
  3468. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  3469. utils.ErrorLog("sub_name")
  3470. code = enums.ErrorCodeParamWrong
  3471. return
  3472. }
  3473. subName, _ := dataBody["sub_name"].(string)
  3474. if len(subName) == 0 {
  3475. utils.ErrorLog("len(sub_name) == 0")
  3476. code = enums.ErrorCodeParamWrong
  3477. return
  3478. }
  3479. solution.SubName = subName
  3480. }
  3481. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  3482. utils.ErrorLog("initiate_mode")
  3483. code = enums.ErrorCodeParamWrong
  3484. return
  3485. }
  3486. initiateMode := int64(dataBody["initiate_mode"].(float64))
  3487. if initiateMode != 1 && initiateMode != 2 {
  3488. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  3489. code = enums.ErrorCodeParamWrong
  3490. return
  3491. }
  3492. solution.InitiateMode = initiateMode
  3493. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  3494. utils.ErrorLog("doctor")
  3495. code = enums.ErrorCodeParamWrong
  3496. return
  3497. }
  3498. doctor := int64(dataBody["doctor"].(float64))
  3499. if doctor <= 0 {
  3500. utils.ErrorLog("doctor <= 0")
  3501. code = enums.ErrorCodeParamWrong
  3502. return
  3503. }
  3504. solution.Doctor = doctor
  3505. return
  3506. }
  3507. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  3508. patientBody := make(map[string]interface{}, 0)
  3509. err := json.Unmarshal(data, &patientBody)
  3510. if err != nil {
  3511. utils.ErrorLog(err.Error())
  3512. code = enums.ErrorCodeParamWrong
  3513. return
  3514. }
  3515. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  3516. formItem, _ := patientBody["formItem"].([]interface{})
  3517. if len(formItem) > 0 {
  3518. for _, item := range formItem {
  3519. items := item.(map[string]interface{})
  3520. project_name, _ := items["project_name"].(string)
  3521. fmt.Println(project_name)
  3522. range_type := int64(items["range_type"].(float64))
  3523. fmt.Println(range_type)
  3524. project_id := int64(items["project_id"].(float64))
  3525. fmt.Println(project_id)
  3526. item_id := int64(items["item_id"].(float64))
  3527. fmt.Println(item_id)
  3528. item, _ := items["item"].(string)
  3529. fmt.Println(items["item"].(string))
  3530. item_name, _ := items["item_name"].(string)
  3531. fmt.Println(item_name)
  3532. value, _ := items["value"].(string)
  3533. fmt.Println(items["value"].(string))
  3534. var form models.FormItem
  3535. form.ProjectName = project_name
  3536. form.RangeType = range_type
  3537. form.ProjectId = project_id
  3538. form.ItemId = item_id
  3539. form.Item = item
  3540. form.ItemName = item_name
  3541. form.Value = value
  3542. formItems = append(formItems, &form)
  3543. }
  3544. }
  3545. }
  3546. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  3547. utils.ErrorLog("avatar")
  3548. code = enums.ErrorCodeParamWrong
  3549. return
  3550. }
  3551. avatar, _ := patientBody["avatar"].(string)
  3552. if len(avatar) == 0 {
  3553. utils.ErrorLog("len(avatar) == 0")
  3554. code = enums.ErrorCodeParamWrong
  3555. return
  3556. }
  3557. patient.Avatar = avatar
  3558. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  3559. utils.ErrorLog("name")
  3560. code = enums.ErrorCodeParamWrong
  3561. return
  3562. }
  3563. name, _ := patientBody["name"].(string)
  3564. if len(name) == 0 {
  3565. utils.ErrorLog("len(name) == 0")
  3566. code = enums.ErrorCodeParamWrong
  3567. return
  3568. }
  3569. patient.Name = name
  3570. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  3571. alias := patientBody["alias"].(string)
  3572. patient.Alias = alias
  3573. }
  3574. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  3575. nation := patientBody["nation"].(string)
  3576. patient.Nation = nation
  3577. }
  3578. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  3579. native_place := patientBody["native_place"].(string)
  3580. patient.NativePlace = native_place
  3581. }
  3582. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  3583. utils.ErrorLog("idCardNo")
  3584. code = enums.ErrorCodeParamWrong
  3585. return
  3586. }
  3587. idCardNo, _ := patientBody["idCardNo"].(string)
  3588. if len(idCardNo) == 0 {
  3589. utils.ErrorLog("len(idCardNo) == 0")
  3590. code = enums.ErrorCodeParamWrong
  3591. return
  3592. }
  3593. patient.IdCardNo = idCardNo
  3594. patient.PatientType = 1
  3595. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  3596. utils.ErrorLog("dialysisNo")
  3597. code = enums.ErrorCodeParamWrong
  3598. return
  3599. }
  3600. dialysisNo, _ := patientBody["dialysisNo"].(string)
  3601. if len(dialysisNo) == 0 {
  3602. utils.ErrorLog("len(dialysisNo) == 0")
  3603. code = enums.ErrorCodeParamWrong
  3604. return
  3605. }
  3606. patient.DialysisNo = dialysisNo
  3607. // }
  3608. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  3609. utils.ErrorLog("lapseto")
  3610. code = enums.ErrorCodeParamWrong
  3611. return
  3612. }
  3613. lapseto := int64(patientBody["lapseto"].(float64))
  3614. if lapseto <= 0 {
  3615. utils.ErrorLog("lapseto == 0")
  3616. code = enums.ErrorCodeParamWrong
  3617. return
  3618. }
  3619. patient.Lapseto = lapseto
  3620. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  3621. utils.ErrorLog("gender")
  3622. code = enums.ErrorCodeParamWrong
  3623. return
  3624. }
  3625. gender := int64(patientBody["gender"].(float64))
  3626. if gender <= 0 {
  3627. utils.ErrorLog("gender <= 0")
  3628. code = enums.ErrorCodeParamWrong
  3629. return
  3630. }
  3631. patient.Gender = gender
  3632. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  3633. response_result := patientBody["response_result"].(string)
  3634. patient.ResponseResult = response_result
  3635. }
  3636. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  3637. utils.ErrorLog("age")
  3638. code = enums.ErrorCodeParamWrong
  3639. return
  3640. }
  3641. age := int64(patientBody["age"].(float64))
  3642. patient.Age = age
  3643. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  3644. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  3645. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  3646. patient.UserSysBeforeCount = count
  3647. }
  3648. timeLayout := "2006-01-02"
  3649. loc, _ := time.LoadLocation("Local")
  3650. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  3651. utils.ErrorLog("birth")
  3652. code = enums.ErrorCodeParamWrong
  3653. return
  3654. }
  3655. birth, _ := patientBody["birth"].(string)
  3656. if len(birth) == 0 {
  3657. utils.ErrorLog("len(birth) == 0")
  3658. code = enums.ErrorCodeParamWrong
  3659. return
  3660. }
  3661. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  3662. if err != nil {
  3663. utils.ErrorLog("birthTime")
  3664. code = enums.ErrorCodeParamWrong
  3665. return
  3666. }
  3667. patient.Birthday = birthTime.Unix()
  3668. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  3669. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  3670. patient.Height = height
  3671. }
  3672. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  3673. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3674. patient.MaritalStatus = maritalStatus
  3675. }
  3676. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3677. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3678. patient.Children = children
  3679. }
  3680. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3681. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3682. patient.AdmissionNumber = admissionNumber
  3683. }
  3684. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3685. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3686. patient.ReimbursementWayId = reimbursementWayID
  3687. }
  3688. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3689. healthCareNo := patientBody["healthCareNo"].(string)
  3690. patient.HealthCareNo = healthCareNo
  3691. }
  3692. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3693. utils.ErrorLog("phone")
  3694. code = enums.ErrorCodeParamWrong
  3695. return
  3696. }
  3697. phone := patientBody["phone"].(string)
  3698. if len(phone) == 0 {
  3699. utils.ErrorLog("len(phone) == 0")
  3700. code = enums.ErrorCodeParamWrong
  3701. return
  3702. }
  3703. if !utils.CheckMobile(phone) {
  3704. utils.ErrorLog("!phone")
  3705. code = enums.ErrorCodeMobileFormat
  3706. return
  3707. }
  3708. patient.Phone = phone
  3709. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3710. homeTelephone := patientBody["homeTelephone"].(string)
  3711. patient.HomeTelephone = homeTelephone
  3712. }
  3713. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3714. relativePhone := patientBody["relative_phone"].(string)
  3715. patient.RelativePhone = relativePhone
  3716. }
  3717. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3718. relativeRelations := patientBody["relative_relations"].(string)
  3719. patient.RelativeRelations = relativeRelations
  3720. }
  3721. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3722. homeAddress := patientBody["homeAddress"].(string)
  3723. patient.HomeAddress = homeAddress
  3724. }
  3725. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3726. work := patientBody["work"].(string)
  3727. patient.WorkUnit = work
  3728. }
  3729. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3730. unitAddress := patientBody["unit_address"].(string)
  3731. patient.UnitAddress = unitAddress
  3732. }
  3733. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3734. profession := int64(patientBody["profession"].(float64))
  3735. patient.Profession = profession
  3736. }
  3737. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3738. education := int64(patientBody["education"].(float64))
  3739. patient.EducationLevel = education
  3740. }
  3741. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3742. utils.ErrorLog("source")
  3743. code = enums.ErrorCodeParamWrong
  3744. return
  3745. }
  3746. source := int64(patientBody["source"].(float64))
  3747. if source <= 0 {
  3748. utils.ErrorLog("source <= 0")
  3749. code = enums.ErrorCodeParamWrong
  3750. return
  3751. }
  3752. patient.Source = source
  3753. zb_patient_id := patientBody["zb_patient_id"].(string)
  3754. patient.ZbPatientId = zb_patient_id
  3755. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3756. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3757. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3758. }
  3759. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3760. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3761. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3762. if err == nil {
  3763. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3764. }
  3765. }
  3766. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3767. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3768. patient.FirstDialysisHospital = firstDialysisHospital
  3769. }
  3770. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3771. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3772. if len(thePredialysisCondition) > 0 {
  3773. conditions := make([]string, 0)
  3774. for _, item := range thePredialysisCondition {
  3775. if reflect.TypeOf(item).String() != "string" {
  3776. continue
  3777. }
  3778. condition := item.(string)
  3779. if len(condition) > 0 {
  3780. conditions = append(conditions, condition)
  3781. }
  3782. }
  3783. patient.PredialysisCondition = strings.Join(conditions, ",")
  3784. }
  3785. }
  3786. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3787. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3788. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3789. }
  3790. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3791. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3792. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3793. }
  3794. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3795. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3796. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3797. if err == nil {
  3798. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3799. }
  3800. }
  3801. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3802. partition := int64(patientBody["partition"].(float64))
  3803. patient.PartitionId = partition
  3804. }
  3805. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3806. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3807. patient.BedId = bed
  3808. }
  3809. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3810. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3811. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3812. if err == nil {
  3813. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3814. }
  3815. }
  3816. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3817. blood := int64(patientBody["blood"].(float64))
  3818. patient.BloodType = blood
  3819. }
  3820. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3821. rh := int64(patientBody["rh"].(float64))
  3822. patient.Rh = rh
  3823. }
  3824. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3825. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3826. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3827. if err == nil {
  3828. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3829. }
  3830. }
  3831. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3832. receivingDate := patientBody["receivingDate"].(string)
  3833. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3834. if err == nil {
  3835. patient.ReceivingDate = receivingDateTime.Unix()
  3836. }
  3837. }
  3838. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3839. induction := int64(patientBody["induction"].(float64))
  3840. patient.InductionPeriod = induction
  3841. }
  3842. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3843. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3844. patient.InitialDialysis = initial
  3845. }
  3846. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3847. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3848. patient.TotalDialysis = dialysisTotal
  3849. }
  3850. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3851. thisContagions, _ := patientBody["contagions"].([]interface{})
  3852. if len(thisContagions) > 0 {
  3853. for _, item := range thisContagions {
  3854. if reflect.TypeOf(item).String() != "float64" {
  3855. continue
  3856. }
  3857. contagion := int64(item.(float64))
  3858. if contagion > 0 {
  3859. contagions = append(contagions, contagion)
  3860. }
  3861. }
  3862. }
  3863. }
  3864. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3865. doctor := int64(patientBody["doctor"].(float64))
  3866. patient.AttendingDoctorId = doctor
  3867. }
  3868. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3869. nurse := int64(patientBody["nurse"].(float64))
  3870. patient.HeadNurseId = nurse
  3871. }
  3872. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3873. assessment := patientBody["assessment"].(string)
  3874. patient.Evaluate = assessment
  3875. }
  3876. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3877. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3878. if len(thisDiseases) > 0 {
  3879. for _, item := range thisDiseases {
  3880. if reflect.TypeOf(item).String() != "float64" {
  3881. continue
  3882. }
  3883. disease := int64(item.(float64))
  3884. if disease > 0 {
  3885. diseases = append(diseases, disease)
  3886. }
  3887. }
  3888. }
  3889. }
  3890. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3891. diagnose := patientBody["diagnose"].(string)
  3892. patient.Diagnose = diagnose
  3893. }
  3894. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3895. remark := patientBody["remark"].(string)
  3896. patient.Remark = remark
  3897. }
  3898. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3899. sch_remark := patientBody["sch_remark"].(string)
  3900. patient.SchRemark = sch_remark
  3901. }
  3902. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3903. patient_complains := patientBody["patient_complains"].(string)
  3904. patient.PatientComplains = patient_complains
  3905. }
  3906. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3907. present_history := patientBody["present_history"].(string)
  3908. patient.PresentHistory = present_history
  3909. }
  3910. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3911. past_history := patientBody["past_history"].(string)
  3912. patient.PastHistory = past_history
  3913. }
  3914. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3915. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3916. patient.Temperature = temperature
  3917. }
  3918. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3919. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3920. patient.Pulse = pulse
  3921. }
  3922. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3923. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3924. patient.Respiratory = respiratory
  3925. }
  3926. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3927. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3928. patient.SBP = sbp
  3929. }
  3930. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3931. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3932. patient.DBP = dbp
  3933. }
  3934. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3935. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3936. patient.DialysisAge = dialysis_age
  3937. }
  3938. fmt.Println(patient.DialysisAge)
  3939. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3940. first_treatment_date := patientBody["first_treatment_date"].(string)
  3941. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3942. if err == nil {
  3943. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3944. }
  3945. }
  3946. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3947. expense_kind := int64(patientBody["expense_kind"].(float64))
  3948. patient.ExpenseKind = expense_kind
  3949. }
  3950. fmt.Println(patient.ExpenseKind)
  3951. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3952. tell_phone := patientBody["tell_phone"].(string)
  3953. patient.TellPhone = tell_phone
  3954. }
  3955. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3956. contact_name := patientBody["contact_name"].(string)
  3957. patient.ContactName = contact_name
  3958. }
  3959. if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
  3960. troble_shoot := int64(patientBody["troble_shoot"].(float64))
  3961. patient.TrobleShoot = troble_shoot
  3962. }
  3963. if patientBody["treatment_plan"] != nil && reflect.TypeOf(patientBody["treatment_plan"]).String() == "string" {
  3964. treatment_plan := patientBody["treatment_plan"].(string)
  3965. patient.TreatmentPlan = treatment_plan
  3966. }
  3967. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3968. doctor := int64(patientBody["doctor"].(float64))
  3969. patient.Doctor = doctor
  3970. }
  3971. return
  3972. }
  3973. func (c *PatientApiController) GetPatientsByKeyWord() {
  3974. keyWord := c.GetString("keyword")
  3975. adminUserInfo := c.GetAdminUserInfo()
  3976. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3977. if err != nil {
  3978. utils.ErrorLog(err.Error())
  3979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3980. return
  3981. }
  3982. c.ServeSuccessJSON(map[string]interface{}{
  3983. "patient": patient,
  3984. })
  3985. }
  3986. func (c *PatientApiController) QueryPatientById() {
  3987. id, _ := c.GetInt64("id")
  3988. fmt.Println(id)
  3989. patientInfo := service.QueryPatientById(id)
  3990. c.ServeSuccessJSON(map[string]interface{}{
  3991. "patient": patientInfo,
  3992. })
  3993. return
  3994. }
  3995. func (c *PatientApiController) GetRemindPatientList() {
  3996. page, _ := c.GetInt64("page", 1)
  3997. limit, _ := c.GetInt64("limit", 10)
  3998. adminUserInfo := c.GetAdminUserInfo()
  3999. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  4000. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  4001. if errcode == gorm.ErrRecordNotFound {
  4002. information, err := service.GetAdminUserRoleInformation(0)
  4003. if err != nil {
  4004. utils.ErrorLog(err.Error())
  4005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4006. return
  4007. }
  4008. c.ServeSuccessJSON(map[string]interface{}{
  4009. "total": total,
  4010. "patients": patients,
  4011. "information": information,
  4012. })
  4013. } else if errcode == nil {
  4014. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  4015. if err != nil {
  4016. utils.ErrorLog(err.Error())
  4017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4018. return
  4019. }
  4020. c.ServeSuccessJSON(map[string]interface{}{
  4021. "total": total,
  4022. "patients": patients,
  4023. "information": information,
  4024. })
  4025. }
  4026. }
  4027. func (c *PatientApiController) PostIsOpenRemind() {
  4028. patient_id, _ := c.GetInt64("id", 1)
  4029. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  4030. adminUserInfo := c.GetAdminUserInfo()
  4031. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  4032. if err == nil {
  4033. c.ServeSuccessJSON(map[string]interface{}{
  4034. "msg": "成功",
  4035. "is_open_remind": is_open_remind,
  4036. })
  4037. } else if err != nil {
  4038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4039. }
  4040. }
  4041. func (c *PatientApiController) GetPatientScheduleOne() {
  4042. id, _ := c.GetInt64("id")
  4043. //查询该病人是否当天是排班
  4044. nowDateTime := time.Now()
  4045. nowDate := nowDateTime.Format("2006-01-02")
  4046. nowDate += " 00:00:00"
  4047. timeLayout := "2006-01-02"
  4048. loc, _ := time.LoadLocation("Local")
  4049. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  4050. nowdate := theTime.Unix()
  4051. fmt.Println("nowdate", nowdate)
  4052. adminUser := c.GetAdminUserInfo()
  4053. orgId := adminUser.CurrentOrgId
  4054. fmt.Println("orgid", orgId)
  4055. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  4056. if err != nil {
  4057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4058. return
  4059. }
  4060. c.ServeSuccessJSON(map[string]interface{}{
  4061. "scheduls": scheduls,
  4062. })
  4063. }
  4064. func (c *PatientApiController) ExportPatients() {
  4065. dataBody := make(map[string]interface{}, 0)
  4066. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  4067. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  4068. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  4069. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4070. if err != nil {
  4071. utils.ErrorLog(err.Error())
  4072. return
  4073. }
  4074. utils.ErrorLog("%v", dataBody)
  4075. export_time := time.Now().Unix()
  4076. var patients []*models.Patients
  4077. var total_patients []interface{}
  4078. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  4079. tempPatients := dataBody["patients"].([]interface{})
  4080. total_patients = tempPatients
  4081. for index, patientMap := range tempPatients {
  4082. patientNameM := patientMap.(map[string]interface{})
  4083. var patient models.Patients
  4084. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  4085. utils.ErrorLog("name")
  4086. return
  4087. }
  4088. name, _ := patientNameM["name"].(string)
  4089. if len(name) == 0 { //名字为空则生成一条导入错误日志
  4090. err_log := models.ExportErrLog{
  4091. LogType: 1,
  4092. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4093. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  4094. Status: 1,
  4095. CreateTime: time.Now().Unix(),
  4096. UpdateTime: time.Now().Unix(),
  4097. ExportTime: export_time,
  4098. }
  4099. service.CreateExportErrLog(&err_log)
  4100. continue
  4101. }
  4102. patient.Name = name
  4103. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  4104. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  4105. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  4106. err_log := models.ExportErrLog{
  4107. LogType: 1,
  4108. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4109. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  4110. Status: 1,
  4111. CreateTime: time.Now().Unix(),
  4112. UpdateTime: time.Now().Unix(),
  4113. ExportTime: export_time,
  4114. }
  4115. service.CreateExportErrLog(&err_log)
  4116. continue
  4117. } else {
  4118. patient.Gender = gender
  4119. }
  4120. }
  4121. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  4122. phone, _ := patientNameM["phone"].(string)
  4123. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  4124. if len(phone) == 0 {
  4125. err_log := models.ExportErrLog{
  4126. LogType: 1,
  4127. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4128. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  4129. Status: 1,
  4130. CreateTime: time.Now().Unix(),
  4131. UpdateTime: time.Now().Unix(),
  4132. ExportTime: export_time,
  4133. }
  4134. service.CreateExportErrLog(&err_log)
  4135. continue
  4136. } else {
  4137. err_log := models.ExportErrLog{
  4138. LogType: 1,
  4139. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4140. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  4141. Status: 1,
  4142. CreateTime: time.Now().Unix(),
  4143. UpdateTime: time.Now().Unix(),
  4144. ExportTime: export_time,
  4145. }
  4146. service.CreateExportErrLog(&err_log)
  4147. continue
  4148. }
  4149. } else {
  4150. //var tempPatient *models.Patients
  4151. //for _, item := range all_patient {
  4152. // if item.Phone == phone {
  4153. // tempPatient = item
  4154. // }
  4155. //}
  4156. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  4157. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  4158. if count >= 1 {
  4159. err_log := models.ExportErrLog{
  4160. LogType: 1,
  4161. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4162. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  4163. Status: 1,
  4164. CreateTime: time.Now().Unix(),
  4165. UpdateTime: time.Now().Unix(),
  4166. ExportTime: export_time,
  4167. }
  4168. service.CreateExportErrLog(&err_log)
  4169. continue
  4170. }
  4171. patient.Phone = phone
  4172. }
  4173. }
  4174. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  4175. id_card_no, _ := patientNameM["id_card_no"].(string)
  4176. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  4177. if len(id_card_no) == 0 {
  4178. err_log := models.ExportErrLog{
  4179. LogType: 1,
  4180. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4181. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  4182. Status: 1,
  4183. CreateTime: time.Now().Unix(),
  4184. UpdateTime: time.Now().Unix(),
  4185. ExportTime: export_time,
  4186. }
  4187. service.CreateExportErrLog(&err_log)
  4188. continue
  4189. } else {
  4190. err_log := models.ExportErrLog{
  4191. LogType: 1,
  4192. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4193. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  4194. Status: 1,
  4195. CreateTime: time.Now().Unix(),
  4196. UpdateTime: time.Now().Unix(),
  4197. ExportTime: export_time,
  4198. }
  4199. service.CreateExportErrLog(&err_log)
  4200. continue
  4201. }
  4202. } else {
  4203. //var tempPatient *models.Patients
  4204. //for _, item := range all_patient {
  4205. // if item.IdCardNo == id_card_no {
  4206. // tempPatient = item
  4207. // }
  4208. //}
  4209. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4210. if count >= 1 {
  4211. //if tempPatient != nil && tempPatient.ID > 0 {
  4212. err_log := models.ExportErrLog{
  4213. LogType: 1,
  4214. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4215. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  4216. Status: 1,
  4217. CreateTime: time.Now().Unix(),
  4218. UpdateTime: time.Now().Unix(),
  4219. ExportTime: export_time,
  4220. }
  4221. service.CreateExportErrLog(&err_log)
  4222. continue
  4223. }
  4224. //}
  4225. patient.IdCardNo = id_card_no
  4226. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  4227. if GetBirthDay(id_card_no) == nil {
  4228. patient.Birthday = 0
  4229. } else {
  4230. patient.Birthday = GetBirthDay(id_card_no).Unix()
  4231. }
  4232. }
  4233. }
  4234. fmt.Println("111112222")
  4235. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  4236. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  4237. timeLayout := "2006/01/02"
  4238. loc, _ := time.LoadLocation("Local")
  4239. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  4240. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4241. if len(first_treatment_date) == 0 {
  4242. err_log := models.ExportErrLog{
  4243. LogType: 1,
  4244. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4245. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4246. Status: 1,
  4247. CreateTime: time.Now().Unix(),
  4248. UpdateTime: time.Now().Unix(),
  4249. ExportTime: export_time,
  4250. }
  4251. service.CreateExportErrLog(&err_log)
  4252. continue
  4253. } else {
  4254. err_log := models.ExportErrLog{
  4255. LogType: 1,
  4256. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4257. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4258. Status: 1,
  4259. CreateTime: time.Now().Unix(),
  4260. UpdateTime: time.Now().Unix(),
  4261. ExportTime: export_time,
  4262. }
  4263. service.CreateExportErrLog(&err_log)
  4264. continue
  4265. }
  4266. } else {
  4267. if len(first_treatment_date) == 0 {
  4268. err_log := models.ExportErrLog{
  4269. LogType: 1,
  4270. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4271. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  4272. Status: 1,
  4273. CreateTime: time.Now().Unix(),
  4274. UpdateTime: time.Now().Unix(),
  4275. ExportTime: export_time,
  4276. }
  4277. service.CreateExportErrLog(&err_log)
  4278. continue
  4279. } else {
  4280. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  4281. err_log := models.ExportErrLog{
  4282. LogType: 1,
  4283. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4284. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  4285. Status: 1,
  4286. CreateTime: time.Now().Unix(),
  4287. UpdateTime: time.Now().Unix(),
  4288. ExportTime: export_time,
  4289. }
  4290. service.CreateExportErrLog(&err_log)
  4291. continue
  4292. } else {
  4293. patient.FirstDialysisDate = first_dialysis_date.Unix()
  4294. }
  4295. }
  4296. }
  4297. }
  4298. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  4299. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  4300. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  4301. err_log := models.ExportErrLog{
  4302. LogType: 1,
  4303. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4304. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  4305. Status: 1,
  4306. CreateTime: time.Now().Unix(),
  4307. UpdateTime: time.Now().Unix(),
  4308. ExportTime: export_time,
  4309. }
  4310. service.CreateExportErrLog(&err_log)
  4311. continue
  4312. } else if source == 3 {
  4313. err_log := models.ExportErrLog{
  4314. LogType: 1,
  4315. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4316. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  4317. Status: 1,
  4318. CreateTime: time.Now().Unix(),
  4319. UpdateTime: time.Now().Unix(),
  4320. ExportTime: export_time,
  4321. }
  4322. service.CreateExportErrLog(&err_log)
  4323. continue
  4324. } else {
  4325. patient.Source = source
  4326. }
  4327. }
  4328. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  4329. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  4330. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  4331. err_log := models.ExportErrLog{
  4332. LogType: 1,
  4333. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4334. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  4335. Status: 1,
  4336. CreateTime: time.Now().Unix(),
  4337. UpdateTime: time.Now().Unix(),
  4338. ExportTime: export_time,
  4339. }
  4340. service.CreateExportErrLog(&err_log)
  4341. continue
  4342. } else if lapseto == 3 {
  4343. err_log := models.ExportErrLog{
  4344. LogType: 1,
  4345. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4346. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  4347. Status: 1,
  4348. CreateTime: time.Now().Unix(),
  4349. UpdateTime: time.Now().Unix(),
  4350. ExportTime: export_time,
  4351. }
  4352. service.CreateExportErrLog(&err_log)
  4353. continue
  4354. } else {
  4355. patient.Lapseto = lapseto
  4356. }
  4357. }
  4358. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  4359. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  4360. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  4361. err_log := models.ExportErrLog{
  4362. LogType: 1,
  4363. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4364. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  4365. Status: 1,
  4366. CreateTime: time.Now().Unix(),
  4367. UpdateTime: time.Now().Unix(),
  4368. ExportTime: export_time,
  4369. }
  4370. service.CreateExportErrLog(&err_log)
  4371. continue
  4372. } else if is_infectious == 3 {
  4373. err_log := models.ExportErrLog{
  4374. LogType: 1,
  4375. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4376. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  4377. Status: 1,
  4378. CreateTime: time.Now().Unix(),
  4379. UpdateTime: time.Now().Unix(),
  4380. ExportTime: export_time,
  4381. }
  4382. service.CreateExportErrLog(&err_log)
  4383. continue
  4384. } else {
  4385. patient.IsInfectious = is_infectious
  4386. }
  4387. }
  4388. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  4389. var contagions []int64
  4390. thisContagions, _ := patientNameM["contagions"].([]interface{})
  4391. if len(thisContagions) > 0 {
  4392. for _, item := range thisContagions {
  4393. if reflect.TypeOf(item).String() != "float64" {
  4394. continue
  4395. }
  4396. contagion := int64(item.(float64))
  4397. if contagion > 0 {
  4398. contagions = append(contagions, contagion)
  4399. }
  4400. }
  4401. }
  4402. patient.ContagionIds = contagions
  4403. }
  4404. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  4405. diagnose, _ := patientNameM["diagnose"].(string)
  4406. patient.Diagnose = diagnose
  4407. }
  4408. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  4409. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  4410. var tempPatient *models.Patients
  4411. for _, item := range all_patient {
  4412. if item.DialysisNo == dialysis_no {
  4413. tempPatient = item
  4414. }
  4415. }
  4416. if tempPatient != nil && tempPatient.ID > 0 {
  4417. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  4418. } else {
  4419. patient.DialysisNo = dialysis_no
  4420. }
  4421. }
  4422. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  4423. height, _ := patientNameM["height"].(string)
  4424. heights, _ := strconv.ParseFloat(height, 64)
  4425. patient.Height = int64(heights)
  4426. }
  4427. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  4428. home_address, _ := patientNameM["home_address"].(string)
  4429. patient.HomeAddress = home_address
  4430. }
  4431. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  4432. dry_weight, _ := patientNameM["dry_weight"].(string)
  4433. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  4434. patient.DryWeight = dry_weights
  4435. }
  4436. patient.CreatedTime = time.Now().Unix()
  4437. patient.UpdatedTime = time.Now().Unix()
  4438. patient.Status = 1
  4439. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  4440. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  4441. patient.IsExcelExport = 1
  4442. patient.PatientType = 1
  4443. patients = append(patients, &patient)
  4444. }
  4445. }
  4446. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  4447. if len(patients) > 0 {
  4448. for _, item := range patients {
  4449. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  4450. }
  4451. log := models.ExportLog{
  4452. LogType: 1,
  4453. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4454. TotalNum: int64(len(total_patients)),
  4455. FailNum: int64(len(errLogs)),
  4456. SuccessNum: int64(len(patients)),
  4457. CreateTime: time.Now().Unix(),
  4458. UpdateTime: time.Now().Unix(),
  4459. ExportTime: export_time,
  4460. Status: 1,
  4461. }
  4462. service.CreateExportLog(&log)
  4463. c.ServeSuccessJSON(map[string]interface{}{
  4464. "msg": "导入成功",
  4465. "total_num": len(total_patients),
  4466. "success_num": len(patients),
  4467. "fail_num": int64(len(errLogs)),
  4468. })
  4469. } else {
  4470. log := models.ExportLog{
  4471. LogType: 1,
  4472. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4473. TotalNum: int64(len(total_patients)),
  4474. FailNum: int64(len(errLogs)),
  4475. SuccessNum: int64(len(patients)),
  4476. CreateTime: time.Now().Unix(),
  4477. UpdateTime: time.Now().Unix(),
  4478. ExportTime: export_time,
  4479. Status: 1,
  4480. }
  4481. service.CreateExportLog(&log)
  4482. c.ServeSuccessJSON(map[string]interface{}{
  4483. "msg": "导入成功",
  4484. "total_num": len(total_patients),
  4485. "success_num": len(patients),
  4486. "fail_num": int64(len(errLogs)),
  4487. })
  4488. }
  4489. }
  4490. func GetBirthDay(IDCardNo string) *time.Time {
  4491. dayStr := IDCardNo[6:14]
  4492. birthDay, err := time.Parse("20060102", dayStr)
  4493. if err != nil {
  4494. fmt.Println(err)
  4495. return nil
  4496. }
  4497. return &birthDay
  4498. }
  4499. func IsIdCard(id string) (res bool) {
  4500. id = strings.ToUpper(id)
  4501. if len(id) != 15 && len(id) != 18 {
  4502. fmt.Println("1111111")
  4503. return false
  4504. }
  4505. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  4506. if !r.MatchString(id) {
  4507. fmt.Println("222222")
  4508. return false
  4509. }
  4510. if len(id) == 15 {
  4511. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  4512. if tm2.Unix() == 0 {
  4513. fmt.Println("44444443333")
  4514. return false
  4515. }
  4516. return true
  4517. } else {
  4518. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  4519. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  4520. fmt.Println(tm2.Unix())
  4521. if tm2.Unix() == 0 {
  4522. fmt.Println("44445555555")
  4523. return false
  4524. }
  4525. //检验18位身份证的校验码是否正确。
  4526. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  4527. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  4528. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  4529. sign := 0
  4530. for k, v := range arr_int {
  4531. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  4532. sign += int_temp * v
  4533. }
  4534. n := sign % 11
  4535. val_num := arr_ch[n]
  4536. if val_num != string([]byte(id)[17:18]) {
  4537. fmt.Println("5556666666")
  4538. return false
  4539. }
  4540. return true
  4541. }
  4542. }
  4543. func (c *PatientApiController) SaveEditAdvices() {
  4544. adminInfo := c.GetAdminUserInfo()
  4545. orgid := adminInfo.CurrentOrgId
  4546. startTime := c.GetString("start_time")
  4547. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  4548. groupno, _ := c.GetInt64("groupno")
  4549. fmt.Println("组", groupno)
  4550. date, _ := c.GetInt64("date")
  4551. fmt.Println("date", date)
  4552. patient_id, _ := c.GetInt64("patient_id")
  4553. fmt.Println("paitent_id", patient_id)
  4554. advice := models.XtDoctorAdvice{
  4555. StartTime: theTime.Unix(),
  4556. }
  4557. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  4558. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  4559. redis := service.RedisClient()
  4560. redis.Set(key, "", time.Second)
  4561. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  4562. redis.Set(keyOne, "", time.Second)
  4563. scheduleTime := theTime.Format("2006-01-02")
  4564. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  4565. fmt.Println("keyFour323223323232323232", keyFour)
  4566. redis.Set(keyFour, "", time.Second)
  4567. defer redis.Close()
  4568. if err != nil {
  4569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4570. return
  4571. }
  4572. c.ServeSuccessJSON(map[string]interface{}{
  4573. "advice": advice,
  4574. })
  4575. }
  4576. func (c *PatientApiController) GetMaxDialysisNo() {
  4577. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  4578. c.ServeSuccessJSON(map[string]interface{}{
  4579. "dialysis_no": dialysisNo,
  4580. })
  4581. }
  4582. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  4583. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  4584. var tempPatient *models.Patients
  4585. for _, item := range patients {
  4586. if item.DialysisNo == dialysisNo2 {
  4587. tempPatient = item
  4588. }
  4589. }
  4590. if tempPatient == nil || tempPatient.ID == 0 {
  4591. return dialysisNo2
  4592. }
  4593. return GenerateDialysisNoTwo(patients)
  4594. }
  4595. func (c *PatientApiController) GetBanner() {
  4596. orgId := c.GetAdminUserInfo().CurrentOrgId
  4597. _, errcodes := service.GetOrgFollowIsExist(orgId)
  4598. if errcodes == gorm.ErrRecordNotFound {
  4599. information, err := service.GetAdminUserRoleInformation(0)
  4600. if err != nil {
  4601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4602. return
  4603. }
  4604. c.ServeSuccessJSON(map[string]interface{}{
  4605. "information": information,
  4606. })
  4607. } else if errcodes == nil {
  4608. information, err := service.GetAdminUserRoleInformation(orgId)
  4609. if err != nil {
  4610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4611. return
  4612. }
  4613. c.ServeSuccessJSON(map[string]interface{}{
  4614. "information": information,
  4615. })
  4616. }
  4617. }
  4618. func (c *PatientApiController) GetPatientDialysisLongSolution() {
  4619. patient_id, _ := c.GetInt64("id", 0)
  4620. page, _ := c.GetInt64("page", 0)
  4621. limit, _ := c.GetInt64("limit", 0)
  4622. if patient_id <= 0 {
  4623. c.ServeSuccessJSON(map[string]interface{}{
  4624. "solutions": nil,
  4625. })
  4626. return
  4627. }
  4628. if page <= 0 {
  4629. page = 1
  4630. }
  4631. if limit <= 0 {
  4632. limit = 10
  4633. }
  4634. adminUserInfo := c.GetAdminUserInfo()
  4635. //获取该患者分组的透析模式
  4636. list, _ := service.GetPatientSolutionGroupList(patient_id, adminUserInfo.CurrentOrgId)
  4637. for _, item := range list {
  4638. //获取该模式最新的1条数据
  4639. solution, _ := service.GetNewPatientSolutionByModeId(patient_id, item.ModeId, adminUserInfo.CurrentOrgId)
  4640. //更新状态值
  4641. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, adminUserInfo.CurrentOrgId, patient_id)
  4642. }
  4643. solution, total, err := service.GetPatientDialysisLongSolution(patient_id, page, limit, adminUserInfo.CurrentOrgId)
  4644. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  4645. if err != nil {
  4646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4647. return
  4648. }
  4649. c.ServeSuccessJSON(map[string]interface{}{
  4650. "solutions": solution,
  4651. "total": total,
  4652. "stockType": stockType,
  4653. })
  4654. }
  4655. func (c *PatientApiController) GetDialysisSolutionDetailList() {
  4656. patient_id, _ := c.GetInt64("patient_id")
  4657. mode_id, _ := c.GetInt64("mode_id")
  4658. page, _ := c.GetInt64("page")
  4659. limit, _ := c.GetInt64("limit")
  4660. orgId := c.GetAdminUserInfo().CurrentOrgId
  4661. list, total, err := service.GetDialysisSolutionDetailList(orgId, patient_id, mode_id, page, limit)
  4662. if err != nil {
  4663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4664. return
  4665. }
  4666. c.ServeSuccessJSON(map[string]interface{}{
  4667. "list": list,
  4668. "total": total,
  4669. })
  4670. }