patient_api_controller.go 163KB

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