patient_api_controller.go 144KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  274. defer redis.Close()
  275. redis.Set(key, "", time.Second)
  276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  277. redis.Set(keyOne, "", time.Second)
  278. isChangeGroup = false
  279. } else {
  280. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  281. isChangeGroup = false
  282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  283. defer redis.Close()
  284. redis.Set(key, "", time.Second)
  285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  286. redis.Set(keyOne, "", time.Second)
  287. }
  288. } else if len(adviceSlice) > 1 {
  289. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  290. if advice.StartTime == sourceAdvice.StartTime {
  291. err = service.UpdateDoctorAdvice(&advice)
  292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  293. defer redis.Close()
  294. redis.Set(key, "", time.Second)
  295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  296. redis.Set(keyOne, "", time.Second)
  297. isChangeGroup = false
  298. } else {
  299. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  300. gruopNo = gruopNo + 1
  301. advice.GroupNo = gruopNo
  302. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  304. defer redis.Close()
  305. redis.Set(key, "", time.Second)
  306. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  307. redis.Set(keyOne, "", time.Second)
  308. isChangeGroup = true
  309. }
  310. }
  311. } else {
  312. isChangeGroup = false
  313. err = service.UpdateDoctorAdvice(&advice)
  314. redis := service.RedisClient()
  315. defer redis.Close()
  316. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  317. redis.Set(key, "", time.Second)
  318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  319. redis.Set(keyOne, "", time.Second)
  320. }
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  323. return
  324. }
  325. if !isChangeGroup {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "msg": "ok",
  328. "advice": advice,
  329. "isChange": isChangeGroup, //方便前端处理数据
  330. })
  331. } else {
  332. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "msg": "ok",
  339. "advice": newGroupAdvice,
  340. "isChange": isChangeGroup, //方便前端处理数据
  341. })
  342. }
  343. return
  344. }
  345. func (c *PatientApiController) StopDoctorAdvice() {
  346. id, _ := c.GetInt64("id", 0)
  347. if id <= 0 {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. adminUserInfo := c.GetMobileAdminUserInfo()
  352. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  353. if advice.ID == 0 {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  355. return
  356. }
  357. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  358. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  359. // return
  360. //}
  361. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  362. //
  363. //if appRole.UserType == 3 {
  364. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  365. // if getPermissionErr != nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // } else if headNursePermission == nil {
  369. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  370. // return
  371. // }
  372. //}
  373. if advice.StopState == 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  375. return
  376. }
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  386. utils.ErrorLog("stop_time")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. stopTime, _ := dataBody["stop_time"].(string)
  391. if len(stopTime) == 0 {
  392. utils.ErrorLog("len(stop_time) == 0")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. advice.StopTime = theTime.Unix()
  403. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  404. utils.ErrorLog("stop_reason")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. stopReason, _ := dataBody["stop_reason"].(string)
  409. if len(stopReason) == 0 {
  410. utils.ErrorLog("len(stop_reason) == 0")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. advice.StopReason = stopReason
  415. advice.Status = 1
  416. advice.UpdatedTime = time.Now().Unix()
  417. advice.StopDoctor = adminUserInfo.AdminUser.Id
  418. advice.StopState = 1
  419. advice.StopTime = time.Now().Unix()
  420. advice.Modifier = adminUserInfo.AdminUser.Id
  421. err = service.StopDoctorAdvice(&advice)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  424. return
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "ok",
  428. "advice": advice,
  429. })
  430. return
  431. }
  432. func (c *PatientApiController) DeleteDoctorAdvice() {
  433. id, _ := c.GetInt64("id", 0)
  434. if id <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetMobileAdminUserInfo()
  439. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  440. if advice.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  442. return
  443. }
  444. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  446. // return
  447. //}
  448. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  449. //
  450. //if appRole.UserType == 3 {
  451. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  452. // if getPermissionErr != nil {
  453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  454. // return
  455. // } else if headNursePermission == nil {
  456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  457. // return
  458. // }
  459. //}
  460. advice.UpdatedTime = time.Now().Unix()
  461. advice.Status = 0
  462. advice.Modifier = adminUserInfo.AdminUser.Id
  463. err := service.DeleteDoctorAdvice(&advice)
  464. if err != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  466. return
  467. }
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "ok",
  470. })
  471. return
  472. }
  473. func (c *PatientApiController) ExecDoctorAdvice() {
  474. execution_time := c.GetString("execution_time")
  475. origin, _ := c.GetInt64("origin", 0)
  476. groupno, _ := c.GetInt64("groupno", -1)
  477. if origin != 2 {
  478. var ids []string
  479. if groupno == 0 {
  480. advice_ids := c.GetString("advice_id")
  481. ids = strings.Split(advice_ids, ",")
  482. }
  483. if groupno < 0 {
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. if len(execution_time) <= 0 {
  488. utils.ErrorLog("execution_time")
  489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  490. return
  491. }
  492. timeLayout2 := "2006-01-02 15:04:05"
  493. loc, _ := time.LoadLocation("Local")
  494. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  495. if errs != nil {
  496. utils.ErrorLog(errs.Error())
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. adminUserInfo := c.GetMobileAdminUserInfo()
  501. var advice models.DoctorAdvice
  502. if groupno > 0 {
  503. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  504. for _, item := range advices {
  505. if item.ExecutionState == 2 {
  506. advice = item
  507. }
  508. }
  509. } else {
  510. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  511. for _, item := range advices {
  512. if item.ExecutionState == 2 {
  513. advice = item
  514. }
  515. }
  516. }
  517. if advice.ExecutionState == 1 {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  519. return
  520. }
  521. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  523. return
  524. }
  525. if advice.StartTime > theTime.Unix() {
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  527. return
  528. }
  529. execution_staff := adminUserInfo.AdminUser.Id
  530. advices := models.DoctorAdvice{
  531. ExecutionStaff: execution_staff,
  532. ExecutionTime: theTime.Unix(),
  533. UpdatedTime: time.Now().Unix(),
  534. }
  535. var err error
  536. if groupno > 0 {
  537. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  539. redis := service.RedisClient()
  540. //清空key 值
  541. redis.Set(key, "", time.Second)
  542. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  543. redis.Set(keyTwo, "", time.Second)
  544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  545. redis.Set(keyThree, "", time.Second)
  546. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  547. theTime := toTime.Format("2006-01-02")
  548. fmt.Println("theTIME", theTime)
  549. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  550. fmt.Println("keyFour323223323232323232", keyFour)
  551. redis.Set(keyFour, "", time.Second)
  552. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  553. redis.Set(keyFive, "", time.Second)
  554. defer redis.Close()
  555. } else {
  556. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  557. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  558. redis := service.RedisClient()
  559. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  560. redis.Set(keyTwo, "", time.Second)
  561. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  562. redis.Set(keyThree, "", time.Second)
  563. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  564. theTime := toTime.Format("2006-01-02")
  565. fmt.Println("theTIME", theTime)
  566. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  567. fmt.Println("keyFour323223323232323232", keyFour)
  568. redis.Set(keyFour, "", time.Second)
  569. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  570. redis.Set(keySix, "", time.Second)
  571. defer redis.Close()
  572. //清空key 值
  573. redis.Set(key, "", time.Second)
  574. }
  575. if err != nil {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  577. return
  578. }
  579. advice.ExecutionStaff = execution_staff
  580. advice.ExecutionTime = theTime.Unix()
  581. advice.ExecutionState = 1
  582. advice.Modifier = adminUserInfo.AdminUser.Id
  583. //处理出库相关逻辑
  584. //1.判断是否启用药品管理和自备药出库功能
  585. //药品管理信息
  586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  587. //自备药信息
  588. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  589. if drugStockConfig.IsOpen == 1 {
  590. if groupno > 0 {
  591. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  592. isHasWay := false //用来判断是否包含来自药品库的医嘱
  593. for _, item := range advices {
  594. if item.Way == 1 {
  595. isHasWay = true
  596. }
  597. }
  598. if isHasWay {
  599. var total int64
  600. var prescribing_number_total int64
  601. for _, item := range advices {
  602. if item.Way == 1 {
  603. //查询该药品的剩余库存
  604. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  605. //查询改药品信息
  606. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  607. //判断单位是否相等
  608. if medical.MaxUnit == item.PrescribingNumberUnit {
  609. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  610. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  611. //转化为最小单位
  612. total = list.Count * medical.MinNumber
  613. prescribing_number_total = count * medical.MinNumber
  614. }
  615. if medical.MinUnit == item.PrescribingNumberUnit {
  616. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  617. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  618. total = list.Count*medical.MinNumber + list.StockMinNumber
  619. prescribing_number_total = count
  620. }
  621. fmt.Println("开医嘱数量", prescribing_number_total)
  622. fmt.Println("剩余库存", total)
  623. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  624. c.ServeSuccessJSON(map[string]interface{}{
  625. "msg": "3",
  626. "advice": advice,
  627. "ids": ids,
  628. })
  629. return
  630. }
  631. if prescribing_number_total > total {
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "msg": "2",
  634. "advice": advice,
  635. "ids": ids,
  636. })
  637. return
  638. }
  639. if prescribing_number_total <= total {
  640. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  641. }
  642. }
  643. }
  644. }
  645. c.ServeSuccessJSON(map[string]interface{}{
  646. "msg": "1",
  647. "advice": advice,
  648. "ids": ids,
  649. })
  650. return
  651. } else {
  652. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  653. isHasWay := false //用来判断是否包含来自药品库的医嘱
  654. for _, item := range advices {
  655. if item.Way == 1 {
  656. isHasWay = true
  657. }
  658. }
  659. if isHasWay {
  660. var total int64
  661. var prescribing_number_total int64
  662. for _, item := range advices {
  663. if item.Way == 1 {
  664. //查询该药品的剩余库存
  665. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  666. //查询改药品信息
  667. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  668. //判断单位是否相等
  669. if medical.MaxUnit == item.PrescribingNumberUnit {
  670. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  671. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  672. //转化为最小单位
  673. total = list.Count*medical.MinNumber + list.StockMinNumber
  674. prescribing_number_total = count * medical.MinNumber
  675. }
  676. if medical.MinUnit == item.PrescribingNumberUnit {
  677. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  678. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  679. total = list.Count*medical.MinNumber + list.StockMinNumber
  680. prescribing_number_total = count
  681. }
  682. fmt.Println("开医嘱数量", prescribing_number_total)
  683. fmt.Println("剩余库存", total)
  684. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  685. c.ServeSuccessJSON(map[string]interface{}{
  686. "msg": "3",
  687. "advice": advice,
  688. "ids": ids,
  689. })
  690. return
  691. }
  692. if prescribing_number_total > total {
  693. c.ServeSuccessJSON(map[string]interface{}{
  694. "msg": "2",
  695. "advice": advice,
  696. "ids": ids,
  697. })
  698. return
  699. }
  700. if prescribing_number_total <= total {
  701. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  702. c.ServeSuccessJSON(map[string]interface{}{
  703. "msg": "1",
  704. "advice": advice,
  705. "ids": ids,
  706. })
  707. return
  708. }
  709. }
  710. }
  711. }
  712. }
  713. }
  714. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  715. if groupno > 0 {
  716. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  717. for _, item := range advices {
  718. if item.ExecutionState == 1 && item.Way == 2 {
  719. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  720. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  721. timeStr := time.Now().Format("2006-01-02")
  722. timeArr := strings.Split(timeStr, "-")
  723. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  724. total = total + 1
  725. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  726. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  727. number = number + total
  728. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  729. //插入自备药出库单
  730. outStock := models.XtSelfOutStock{
  731. DrugName: item.AdviceName,
  732. DrugNameId: item.DrugNameId,
  733. DrugSpec: item.AdviceDesc,
  734. OutstoreNumber: count,
  735. AdminUserId: adminUserInfo.AdminUser.Id,
  736. StorckTime: item.AdviceDate,
  737. UserOrgId: adminUserInfo.Org.Id,
  738. CreatedTime: time.Now().Unix(),
  739. Status: 1,
  740. PatientId: item.PatientId,
  741. ExitMode: 2,
  742. MedicId: item.DrugId,
  743. StockOutNumber: warehousing_out_order,
  744. }
  745. //查询 该患者是否已出库
  746. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  747. if errcode == gorm.ErrRecordNotFound {
  748. service.CreateOutStock(&outStock)
  749. } else if errcode == nil {
  750. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  751. fmt.Println("err", err)
  752. }
  753. }
  754. }
  755. } else {
  756. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  757. for _, item := range advices {
  758. if item.ExecutionState == 1 && item.Way == 2 {
  759. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  760. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  761. timeStr := time.Now().Format("2006-01-02")
  762. timeArr := strings.Split(timeStr, "-")
  763. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  764. total = total + 1
  765. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  766. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  767. number = number + total
  768. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  769. //插入自备药出库单
  770. outStock := models.XtSelfOutStock{
  771. DrugName: item.AdviceName,
  772. DrugNameId: item.DrugNameId,
  773. DrugSpec: item.AdviceDesc,
  774. OutstoreNumber: count,
  775. AdminUserId: adminUserInfo.AdminUser.Id,
  776. StorckTime: item.AdviceDate,
  777. UserOrgId: adminUserInfo.Org.Id,
  778. CreatedTime: time.Now().Unix(),
  779. Status: 1,
  780. PatientId: item.PatientId,
  781. ExitMode: 2,
  782. MedicId: item.DrugId,
  783. StockOutNumber: warehousing_out_order,
  784. }
  785. //查询 该患者是否已出库
  786. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  787. if errcode == gorm.ErrRecordNotFound {
  788. service.CreateOutStock(&outStock)
  789. } else if errcode == nil {
  790. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  791. fmt.Println("err", err)
  792. }
  793. }
  794. }
  795. c.ServeSuccessJSON(map[string]interface{}{
  796. "msg": "1",
  797. "advice": advice,
  798. "ids": ids,
  799. })
  800. return
  801. }
  802. }
  803. c.ServeSuccessJSON(map[string]interface{}{
  804. "msg": "1",
  805. "advice": advice,
  806. "ids": ids,
  807. })
  808. return
  809. } else if origin == 2 {
  810. var ids []string
  811. advice_ids := c.GetString("advice_id")
  812. ids = strings.Split(advice_ids, ",")
  813. if len(execution_time) <= 0 {
  814. utils.ErrorLog("execution_time")
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  816. return
  817. }
  818. timeLayout2 := "2006-01-02 15:04:05"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  821. if errs != nil {
  822. utils.ErrorLog(errs.Error())
  823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  824. return
  825. }
  826. adminInfo := c.GetMobileAdminUserInfo()
  827. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  828. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  829. var err error
  830. for _, item := range advices {
  831. if item.ExecutionState == 1 {
  832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  833. return
  834. }
  835. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  837. return
  838. }
  839. if item.StartTime > theTime.Unix() {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  841. return
  842. }
  843. item.ExecutionState = 1
  844. item.ExecutionStaff = adminInfo.AdminUser.Id
  845. item.ExecutionTime = theTime.Unix()
  846. err = service.SaveHisDoctorAdvice(item)
  847. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  848. redis := service.RedisClient()
  849. //清空key 值
  850. redis.Set(key, "", time.Second)
  851. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  852. redis.Set(keyTwo, "", time.Second)
  853. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  854. redis.Set(keyThree, "", time.Second)
  855. recordDate := theTime.Format("2006-01-02")
  856. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  857. redis.Set(keyFour, "", time.Second)
  858. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  859. redis.Set(keyFive, "", time.Second)
  860. defer redis.Close()
  861. }
  862. if err == nil {
  863. //药品管理信息
  864. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  865. if drugStockConfig.IsOpen == 1 {
  866. for _, item := range advices {
  867. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  868. var total int64
  869. var prescribing_number_total int64
  870. //查询该药品是否有库存
  871. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  872. //查询改药品信息
  873. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  874. //判断单位是否相等
  875. if medical.MaxUnit == advice.PrescribingNumberUnit {
  876. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  877. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  878. //转化为最小单位
  879. total = list.Count*medical.MinNumber + list.StockMinNumber
  880. prescribing_number_total = count * medical.MinNumber
  881. }
  882. fmt.Println("医嘱开的数量", total)
  883. if medical.MinUnit == advice.PrescribingNumberUnit {
  884. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  885. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  886. total = list.Count*medical.MinNumber + list.StockMinNumber
  887. prescribing_number_total = count
  888. }
  889. fmt.Println("数量一", prescribing_number_total)
  890. fmt.Println("数量二", total)
  891. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  892. c.ServeSuccessJSON(map[string]interface{}{
  893. "msg": "3",
  894. "advice": advice,
  895. "ids": ids,
  896. })
  897. return
  898. }
  899. if prescribing_number_total > total {
  900. c.ServeSuccessJSON(map[string]interface{}{
  901. "msg": "2",
  902. "advice": advice,
  903. "ids": ids,
  904. })
  905. return
  906. }
  907. if prescribing_number_total <= total {
  908. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  909. }
  910. }
  911. }
  912. for _, item := range advices {
  913. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  914. c.ServeSuccessJSON(map[string]interface{}{
  915. "msg": "1",
  916. "advice": advice,
  917. "ids": ids,
  918. })
  919. }
  920. } else {
  921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  922. }
  923. }
  924. }
  925. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  926. execution_time := c.GetString("execution_time")
  927. fmt.Println("execution_time", execution_time)
  928. groupno, _ := c.GetInt64("groupno", -1)
  929. var ids []string
  930. if groupno == 0 {
  931. advice_ids := c.GetString("advice_id")
  932. ids = strings.Split(advice_ids, ",")
  933. }
  934. if groupno < 0 {
  935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. if len(execution_time) <= 0 {
  939. utils.ErrorLog("execution_time")
  940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  941. return
  942. }
  943. timeLayout2 := "2006-01-02 15:04:05"
  944. loc, _ := time.LoadLocation("Local")
  945. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  946. if errs != nil {
  947. utils.ErrorLog(errs.Error())
  948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. adminUserInfo := c.GetMobileAdminUserInfo()
  952. var advice models.DoctorAdvice
  953. if groupno > 0 {
  954. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  955. for _, item := range advices {
  956. if item.ExecutionState == 1 {
  957. advice = item
  958. }
  959. }
  960. } else {
  961. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  962. for _, item := range advices {
  963. if item.ExecutionState == 1 {
  964. advice = item
  965. }
  966. }
  967. }
  968. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  969. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  970. // if getPermissionErr != nil {
  971. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  972. // return
  973. // } else if headNursePermission == nil {
  974. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  975. // return
  976. // }
  977. //}
  978. if advice.StartTime > theTime.Unix() {
  979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  980. return
  981. }
  982. advices := models.DoctorAdvice{
  983. ExecutionTime: theTime.Unix(),
  984. UpdatedTime: time.Now().Unix(),
  985. }
  986. var err error
  987. if groupno > 0 {
  988. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  989. redis := service.RedisClient()
  990. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  991. fmt.Println("keyThh322323232323232323223", key)
  992. redis.Set(key, "", time.Second)
  993. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  994. redis.Set(keyOne, "", time.Second)
  995. defer redis.Close()
  996. } else {
  997. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  998. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  999. redis := service.RedisClient()
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1001. fmt.Println("keyTwohh322323232323232323223", key)
  1002. redis.Set(key, "", time.Second)
  1003. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1004. redis.Set(keyOne, "", time.Second)
  1005. defer redis.Close()
  1006. }
  1007. //判断是否开启his
  1008. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1009. //如果开启去修改执行时间
  1010. if config.IsOpen == 1 {
  1011. advicesinfo := models.HisDoctorAdviceInfo{
  1012. ExecutionTime: theTime.Unix(),
  1013. UpdatedTime: time.Now().Unix(),
  1014. }
  1015. fmt.Println("ids2323232232323", ids)
  1016. var advicehis models.HisDoctorAdviceInfo
  1017. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1018. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1019. for _, item := range his_advices {
  1020. if item.ExecutionState == 1 {
  1021. advicehis = item
  1022. }
  1023. }
  1024. redis := service.RedisClient()
  1025. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1026. redis.Set(keyThree, "", time.Second)
  1027. recordDate := theTime.Format("2006-01-02")
  1028. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1029. redis.Set(keyFour, "", time.Second)
  1030. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1031. redis.Set(keyFive, "", time.Second)
  1032. defer redis.Close()
  1033. project := models.HisPrescriptionProject{
  1034. ExecutionTime: theTime.Unix(),
  1035. Mtime: time.Now().Unix(),
  1036. }
  1037. service.ModifyHisPrescriptionProject(&project, ids)
  1038. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1039. redis.Set(keyEnd, "", time.Second)
  1040. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyFours, "", time.Second)
  1042. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1043. redis.Set(keyFives, "", time.Second)
  1044. defer redis.Close()
  1045. }
  1046. if err != nil {
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1048. return
  1049. }
  1050. advice.ExecutionTime = theTime.Unix()
  1051. c.ServeSuccessJSON(map[string]interface{}{
  1052. "msg": "ok",
  1053. "advice": advice,
  1054. "ids": ids,
  1055. })
  1056. return
  1057. }
  1058. func (c *PatientApiController) CheckDoctorAdvice() {
  1059. origin, _ := c.GetInt64("origin", 0)
  1060. if origin != 2 {
  1061. groupno, _ := c.GetInt64("groupno", -1)
  1062. var ids []string
  1063. if groupno == 0 {
  1064. advice_ids := c.GetString("advice_id")
  1065. if advice_ids == "" {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. } else {
  1069. ids = strings.Split(advice_ids, ",")
  1070. if len(ids) <= 0 {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1072. return
  1073. }
  1074. }
  1075. }
  1076. if groupno < 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. var advice models.DoctorAdvice
  1082. if groupno > 0 {
  1083. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1084. for _, item := range advices {
  1085. if item.CheckState == 0 {
  1086. advice = item
  1087. }
  1088. }
  1089. if advice.CheckState == 1 {
  1090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1091. return
  1092. }
  1093. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1095. return
  1096. }
  1097. } else {
  1098. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1099. for _, item := range advices {
  1100. if item.CheckState == 0 {
  1101. advice = item
  1102. }
  1103. }
  1104. if advice.CheckState == 1 {
  1105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1106. return
  1107. }
  1108. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1110. return
  1111. }
  1112. }
  1113. checker := adminUserInfo.AdminUser.Id
  1114. theTime := time.Now()
  1115. advices := models.DoctorAdvice{
  1116. CheckTime: theTime.Unix(),
  1117. Checker: checker,
  1118. UpdatedTime: time.Now().Unix(),
  1119. }
  1120. var err error
  1121. if groupno > 0 {
  1122. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1123. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1124. redis := service.RedisClient()
  1125. //清空key 值
  1126. redis.Set(key, "", time.Second)
  1127. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1128. redis.Set(keyTwo, "", time.Second)
  1129. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1130. redis.Set(keyThree, "", time.Second)
  1131. recordDate := theTime.Format("2006-01-02")
  1132. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1133. redis.Set(keyFour, "", time.Second)
  1134. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1135. redis.Set(keyFive, "", time.Second)
  1136. defer redis.Close()
  1137. } else {
  1138. if len(ids[0]) <= 0 {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1140. return
  1141. } else {
  1142. //t := time.Now().Format("2006-01-02")/**/
  1143. //timeLayout2 := "2006-01-02"
  1144. //loc, _ := time.LoadLocation("Local")
  1145. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1146. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1147. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1148. redis := service.RedisClient()
  1149. //清空key 值
  1150. redis.Set(key, "", time.Second)
  1151. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1152. redis.Set(keyTwo, "", time.Second)
  1153. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1154. redis.Set(keyThree, "", time.Second)
  1155. recordDate := theTime.Format("2006-01-02")
  1156. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1157. redis.Set(keyFour, "", time.Second)
  1158. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1159. redis.Set(keyFive, "", time.Second)
  1160. defer redis.Close()
  1161. }
  1162. }
  1163. if err != nil {
  1164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1165. return
  1166. }
  1167. advice.Checker = checker
  1168. advice.CheckTime = theTime.Unix()
  1169. advice.CheckState = 1
  1170. c.ServeSuccessJSON(map[string]interface{}{
  1171. "msg": "ok",
  1172. "advice": advice,
  1173. })
  1174. } else if origin == 2 {
  1175. adminInfo := c.GetMobileAdminUserInfo()
  1176. var ids []string
  1177. advice_ids := c.GetString("advice_id")
  1178. ids = strings.Split(advice_ids, ",")
  1179. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1180. var err error
  1181. for _, item := range advices {
  1182. if item.CheckState == 1 {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1184. return
  1185. }
  1186. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1188. return
  1189. }
  1190. item.Checker = adminInfo.AdminUser.Id
  1191. item.CheckTime = time.Now().Unix()
  1192. item.CheckState = 1
  1193. err = service.SaveHisDoctorAdvice(item)
  1194. redis := service.RedisClient()
  1195. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1196. //清空key 值
  1197. redis.Set(key, "", time.Second)
  1198. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1199. redis.Set(keyTwo, "", time.Second)
  1200. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1201. redis.Set(keyThree, "", time.Second)
  1202. theTime := time.Now()
  1203. recordDate := theTime.Format("2006-01-02")
  1204. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1205. redis.Set(keyFour, "", time.Second)
  1206. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1207. redis.Set(keyFive, "", time.Second)
  1208. defer redis.Close()
  1209. }
  1210. if err == nil {
  1211. c.ServeSuccessJSON(map[string]interface{}{
  1212. "msg": "ok",
  1213. "advice": advices,
  1214. })
  1215. } else {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1217. return
  1218. }
  1219. }
  1220. return
  1221. }
  1222. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1223. id, _ := c.GetInt64("patient", 0)
  1224. assessmentDate := c.GetString("assessment_date", "")
  1225. if id <= 0 || len(assessmentDate) != 10 {
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1227. return
  1228. }
  1229. timeLayout := "2006-01-02"
  1230. loc, _ := time.LoadLocation("Local")
  1231. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1232. if err != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1234. return
  1235. }
  1236. theAssessmentDateTime := theTime.Unix()
  1237. adminUserInfo := c.GetMobileAdminUserInfo()
  1238. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1239. if patient.ID == 0 {
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1241. return
  1242. }
  1243. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1244. if getPEErr != nil {
  1245. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. }
  1249. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1250. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1251. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1252. var evaluation models.PredialysisEvaluation
  1253. if theEvaluation != nil {
  1254. evaluation = *theEvaluation
  1255. }
  1256. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1257. if code > 0 {
  1258. c.ServeFailJSONWithSGJErrorCode(code)
  1259. return
  1260. }
  1261. if theEvaluation == nil {
  1262. evaluation.CreatedTime = time.Now().Unix()
  1263. evaluation.Status = 1
  1264. evaluation.AssessmentDate = theAssessmentDateTime
  1265. evaluation.PatientId = id
  1266. evaluation.UserOrgId = adminUserInfo.Org.Id
  1267. if appRole.UserType == 2 || appRole.UserType == 1 {
  1268. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1269. evaluation.AssessmentTime = time.Now().Unix()
  1270. } else {
  1271. evaluation.Creater = adminUserInfo.AdminUser.Id
  1272. }
  1273. } else {
  1274. evaluation.UpdatedTime = time.Now().Unix()
  1275. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1276. if appRole.UserType == 2 || appRole.UserType == 1 {
  1277. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1278. evaluation.AssessmentTime = time.Now().Unix()
  1279. } else {
  1280. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1281. if evaluation.Creater == 0 {
  1282. evaluation.Creater = adminUserInfo.AdminUser.Id
  1283. }
  1284. }
  1285. }
  1286. //新增逻辑
  1287. var dewater_amount float64
  1288. dewater_amount = 0
  1289. if evaluation.DryWeight > 0 {
  1290. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1291. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
  1292. dewater_amount = dewater_amount * 1000
  1293. }
  1294. if dewater_amount <= 0 {
  1295. dewater_amount = 0
  1296. }
  1297. } else {
  1298. dewater_amount = 0
  1299. }
  1300. // 计算透析处方的相关超滤量
  1301. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1302. var lastDialysisPrescribe *models.DialysisPrescription
  1303. var dialysisSolution *models.DialysisSolution
  1304. var dialysisPrescribe *models.DialysisPrescription
  1305. var system_dialysisPrescribe *models.SystemPrescription
  1306. var mode_id int64
  1307. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1308. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1309. if schedual != nil {
  1310. // 获取透析模版
  1311. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1312. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1313. mode_id = schedual.ModeId
  1314. } else {
  1315. // 获取透析模版
  1316. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1317. if dialysisPrescribe == nil && dialysisSolution != nil {
  1318. mode_id = dialysisSolution.ModeId
  1319. }
  1320. if dialysisPrescribe == nil && dialysisSolution == nil {
  1321. mode_id = 0
  1322. }
  1323. }
  1324. // 插入透析处方
  1325. if dialysisPrescribe == nil && dialysisSolution != nil {
  1326. var newprescribe models.DialysisPrescription
  1327. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1328. newprescribe.PatientId = dialysisSolution.PatientId
  1329. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1330. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1331. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1332. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1333. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1334. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1335. newprescribe.ModeId = dialysisSolution.ModeId
  1336. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1337. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1338. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1339. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1340. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1341. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1342. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1343. newprescribe.Glucose = dialysisSolution.Glucose
  1344. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1345. newprescribe.Kalium = dialysisSolution.Kalium
  1346. newprescribe.Sodium = dialysisSolution.Sodium
  1347. newprescribe.Calcium = dialysisSolution.Calcium
  1348. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1349. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1350. newprescribe.Conductivity = dialysisSolution.Conductivity
  1351. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1352. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1353. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1354. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1355. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1356. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1357. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1358. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1359. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1360. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1361. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1362. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1363. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1364. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1365. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1366. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1367. newprescribe.CreatedTime = time.Now().Unix()
  1368. newprescribe.UpdatedTime = time.Now().Unix()
  1369. newprescribe.RecordDate = theAssessmentDateTime
  1370. newprescribe.DewaterAmount = dewater_amount
  1371. newprescribe.TargetUltrafiltration = dewater_amount
  1372. newprescribe.Status = 1
  1373. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1374. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1375. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1376. newprescribe.ID = dialysisPrescription.ID
  1377. if dialysisPrescription.ID == 0 {
  1378. fmt.Println("处方11111111111")
  1379. err := service.AddSigleRecord(&newprescribe)
  1380. //获取key,清空redis
  1381. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1382. redis := service.RedisClient()
  1383. //清空key 值
  1384. redis.Set(key, "", time.Second)
  1385. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1386. //清空key 值
  1387. redis.Set(keyOne, "", time.Second)
  1388. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1389. //清空key 值
  1390. redis.Set(keyTwo, "", time.Second)
  1391. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1392. redis.Set(keySix, "", time.Second)
  1393. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1394. redis.Set(keySeven, "", time.Second)
  1395. if err != nil {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1397. }
  1398. } else {
  1399. err := service.UpDateDialysisPrescription(&newprescribe)
  1400. //获取key,清空redis
  1401. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1402. redis := service.RedisClient()
  1403. //清空key 值
  1404. redis.Set(key, "", time.Second)
  1405. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1406. //清空key 值
  1407. redis.Set(keyOne, "", time.Second)
  1408. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1409. //清空key 值
  1410. redis.Set(keyTwo, "", time.Second)
  1411. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1412. redis.Set(keySix, "", time.Second)
  1413. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1414. redis.Set(keySeven, "", time.Second)
  1415. if err != nil {
  1416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1417. }
  1418. }
  1419. }
  1420. if dialysisPrescribe == nil && dialysisSolution == nil {
  1421. if lastDialysisPrescribe != nil {
  1422. var newprescribe models.DialysisPrescription
  1423. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1424. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1425. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1426. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1427. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1428. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1429. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1430. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1431. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1432. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1433. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1434. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1435. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1436. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1437. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1438. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1439. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1440. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1441. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1442. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1443. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1444. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1445. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1446. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1447. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1448. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1449. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1450. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1451. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1452. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1453. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1454. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1455. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1456. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1457. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1458. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1459. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1460. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1461. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1462. newprescribe.CreatedTime = time.Now().Unix()
  1463. newprescribe.UpdatedTime = time.Now().Unix()
  1464. newprescribe.RecordDate = theAssessmentDateTime
  1465. newprescribe.DewaterAmount = dewater_amount
  1466. newprescribe.TargetUltrafiltration = dewater_amount
  1467. newprescribe.Status = 1
  1468. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1469. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1470. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1471. newprescribe.ID = dialysisPrescription.ID
  1472. if dialysisPrescription.ID == 0 {
  1473. err := service.AddSigleRecord(&newprescribe)
  1474. //获取key,清空redis
  1475. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1476. redis := service.RedisClient()
  1477. //清空key 值
  1478. redis.Set(key, "", time.Second)
  1479. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1480. //清空key 值
  1481. redis.Set(keyOne, "", time.Second)
  1482. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1483. //清空key 值
  1484. redis.Set(keyTwo, "", time.Second)
  1485. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1486. redis.Set(keySix, "", time.Second)
  1487. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1488. redis.Set(keySeven, "", time.Second)
  1489. fmt.Println("处方2222222222")
  1490. if err != nil {
  1491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1492. }
  1493. } else {
  1494. err := service.UpDateDialysisPrescription(&newprescribe)
  1495. //获取key,清空redis
  1496. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1497. redis := service.RedisClient()
  1498. //清空key 值
  1499. redis.Set(key, "", time.Second)
  1500. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1501. //清空key 值
  1502. redis.Set(keyOne, "", time.Second)
  1503. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1504. //清空key 值
  1505. redis.Set(keyTwo, "", time.Second)
  1506. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1507. redis.Set(keySix, "", time.Second)
  1508. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1509. redis.Set(keySeven, "", time.Second)
  1510. if err != nil {
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1512. }
  1513. }
  1514. if err != nil {
  1515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1516. }
  1517. } else if system_dialysisPrescribe != nil {
  1518. var newprescribe models.DialysisPrescription
  1519. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1520. newprescribe.PatientId = id
  1521. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1522. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1523. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1524. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1525. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1526. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1527. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1528. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1529. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1530. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1531. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1532. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1533. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1534. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1535. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1536. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1537. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1538. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1539. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1540. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1541. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1542. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1543. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1544. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1545. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1546. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1547. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1548. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1549. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1550. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1551. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1552. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1553. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1554. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1555. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1556. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1557. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1558. newprescribe.CreatedTime = time.Now().Unix()
  1559. newprescribe.UpdatedTime = time.Now().Unix()
  1560. newprescribe.RecordDate = theAssessmentDateTime
  1561. newprescribe.DewaterAmount = dewater_amount
  1562. newprescribe.TargetUltrafiltration = dewater_amount
  1563. newprescribe.Status = 1
  1564. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1565. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1566. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1567. newprescribe.ID = dialysisPrescription.ID
  1568. if dialysisPrescription.ID == 0 {
  1569. err := service.AddSigleRecord(&newprescribe)
  1570. fmt.Println("处方2222222222")
  1571. //获取key,清空redis
  1572. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1573. redis := service.RedisClient()
  1574. //清空key 值
  1575. redis.Set(key, "", time.Second)
  1576. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1577. //清空key 值
  1578. redis.Set(keyOne, "", time.Second)
  1579. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1580. //清空key 值
  1581. redis.Set(keyTwo, "", time.Second)
  1582. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1583. redis.Set(keySix, "", time.Second)
  1584. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1585. redis.Set(keySeven, "", time.Second)
  1586. if err != nil {
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1588. }
  1589. } else {
  1590. err := service.UpDateDialysisPrescription(&newprescribe)
  1591. //获取key,清空redis
  1592. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1593. redis := service.RedisClient()
  1594. //清空key 值
  1595. redis.Set(key, "", time.Second)
  1596. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1597. //清空key 值
  1598. redis.Set(keyOne, "", time.Second)
  1599. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1600. //清空key 值
  1601. redis.Set(keyTwo, "", time.Second)
  1602. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1603. redis.Set(keySix, "", time.Second)
  1604. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1605. redis.Set(keySeven, "", time.Second)
  1606. if err != nil {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1608. }
  1609. }
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1612. }
  1613. } else {
  1614. var newprescribe models.DialysisPrescription
  1615. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1616. newprescribe.PatientId = id
  1617. newprescribe.ModeId = mode_id
  1618. newprescribe.CreatedTime = time.Now().Unix()
  1619. newprescribe.UpdatedTime = time.Now().Unix()
  1620. newprescribe.RecordDate = theAssessmentDateTime
  1621. newprescribe.DewaterAmount = dewater_amount
  1622. newprescribe.TargetUltrafiltration = dewater_amount
  1623. newprescribe.Status = 1
  1624. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1625. newprescribe.ID = dialysisPrescription.ID
  1626. if dialysisPrescription.ID == 0 {
  1627. err := service.AddSigleRecord(&newprescribe)
  1628. fmt.Println("处方44444444444")
  1629. //获取key,清空redis
  1630. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1631. redis := service.RedisClient()
  1632. //清空key 值
  1633. redis.Set(key, "", time.Second)
  1634. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1635. //清空key 值
  1636. redis.Set(keyOne, "", time.Second)
  1637. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1638. //清空key 值
  1639. redis.Set(keyTwo, "", time.Second)
  1640. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1641. redis.Set(keySix, "", time.Second)
  1642. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1643. redis.Set(keySeven, "", time.Second)
  1644. if err != nil {
  1645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1646. }
  1647. } else {
  1648. err := service.UpDateDialysisPrescription(&newprescribe)
  1649. //获取key,清空redis
  1650. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1651. redis := service.RedisClient()
  1652. //清空key 值
  1653. redis.Set(key, "", time.Second)
  1654. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1655. //清空key 值
  1656. redis.Set(keyOne, "", time.Second)
  1657. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1658. //清空key 值
  1659. redis.Set(keyTwo, "", time.Second)
  1660. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1661. redis.Set(keySix, "", time.Second)
  1662. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1663. redis.Set(keySeven, "", time.Second)
  1664. if err != nil {
  1665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1666. }
  1667. }
  1668. if err != nil {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1670. }
  1671. }
  1672. }
  1673. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1674. // if dialysisPrescribe != nil {
  1675. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1676. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1677. // dialysisPrescribe.DewaterAmount = dewater_amount
  1678. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1679. // dialysisPrescribe.Status = 1
  1680. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1681. // if updateErr != nil {
  1682. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1683. // }
  1684. // }
  1685. err = service.UpadatePredialysisEvaluation(&evaluation)
  1686. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  1687. redis := service.RedisClient()
  1688. defer redis.Close()
  1689. //清空key 值
  1690. redis.Set(key, "", time.Second)
  1691. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  1692. redis.Set(keyOne, "", time.Second)
  1693. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1694. redis.Set(keyTwo, "", time.Second)
  1695. if err != nil {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1697. return
  1698. }
  1699. c.ServeSuccessJSON(map[string]interface{}{
  1700. "msg": "ok",
  1701. "evaluation": evaluation,
  1702. })
  1703. return
  1704. }
  1705. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1706. dataBody := make(map[string]interface{}, 0)
  1707. err := json.Unmarshal(data, &dataBody)
  1708. utils.InfoLog(string(data))
  1709. if err != nil {
  1710. utils.ErrorLog(err.Error())
  1711. code = enums.ErrorCodeParamWrong
  1712. return
  1713. }
  1714. // if method == "create" {
  1715. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1716. utils.ErrorLog("mode")
  1717. code = enums.ErrorCodeParamWrong
  1718. return
  1719. }
  1720. mode := int64(dataBody["mode"].(float64))
  1721. if mode <= 0 {
  1722. utils.ErrorLog("mode <= 0")
  1723. code = enums.ErrorCodeParamWrong
  1724. return
  1725. }
  1726. solution.ModeId = mode
  1727. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1728. utils.ErrorLog("mode_name")
  1729. code = enums.ErrorCodeParamWrong
  1730. return
  1731. }
  1732. modeName, _ := dataBody["mode_name"].(string)
  1733. if len(modeName) == 0 {
  1734. utils.ErrorLog("len(mode_name) == 0")
  1735. code = enums.ErrorCodeParamWrong
  1736. return
  1737. }
  1738. solution.ModeName = modeName
  1739. solution.Name = modeName
  1740. // }
  1741. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1742. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1743. solution.DialysisDuration = dialysisDuration
  1744. }
  1745. if dataBody["dialysis_duration"] != nil {
  1746. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1747. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1748. solution.DialysisDuration = dialysisDuration
  1749. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1750. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1751. solution.DialysisDuration = dialysisDuration
  1752. }
  1753. }
  1754. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1755. dialyzer := int64(dataBody["dialyzer"].(float64))
  1756. solution.Dialyzer = dialyzer
  1757. }
  1758. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1759. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1760. solution.PerfusionApparatus = perfusionApparatus
  1761. }
  1762. if dataBody["blood_flow_volume"] != nil {
  1763. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1764. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1765. solution.BloodFlowVolume = bloodFlowVolume
  1766. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1767. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1768. solution.BloodFlowVolume = bloodFlowVolume
  1769. }
  1770. }
  1771. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1772. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1773. solution.HemodialysisMachine = hemodialysisMachine
  1774. }
  1775. if dataBody["dewater"] != nil {
  1776. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1777. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1778. solution.Dewater = dewater
  1779. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1780. dewater := dataBody["dewater"].(float64)
  1781. solution.Dewater = dewater
  1782. }
  1783. }
  1784. if dataBody["replacement_total"] != nil {
  1785. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1786. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1787. solution.ReplacementTotal = replacementTotal
  1788. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1789. replacementTotal := dataBody["replacement_total"].(float64)
  1790. solution.ReplacementTotal = replacementTotal
  1791. }
  1792. }
  1793. if dataBody["displace_liqui"] != nil {
  1794. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1795. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1796. solution.DisplaceLiqui = displaceLiqui
  1797. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1798. displaceLiqui := dataBody["displace_liqui"].(float64)
  1799. solution.DisplaceLiqui = displaceLiqui
  1800. }
  1801. }
  1802. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1803. replacementWay := int64(dataBody["replacement_way"].(float64))
  1804. solution.ReplacementWay = replacementWay
  1805. }
  1806. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1807. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1808. solution.Anticoagulant = anticoagulant
  1809. }
  1810. if dataBody["anticoagulant_shouji"] != nil {
  1811. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1812. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1813. solution.AnticoagulantShouji = anticoagulantShouji
  1814. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1815. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1816. solution.AnticoagulantShouji = anticoagulantShouji
  1817. }
  1818. }
  1819. if dataBody["anticoagulant_weichi"] != nil {
  1820. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1821. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1822. solution.AnticoagulantWeichi = anticoagulantWeichi
  1823. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1824. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1825. solution.AnticoagulantWeichi = anticoagulantWeichi
  1826. }
  1827. }
  1828. if dataBody["anticoagulant_zongliang"] != nil {
  1829. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1830. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1831. solution.AnticoagulantZongliang = anticoagulantZongliang
  1832. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1833. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1834. solution.AnticoagulantZongliang = anticoagulantZongliang
  1835. }
  1836. }
  1837. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1838. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1839. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1840. }
  1841. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1842. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1843. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1844. }
  1845. if dataBody["kalium"] != nil {
  1846. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1847. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1848. solution.Kalium = kalium
  1849. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1850. kalium := dataBody["kalium"].(float64)
  1851. solution.Kalium = kalium
  1852. }
  1853. }
  1854. if dataBody["sodium"] != nil {
  1855. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1856. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1857. solution.Sodium = sodium
  1858. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1859. sodium := dataBody["sodium"].(float64)
  1860. solution.Sodium = sodium
  1861. }
  1862. }
  1863. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1864. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1865. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1866. solution.Calcium = calcium
  1867. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1868. calcium := dataBody["calcium"].(float64)
  1869. solution.Calcium = calcium
  1870. }
  1871. }
  1872. if dataBody["bicarbonate"] != nil {
  1873. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1874. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1875. solution.Bicarbonate = bicarbonate
  1876. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1877. bicarbonate := dataBody["bicarbonate"].(float64)
  1878. solution.Bicarbonate = bicarbonate
  1879. }
  1880. }
  1881. if dataBody["glucose"] != nil {
  1882. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1883. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1884. solution.Glucose = glucose
  1885. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1886. glucose := dataBody["glucose"].(float64)
  1887. solution.Glucose = glucose
  1888. }
  1889. }
  1890. // if dataBody["dry_weight"] != nil {
  1891. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1892. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1893. // solution.DryWeight = dryWeight
  1894. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1895. // dryWeight := dataBody["dry_weight"].(float64)
  1896. // solution.DryWeight = dryWeight
  1897. // }
  1898. // }
  1899. if dataBody["dialysate_flow"] != nil {
  1900. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1901. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1902. solution.DialysateFlow = dialysateFlow
  1903. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1904. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1905. solution.DialysateFlow = dialysateFlow
  1906. }
  1907. }
  1908. if dataBody["dialysate_temperature"] != nil {
  1909. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1910. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1911. solution.DialysateTemperature = dialysateTemperature
  1912. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1913. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1914. solution.DialysateTemperature = dialysateTemperature
  1915. }
  1916. }
  1917. if dataBody["conductivity"] != nil {
  1918. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1919. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1920. solution.Conductivity = conductivity
  1921. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1922. conductivity := dataBody["conductivity"].(float64)
  1923. solution.Conductivity = conductivity
  1924. }
  1925. }
  1926. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1927. remark := dataBody["remark"].(string)
  1928. solution.Remark = remark
  1929. }
  1930. if dataBody["dialysis_duration_hour"] != nil {
  1931. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1932. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1933. solution.DialysisDurationHour = dialysisDurationHour
  1934. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1935. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1936. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1937. }
  1938. }
  1939. if dataBody["dialysis_duration_minute"] != nil {
  1940. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1941. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1942. solution.DialysisDurationMinute = dialysisDurationMinute
  1943. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1944. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1945. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1946. }
  1947. }
  1948. if dataBody["target_ultrafiltration"] != nil {
  1949. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1950. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1951. solution.TargetUltrafiltration = targetUltrafiltration
  1952. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1953. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1954. solution.TargetUltrafiltration = targetUltrafiltration
  1955. }
  1956. }
  1957. if dataBody["dialysate_formulation"] != nil {
  1958. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1959. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1960. solution.DialysateFormulation = dialysateFormulation
  1961. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1962. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1963. solution.DialysateFormulation = int64(dialysateFormulation)
  1964. }
  1965. }
  1966. return
  1967. }
  1968. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1969. dataBody := make(map[string]interface{}, 0)
  1970. err := json.Unmarshal(data, &dataBody)
  1971. utils.InfoLog(string(data))
  1972. if err != nil {
  1973. utils.ErrorLog(err.Error())
  1974. code = enums.ErrorCodeParamWrong
  1975. return
  1976. }
  1977. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1978. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1979. evaluation.WeightBefore = weightVefore
  1980. }
  1981. // fmt.Println(dataBody["dry_weight"])
  1982. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1983. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1984. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1985. fmt.Println(additionalWeight)
  1986. evaluation.DryWeight = additionalWeight
  1987. }
  1988. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1989. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1990. fmt.Println(additionalWeight)
  1991. evaluation.AdditionalWeight = additionalWeight
  1992. }
  1993. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1994. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1995. evaluation.Temperature = Temperature
  1996. }
  1997. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1998. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1999. evaluation.SystolicBloodPressure = systolicBloodPressure
  2000. }
  2001. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2002. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2003. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2004. }
  2005. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2006. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2007. evaluation.PulseFrequency = pulseFrequency
  2008. }
  2009. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2010. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  2011. evaluation.BreathingRate = breathingRate
  2012. }
  2013. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2014. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2015. evaluation.LastPostDialysis = lastPostDialysis
  2016. }
  2017. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2018. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2019. evaluation.DialysisInterphase = dialysisInterphase
  2020. }
  2021. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2022. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2023. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2024. }
  2025. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2026. catheter, _ := dataBody["catheter"].(string)
  2027. evaluation.Catheter = catheter
  2028. }
  2029. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2030. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2031. evaluation.CatheterBend = catheter_bend
  2032. }
  2033. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2034. Complication, _ := dataBody["complication"].(string)
  2035. evaluation.Complication = Complication
  2036. }
  2037. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2038. remark := dataBody["remark"].(string)
  2039. evaluation.Remark = remark
  2040. }
  2041. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2042. machine_type := dataBody["machine_type"].(string)
  2043. evaluation.MachineType = machine_type
  2044. }
  2045. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2046. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2047. evaluation.BloodAccessPartId = blood_access_part_id
  2048. }
  2049. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2050. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2051. // evaluation.BloodAccessPartId = blood_access_part_id
  2052. //}
  2053. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2054. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2055. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2056. }
  2057. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2058. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2059. evaluation.InternalFistula = internal_fistula
  2060. }
  2061. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2062. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2063. evaluation.InternalFistulaSkin = internal_fistula_skin
  2064. }
  2065. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2066. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2067. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2068. evaluation.IsHemorrhage = is_hemorrhage
  2069. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2070. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2071. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2072. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2073. is_hemorrhage = 0
  2074. }
  2075. evaluation.IsHemorrhage = is_hemorrhage
  2076. if is_hemorrhage == 1 {
  2077. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2078. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2079. evaluation.Hemorrhage = hemorrhage
  2080. }
  2081. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2082. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2083. evaluation.HemorrhageOther = hemorrhage_other
  2084. }
  2085. }
  2086. } else {
  2087. evaluation.IsHemorrhage = 0
  2088. }
  2089. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2090. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2091. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2092. }
  2093. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2094. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2095. evaluation.InternalFistulaOther = internal_fistula_other
  2096. }
  2097. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2098. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2099. evaluation.BloodAccessNoise = blood_access_noise
  2100. }
  2101. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2102. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2103. puncture_way := dataBody["puncture_way"].(string)
  2104. evaluation.PunctureWay = puncture_way
  2105. }
  2106. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2107. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2108. evaluation.VenousCatheterization = venous_catheterization
  2109. }
  2110. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2111. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2112. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2113. }
  2114. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2115. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2116. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2117. }
  2118. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2119. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2120. evaluation.DuctusArantii = ductus_arantii
  2121. }
  2122. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2123. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2124. evaluation.EmergencyTreatment = emergency_treatment
  2125. }
  2126. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2127. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2128. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2129. }
  2130. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2131. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2132. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2133. evaluation.DialysisCount = dialysis_count
  2134. }
  2135. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2136. is_infect, _ := dataBody["is_infect"].(string)
  2137. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2138. evaluation.IsInfect = infect
  2139. }
  2140. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2141. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2142. evaluation.Exposed = exposed
  2143. }
  2144. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2145. skin, _ := dataBody["skin"].(string)
  2146. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2147. evaluation.Skin = skin
  2148. }
  2149. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2150. skin_other, _ := dataBody["skin_other"].(string)
  2151. evaluation.SkinOther = skin_other
  2152. }
  2153. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2154. infect_other, _ := dataBody["infect_other"].(string)
  2155. evaluation.InfectOther = infect_other
  2156. }
  2157. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2158. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2159. evaluation.DuctusArantiiOther = ductus_arantii_other
  2160. }
  2161. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2162. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2163. evaluation.PunctureNeedle = punctureNeedle
  2164. }
  2165. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2166. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2167. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2168. }
  2169. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2170. pinholing := dataBody["pinholing"].(string)
  2171. evaluation.Phinholing = pinholing
  2172. }
  2173. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2174. catheter_suture := dataBody["catheter_suture"].(string)
  2175. evaluation.CatheterSuture = catheter_suture
  2176. }
  2177. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2178. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2179. evaluation.CatheterSutureOther = catheter_suture_other
  2180. }
  2181. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2182. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2183. evaluation.UrineVolume = urine_volume
  2184. }
  2185. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2186. edema := dataBody["edema"].(string)
  2187. evaluation.Edema = edema
  2188. }
  2189. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2190. specialTreatment := dataBody["special_treatment"].(string)
  2191. evaluation.SpecialTreatment = specialTreatment
  2192. }
  2193. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2194. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2195. evaluation.CatheterMaintenance = catheter_maintenance
  2196. }
  2197. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2198. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2199. evaluation.ThromubusType = thromubusType
  2200. }
  2201. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2202. thrombus_av := dataBody["thrombus_av"].(string)
  2203. evaluation.ThrombusAv = thrombus_av
  2204. }
  2205. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2206. thromubus_a := dataBody["thromubus_a"].(string)
  2207. evaluation.ThromubusA = thromubus_a
  2208. }
  2209. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2210. thromubus_v := dataBody["thromubus_v"].(string)
  2211. evaluation.ThromubusV = thromubus_v
  2212. }
  2213. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2214. dehydration := dataBody["dehydration"].(string)
  2215. evaluation.Dehydration = dehydration
  2216. }
  2217. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2218. period := int64(dataBody["period"].(float64))
  2219. evaluation.Period = period
  2220. }
  2221. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2222. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2223. evaluation.EstimatedFoodIntake = estimated_food_intake
  2224. }
  2225. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2226. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2227. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2228. }
  2229. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2230. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2231. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2232. }
  2233. return
  2234. }
  2235. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2236. dataBody := make(map[string]interface{}, 0)
  2237. err := json.Unmarshal(data, &dataBody)
  2238. if err != nil {
  2239. utils.ErrorLog(err.Error())
  2240. code = enums.ErrorCodeParamWrong
  2241. return
  2242. }
  2243. timeLayout := "2006-01-02"
  2244. loc, _ := time.LoadLocation("Local")
  2245. isChild := false
  2246. if action == "create" {
  2247. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2248. utils.ErrorLog("advice_type")
  2249. code = enums.ErrorCodeParamWrong
  2250. return
  2251. }
  2252. adviceType := int64(dataBody["advice_type"].(float64))
  2253. if adviceType != 1 && adviceType != 2 {
  2254. utils.ErrorLog("advice_type != 1&&2")
  2255. code = enums.ErrorCodeParamWrong
  2256. return
  2257. }
  2258. advice.AdviceType = adviceType
  2259. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2260. utils.ErrorLog("advice_date")
  2261. code = enums.ErrorCodeParamWrong
  2262. return
  2263. }
  2264. adviceDate, _ := dataBody["advice_date"].(string)
  2265. if len(adviceDate) == 0 {
  2266. utils.ErrorLog("len(adviceDate) == 0")
  2267. code = enums.ErrorCodeParamWrong
  2268. return
  2269. }
  2270. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2271. if err != nil {
  2272. utils.ErrorLog(err.Error())
  2273. code = enums.ErrorCodeParamWrong
  2274. return
  2275. }
  2276. advice.AdviceDate = theTime.Unix()
  2277. advice.RecordDate = theTime.Unix()
  2278. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2279. parentId := int64(dataBody["parent_id"].(float64))
  2280. advice.ParentId = parentId
  2281. if parentId > 0 {
  2282. isChild = true
  2283. }
  2284. }
  2285. } else {
  2286. isChild = advice.ParentId > 0
  2287. }
  2288. if !isChild {
  2289. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2290. utils.ErrorLog("start_time")
  2291. code = enums.ErrorCodeParamWrong
  2292. return
  2293. }
  2294. startTime, _ := dataBody["start_time"].(string)
  2295. if len(startTime) == 0 {
  2296. utils.ErrorLog("len(start_time) == 0")
  2297. code = enums.ErrorCodeParamWrong
  2298. return
  2299. }
  2300. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2301. if err != nil {
  2302. utils.ErrorLog(err.Error())
  2303. code = enums.ErrorCodeParamWrong
  2304. return
  2305. }
  2306. advice.StartTime = theTime.Unix()
  2307. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2308. deliveryWay, _ := dataBody["delivery_way"].(string)
  2309. advice.DeliveryWay = deliveryWay
  2310. }
  2311. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2312. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2313. advice.ExecutionFrequency = executionFrequency
  2314. }
  2315. }
  2316. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2317. deliveryWay, _ := dataBody["delivery_way"].(string)
  2318. advice.DeliveryWay = deliveryWay
  2319. }
  2320. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2321. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2322. advice.ExecutionFrequency = executionFrequency
  2323. }
  2324. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2325. utils.ErrorLog("advice_name")
  2326. code = enums.ErrorCodeParamWrong
  2327. return
  2328. }
  2329. adviceName, _ := dataBody["advice_name"].(string)
  2330. if len(adviceName) == 0 {
  2331. utils.ErrorLog("len(advice_name) == 0")
  2332. code = enums.ErrorCodeParamWrong
  2333. return
  2334. }
  2335. advice.AdviceName = adviceName
  2336. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2337. adviceDsc, _ := dataBody["advice_desc"].(string)
  2338. advice.AdviceDesc = adviceDsc
  2339. }
  2340. if dataBody["way"] == nil {
  2341. advice.Way = 0
  2342. } else {
  2343. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2344. way := int64(dataBody["way"].(float64))
  2345. advice.Way = way
  2346. }
  2347. }
  2348. if dataBody["drug_id"] == nil {
  2349. advice.DrugId = 0
  2350. } else {
  2351. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2352. drug_id := int64(dataBody["drug_id"].(float64))
  2353. advice.DrugId = drug_id
  2354. }
  2355. }
  2356. if dataBody["drug_name_id"] == nil {
  2357. advice.DrugNameId = 0
  2358. } else {
  2359. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2360. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2361. advice.DrugNameId = drug_name_id
  2362. fmt.Println("0000000000", advice.DrugNameId)
  2363. }
  2364. }
  2365. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2366. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2367. advice.SingleDose = singleDose
  2368. }
  2369. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2370. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2371. advice.SingleDoseUnit = singleDoseUnit
  2372. }
  2373. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2374. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2375. advice.DrugSpec = drugSpec
  2376. }
  2377. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2378. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2379. advice.DrugSpecUnit = drugSpecUnit
  2380. }
  2381. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2382. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2383. advice.PrescribingNumber = prescribingNumber
  2384. }
  2385. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2386. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2387. advice.PrescribingNumberUnit = prescribingNumberUnit
  2388. }
  2389. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2390. remark, _ := dataBody["remark"].(string)
  2391. advice.Remark = remark
  2392. }
  2393. return
  2394. }
  2395. func (c *PatientApiController) GetPatientEducation() {
  2396. patientID, _ := c.GetInt64("patient_id", 0)
  2397. page, _ := c.GetInt64("page", 0)
  2398. limit, _ := c.GetInt64("limit", 0)
  2399. startTime := c.GetString("start_time", "")
  2400. endTime := c.GetString("end_time", "")
  2401. if page <= 0 {
  2402. page = 1
  2403. }
  2404. if limit <= 0 {
  2405. limit = 10
  2406. }
  2407. if patientID <= 0 {
  2408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2409. return
  2410. }
  2411. timeLayout := "2006-01-02"
  2412. loc, _ := time.LoadLocation("Local")
  2413. var theStartTIme int64
  2414. if len(startTime) > 0 {
  2415. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2416. if err != nil {
  2417. theStartTIme = 0
  2418. }
  2419. theStartTIme = theTime.Unix()
  2420. }
  2421. var theEndtTIme int64
  2422. if len(endTime) > 0 {
  2423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2424. if err != nil {
  2425. theEndtTIme = 0
  2426. }
  2427. theEndtTIme = theTime.Unix()
  2428. }
  2429. adminUserInfo := c.GetMobileAdminUserInfo()
  2430. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2431. c.ServeSuccessJSON(map[string]interface{}{
  2432. "total": total,
  2433. "edus": edus,
  2434. })
  2435. return
  2436. }
  2437. func (c *PatientApiController) GetPatientSchedulesList() {
  2438. patientID, _ := c.GetInt64("patient_id", 0)
  2439. page, _ := c.GetInt64("page", 0)
  2440. limit, _ := c.GetInt64("limit", 0)
  2441. if patientID <= 0 {
  2442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2443. return
  2444. }
  2445. adminUserInfo := c.GetMobileAdminUserInfo()
  2446. todayTime := time.Now().Format("2006-01-02")
  2447. timeLayout := "2006-01-02 15:04:05"
  2448. loc, _ := time.LoadLocation("Local")
  2449. var theStartTime int64
  2450. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2451. theStartTime = theTime.Unix()
  2452. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2453. if len(schedules) > 0 {
  2454. for index, item := range schedules {
  2455. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2456. schedules[index].Week = int64(week)
  2457. }
  2458. }
  2459. c.ServeSuccessJSON(map[string]interface{}{
  2460. "schedules": schedules,
  2461. })
  2462. return
  2463. }
  2464. func (c *PatientApiController) GetRecords() {
  2465. patientID, _ := c.GetInt64("patient_id", 0)
  2466. page, _ := c.GetInt64("page", 0)
  2467. limit, _ := c.GetInt64("limit", 0)
  2468. startTime := c.GetString("start_time", "")
  2469. endTime := c.GetString("end_time", "")
  2470. mode_id, _ := c.GetInt64("mode_id", 0)
  2471. if page <= 0 {
  2472. page = 1
  2473. }
  2474. if limit <= 0 {
  2475. limit = 10
  2476. }
  2477. if patientID <= 0 {
  2478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2479. return
  2480. }
  2481. timeLayout := "2006-01-02"
  2482. loc, _ := time.LoadLocation("Local")
  2483. var theStartTIme int64
  2484. if len(startTime) > 0 {
  2485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2486. if err != nil {
  2487. theStartTIme = 0
  2488. }
  2489. theStartTIme = theTime.Unix()
  2490. }
  2491. var theEndtTIme int64
  2492. if len(endTime) > 0 {
  2493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2494. if err != nil {
  2495. theEndtTIme = 0
  2496. }
  2497. theEndtTIme = theTime.Unix()
  2498. }
  2499. adminUserInfo := c.GetMobileAdminUserInfo()
  2500. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2501. c.ServeSuccessJSON(map[string]interface{}{
  2502. "total": total,
  2503. "records": records,
  2504. })
  2505. return
  2506. }
  2507. func (c *PatientApiController) GetPatientMonitor() {
  2508. partition, _ := c.GetInt64("partition")
  2509. monitorDate := c.GetString("date")
  2510. patient_id, _ := c.GetInt64("patient_id")
  2511. timeLayout := "2006-01-02"
  2512. loc, _ := time.LoadLocation("Local")
  2513. var theStartTime int64
  2514. if len(monitorDate) > 0 {
  2515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2516. if err != nil {
  2517. theStartTime = 0
  2518. }
  2519. theStartTime = theTime.Unix()
  2520. }
  2521. adminInfo := c.GetMobileAdminUserInfo()
  2522. orgID := adminInfo.Org.Id
  2523. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2524. if err != nil {
  2525. c.ErrorLog("获取排班信息失败:%v", err)
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2527. } else {
  2528. if len(monitor) > 0 {
  2529. //获取所有床位
  2530. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  2531. //获取所有分区
  2532. zoneList, _ := service.GetAllZoneByList(orgID)
  2533. //获取透析处方
  2534. prescriptions, _ := service.GetAllPrescriptionByList(orgID, theStartTime)
  2535. //获取透前评估
  2536. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  2537. //获取上机
  2538. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  2539. //获取透后
  2540. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListOne(orgID, theStartTime)
  2541. //获取透后监测
  2542. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  2543. //获取所有的患者
  2544. patients, _ := service.GetAllPatientListByListOne(orgID)
  2545. //获取所有透析模式
  2546. treatments, _ := service.GetAllTreatModeByList(orgID)
  2547. for key, item := range monitor {
  2548. // 获取床位信息
  2549. for _, it := range numberList {
  2550. if item.BedId == it.ID {
  2551. monitor[key].DeviceNumber = it
  2552. break
  2553. }
  2554. }
  2555. //获取分区信息
  2556. for _, it := range zoneList {
  2557. if item.PartitionId == it.ID {
  2558. monitor[key].DeviceZone = it
  2559. }
  2560. }
  2561. for _, prescription := range prescriptions {
  2562. if item.PatientId == prescription.PatientId {
  2563. monitor[key].Prescription = prescription
  2564. break
  2565. }
  2566. }
  2567. // 透前评估
  2568. for _, assessmentBefore := range assessmentBefores {
  2569. if item.PatientId == assessmentBefore.PatientId {
  2570. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  2571. break
  2572. }
  2573. }
  2574. // 透析上下机
  2575. for _, dialysisOrder := range dialysisOrders {
  2576. if item.PatientId == dialysisOrder.PatientId {
  2577. monitor[key].DialysisOrder = dialysisOrder
  2578. break
  2579. }
  2580. }
  2581. // 治疗小节
  2582. for _, afterDislysis := range AssessmentAfterDislysis {
  2583. if item.PatientId == afterDislysis.PatientId {
  2584. monitor[key].AssessmentAfterDislysis = afterDislysis
  2585. break
  2586. }
  2587. }
  2588. for _, it := range monitorlist {
  2589. if item.PatientId == it.PatientId {
  2590. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  2591. }
  2592. }
  2593. for _, patient := range patients {
  2594. if item.PatientId == patient.ID {
  2595. monitor[key].MonitorPatients = patient
  2596. break
  2597. }
  2598. }
  2599. for _, treatment := range treatments {
  2600. if item.ModeId == treatment.ID {
  2601. monitor[key].TreatmentMode = treatment
  2602. break
  2603. }
  2604. }
  2605. }
  2606. }
  2607. }
  2608. //获取患者的透析次数
  2609. count, err := service.GetDialysisCount(orgID, partition)
  2610. patients, err := service.GetAllpatient(orgID)
  2611. if err == nil {
  2612. c.ServeSuccessJSON(map[string]interface{}{
  2613. "monitor": monitor,
  2614. "patientCount": count,
  2615. "patients": patients,
  2616. })
  2617. } else {
  2618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2619. }
  2620. }
  2621. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2622. // @param keyword:string 病人姓名或透析号
  2623. // @param page:int
  2624. func (this *PatientApiController) SearchMonitorPatient() {
  2625. keyword := this.GetString("keyword")
  2626. page, _ := this.GetInt("page")
  2627. if page <= 0 {
  2628. page = 1
  2629. }
  2630. if len(keyword) == 0 {
  2631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2632. return
  2633. }
  2634. adminUserInfo := this.GetMobileAdminUserInfo()
  2635. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2636. if getMonitorErr != nil {
  2637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2638. return
  2639. } else {
  2640. this.ServeSuccessJSON(map[string]interface{}{
  2641. "monitor": monitors,
  2642. })
  2643. }
  2644. }
  2645. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2646. id, _ := c.GetInt64("id", 0)
  2647. page, _ := c.GetInt64("page", 0)
  2648. limit, _ := c.GetInt64("limit", 0)
  2649. if id <= 0 {
  2650. c.ServeSuccessJSON(map[string]interface{}{
  2651. "solutions": nil,
  2652. })
  2653. return
  2654. }
  2655. if page <= 0 {
  2656. page = 1
  2657. }
  2658. if limit <= 0 {
  2659. limit = 10
  2660. }
  2661. adminInfo := c.GetMobileAdminUserInfo()
  2662. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2663. c.ServeSuccessJSON(map[string]interface{}{
  2664. "solutions": solutions,
  2665. "total": total,
  2666. })
  2667. return
  2668. }
  2669. //GetDoctorAdvices 医嘱列表
  2670. func (c *PatientApiController) GetDoctorAdvices() {
  2671. id, _ := c.GetInt64("id", 0)
  2672. adviceType, _ := c.GetInt64("advice_type", 0)
  2673. stopType, _ := c.GetInt64("stop_state", 0)
  2674. startTime := c.GetString("start_time", "")
  2675. endTime := c.GetString("end_time", "")
  2676. keywords := c.GetString("keywords", "")
  2677. need, _ := c.GetInt64("need_doctor", 0)
  2678. adminUserInfo := c.GetMobileAdminUserInfo()
  2679. timeLayout := "2006-01-02"
  2680. loc, _ := time.LoadLocation("Local")
  2681. var theStartTIme int64
  2682. if len(startTime) > 0 {
  2683. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2684. if err != nil {
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. theStartTIme = theTime.Unix()
  2689. }
  2690. var theEndtTIme int64
  2691. if len(endTime) > 0 {
  2692. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2693. if err != nil {
  2694. utils.ErrorLog(err.Error())
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2696. return
  2697. }
  2698. theEndtTIme = theTime.Unix()
  2699. }
  2700. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2701. if need == 1 {
  2702. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2703. c.ServeSuccessJSON(map[string]interface{}{
  2704. "advices": advices,
  2705. "total": total,
  2706. "users": users,
  2707. })
  2708. } else {
  2709. c.ServeSuccessJSON(map[string]interface{}{
  2710. "advices": advices,
  2711. "total": total,
  2712. "users": []string{},
  2713. })
  2714. }
  2715. return
  2716. }
  2717. func (c *PatientApiController) GetPrintDialysisOrder() {
  2718. xtno := c.GetString("xtno")
  2719. xtdate := c.GetString("xtdate")
  2720. timeLayout := "2006-01-02"
  2721. loc, _ := time.LoadLocation("Local")
  2722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2723. if err != nil {
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. return
  2726. }
  2727. xttime := theTime.Unix()
  2728. //获取当前日期月份的第一天
  2729. firstmonth := service.GetFirstDateOfMonth(theTime)
  2730. firstMonthDate := firstmonth.Unix()
  2731. operatorIDs := make([]int64, 0)
  2732. adminUserInfo := c.GetMobileAdminUserInfo()
  2733. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2734. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2735. //透析单
  2736. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2737. if dialysisOrder != nil {
  2738. if dialysisOrder.FinishNurse > 0 {
  2739. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2740. }
  2741. if dialysisOrder.StartNurse > 0 {
  2742. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2743. }
  2744. }
  2745. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2746. //透前评估
  2747. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2748. //透后评估
  2749. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2750. if AssessmentAfterDislysis.Modifier > 0 {
  2751. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2752. }
  2753. //透析处方
  2754. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2755. if dialysisPrescription.PrescriptionDoctor > 0 {
  2756. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2757. }
  2758. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2759. patientInfo.TotalDialysis = dialysis_count
  2760. //临时医嘱
  2761. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2762. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2763. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  2764. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  2765. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2766. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2767. for _, item := range projects {
  2768. cnt, _ := strconv.ParseFloat(item.Count, 64)
  2769. var advice models.HisDoctorAdviceInfo
  2770. advice.ID = item.ID
  2771. advice.Checker = item.Checker
  2772. advice.CheckTime = item.CheckTime
  2773. advice.CheckState = item.CheckState
  2774. advice.ExecutionState = item.ExecutionState
  2775. advice.ExecutionStaff = item.ExecutionStaff
  2776. //advice.PrescribingNumber = float64(item.Count)
  2777. advice.PrescribingNumber = cnt
  2778. advice.PrescribingNumberUnit = item.Unit
  2779. advice.AdviceDoctor = item.Doctor
  2780. if item.Type == 3 {
  2781. advice.AdviceName = item.GoodInfo.GoodName
  2782. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  2783. } else if item.Type == 2 {
  2784. advice.AdviceName = item.HisProject.ProjectName
  2785. }
  2786. advice.StartTime = item.StartTime
  2787. hisAdvice = append(hisAdvice, &advice)
  2788. }
  2789. }
  2790. if len(DoctorAdvice) > 0 {
  2791. for _, item := range DoctorAdvice {
  2792. if item.AdviceDoctor > 0 {
  2793. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2794. }
  2795. if item.ExecutionStaff > 0 {
  2796. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2797. }
  2798. if item.Checker > 0 {
  2799. operatorIDs = append(operatorIDs, item.Checker)
  2800. }
  2801. }
  2802. }
  2803. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2804. //透析监测
  2805. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2806. //透析小结
  2807. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2808. //接诊评估
  2809. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2810. //相关操作对应的操作人
  2811. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  2812. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  2813. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2814. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2815. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  2816. if config.IsOpen == 1 {
  2817. c.ServeSuccessJSON(map[string]interface{}{
  2818. "users": adminUser,
  2819. "patientInfo": patientInfo,
  2820. "PredialysisEvaluation": PredialysisEvaluation,
  2821. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2822. "dialysisPrescription": dialysisPrescription,
  2823. "advices": hisAdvice,
  2824. "monitors": Record,
  2825. "summary": TreatmentSummary,
  2826. "receiverTreatmentAccess": receiverTreatmentAccess,
  2827. "dialysisOrder": dialysisOrder,
  2828. "operators": operators,
  2829. "org_template_info": templateInfo,
  2830. "check": check,
  2831. "dialysiscount": dialysiscount,
  2832. "last_order": last_order,
  2833. "projects": projects,
  2834. "project_config": project_config,
  2835. })
  2836. }
  2837. if config.IsOpen == 0 || config.IsOpen == 2 {
  2838. c.ServeSuccessJSON(map[string]interface{}{
  2839. "users": adminUser,
  2840. "patientInfo": patientInfo,
  2841. "PredialysisEvaluation": PredialysisEvaluation,
  2842. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2843. "dialysisPrescription": dialysisPrescription,
  2844. "advices": DoctorAdvice,
  2845. "monitors": Record,
  2846. "summary": TreatmentSummary,
  2847. "receiverTreatmentAccess": receiverTreatmentAccess,
  2848. "dialysisOrder": dialysisOrder,
  2849. "operators": operators,
  2850. "org_template_info": templateInfo,
  2851. "check": check,
  2852. "dialysiscount": dialysiscount,
  2853. "last_order": last_order,
  2854. "projects": projects,
  2855. "project_config": project_config,
  2856. })
  2857. }
  2858. }
  2859. func (c *PatientApiController) CreateGroupAdvice() {
  2860. is_child, _ := c.GetInt64("is_child", 0)
  2861. if is_child == 1 {
  2862. patient, _ := c.GetInt64("id", 0)
  2863. if patient <= 0 {
  2864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2865. return
  2866. }
  2867. adminUserInfo := c.GetMobileAdminUserInfo()
  2868. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2869. if patientInfo.ID == 0 {
  2870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2871. return
  2872. }
  2873. group_no, _ := c.GetInt64("group_no")
  2874. if group_no <= 0 {
  2875. group_no = 0
  2876. }
  2877. dataBody := make(map[string]interface{}, 0)
  2878. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2879. if err != nil {
  2880. utils.ErrorLog(err.Error())
  2881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2882. return
  2883. }
  2884. timeLayout := "2006-01-02"
  2885. loc, _ := time.LoadLocation("Local")
  2886. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2887. utils.ErrorLog("advice_type")
  2888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2889. return
  2890. }
  2891. adviceType := int64(dataBody["advice_type"].(float64))
  2892. if adviceType != 1 && adviceType != 2 {
  2893. utils.ErrorLog("advice_type != 1&&2")
  2894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2895. return
  2896. }
  2897. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2898. utils.ErrorLog("start_time")
  2899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2900. return
  2901. }
  2902. startTime2, _ := dataBody["start_time"].(string)
  2903. time_arr := strings.Split(startTime2, " ")
  2904. if len(time_arr) > 0 {
  2905. startTime2 = time_arr[0]
  2906. }
  2907. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2908. utils.ErrorLog("advice_date")
  2909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2910. return
  2911. }
  2912. adviceDate := startTime2
  2913. if len(adviceDate) == 0 {
  2914. utils.ErrorLog("len(adviceDate) == 0")
  2915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2916. return
  2917. }
  2918. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2919. if err != nil {
  2920. utils.ErrorLog(err.Error())
  2921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2922. return
  2923. }
  2924. AdviceDate := theTime.Unix()
  2925. RecordDate := theTime.Unix()
  2926. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2927. utils.ErrorLog("start_time")
  2928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2929. return
  2930. }
  2931. startTime, _ := dataBody["start_time"].(string)
  2932. if len(startTime) == 0 {
  2933. utils.ErrorLog("len(start_time) == 0")
  2934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2935. return
  2936. }
  2937. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2938. if err != nil {
  2939. utils.ErrorLog(err.Error())
  2940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2941. return
  2942. }
  2943. StartTime := theTime.Unix()
  2944. Remark := ""
  2945. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2946. remark, _ := dataBody["remark"].(string)
  2947. Remark = remark
  2948. }
  2949. var advices []*models.GroupAdvice
  2950. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2951. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2952. utils.ErrorLog("adviceNames")
  2953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2954. return
  2955. }
  2956. adviceNames := dataBody["adviceNames"].([]interface{})
  2957. for _, adviceNameMap := range adviceNames {
  2958. adviceNameM := adviceNameMap.(map[string]interface{})
  2959. var advice models.GroupAdvice
  2960. advice.Remark = Remark
  2961. advice.AdviceType = adviceType
  2962. advice.StartTime = StartTime
  2963. advice.AdviceDate = AdviceDate
  2964. advice.RecordDate = RecordDate
  2965. advice.Status = 1
  2966. advice.CreatedTime = time.Now().Unix()
  2967. advice.UpdatedTime = time.Now().Unix()
  2968. advice.StopState = 2
  2969. advice.ExecutionState = 2
  2970. advice.UserOrgId = adminUserInfo.Org.Id
  2971. advice.PatientId = patientInfo.ID
  2972. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2973. //入口
  2974. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2975. if errcode > 0 {
  2976. c.ServeFailJSONWithSGJErrorCode(errcode)
  2977. return
  2978. }
  2979. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2980. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2981. if len(subdrugs) > 0 {
  2982. for _, subdrug := range subdrugs {
  2983. var s models.GroupAdvice
  2984. s.Remark = Remark
  2985. s.AdviceType = adviceType
  2986. s.StartTime = StartTime
  2987. s.AdviceDate = AdviceDate
  2988. s.RecordDate = RecordDate
  2989. s.Status = 1
  2990. s.CreatedTime = time.Now().Unix()
  2991. s.UpdatedTime = time.Now().Unix()
  2992. s.StopState = 2
  2993. s.ExecutionState = 2
  2994. s.UserOrgId = adminUserInfo.Org.Id
  2995. s.PatientId = patientInfo.ID
  2996. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2997. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2998. if errcode > 0 {
  2999. c.ServeFailJSONWithSGJErrorCode(errcode)
  3000. return
  3001. }
  3002. advice.Children = append(advice.Children, &s)
  3003. }
  3004. }
  3005. }
  3006. advices = append(advices, &advice)
  3007. }
  3008. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3009. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3010. redis := service.RedisClient()
  3011. //清空key 值
  3012. redis.Set(key, "", time.Second)
  3013. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3014. redis.Set(keyOne, "", time.Second)
  3015. defer redis.Close()
  3016. if createErr != nil {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3018. return
  3019. }
  3020. c.ServeSuccessJSON(map[string]interface{}{
  3021. "msg": "ok",
  3022. "advices": newAdvices,
  3023. })
  3024. return
  3025. } else if is_child == 2 {
  3026. patient, _ := c.GetInt64("id", 0)
  3027. if patient <= 0 {
  3028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3029. return
  3030. }
  3031. adminUserInfo := c.GetMobileAdminUserInfo()
  3032. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3033. if patientInfo.ID == 0 {
  3034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3035. return
  3036. }
  3037. var advice models.DoctorAdvice
  3038. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3039. if code > 0 {
  3040. c.ServeFailJSONWithSGJErrorCode(code)
  3041. return
  3042. }
  3043. if advice.ParentId > 0 {
  3044. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3045. if old.ID == 0 || old.PatientId != patient {
  3046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3047. return
  3048. }
  3049. if old.StopState == 1 || old.ExecutionState == 1 {
  3050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3051. return
  3052. }
  3053. if old.ParentId > 0 {
  3054. advice.ParentId = old.ParentId
  3055. }
  3056. advice.StartTime = old.StartTime
  3057. advice.AdviceDoctor = old.AdviceDoctor
  3058. advice.DeliveryWay = old.DeliveryWay
  3059. advice.ExecutionFrequency = old.ExecutionFrequency
  3060. advice.GroupNo = old.GroupNo
  3061. }
  3062. advice.Status = 1
  3063. advice.CreatedTime = time.Now().Unix()
  3064. advice.UpdatedTime = time.Now().Unix()
  3065. advice.StopState = 2
  3066. advice.ExecutionState = 2
  3067. advice.UserOrgId = adminUserInfo.Org.Id
  3068. advice.PatientId = patient
  3069. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3070. err := service.CreateDoctorAdvice(&advice)
  3071. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3072. redis := service.RedisClient()
  3073. //清空key 值
  3074. redis.Set(key, "", time.Second)
  3075. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3076. redis.Set(keyOne, "", time.Second)
  3077. fmt.Println("key`2232333332233223233232", key)
  3078. defer redis.Close()
  3079. if err != nil {
  3080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3081. return
  3082. }
  3083. c.ServeSuccessJSON(map[string]interface{}{
  3084. "msg": "ok",
  3085. "advice": advice,
  3086. })
  3087. return
  3088. }
  3089. }
  3090. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3091. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3092. utils.ErrorLog("advice_name")
  3093. return enums.ErrorCodeParamWrong
  3094. }
  3095. adviceName, _ := json["advice_name"].(string)
  3096. if len(adviceName) == 0 {
  3097. utils.ErrorLog("len(advice_name) == 0")
  3098. return enums.ErrorCodeParamWrong
  3099. }
  3100. advice.AdviceName = adviceName
  3101. adviceDesc, _ := json["advice_desc"].(string)
  3102. advice.AdviceDesc = adviceDesc
  3103. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3104. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3105. advice.DrugSpec = drugSpec
  3106. }
  3107. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3108. remark, _ := json["remark"].(string)
  3109. advice.Remark = remark
  3110. }
  3111. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3112. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3113. // advice.Way = src_type
  3114. //}
  3115. if json["way"] == nil {
  3116. advice.Way = 0
  3117. } else {
  3118. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3119. way := int64(json["way"].(float64))
  3120. advice.Way = way
  3121. }
  3122. }
  3123. if json["drug_id"] == nil {
  3124. advice.DrugId = 0
  3125. } else {
  3126. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3127. drug_id := int64(json["drug_id"].(float64))
  3128. advice.DrugId = drug_id
  3129. }
  3130. }
  3131. if json["drug_name_id"] == nil {
  3132. advice.DrugNameId = 0
  3133. } else {
  3134. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3135. drug_name_id := int64(json["drug_name_id"].(float64))
  3136. advice.DrugNameId = drug_name_id
  3137. }
  3138. }
  3139. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3140. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3141. advice.DrugSpecUnit = drugSpecUnit
  3142. }
  3143. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3144. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3145. advice.SingleDose = singleDose
  3146. }
  3147. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3148. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3149. advice.SingleDoseUnit = singleDoseUnit
  3150. }
  3151. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3152. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3153. advice.PrescribingNumber = prescribingNumber
  3154. }
  3155. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3156. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3157. advice.PrescribingNumberUnit = prescribingNumberUnit
  3158. }
  3159. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3160. deliveryWay, _ := json["delivery_way"].(string)
  3161. advice.DeliveryWay = deliveryWay
  3162. }
  3163. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3164. executionFrequency, _ := json["execution_frequency"].(string)
  3165. advice.ExecutionFrequency = executionFrequency
  3166. }
  3167. return 0
  3168. }
  3169. func (c *PatientApiController) DelDoctorAdvice() {
  3170. groupno, _ := c.GetInt64("groupno", -1)
  3171. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3172. patient_id, _ := c.GetInt64("patient_id")
  3173. doc_advice_date, _ := c.GetInt64("advice_date")
  3174. redis := service.RedisClient()
  3175. if is_sub == 1 { //是
  3176. advice_id, _ := c.GetInt64("advice_id")
  3177. adminUserInfo := c.GetMobileAdminUserInfo()
  3178. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3179. if advice.ID == 0 {
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3181. return
  3182. }
  3183. advice.Status = 0
  3184. advice.UpdatedTime = time.Now().Unix()
  3185. advice.Modifier = adminUserInfo.AdminUser.Id
  3186. err := service.DeleteDoctorAdvice(&advice)
  3187. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3188. redis.Set(key, "", time.Second)
  3189. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3190. redis.Set(keyTwo, "", time.Second)
  3191. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3192. redis.Set(keyThree, "", time.Second)
  3193. redis.Close()
  3194. if err != nil {
  3195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3196. return
  3197. }
  3198. c.ServeSuccessJSON(map[string]interface{}{
  3199. "msg": "ok",
  3200. })
  3201. return
  3202. } else { //
  3203. var ids []string
  3204. if groupno == 0 {
  3205. advice_id := c.GetString("advice_id")
  3206. ids = strings.Split(advice_id, ",")
  3207. if len(ids) <= 0 {
  3208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3209. return
  3210. }
  3211. }
  3212. if groupno < 0 {
  3213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3214. return
  3215. }
  3216. adminUserInfo := c.GetMobileAdminUserInfo()
  3217. var advice models.DoctorAdvice
  3218. if groupno > 0 {
  3219. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  3220. if advice.ID == 0 {
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3222. return
  3223. }
  3224. } else {
  3225. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  3226. for _, item := range advices {
  3227. if item.ID == 0 {
  3228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3229. return
  3230. }
  3231. }
  3232. }
  3233. advice.UpdatedTime = time.Now().Unix()
  3234. advice.Status = 0
  3235. advice.GroupNo = groupno
  3236. advice.Modifier = adminUserInfo.AdminUser.Id
  3237. var err error
  3238. if groupno > 0 {
  3239. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  3240. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3241. fmt.Println("key2332323223323232323232323", key)
  3242. redis.Set(key, "", time.Second)
  3243. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3244. redis.Set(keyTwo, "", time.Second)
  3245. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3246. redis.Set(keyThree, "", time.Second)
  3247. } else {
  3248. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  3249. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3250. redis.Set(key, "", time.Second)
  3251. fmt.Println("key2332323223323232323232323", key)
  3252. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3253. fmt.Println("key2332323223323232323232323", keyTwo)
  3254. redis.Set(keyTwo, "", time.Second)
  3255. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3256. redis.Set(keyThree, "", time.Second)
  3257. redis.Close()
  3258. }
  3259. if err != nil {
  3260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3261. return
  3262. }
  3263. c.ServeSuccessJSON(map[string]interface{}{
  3264. "msg": "ok",
  3265. })
  3266. return
  3267. }
  3268. }
  3269. // /m/api/advice/group/modify_starttime [post]
  3270. // @param group_no:int
  3271. // @param start_time:string yyyy-MM-dd hh:mm:ss
  3272. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  3273. group_no, _ := this.GetInt64("group_no")
  3274. start_time_str := this.GetString("start_time")
  3275. if group_no <= 0 || len(start_time_str) == 0 {
  3276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3277. return
  3278. }
  3279. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  3280. if parseTimeErr != nil {
  3281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  3282. return
  3283. }
  3284. adminUserInfo := this.GetMobileAdminUserInfo()
  3285. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  3286. if updateStartTimeErr != nil {
  3287. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  3288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3289. return
  3290. }
  3291. this.ServeSuccessJSON(map[string]interface{}{
  3292. "start_time": startTime.Unix(),
  3293. })
  3294. }
  3295. func (this *PatientApiController) DelSubDoctorAdvice() {
  3296. advice_id, _ := this.GetInt64("advice_id")
  3297. adminUserInfo := this.GetMobileAdminUserInfo()
  3298. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3299. if advice.ID == 0 {
  3300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3301. return
  3302. }
  3303. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3304. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  3305. // return
  3306. //}
  3307. advice.Status = 0
  3308. advice.UpdatedTime = time.Now().Unix()
  3309. advice.Modifier = adminUserInfo.AdminUser.Id
  3310. err := service.DeleteDoctorAdvice(&advice)
  3311. if err != nil {
  3312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3313. return
  3314. }
  3315. this.ServeSuccessJSON(map[string]interface{}{
  3316. "msg": "ok",
  3317. })
  3318. return
  3319. }
  3320. func (this *PatientApiController) GetAdviceUnReadMessage() {
  3321. //adminUserInfo := this.GetMobileAdminUserInfo()
  3322. //service.FindUnReadDoctorAdviceMessage()
  3323. }
  3324. func (this *PatientApiController) GetPatientsByKeyWord() {
  3325. keyWord := this.GetString("keyword")
  3326. adminUserInfo := this.GetMobileAdminUserInfo()
  3327. today := utils.ZeroHourTimeOfDay(time.Now())
  3328. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  3329. if err != nil {
  3330. utils.ErrorLog(err.Error())
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3332. return
  3333. }
  3334. this.ServeSuccessJSON(map[string]interface{}{
  3335. "patient": patient,
  3336. })
  3337. }
  3338. func (this *PatientApiController) GetSearchPatient() {
  3339. keyWord := this.GetString("keyword")
  3340. adminUserInfo := this.GetMobileAdminUserInfo()
  3341. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  3342. if err != nil {
  3343. utils.ErrorLog(err.Error())
  3344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3345. return
  3346. }
  3347. this.ServeSuccessJSON(map[string]interface{}{
  3348. "patient": patient,
  3349. })
  3350. }
  3351. func (c *PatientApiController) ExecProject() {
  3352. execution_time := c.GetString("execution_time")
  3353. project_id, _ := c.GetInt64("project_id")
  3354. team_id, _ := c.GetInt64("team_id")
  3355. is_check_team, _ := c.GetInt64("is_check_team")
  3356. if len(execution_time) <= 0 {
  3357. utils.ErrorLog("execution_time")
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3359. return
  3360. }
  3361. timeLayout2 := "2006-01-02 15:04:05"
  3362. loc, _ := time.LoadLocation("Local")
  3363. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3364. if errs != nil {
  3365. utils.ErrorLog(errs.Error())
  3366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3367. return
  3368. }
  3369. adminInfo := c.GetMobileAdminUserInfo()
  3370. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3371. if project.ExecutionState == 1 {
  3372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  3373. return
  3374. }
  3375. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  3376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3377. return
  3378. }
  3379. project.ExecutionState = 1
  3380. project.ExecutionStaff = adminInfo.AdminUser.Id
  3381. project.ExecutionTime = theTime.Unix()
  3382. if team_id == 0 {
  3383. err := service.SaveHisProject(&project)
  3384. if err == nil {
  3385. c.ServeSuccessJSON(map[string]interface{}{
  3386. "project": project,
  3387. })
  3388. } else {
  3389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3390. return
  3391. }
  3392. } else {
  3393. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3394. err := service.SaveHisProject(&project)
  3395. if err == nil {
  3396. c.ServeSuccessJSON(map[string]interface{}{
  3397. "project": project,
  3398. })
  3399. } else {
  3400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3401. return
  3402. }
  3403. } else {
  3404. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3405. var ids []int64
  3406. for _, items := range ps {
  3407. ids = append(ids, items.ID)
  3408. }
  3409. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  3410. if err == nil {
  3411. c.ServeSuccessJSON(map[string]interface{}{
  3412. "project": project,
  3413. })
  3414. } else {
  3415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3416. return
  3417. }
  3418. }
  3419. }
  3420. }
  3421. func (c *PatientApiController) CheckProject() {
  3422. adminInfo := c.GetMobileAdminUserInfo()
  3423. project_id, _ := c.GetInt64("project_id")
  3424. team_id, _ := c.GetInt64("team_id")
  3425. is_check_team, _ := c.GetInt64("is_check_team")
  3426. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3427. if project.CheckState == 1 {
  3428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3429. return
  3430. }
  3431. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  3432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3433. return
  3434. }
  3435. project.Checker = adminInfo.AdminUser.Id
  3436. project.CheckTime = time.Now().Unix()
  3437. project.CheckState = 1
  3438. if team_id == 0 {
  3439. err := service.SaveHisProject(&project)
  3440. if err == nil {
  3441. c.ServeSuccessJSON(map[string]interface{}{
  3442. "msg": "ok",
  3443. "project": project,
  3444. })
  3445. } else {
  3446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3447. return
  3448. }
  3449. } else {
  3450. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3451. err := service.SaveHisProject(&project)
  3452. if err == nil {
  3453. c.ServeSuccessJSON(map[string]interface{}{
  3454. "msg": "ok",
  3455. "project": project,
  3456. })
  3457. } else {
  3458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3459. return
  3460. }
  3461. } else {
  3462. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3463. var ids []int64
  3464. for _, items := range ps {
  3465. ids = append(ids, items.ID)
  3466. }
  3467. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  3468. if err == nil {
  3469. c.ServeSuccessJSON(map[string]interface{}{
  3470. "project": project,
  3471. })
  3472. } else {
  3473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3474. return
  3475. }
  3476. }
  3477. }
  3478. }