Skip to content

Commit

Permalink
fix latest commit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybabb committed Dec 5, 2024
1 parent 5eb6101 commit 1293d14
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/parsing-funcs/parse-parseAggDescription-func.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
10 changes: 2 additions & 8 deletions src/parse-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3556,10 +3556,6 @@ interface AggDescriptionOutput {
description: Array<DescriptionItemOutput> | null;
}

interface AggDescriptionData {
Description?: AggDescriptionInput;
}

/**
* Builds a AggDescriptionOutput object based on the provided AggDescriptionInput.
* @param item - The AggDescriptionInput object.
Expand All @@ -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);
}

28 changes: 28 additions & 0 deletions test/parse-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 1293d14

Please sign in to comment.