patient_api_controller.go 158KB

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