report.api.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import {
  2. type AnalysisRecordModel,
  3. type List,
  4. type PatientRecordModel,
  5. type ReportIndicatorModel,
  6. type ReportModel,
  7. type ReportSchemeItemModel,
  8. transformAnalysisRecord,
  9. transformIndicators,
  10. transformPatientRecord,
  11. transformReportScheme,
  12. transformReportSchemeItem,
  13. } from '@/model';
  14. import request from '@/request/alova';
  15. import dayjs from 'dayjs';
  16. import { fromHealthIndicator, fromHealthReport, type HealthIndicatorItemVO, type HealthIndicatorVO, type HealthReportDTO, type HealthReportVO } from '@/model/health-report.model';
  17. import { type DiagnosisReportDTO, type DiagnosisReportVO, fromDiagnosisReport } from '@/model/diagnosis-report.model';
  18. import { type FollowUpReportDTO, type FollowUpReportVO, fromFollowUpReport } from '@/model/follow-up-report.model';
  19. export function reportsMethod(patientId: string) {
  20. return request.Get<ReportModel[], any[]>(`/fdhb-pc/analysisManage/getHarsTid`, {
  21. name: 'list-report',
  22. params: { patientId },
  23. transform(data, headers) {
  24. return data?.map(item => {
  25. return {
  26. ...item,
  27. id: item.healthAnalysisReportId,
  28. time: item.time2,
  29. };
  30. }) ?? [];
  31. },
  32. });
  33. }
  34. export function reportMethod(id: string) {
  35. return request.Get<ReportModel, any>(`/fdhb-pc/analysisManage/getHealRepDetailById`, {
  36. hitSource: 'confirm-scheme',
  37. name: 'get-report',
  38. params: { healthAnalysisReportId: id },
  39. transform(data, headers) {
  40. return {
  41. ...data,
  42. id: data.healthAnalysisReportId,
  43. time: data.reportTime,
  44. analysable: data.reportTime === dayjs().format('YYYY年MM月DD日'),
  45. scheme: {
  46. show: data.isHaveConditioningProgram === 'Y',
  47. editable: data.isConfirmConditioningProgram !== 'Y',
  48. },
  49. };
  50. },
  51. });
  52. }
  53. export function patientHealthReportMethod(id: string) {
  54. return request.Get<HealthReportVO, HealthReportDTO>(`/fdhb-pc/analysisManage/getHealRepDetailById`, {
  55. hitSource: 'confirm-scheme',
  56. name: 'get-report',
  57. params: { healthAnalysisReportId: id },
  58. transform: fromHealthReport,
  59. });
  60. }
  61. export function reportSchemeMethod(reportId: string) {
  62. return request.Get(`/fdhb-pc/analysisManage/getCondProgDetailById`, {
  63. hitSource: /-scheme$/,
  64. name: 'report-scheme',
  65. params: { healthAnalysisReportId: reportId },
  66. transform(data: any, headers) {
  67. data.healthAnalysisReportId ??= reportId;
  68. return transformReportScheme(data);
  69. },
  70. });
  71. }
  72. export function searchSchemeMethod(keyword?: string, query?: Partial<ReportSchemeItemModel>) {
  73. return request.Get(`/fdhb-pc/analysisManage/condProgramQuery`, {
  74. params: { type: query?.category, name: keyword ?? query?.name ?? '' },
  75. transform(data: any[], headers) {
  76. const groups = data.map((group: any, index: number) => {
  77. const { id, ...scheme } = transformReportSchemeItem(query?.category!, group);
  78. return {
  79. ...scheme,
  80. name: scheme.name ?? `预设 ${ index + 1 }`,
  81. label: scheme.name ?? `预设 ${ index + 1 }`,
  82. };
  83. });
  84. if ( keyword && !groups.find(group => group.label === keyword) ) groups.unshift(<any>{ name: keyword, label: keyword });
  85. return groups;
  86. },
  87. });
  88. }
  89. export function editSchemeMethod(reportId: string, scheme: ReportSchemeItemModel) {
  90. const method = scheme.id ? `Update` : `Add`;
  91. const filterData = (data?: any[]) => data?.filter(t => t.name)?.map(({ id, ...t }) => Object.assign(t, { id: /^custom-/.test(id!) ? '' : id }));
  92. return request.Post(`/fdhb-pc/analysisManage/condProgram${ method }`, {
  93. healthAnalysisReportId: reportId,
  94. type: scheme.category,
  95. id: scheme.id,
  96. name: scheme.name ?? '',
  97. items: filterData(scheme.content),
  98. attrs: filterData(scheme.descriptions),
  99. }, {
  100. name: 'edit-scheme',
  101. transform(data: string, headers) {
  102. scheme.id ??= data;
  103. return scheme;
  104. },
  105. });
  106. }
  107. export function deleteSchemeMethod(reportId: string, scheme: ReportSchemeItemModel) {
  108. return request.Get(`/fdhb-pc/analysisManage/condProgramDelete`, {
  109. name: 'delete-scheme',
  110. params: { id: scheme.id },
  111. transform(data: any, headers) {
  112. return scheme;
  113. },
  114. });
  115. }
  116. /**
  117. * 确认调理方案
  118. * @param reportId 报告 ID
  119. */
  120. export function confirmSchemeMethod(reportId: string) {
  121. return request.Get(`/fdhb-pc/analysisManage/condProgramConfirm`, {
  122. name: 'confirm-scheme',
  123. params: { healthAnalysisReportId: reportId },
  124. cacheFor: null,
  125. });
  126. }
  127. /**
  128. * 报告指标
  129. * @param reportId 报告 ID
  130. * @param filter 默认过滤空值
  131. */
  132. export function indicatorByReportIdMethod(reportId: string, filter = true) {
  133. return request.Get<ReportIndicatorModel[], any[]>(`/fdhb-pc/analysisManage/getLast7Day`, {
  134. hitSource: 'update-indicator',
  135. name: 'report-indicator',
  136. params: { healthAnalysisReportId: reportId },
  137. transform(data, headers) {
  138. const indicators = transformIndicators(data);
  139. return filter ? indicators.filter(model => !!model.value) : indicators;
  140. },
  141. });
  142. }
  143. /**
  144. * 患者指标
  145. * @param patientId 患者ID
  146. * @param filter 默认过滤空值
  147. */
  148. export function indicatorByPatientIdMethod(patientId: string, filter = true) {
  149. return request.Get<ReportIndicatorModel[], any[]>(`/fdhb-pc/patientQuota/getCurQuovalByPatId`, {
  150. hitSource: 'update-indicator',
  151. name: 'patient-indicator',
  152. params: { patientId },
  153. transform(data, headers) {
  154. const indicators = transformIndicators(data);
  155. return filter ? indicators.filter(model => !!model.value) : indicators;
  156. },
  157. });
  158. }
  159. /**
  160. * 患者指标更新记录
  161. * @param patientId 患者ID
  162. * @param filter 默认过滤空值
  163. */
  164. export function indicatorUpdateRecordsMethod(patientId: string, filter = true) {
  165. return request.Get<ReportIndicatorModel[], any[]>(`/fdhb-pc/patientQuota/getQuovalRecord`, {
  166. hitSource: 'update-indicator',
  167. params: { patientId },
  168. transform(data, headers) {
  169. const indicators = transformIndicators(data);
  170. return filter ? indicators.filter(model => !!model.records?.length) : indicators;
  171. },
  172. });
  173. }
  174. /**
  175. * 更新患者指标
  176. * @param patientId 患者ID
  177. * @param model 指标数据
  178. */
  179. export function updateIndicatorByPatientIdMethod(patientId: string, model: Record<string, number>) {
  180. const data = Object.entries(model).map(([ quotaId, quotaVal ]) => (
  181. {
  182. quotaId,
  183. quotaVal,
  184. }
  185. )).filter(item => !!item.quotaVal);
  186. return request.Post(`/fdhb-pc/patientQuota/updateQuovalByPatId`, { patientId, updatePatientQuotaVOS: data }, {
  187. name: 'update-indicator',
  188. });
  189. }
  190. // 患者数据更新记录
  191. export function patientUpdateRecordsMethod(page: number, size: number, query: { patientId: string }) {
  192. return request.Get<List<PatientRecordModel>, List<any>>(`/fdhb-pc/patientInfoManage/pageChangeRecordById`, {
  193. params: { pageNum: page, pageSize: size, ...query },
  194. transform({ data, total }, headers) {
  195. return { total, data: data.map(transformPatientRecord) };
  196. },
  197. });
  198. }
  199. // 患者分析更新记录
  200. export function analysisUpdateRecordsMethod(page: number, size: number, query: { patientId: string }) {
  201. return request.Post<List<AnalysisRecordModel>, List<any>>(`/fdhb-pc/analysisManage/pageHarStatu`, {}, {
  202. params: { pageNum: page, pageSize: size, ...query },
  203. transform({ data, total }, headers) {
  204. return { total, data: data.map(transformAnalysisRecord) };
  205. },
  206. });
  207. }
  208. /**
  209. * 获取患者健康分析记录列表
  210. * @param page
  211. * @param size
  212. * @param query
  213. */
  214. export function getPatientHealthRecordsMethod(page: number, size: number, query: { patientId: string }) {
  215. return request.Post<{ total: number; data: HealthReportVO[] }, { total: number; data: HealthReportDTO[] }>(`/fdhb-pc/analysisManage/pageHarStatu`, query, {
  216. params: { pageNum: page, pageSize: size, ...query },
  217. transform({ data, total }) {
  218. return { total, data: data.map(fromHealthReport) };
  219. },
  220. });
  221. }
  222. export function getPatientHealthRecordMethod(id: string) {
  223. return request.Get<HealthReportVO, HealthReportDTO>(`/fdhb-pc/analysisManage/getHealRepDetailById`, {
  224. params: { healthAnalysisReportId: id },
  225. transform(data) {
  226. return fromHealthReport(data);
  227. },
  228. });
  229. }
  230. export function getPatientHealthIndicatorsMethod(patientId: string) {
  231. return request.Get<HealthIndicatorVO[], any[]>(`/fdhb-pc/patientQuota/getQuovalRecord`, {
  232. hitSource: 'update-indicator',
  233. name: 'patient-indicator',
  234. params: { patientId },
  235. transform(data) {
  236. return data.map(fromHealthIndicator).filter(indicator => indicator.items.length);
  237. },
  238. });
  239. }
  240. export function getPatientHealthIndicatorMethod(patientId: string) {
  241. return request.Get<HealthIndicatorItemVO[], any[]>(`/fdhb-pc/patientQuota/getCurQuovalByPatId`, {
  242. hitSource: 'update-indicator',
  243. name: 'patient-indicator',
  244. params: { patientId },
  245. transform(data) {
  246. return data.map((indicator) => {
  247. const { items, ...collection } = fromHealthIndicator(indicator);
  248. return { ...collection, ...items[0] };
  249. }).filter(item => !!item.value);
  250. },
  251. });
  252. }
  253. /**
  254. * 获取患者就诊记录列表
  255. * @param page
  256. * @param size
  257. * @param query
  258. */
  259. export function getPatientDiagnosisRecordsMethod(page: number, size: number, query: { patientId: string }) {
  260. const start = (page - 1) * size;
  261. return request.Post<{ total: number; data: DiagnosisReportVO[] }, { total: number; data: DiagnosisReportDTO[] }>(`/fdhb-pc/patientMedicalManage/pagePatientMedical`, query, {
  262. params: { pageNum: page, pageSize: size, ...query },
  263. transform({ data, total }) {
  264. return { total, data: data.map((item, index) => Object.assign(fromDiagnosisReport(item), { id: start + index })) };
  265. },
  266. });
  267. }
  268. export function getPatientDiagnosisReportMethod(id: string | number, patientId?: string) {
  269. if (typeof id === 'string') return request.Post<DiagnosisReportVO, any>('/');
  270. const size = 100;
  271. const page = ~~(id / size) + 1;
  272. const index = id % size;
  273. return request.Post<DiagnosisReportVO, { total: number; data: DiagnosisReportDTO[] }>(
  274. `/fdhb-pc/patientMedicalManage/pagePatientMedical`,
  275. { patientId },
  276. {
  277. params: { pageNum: page, pageSize: size, patientId },
  278. transform({ data }) {
  279. return fromDiagnosisReport(data[index]);
  280. },
  281. },
  282. );
  283. }
  284. }