patient_api_controller.go 181KB

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