patient_api_controller.go 179KB

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