patient_api_controller.go 158KB

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