patient_api_controller.go 152KB

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