patient_api_controller.go 181KB

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