patient_api_controller.go 151KB

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