patient_api_controller.go 115KB

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