Skip to content

Commit

Permalink
Date query builder uses name instead of xpath (#51)
Browse files Browse the repository at this point in the history
* Date query builder uses name instead of xpath

* Fix comment
  • Loading branch information
elsaperelli authored Aug 21, 2024
1 parent 888020b commit 1ba05f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/util/exportToNDJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const buildSearchParamList = resourceType => {
try {
const searchParameterList = getSearchParameters(resourceType, '4_0_1');
searchParameterList.forEach(paramDef => {
// map xpath to parameter description
// map name to parameter description
{
searchParams[paramDef.xpath.substring(paramDef.xpath.indexOf('.') + 1)] = paramDef;
searchParams[paramDef.name] = paramDef;
}
});
return searchParams;
Expand Down
23 changes: 11 additions & 12 deletions test/util/exportToNDJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ describe('check export logic', () => {

test('returns empty record of valid search params for invalid resource type', () => {
const results = buildSearchParamList('BiologicallyDerivedProduct');
console.log(results);
expect(results).toBeDefined();
});
});
Expand Down Expand Up @@ -108,9 +107,9 @@ describe('check export logic', () => {

describe('getDocuments', () => {
describe('_typeFilter tests', () => {
test('returns Condition document when _typeFilter=Condition?recordedDate=gt2019-01-03T00:00:00Z', async () => {
test('returns Condition document when _typeFilter=Condition?recorded-date=gt2019-01-03T00:00:00Z', async () => {
const property = {
recordedDate: 'gt2019-01-03T00:00:00Z'
'recorded-date': 'gt2019-01-03T00:00:00Z'
};
const searchParams = buildSearchParamList('Condition');
const filter = qb.buildSearchQuery({
Expand All @@ -122,11 +121,11 @@ describe('check export logic', () => {
expect(docObj.document.length).toEqual(1);
});

test('returns Condition document when _typeFilter=Condition?recordedDate=gt2019-01-03T00:00:00Z&onsetDateTime=gt2019-01-03T00:00:00Z', async () => {
test('returns Condition document when _typeFilter=Condition?recorded-date=gt2019-01-03T00:00:00Z&onset-date=gt2019-01-03T00:00:00Z', async () => {
// test for the "&" operator within the query
const properties = {
recordedDate: 'gt2019-01-03T00:00:00Z',
onsetDateTime: 'gt2019-01-03T00:00:00Z'
'recorded-date': 'gt2019-01-03T00:00:00Z',
'onset-date': 'gt2019-01-03T00:00:00Z'
};
const searchParams = buildSearchParamList('Condition');
const filter = qb.buildSearchQuery({
Expand All @@ -138,10 +137,10 @@ describe('check export logic', () => {
expect(docObj.document.length).toEqual(1);
});

test('returns no documents when _typeFilter filters out all documents (_typeFilter=Condition?recordedDate=gt2019-01-03T00:00:00Z&onsetDateTime=lt2019-01-03T00:00:00Z', async () => {
test('returns no documents when _typeFilter filters out all documents (_typeFilter=Condition?recorded-date=gt2019-01-03T00:00:00Z&onset-date=lt2019-01-03T00:00:00Z', async () => {
const properties = {
recordedDate: 'gt2019-01-03T00:00:00Z',
onsetDateTime: 'lt2019-01-03T00:00:00Z'
'recorded-date': 'gt2019-01-03T00:00:00Z',
'onset-date': 'lt2019-01-03T00:00:00Z'
};
const searchParams = buildSearchParamList('Condition');
const filter = qb.buildSearchQuery({
Expand All @@ -153,12 +152,12 @@ describe('check export logic', () => {
expect(docObj.document.length).toEqual(0);
});

test('returns Condition document when _typeFilter has "or" condition (_typeFilter=Condition?recordedDate=gt2019-01-03T00:00:00Z,onsetDateTime=lt2019-01-03T00:00:00Z', async () => {
test('returns Condition document when _typeFilter has "or" condition (_typeFilter=Condition?recorded-date=gt2019-01-03T00:00:00Z,onset-date=lt2019-01-03T00:00:00Z', async () => {
const recordedDateProperty = {
recordedDate: 'gt2019-01-03T00:00:00Z'
'recorded-date': 'gt2019-01-03T00:00:00Z'
};
const onsetDateTimeProperty = {
onsetDateTime: 'lt2019-01-03T00:00:00Z'
'onset-date': 'lt2019-01-03T00:00:00Z'
};
const searchParams = buildSearchParamList('Condition');
const recordedDateFilter = qb.buildSearchQuery({
Expand Down

0 comments on commit 1ba05f4

Please sign in to comment.