patient_api_controller.go 149KB

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