health.model.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. export interface AnalysisModel {
  2. table: {
  3. columns: string[];
  4. data: { exception?: boolean; invalid?: boolean; }[];
  5. };
  6. exception: AnalysisException[];
  7. cover: string[];
  8. result: string;
  9. }
  10. export interface AnalysisException {
  11. key: string;
  12. title: string;
  13. cover?: string;
  14. description?: string;
  15. descriptions: { label: string; value: string }[];
  16. tags: string[];
  17. }
  18. export function healthAnalysisModel(data: AnyObject) {
  19. return {
  20. id: data?.id ?? '',
  21. reportTime: data?.reportTime,
  22. tongue: tongueAnalysisModel(data),
  23. face: faceAnalysisModel(data),
  24. }
  25. }
  26. export function healthReportModel(data: AnyObject) {
  27. const fn = (label: string, value?: string, force = false) => value || force ? { label, value: value ?? '' } : void 0;
  28. return {
  29. id: data?.healthAnalysisReportId ?? '',
  30. reportTime: data?.reportTime,
  31. reportId: data?.healthAnalysisReportId ?? '',
  32. analysisId: data?.tonguefaceAnalysisReportId ?? '',
  33. tongue: tongueAnalysisModel(data),
  34. face: faceAnalysisModel(data),
  35. report: [
  36. fn('结果显示您是', data?.willillStateName, true),
  37. fn('程度', data?.willillDegreeName, true),
  38. fn('类型', data?.willillSocialName, true),
  39. fn('表现', data?.willillFunctionName, true),
  40. fn('体质', data?.constitutionGroupName, true),
  41. fn('证素', data?.factorItemSummary, true),
  42. fn('证型', data?.diagnoseSyndromeSummary, true),
  43. ].filter(Boolean),
  44. result: data?.constitutionGroupDefinition ?? '',
  45. physique: [
  46. fn('总体特征', data?.constitutionGroupGeneralCharacteristics, true),
  47. fn('形体特征', data?.constitutionGroupPhysicalCharacteristics, true),
  48. fn('精神特征', data?.constitutionGroupPsychicCharacteristics, true),
  49. fn('常见表现', data?.constitutionGroupCommonManifestations, true),
  50. fn('发病倾向', data?.constitutionGroupDiseaseTendency, true),
  51. fn('环境适应能力', data?.constitutionGroupAdaptability, true),
  52. ].filter(Boolean),
  53. __origin__: data ?? {},
  54. }
  55. }
  56. /**
  57. * 健康档案显示数据
  58. * @param data
  59. */
  60. export function healthRecord(data: ReturnType<typeof healthReportModel>) {
  61. const fn = (label: string, value?: string, force = false) => value || force ? { label, value: value ?? '' } : void 0;
  62. const conditProgram = data?.__origin__?.conditProgram;
  63. if (Array.isArray(conditProgram?.types)) {
  64. conditProgram.types = conditProgram.types.map((item: AnyObject) => ({ type: item.type }))
  65. }
  66. return {
  67. reportId: data?.reportId,
  68. analysisId: data?.analysisId,
  69. condition: [fn('症状信息', data?.__origin__?.pickedSymptom)].filter(Boolean),
  70. report: data?.report ?? [],
  71. analysis: [
  72. data?.tongue?.result ? { value: data.tongue.result, cover: data.tongue.cover } : void 0,
  73. ].filter(Boolean),
  74. conditProgram,
  75. }
  76. }
  77. function tongueAnalysisModel(data: AnyObject): AnalysisModel {
  78. const exception: AnalysisException[] = [];
  79. const tongueException = analysisException(exception);
  80. const c1 = data?.upImg;
  81. const c2 = data?.downImg;
  82. return {
  83. table: {
  84. columns: ['舌象维度', '检测结果', '标准值'],
  85. data: [
  86. tongueException(data?.tongueColor, '舌色'),
  87. tongueException(data?.tongueCoatingColor, '苔色'),
  88. tongueException(data?.tongueShape, '舌形'),
  89. tongueException(data?.tongueCoating, '苔质'),
  90. tongueException(data?.bodyFluid, '津液'),
  91. tongueException(data?.sublingualVein, '舌下'),
  92. ],
  93. },
  94. exception,
  95. result: data?.tongueAnalysisResult ?? '',
  96. cover: Object.assign([c1, c2].filter(Boolean), {
  97. ['舌上']: c1,
  98. ['舌下']: c2,
  99. }),
  100. }
  101. }
  102. function faceAnalysisModel(data: AnyObject): AnalysisModel {
  103. const exception: AnalysisException[] = [];
  104. const faceException = analysisException(exception, (label, value) => `${label}${value}`);
  105. const c1 = data?.faceImg ?? data?.faceImgUrl;
  106. const c2 = data?.faceLeft ?? data?.faceLeftImgUrl;
  107. const c3 = data?.faceRight ?? data?.faceRightImgUrl;
  108. return {
  109. table: {
  110. columns: ['面象维度', '检测结果', '标准值'],
  111. data: [
  112. faceException(data?.faceColor, '面色'),
  113. faceException(data?.mainColor, '主色'),
  114. faceException(data?.shine, '光泽'),
  115. // faceException(data?.leftBlackEye, '左黑眼圈'),
  116. // faceException(data?.rightBlackEye, '右黑眼圈'),
  117. faceException(data?.blackEye, '黑眼圈'),
  118. faceException(data?.lipColor, '唇色'),
  119. faceException(data?.eyeContact, '眼神'),
  120. // faceException(data?.leftEyeColor, '左目色'),
  121. // faceException(data?.rightEyeColor, '右目色'),
  122. faceException(data?.eyeColor, '目色'),
  123. faceException(data?.hecticCheek, '两颧红'),
  124. faceException(data?.noseFold, '鼻褶'),
  125. faceException(data?.cyanGlabella, '眉间/鼻柱青色'),
  126. faceException(data?.faceSkinDefects, '面部皮损'),
  127. ],
  128. },
  129. exception,
  130. result: data?.faceAnalysisResult ?? data?.face ?? '',
  131. cover: Object.assign([c1, c2, c3].filter(Boolean), {
  132. ['正面']: c1,
  133. ['左面']: c2,
  134. ['右面']: c3,
  135. }),
  136. };
  137. }
  138. function analysisException(exception: AnalysisException[], $title = (label: string, value: string) => value,) {
  139. return (data: { actualList?: AnyObject[]; standardValue?: string }, label: string) => {
  140. let is = false;
  141. let invalid = false;
  142. const values = data?.actualList?.map((item) => {
  143. let title: string = item?.actualValue ?? '';
  144. const suffix = item?.contrast ?? 's';
  145. if (title.endsWith('不符合检测要求')) {
  146. invalid = true;
  147. } else if (suffix !== 's') {
  148. if (suffix !== 'r') title += ` (${suffix || ''}) `;
  149. is = true;
  150. exception.push({
  151. key: title,
  152. title: $title(label, title),
  153. cover: item.splitImage,
  154. descriptions: [
  155. item.features ? { label: '【特征】', value: item.features } : null,
  156. item.clinicalSignificance ? { label: '【临床意义】', value: item.clinicalSignificance } : null,
  157. ].filter(Boolean) as any,
  158. tags: item.attrs ?? [],
  159. });
  160. }
  161. return title;
  162. }) ?? [];
  163. return Object.assign({
  164. 0: label,
  165. 1: values.join('<br>'),
  166. 2: data?.standardValue ?? ''
  167. }, { exception: is, invalid });
  168. }
  169. }