import { ConfigJsonFieldGenotype, ConfigJsonFieldInfo } from "../../types/config"; import { CellValueGenotype, CellValueInfo, ConfigCellGenotype, ConfigCellInfo } from "../../types/configCells"; import { VcfRecord } from "@molgenis/vip-report-vcf"; import { FieldMetadataWrapper, getInfoFieldsRegex, getInfoValue, getInfoValueCount, getSampleFieldsRegex, getSampleValue, getSampleValueCount, } from "../vcf.ts"; import { Item } from "@molgenis/vip-report-api"; import { SampleContainer, VcfMetadataContainer } from "../api.ts"; import { getDescription, getLabel } from "./config.ts"; export function initConfigCellInfo( configStatic: ConfigJsonFieldInfo, metadata: VcfMetadataContainer, ): ConfigCellInfo[] { return getInfoFieldsRegex(metadata, new RegExp(`^${configStatic.name}$`)) .filter((field) => !field.nested) .map((field) => createConfigFieldInfo(configStatic, field)); } function createConfigFieldInfo(configStatic: ConfigJsonFieldInfo, field: FieldMetadataWrapper): ConfigCellInfo { return { type: "info", field, parentLabel: () => field.parent !== undefined ? getLabel(configStatic, field.parent.label || field.parent.id) : "", label: () => getLabel(configStatic, field.label || field.id), description: () => getDescription(configStatic, field.description), valueCount: (record: Item) => getInfoValueCount(record, field), value: (record: Item, valueIndex: number): CellValueInfo => getInfoValue(record, valueIndex, field), }; } export function initConfigCellGenotype( configStatic: ConfigJsonFieldGenotype, metadata: VcfMetadataContainer, sample: SampleContainer, ): ConfigCellGenotype[] { return getSampleFieldsRegex(metadata, new RegExp(`^${configStatic.name}$`)) .filter((field) => !field.nested) .map((field) => createConfigFieldGenotype(configStatic, field, sample)); } function createConfigFieldGenotype( configStatic: ConfigJsonFieldGenotype, field: FieldMetadataWrapper, sample: SampleContainer, ): ConfigCellGenotype { return { type: "genotype", field, label: () => getLabel(configStatic, field.label || field.id), description: () => getDescription(configStatic, field.description), valueCount: (record: Item) => getSampleValueCount(sample, record, field), value: (record: Item, valueIndex: number): CellValueGenotype => getSampleValue(sample, record, valueIndex, field), }; }