patient_api_controller.go 116KB

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