patient_api_controller.go 119KB

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