From 1293d14e28098043f13d25491cf8ccbe7696c513 Mon Sep 17 00:00:00 2001 From: Lawrence Babb Date: Thu, 5 Dec 2024 17:38:17 -0500 Subject: [PATCH] fix latest commit bug --- .../parse-parseAggDescription-func.sql | 2 +- src/parse-utils.ts | 10 ++----- test/parse-utils.test.js | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/scripts/parsing-funcs/parse-parseAggDescription-func.sql b/scripts/parsing-funcs/parse-parseAggDescription-func.sql index 2aa6079..b5443f1 100644 --- a/scripts/parsing-funcs/parse-parseAggDescription-func.sql +++ b/scripts/parsing-funcs/parse-parseAggDescription-func.sql @@ -39,7 +39,7 @@ WITH x as ( """ as content ), aggDescriptions as ( - select `clinvar_ingest.parseAggDescription`(x.content)) as aggDescription from x + select `clinvar_ingest.parseAggDescription`(x.content) as aggDescription from x ) select ad.* from aggDescriptions as ad ; \ No newline at end of file diff --git a/src/parse-utils.ts b/src/parse-utils.ts index e9d8318..06f09b3 100644 --- a/src/parse-utils.ts +++ b/src/parse-utils.ts @@ -3556,10 +3556,6 @@ interface AggDescriptionOutput { description: Array | null; } -interface AggDescriptionData { - Description?: AggDescriptionInput; -} - /** * Builds a AggDescriptionOutput object based on the provided AggDescriptionInput. * @param item - The AggDescriptionInput object. @@ -3578,15 +3574,13 @@ function buildAggDescriptionOutput(item: AggDescriptionInput): AggDescriptionOut * @throws {Error} If the JSON input is invalid. */ function parseAggDescription(json: string): AggDescriptionOutput { - let data: AggDescriptionData; + let data: AggDescriptionInput; try { data = JSON.parse(json); } catch (e) { throw new Error('Invalid JSON input'); } - let AggDescription = data && data.Description ? data.Description : {}; - - return buildAggDescriptionOutput(AggDescription); + return buildAggDescriptionOutput(data); } diff --git a/test/parse-utils.test.js b/test/parse-utils.test.js index d18d541..24d9dc2 100644 --- a/test/parse-utils.test.js +++ b/test/parse-utils.test.js @@ -1312,3 +1312,31 @@ test('buildAggDescriptionOutput should build AggDescriptionOutput correctly', () expect(buildAggDescriptionOutput(json)).toEqual(expectedOutput); }); + +test('parseAggDescription should parse JSON input correctly', () => { + const json = '{"Description":[{"@ClinicalImpactAssertionType":"diagnostic","@ClinicalImpactClinicalSignificance":"supports diagnosis","@DateLastEvaluated":"2024-01-24","@SubmissionCount":"1","$":"Tier I - Strong"},{"@ClinicalImpactAssertionType":"prognostic","@ClinicalImpactClinicalSignificance":"better outcome","@DateLastEvaluated":"2024-01-23","@SubmissionCount":"1","$":"Tier I - Strong"}]}'; + const expectedOutput = { + description: [ + { + clinical_impact_assertion_type: 'diagnostic', + clinical_impact_clinical_significance: 'supports diagnosis', + date_last_evaluated: new Date('2024-01-24T00:00:00.000Z'), + num_submissions: 1, + interp_description: 'Tier I - Strong' + }, + { + clinical_impact_assertion_type: 'prognostic', + clinical_impact_clinical_significance: 'better outcome', + date_last_evaluated: new Date('2024-01-23T00:00:00.000Z'), + num_submissions: 1, + interp_description: 'Tier I - Strong' + } + ] + }; + expect(parseAggDescription(json)).toEqual(expectedOutput); +}); + +test('parseAggDescription should throw error for invalid JSON input', () => { + const json = 'invalid json'; + expect(() => parseAggDescription(json)).toThrow('Invalid JSON input'); +});