Skip to content

Commit

Permalink
Check observation code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpotter44 committed May 31, 2024
1 parent 3766558 commit 3f9e2e4
Show file tree
Hide file tree
Showing 7 changed files with 447 additions and 230 deletions.
150 changes: 149 additions & 1 deletion spec/fhir-util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { FhirResource } from 'fhir/r4';
import { FHIRDate, FHIRDateAccuracy, resourceContainsProfile } from '../src/fhir-util';
import {
FHIRDate,
FHIRDateAccuracy,
codeableConceptContains,
codeableConceptContainsCode,
resourceContainsProfile
} from '../src/fhir-util';

describe('#resourceContainsProfile', () => {
it('handles resources with no meta', () => {
Expand Down Expand Up @@ -117,3 +123,145 @@ describe('FHIRDate', () => {
});
});
});

describe('codeableConceptContains', () => {
// Simple test set
const CODE_SET = { '1_2': ['1', '2'], '3_4': ['3', '4'] };
it('handles a codeable concept with no codes', () => {
expect(codeableConceptContains({}, CODE_SET)).toBeFalse();
});
it('returns false for codes in the other system', () => {
expect(
codeableConceptContains(
{
coding: [
{
system: '1_2',
code: '3'
},
{
system: '3_4',
code: '1'
}
]
},
CODE_SET
)
).toBeFalse();
});
it('handles partial codes', () => {
expect(
codeableConceptContains(
{
coding: [
{
code: '1'
},
{
system: '3_4'
}
]
},
CODE_SET
)
).toBeFalse();
});
it('returns true for codes that exist', () => {
expect(
codeableConceptContains(
{
coding: [
{
system: 'ignore me',
code: 'code'
},
{
system: '3_4',
code: '4'
}
]
},
CODE_SET
)
).toBeTrue();
});
});

describe('codeableConceptContainsCode', () => {
// Simple test set
const SYSTEM = '1_2';
const CODE_SET = ['1', '2'];
it('handles a codeable concept with no codes', () => {
expect(codeableConceptContainsCode({}, SYSTEM, CODE_SET)).toBeFalse();
});
it("returns false for codes that don't exist", () => {
expect(
codeableConceptContainsCode(
{
coding: [
{
system: '1_2',
code: '3'
}
]
},
SYSTEM,
CODE_SET
)
).toBeFalse();
});
it('returns false for codes in another system', () => {
expect(
codeableConceptContainsCode(
{
coding: [
{
system: '3_4',
code: '1'
}
]
},
SYSTEM,
CODE_SET
)
).toBeFalse();
});
it('handles partial codes', () => {
expect(
codeableConceptContainsCode(
{
coding: [
{
code: '1'
},
{
system: '3_4'
}
]
},
SYSTEM,
CODE_SET
)
).toBeFalse();
});
it('returns true for codes that exist', () => {
expect(
codeableConceptContainsCode(
{
coding: [
{
system: 'ignore me',
code: 'code'
},
{
system: '1_2',
code: '2'
}
]
},
SYSTEM,
CODE_SET
)
).toBeTrue();
});
});
Loading

0 comments on commit 3f9e2e4

Please sign in to comment.