patient_api_controller.go 145KB

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