patient_api_controller.go 175KB

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