patient_api_controller.go 116KB

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