patient_api_controller.go 179KB

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