Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import StaticWadoClient from './StaticWadoClient';

describe('StaticWadoClient', () => {
const client = Object.create(StaticWadoClient.prototype) as StaticWadoClient;
(client as any).config = {};

describe('compareValues', () => {
it('matches wildcard string filters case-insensitively', () => {
expect(client.compareValues('*brain*', 'BRAIN WO CONTRAST', {})).toBe(true);
expect(client.compareValues('abc*', 'ABC123', {})).toBe(true);
expect(client.compareValues('*xyz', 'ABCXYZ', {})).toBe(true);
});

it('matches exact string filters case-insensitively', () => {
expect(client.compareValues('mrn123', 'MRN123', {})).toBe(true);
expect(client.compareValues('acc-42', 'ACC-42', {})).toBe(true);
});
});

describe('filterItem', () => {
it('matches study text filters case-insensitively', () => {
const study = {
'00100020': { Value: ['MRN123'] },
'00081030': { Value: ['BRAIN WO CONTRAST'] },
'00080050': { Value: ['ACC-42'] },
};

expect(
client.filterItem(
'00100020',
{ '00100020': '*mrn123*' },
study,
StaticWadoClient.studyFilterKeys
)
).toBeTruthy();
expect(
client.filterItem(
'studydescription',
{ studydescription: '*brain*' },
study,
StaticWadoClient.studyFilterKeys
)
).toBeTruthy();
expect(
client.filterItem(
'accessionnumber',
{ accessionnumber: '*acc-42*' },
study,
StaticWadoClient.studyFilterKeys
)
).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,33 @@ export default class StaticWadoClient extends api.DICOMwebClient {
);
}

if (typeof actual == 'string') {
if (typeof actual === 'string' && typeof desired === 'string') {
const normalizedActual = actual.toLowerCase();
const normalizedDesired = desired.toLowerCase();

if (actual.length === 0) {
return true;
}
if (desired.length === 0 || desired === '*') {
return true;
}
if (desired[0] === '*' && desired[desired.length - 1] === '*') {
// console.log(`Comparing ${actual} to ${desired.substring(1, desired.length - 1)}`)
return actual.indexOf(desired.substring(1, desired.length - 1)) != -1;
} else if (desired[desired.length - 1] === '*') {
return actual.indexOf(desired.substring(0, desired.length - 1)) != -1;
} else if (desired[0] === '*') {
return actual.indexOf(desired.substring(1)) === actual.length - desired.length + 1;
if (normalizedDesired[0] === '*' && normalizedDesired[normalizedDesired.length - 1] === '*') {
return (
normalizedActual.indexOf(normalizedDesired.substring(1, normalizedDesired.length - 1)) !=
-1
);
} else if (normalizedDesired[normalizedDesired.length - 1] === '*') {
return (
normalizedActual.indexOf(normalizedDesired.substring(0, normalizedDesired.length - 1)) !=
-1
);
} else if (normalizedDesired[0] === '*') {
return (
normalizedActual.indexOf(normalizedDesired.substring(1)) ===
normalizedActual.length - normalizedDesired.length + 1
);
}
return normalizedDesired === normalizedActual;
}
return desired === actual;
}
Expand Down