patient_api_controller.go 163KB

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