patient_api_controller.go 181KB

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