patient_api_controller.go 173KB

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