patient_api_controller.go 157KB

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