From 2d424055e9d337401f31d9ad0e69967dbb756cf2 Mon Sep 17 00:00:00 2001 From: Hunter Craft <118154470+hunterckx@users.noreply.github.com> Date: Tue, 16 May 2023 21:08:44 -0700 Subject: [PATCH] feat: add consent code descriptions to ncpi catalog (anvilproject/anvil-portal#2665) (#3354) feat: add consent code descriptions to ncpi catalog (anvil#2665) --- .../catalog/ncpi-catalog-dug/common/utils.ts | 1 + .../catalog/ncpi-catalog/common/entities.ts | 3 +++ .../apis/catalog/ncpi-catalog/common/utils.ts | 2 ++ .../ConsentTooltip/consentTooltip.tsx | 18 +++++++++++++ .../ConsentCodesCell/consentCodesCell.tsx | 22 ++++++++++++++++ explorer/app/components/index.tsx | 2 ++ .../ncpi-catalog/common/viewModelBuilders.ts | 26 +++++++++++++++---- .../files/ncpi-catalog/build-plaftorms.ts | 5 ++++ .../ncpi-catalog/build-platform-studies.ts | 10 +++++++ .../dev/index/platformsEntityConfig.ts | 4 +-- .../dev/index/studiesEntityConfig.ts | 4 +-- 11 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 explorer/app/components/Detail/components/ConsentTooltip/consentTooltip.tsx create mode 100644 explorer/app/components/Index/components/ConsentCodesCell/consentCodesCell.tsx diff --git a/explorer/app/apis/catalog/ncpi-catalog-dug/common/utils.ts b/explorer/app/apis/catalog/ncpi-catalog-dug/common/utils.ts index 4b2a9a697..4816ff24f 100644 --- a/explorer/app/apis/catalog/ncpi-catalog-dug/common/utils.ts +++ b/explorer/app/apis/catalog/ncpi-catalog-dug/common/utils.ts @@ -26,6 +26,7 @@ export function DugStudyInputMapper(dugStudy: DugStudy): DugCatalogStudy { function sanitizeStudy(dugStudy: DugStudy): DugCatalogStudy { return { consentCode: sanitizeStringArray(dugStudy.consentCodes), + consentLongName: sanitizeStringArray(dugStudy.consentLongNames), dataType: sanitizeStringArray(dugStudy.dataTypes), dbGapId: dugStudy.dbGapId, focus: sanitizeString(dugStudy.focus), diff --git a/explorer/app/apis/catalog/ncpi-catalog/common/entities.ts b/explorer/app/apis/catalog/ncpi-catalog/common/entities.ts index f255f6fb0..d62d9fc57 100644 --- a/explorer/app/apis/catalog/ncpi-catalog/common/entities.ts +++ b/explorer/app/apis/catalog/ncpi-catalog/common/entities.ts @@ -6,6 +6,7 @@ export interface PlatformStudy { } export interface NCPIStudy extends DbGapStudy { + consentLongNames: string[]; platforms: string[]; } @@ -15,6 +16,7 @@ export type NCPICatalogEntity = NCPICatalogPlatform | NCPICatalogStudy; export interface NCPICatalogPlatform { consentCode: string[]; + consentLongName: string[]; dataType: string[]; dbGapId: string[]; focus: string[]; @@ -27,6 +29,7 @@ export interface NCPICatalogPlatform { export interface NCPICatalogStudy { consentCode: string[]; + consentLongName: string[]; dataType: string[]; dbGapId: string; focus: string; diff --git a/explorer/app/apis/catalog/ncpi-catalog/common/utils.ts b/explorer/app/apis/catalog/ncpi-catalog/common/utils.ts index 87b7491ce..13eb0cf74 100644 --- a/explorer/app/apis/catalog/ncpi-catalog/common/utils.ts +++ b/explorer/app/apis/catalog/ncpi-catalog/common/utils.ts @@ -7,6 +7,7 @@ import { NCPICatalogPlatform, NCPICatalogStudy, NCPIStudy } from "./entities"; export function NCPIStudyInputMapper(ncpiStudy: NCPIStudy): NCPICatalogStudy { const ncpiCatalogStudy: NCPICatalogStudy = { consentCode: sanitizeStringArray(ncpiStudy.consentCodes), + consentLongName: sanitizeStringArray(ncpiStudy.consentLongNames), dataType: sanitizeStringArray(ncpiStudy.dataTypes), dbGapId: ncpiStudy.dbGapId, focus: sanitizeString(ncpiStudy.focus), @@ -25,6 +26,7 @@ export function NCPIPlatformInputMapper( ): NCPICatalogPlatform { const ncpiCatalogPlatform: NCPICatalogPlatform = { consentCode: sanitizeStringArray(ncpiPlatform.consentCode), + consentLongName: sanitizeStringArray(ncpiPlatform.consentLongName), dataType: sanitizeStringArray(ncpiPlatform.dataType), dbGapId: sanitizeStringArray(ncpiPlatform.dbGapId), focus: sanitizeStringArray(ncpiPlatform.focus), diff --git a/explorer/app/components/Detail/components/ConsentTooltip/consentTooltip.tsx b/explorer/app/components/Detail/components/ConsentTooltip/consentTooltip.tsx new file mode 100644 index 000000000..f981f485b --- /dev/null +++ b/explorer/app/components/Detail/components/ConsentTooltip/consentTooltip.tsx @@ -0,0 +1,18 @@ +import { Tooltip } from "@mui/material"; + +interface ConsentTooltipProps { + consentCode: string; + consentLongName: string; +} + +export const ConsentTooltip = ({ + consentCode, + consentLongName, +}: ConsentTooltipProps): JSX.Element => { + if (/^unspecified$|^error/i.test(consentLongName)) consentLongName = ""; + return ( + + {consentCode} + + ); +}; diff --git a/explorer/app/components/Index/components/ConsentCodesCell/consentCodesCell.tsx b/explorer/app/components/Index/components/ConsentCodesCell/consentCodesCell.tsx new file mode 100644 index 000000000..ef56b6b8d --- /dev/null +++ b/explorer/app/components/Index/components/ConsentCodesCell/consentCodesCell.tsx @@ -0,0 +1,22 @@ +import { ConsentTooltip, NTagCell } from "app/components"; + +interface ConsentCodesCellProps { + consentCode: string[]; + consentLongName: string[]; + label: string; +} + +export const ConsentCodesCell = ({ + consentCode, + consentLongName, + label, +}: ConsentCodesCellProps): JSX.Element => { + return consentCode.length === 1 ? ( + + ) : ( + + ); +}; diff --git a/explorer/app/components/index.tsx b/explorer/app/components/index.tsx index 015311388..9da21a044 100644 --- a/explorer/app/components/index.tsx +++ b/explorer/app/components/index.tsx @@ -41,9 +41,11 @@ export { Publications } from "@clevercanary/data-explorer-ui/lib/components/Proj export { SupplementaryLinks } from "@clevercanary/data-explorer-ui/lib/components/Project/components/SupplementaryLinks/supplementaryLinks"; export { TitledText } from "@clevercanary/data-explorer-ui/lib/components/Project/components/TitledText/titledText"; export { MdxMarkdown } from "./common/MDXMarkdown/mdxMarkdown"; +export { ConsentTooltip } from "./Detail/components/ConsentTooltip/consentTooltip"; export { ConsortiumOverview } from "./Detail/components/Consortium/ConsortiumOverview/consortiumOverview"; export { FileLocationArchivePreview } from "./Detail/components/GeneratedMatricesTables/components/FileLocationArchivePreview/fileLocationArchivePreview"; export { FileLocationCopy } from "./Detail/components/GeneratedMatricesTables/components/FileLocationCopy/fileLocationCopy"; export { FileLocationDownload } from "./Detail/components/GeneratedMatricesTables/components/FileLocationDownload/fileLocationDownload"; export { FileNameCell } from "./Detail/components/GeneratedMatricesTables/components/FileNameCell/fileNameCell"; export { GeneratedMatricesTables } from "./Detail/components/GeneratedMatricesTables/generatedMatricesTables"; +export { ConsentCodesCell } from "./Index/components/ConsentCodesCell/consentCodesCell"; diff --git a/explorer/app/viewModelBuilders/catalog/ncpi-catalog/common/viewModelBuilders.ts b/explorer/app/viewModelBuilders/catalog/ncpi-catalog/common/viewModelBuilders.ts index 1d7a806dc..62bdbc732 100644 --- a/explorer/app/viewModelBuilders/catalog/ncpi-catalog/common/viewModelBuilders.ts +++ b/explorer/app/viewModelBuilders/catalog/ncpi-catalog/common/viewModelBuilders.ts @@ -23,10 +23,11 @@ import { getPluralizedMetadataLabel } from "../../../../components/Index/common/ */ export const buildConsentCodes = ( ncpiCatalogEntry: NCPICatalogEntity -): React.ComponentProps => { +): React.ComponentProps => { return { + consentCode: ncpiCatalogEntry.consentCode, + consentLongName: ncpiCatalogEntry.consentLongName, label: getPluralizedMetadataLabel(METADATA_KEY.CONSENT_CODE), - values: ncpiCatalogEntry.consentCode, }; }; @@ -239,10 +240,25 @@ export const buildStudyHero = ( export const buildStudySummary = ( ncpiCatalogStudy: NCPICatalogStudy ): React.ComponentProps => { - const { consentCode, dataType, focus, participantCount, studyDesign } = - ncpiCatalogStudy; + const { + consentCode, + consentLongName, + dataType, + focus, + participantCount, + studyDesign, + } = ncpiCatalogStudy; const keyValuePairs = new Map(); - keyValuePairs.set("Consent Codes", stringifyValues(consentCode)); + keyValuePairs.set( + "Consent Codes", + consentCode.map((code, i) => [ + i ? ", " : "", + C.ConsentTooltip({ + consentCode: code, + consentLongName: consentLongName[i], + }), + ]) + ); keyValuePairs.set("Focus / Diseases", focus); keyValuePairs.set("Study Design", stringifyValues(studyDesign)); keyValuePairs.set("Data Types", stringifyValues(dataType)); diff --git a/explorer/files/ncpi-catalog/build-plaftorms.ts b/explorer/files/ncpi-catalog/build-plaftorms.ts index 93cadf99f..b8b254ee4 100644 --- a/explorer/files/ncpi-catalog/build-plaftorms.ts +++ b/explorer/files/ncpi-catalog/build-plaftorms.ts @@ -50,6 +50,10 @@ function buildNCPICatalogPlatform( ncpiCatalogPlatform.consentCode, ncpiStudy.consentCodes ); + const consentLongName = accumulateValues( + ncpiCatalogPlatform.consentLongName, + ncpiStudy.consentLongNames + ); const dataType = accumulateValues( ncpiCatalogPlatform.dataType, ncpiStudy.dataTypes @@ -74,6 +78,7 @@ function buildNCPICatalogPlatform( ); return { consentCode, + consentLongName, dataType, dbGapId, focus, diff --git a/explorer/files/ncpi-catalog/build-platform-studies.ts b/explorer/files/ncpi-catalog/build-platform-studies.ts index ac0657c00..97d73167c 100644 --- a/explorer/files/ncpi-catalog/build-platform-studies.ts +++ b/explorer/files/ncpi-catalog/build-platform-studies.ts @@ -3,6 +3,7 @@ import { NCPIStudy, PlatformStudy, } from "../../app/apis/catalog/ncpi-catalog/common/entities"; +import { generateConsentDescriptions } from "../common/consent-codes"; import { getStudy } from "../common/dbGaP"; /** @@ -34,8 +35,17 @@ export async function buildNCPIPlatformStudies( continue; } + const consentLongNames = []; + + for (const code of study.consentCodes) { + consentLongNames.push( + (await generateConsentDescriptions(code)).consentLongName + ); + } + const ncpiStudy = { ...study, + consentLongNames, platforms: [stub.platform], }; diff --git a/explorer/site-config/ncpi-catalog/dev/index/platformsEntityConfig.ts b/explorer/site-config/ncpi-catalog/dev/index/platformsEntityConfig.ts index 867e2f0b7..51c5bf43e 100644 --- a/explorer/site-config/ncpi-catalog/dev/index/platformsEntityConfig.ts +++ b/explorer/site-config/ncpi-catalog/dev/index/platformsEntityConfig.ts @@ -86,9 +86,9 @@ export const platformsEntityConfig: EntityConfig = { }, { componentConfig: { - component: Components.NTagCell, + component: Components.ConsentCodesCell, viewBuilder: ViewBuilder.buildConsentCodes, - } as ComponentConfig, + } as ComponentConfig, header: NCPI_CATALOG_CATEGORY_LABEL.CONSENT_CODE, id: NCPI_CATALOG_CATEGORY_KEY.CONSENT_CODE, width: { max: "1.6fr", min: "160px" }, diff --git a/explorer/site-config/ncpi-catalog/dev/index/studiesEntityConfig.ts b/explorer/site-config/ncpi-catalog/dev/index/studiesEntityConfig.ts index 4f9f688c0..f1d276417 100644 --- a/explorer/site-config/ncpi-catalog/dev/index/studiesEntityConfig.ts +++ b/explorer/site-config/ncpi-catalog/dev/index/studiesEntityConfig.ts @@ -96,9 +96,9 @@ export const studiesEntityConfig: EntityConfig = { }, { componentConfig: { - component: Components.NTagCell, + component: Components.ConsentCodesCell, viewBuilder: ViewBuilder.buildConsentCodes, - } as ComponentConfig, + } as ComponentConfig, header: NCPI_CATALOG_CATEGORY_LABEL.CONSENT_CODE, id: NCPI_CATALOG_CATEGORY_KEY.CONSENT_CODE, width: { max: "1.6fr", min: "160px" },