patient_api_controller.go 116KB

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