patient_api_controller.go 159KB

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