patient_api_controller.go 122KB

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