patient_api_controller.go 115KB

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