patient_api_controller.go 146KB

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