From 8fa7f54acc928761e24411c7500432bd7769114d Mon Sep 17 00:00:00 2001 From: jekabskarklins Date: Fri, 30 Oct 2026 12:13:41 +0100 Subject: [PATCH] feat: add getCreateScicatSampleDto function and update sample filtering logic --- .../uoToScicatExperiment.mapper.spec.ts | 44 ++++++++++++++++++- .../mappers/uoToScicatExperiment.mapper.ts | 4 +- .../userOfficeApi/type/uoExperiment.type.ts | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts index a8124863..1005f9e4 100644 --- a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts +++ b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.spec.ts @@ -6,9 +6,13 @@ jest.mock('../utils/scicatApi', () => ({ import { getCreateScicatExperimentDto, + getCreateScicatSampleDto, getUpdateScicatExperimentDto, } from './uoToScicatExperiment.mapper'; -import { UOExperimentDto } from '../../../../../services/userOfficeApi/type/uoExperiment.type'; +import { + UOExperimentDto, + UOExperimentSafetySample, +} from '../../../../../services/userOfficeApi/type/uoExperiment.type'; const createBaseUoExperiment = ( overrides: Partial = {} @@ -242,3 +246,41 @@ describe('getUpdateScicatExperimentDto', () => { expect((dto as any).proposalId).toBeUndefined(); }); }); + +describe('getCreateScicatSampleDto', () => { + it('skips fields whose natural key starts with skip_metadata', () => { + const sample: UOExperimentSafetySample = { + sampleId: 1, + sample: { id: 1, title: 'Sample 1' }, + questionary: { + steps: [ + { + fields: [ + { + question: { id: 'q1', question: 'Kept', naturalKey: 'kept' }, + value: 'a', + }, + { + question: { + id: 'q2', + question: 'Skipped', + naturalKey: 'skip_metadata_notes', + }, + value: 'b', + }, + ], + }, + ], + }, + }; + + const { sampleCharacteristics } = getCreateScicatSampleDto( + sample, + createBaseUoExperiment() + ); + + expect(sampleCharacteristics).toHaveProperty('q1'); + expect(sampleCharacteristics).not.toHaveProperty('q2'); + expect(sampleCharacteristics).toHaveProperty('questionary_length.value', 1); + }); +}); diff --git a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts index 897e87cf..e79e8f8d 100644 --- a/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts +++ b/src/queue/consumers/scicat/scicatProposal/mappers/uoToScicatExperiment.mapper.ts @@ -189,7 +189,9 @@ const buildSampleCharacteristics = ( sample: UOExperimentSafetySample, experiment: UOExperimentDto ): Record => { - const fields = sample.questionary.steps.flatMap((step) => step.fields); + const fields = sample.questionary.steps + .flatMap((step) => step.fields) + .filter((field) => !field.question.naturalKey?.startsWith('skip_metadata')); const sampleLookup = `${experiment.experimentId}-${sample.sampleId}`; const rows: [string, MdEntryValue][] = [ diff --git a/src/services/userOfficeApi/type/uoExperiment.type.ts b/src/services/userOfficeApi/type/uoExperiment.type.ts index 1fd85d27..c7b9510f 100644 --- a/src/services/userOfficeApi/type/uoExperiment.type.ts +++ b/src/services/userOfficeApi/type/uoExperiment.type.ts @@ -8,6 +8,7 @@ export interface UOExperimentSafetySample { question: { id: string; question: string; + naturalKey: string; }; value: string | number | boolean | null; }[];