Skip to content

Commit

Permalink
feat: add consent code descriptions to ncpi catalog (anvilproject/anv…
Browse files Browse the repository at this point in the history
…il-portal#2665) (#3354)

feat: add consent code descriptions to ncpi catalog (anvil#2665)
  • Loading branch information
hunterckx committed Aug 11, 2023
1 parent 4821a14 commit 2d42405
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 9 deletions.
1 change: 1 addition & 0 deletions explorer/app/apis/catalog/ncpi-catalog-dug/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions explorer/app/apis/catalog/ncpi-catalog/common/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PlatformStudy {
}

export interface NCPIStudy extends DbGapStudy {
consentLongNames: string[];
platforms: string[];
}

Expand All @@ -15,6 +16,7 @@ export type NCPICatalogEntity = NCPICatalogPlatform | NCPICatalogStudy;

export interface NCPICatalogPlatform {
consentCode: string[];
consentLongName: string[];
dataType: string[];
dbGapId: string[];
focus: string[];
Expand All @@ -27,6 +29,7 @@ export interface NCPICatalogPlatform {

export interface NCPICatalogStudy {
consentCode: string[];
consentLongName: string[];
dataType: string[];
dbGapId: string;
focus: string;
Expand Down
2 changes: 2 additions & 0 deletions explorer/app/apis/catalog/ncpi-catalog/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Tooltip arrow={true} placement="top" title={consentLongName}>
<span>{consentCode}</span>
</Tooltip>
);
};
Original file line number Diff line number Diff line change
@@ -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 ? (
<ConsentTooltip
consentCode={consentCode[0]}
consentLongName={consentLongName[0]}
/>
) : (
<NTagCell label={label} values={consentCode} />
);
};
2 changes: 2 additions & 0 deletions explorer/app/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import { getPluralizedMetadataLabel } from "../../../../components/Index/common/
*/
export const buildConsentCodes = (
ncpiCatalogEntry: NCPICatalogEntity
): React.ComponentProps<typeof C.NTagCell> => {
): React.ComponentProps<typeof C.ConsentCodesCell> => {
return {
consentCode: ncpiCatalogEntry.consentCode,
consentLongName: ncpiCatalogEntry.consentLongName,
label: getPluralizedMetadataLabel(METADATA_KEY.CONSENT_CODE),
values: ncpiCatalogEntry.consentCode,
};
};

Expand Down Expand Up @@ -239,10 +240,25 @@ export const buildStudyHero = (
export const buildStudySummary = (
ncpiCatalogStudy: NCPICatalogStudy
): React.ComponentProps<typeof C.Details> => {
const { consentCode, dataType, focus, participantCount, studyDesign } =
ncpiCatalogStudy;
const {
consentCode,
consentLongName,
dataType,
focus,
participantCount,
studyDesign,
} = ncpiCatalogStudy;
const keyValuePairs = new Map<Key, Value>();
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));
Expand Down
5 changes: 5 additions & 0 deletions explorer/files/ncpi-catalog/build-plaftorms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function buildNCPICatalogPlatform(
ncpiCatalogPlatform.consentCode,
ncpiStudy.consentCodes
);
const consentLongName = accumulateValues(
ncpiCatalogPlatform.consentLongName,
ncpiStudy.consentLongNames
);
const dataType = accumulateValues(
ncpiCatalogPlatform.dataType,
ncpiStudy.dataTypes
Expand All @@ -74,6 +78,7 @@ function buildNCPICatalogPlatform(
);
return {
consentCode,
consentLongName,
dataType,
dbGapId,
focus,
Expand Down
10 changes: 10 additions & 0 deletions explorer/files/ncpi-catalog/build-platform-studies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export const platformsEntityConfig: EntityConfig<NCPICatalogPlatform> = {
},
{
componentConfig: {
component: Components.NTagCell,
component: Components.ConsentCodesCell,
viewBuilder: ViewBuilder.buildConsentCodes,
} as ComponentConfig<typeof Components.NTagCell>,
} as ComponentConfig<typeof Components.ConsentCodesCell>,
header: NCPI_CATALOG_CATEGORY_LABEL.CONSENT_CODE,
id: NCPI_CATALOG_CATEGORY_KEY.CONSENT_CODE,
width: { max: "1.6fr", min: "160px" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export const studiesEntityConfig: EntityConfig<NCPICatalogStudy> = {
},
{
componentConfig: {
component: Components.NTagCell,
component: Components.ConsentCodesCell,
viewBuilder: ViewBuilder.buildConsentCodes,
} as ComponentConfig<typeof Components.NTagCell>,
} as ComponentConfig<typeof Components.ConsentCodesCell>,
header: NCPI_CATALOG_CATEGORY_LABEL.CONSENT_CODE,
id: NCPI_CATALOG_CATEGORY_KEY.CONSENT_CODE,
width: { max: "1.6fr", min: "160px" },
Expand Down

0 comments on commit 2d42405

Please sign in to comment.