Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

67 resourceutilities types #68

Merged
merged 9 commits into from
May 31, 2024
Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## 2.2.2
## 2.2.0
AD1306 marked this conversation as resolved.
Show resolved Hide resolved

* Update `ResourceUtils` with strong typing to catch incorrect input data types for all FHIR versions.
* Update some cardinalities for base data types and structures

## 2.1.2

* Add `QueryBuilder` for ease of generating queries.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smile-cdr/fhirts",
"version": "2.1.2",
"version": "2.2.0",
"description": "Fhir ts/js library for frontend apps",
"license": "Apache-2.0",
"main": "dist/index.js",
Expand Down
46 changes: 23 additions & 23 deletions src/FHIR-DSTU2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This is base class from which other elements are derived */
export class FHIRElement {
id: string;
extension: Extension[];
id?: string;
extension?: Extension[];
AD1306 marked this conversation as resolved.
Show resolved Hide resolved
}

export class BackboneElement extends FHIRElement {
Expand All @@ -22,7 +22,7 @@ export class Id {
}
}

export class DomainResource {
export class DomainResource {
text: Narrative;
contained: Resource[];
extension: Extension[];
Expand Down Expand Up @@ -56,12 +56,12 @@ export class CodeableConcept extends FHIRElement {
}

export class Identifier extends FHIRElement {
use: string;
type: CodeableConcept;
system: string;
value: string;
period: Period;
assigner: Reference;
use?: string;
type?: CodeableConcept;
system?: string;
value?: string;
period?: Period;
assigner?: Reference;
}

export class Reference extends FHIRElement {
Expand All @@ -83,25 +83,25 @@ export class HumanName extends FHIRElement {

export class Extension {
url: string;
valueString: string;
valueCode: string;
valueAddress: Address;
valueString?: string;
valueCode?: string;
valueAddress?: Address;
valueBoolean?: boolean;
valueHumanName: HumanName;
valueReference: Reference;
valueDate: Date;
valueIdentifier: string;
valueHumanName?: HumanName;
valueReference?: Reference;
valueDate?: Date;
valueIdentifier?: string;
valueDecimal?: number;
valueInteger: number;
valuePeriod: Period;
valueInteger?: number;
valuePeriod?: Period;
AD1306 marked this conversation as resolved.
Show resolved Hide resolved
}

export class Coding extends FHIRElement {
system: string;
version: string;
code: string;
display: string;
userSelected: boolean;
system?: string;
version?: string;
code?: string;
display?: string;
userSelected?: boolean;
}

export class Period extends FHIRElement {
Expand Down
117 changes: 58 additions & 59 deletions src/FHIR-R3.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* This is base class from which other elements are derived */
export class FHIRElement {
id: string;
extension: Extension[];
id?: string;
extension?: Extension[];
}

export class BackboneElement extends FHIRElement {
modifierExtension: any;
}
/* FHIR classes used in resources */

export class DomainResource {
export class DomainResource {
text: Narrative;
contained: Resource[];
extension: Extension[];
Expand Down Expand Up @@ -60,13 +60,12 @@ export class Code extends FHIRElement {
}

export class Coding extends FHIRElement {
system: string;
version: string;
system?: string;
version?: string;
// should be of type Code
code: string;
display: string;
userSelected: boolean;
value: string;
code?: string;
display?: string;
userSelected?: boolean;
}

export class DoseCoding extends FHIRElement {
Expand All @@ -87,16 +86,16 @@ export class HumanName extends FHIRElement {

export class Extension {
url: string;
valueString: string;
valueCode: string;
valueAddress: Address;
valueString?: string;
valueCode?: string;
valueAddress?: Address;
valueBoolean?: boolean;
valueHumanName: HumanName;
valueReference: Reference;
valueDate: Date;
valueIdentifier: string;
valueHumanName?: HumanName;
valueReference?: Reference;
valueDate?: Date;
valueIdentifier?: string;
valueDecimal?: number;
valueInteger: number;
valueInteger?: number;
}

export class Address extends FHIRElement {
Expand Down Expand Up @@ -256,12 +255,12 @@ export class Reference extends FHIRElement {
}

export class Identifier extends FHIRElement {
use: string;
type: CodeableConcept;
system: string;
value: string;
period: Period;
assigner: Reference;
use?: string;
type?: CodeableConcept;
system?: string;
value?: string;
period?: Period;
assigner?: Reference;
}

export class Payload extends BackboneElement {
Expand Down Expand Up @@ -815,48 +814,48 @@ export class Encounter extends BaseResource {
identifier: Identifier[];
status: 'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
statusHistory: {
status:'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
status: 'planned' | 'arrived' | 'triaged' | 'in-progress' | 'onleave' | 'finished' | 'cancelled' | 'entered-in-error' | 'unknown';
period: Period;
}[];
class:Coding;
classHistory:{
class:Coding;
period:Period;
class: Coding;
classHistory: {
class: Coding;
period: Period;
}[];
type:CodeableConcept[];
priority:CodeableConcept;
type: CodeableConcept[];
priority: CodeableConcept;
episodeOfCare: Reference[];
subject: Reference;
incomingReferral:Reference[];
incomingReferral: Reference[];
participant: EncounterParticipant[];
appointment:Reference;
period:Period;
length:Quantity;
reason:CodeableConcept[];
diagnosis:{
condition:Reference;
role:CodeableConcept;
rank:number
appointment: Reference;
period: Period;
length: Quantity;
reason: CodeableConcept[];
diagnosis: {
condition: Reference;
role: CodeableConcept;
rank: number
}[];
account:Reference[];
hospitalization:{
preAdmissionIdentifer:Identifier;
origin:Reference;
admitSource:CodeableConcept;
reAdmission:CodeableConcept;
dietPreference:CodeableConcept[];
specialCourtesy:CodeableConcept[];
specialArrangement:CodeableConcept[];
destination:Reference;
dischargeDiposition:CodeableConcept;
account: Reference[];
hospitalization: {
preAdmissionIdentifer: Identifier;
origin: Reference;
admitSource: CodeableConcept;
reAdmission: CodeableConcept;
dietPreference: CodeableConcept[];
specialCourtesy: CodeableConcept[];
specialArrangement: CodeableConcept[];
destination: Reference;
dischargeDiposition: CodeableConcept;
};
location:{
location:Reference;
location: {
location: Reference;
status: 'planned' | 'active' | 'reserved' | 'completed';
period: Period
}[];
serviceProvider:Reference;
partOf:Reference;
serviceProvider: Reference;
partOf: Reference;
}

export class CareTeamParticipant extends BackboneElement {
Expand Down Expand Up @@ -1283,11 +1282,11 @@ export class AllergyIntoleranceReaction extends BackboneElement {
}

export class Age extends FHIRElement {
value: number;
comparator: '<' | '<=' | '>=' | '>';
unit: string;
system: string;
code: Code;
value: number;
comparator: '<' | '<=' | '>=' | '>';
unit: string;
system: string;
code: Code;
}

export class ValueSet extends BaseResource {
Expand Down
4 changes: 2 additions & 2 deletions src/FHIR-R4/classes/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { UsageContext } from './usageContext';
/**
* Optional Extension Element - found in all resources.
*/
export class Extension {
export class Extension {
/**
* Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.
*/
Expand All @@ -57,7 +57,7 @@ export class Extension {
/**
* Source of the definition for the extension code - a logical name or a URL.
*/
url?: Uri;
url: Uri;
AD1306 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list).
*/
Expand Down
24 changes: 13 additions & 11 deletions src/library/ResourceUtils/ResourceUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ResourceUtils } from "./ResourceUtils";
import { Coding, Extension, Identifier, } from "../dataTypes";

const patientPayload = require("./../../test-resources/Patient-R4.json");
const careTeamPayload = require("./../../test-resources/CareTeam-R4.json");
Expand Down Expand Up @@ -41,7 +42,7 @@ describe("ResourceUtils", () => {
});

describe("#getIdentifiersByProperty()", () => {
const identifierList = [
const identifierList: Identifier[] = [
{
use: "temp",
system: "http://hl7.org/fhir/sid/us-ssn",
Expand All @@ -56,11 +57,11 @@ describe("ResourceUtils", () => {

it("should return empty array if null is passed as identifier list", () => {
// setup
const value = "abc";
const value = "shouldBeIgnored";
// execute
const actual = resourceUtils.getIdentifiersByProperty(
null,
"abc",
"id",
value
);
// validate
Expand All @@ -73,7 +74,7 @@ describe("ResourceUtils", () => {
// execute
const actual = resourceUtils.getIdentifiersByProperty(
identifierList,
"abc",
"extension", // no extensions in test data
value
);
// validate
Expand Down Expand Up @@ -108,7 +109,7 @@ describe("ResourceUtils", () => {
});

describe("#getExtensionsByUrl()", () => {
const extensionList = [
const extensionList: Extension[] = [
{
url: "http://hl7.org/fhir/sid/us-ssn",
valueBoolean: true,
Expand All @@ -130,11 +131,12 @@ describe("ResourceUtils", () => {
// setup
const extensionListInvalid = [
{
// @ts-ignore
use: "temp",
system: "http://hl7.org/fhir/sid/us-ssn",
value: "abc",
},
];
] as Extension[]; // disabling compiler warning for the test
const url = "http://ns.electronichealth.net.au/id/hi/ihi/1.0";
// execute
const actual = resourceUtils.getExtensionsByUrl(
Expand Down Expand Up @@ -165,7 +167,7 @@ describe("ResourceUtils", () => {
});

describe("#getCodingsByProperty()", () => {
const codingList = [
const codingList: Coding[] = [
{
version: "1.0",
system: "http://hl7.org/fhir/sid/us-ssn",
Expand All @@ -183,9 +185,9 @@ describe("ResourceUtils", () => {

it("should return empty array if null is passed as coding list", () => {
// setup
const value = "abc";
const value = "shouldBeIgnored";
// execute
const actual = resourceUtils.getCodingsByProperty(null, "abc", value);
const actual = resourceUtils.getCodingsByProperty(null, "extension", value);
// validate
expect(actual.length).toEqual(0);
});
Expand All @@ -196,7 +198,7 @@ describe("ResourceUtils", () => {
// execute
const actual = resourceUtils.getCodingsByProperty(
codingList,
"abc",
"id", // expect no ID in codingList
value
);
// validate
Expand Down Expand Up @@ -244,7 +246,7 @@ describe("ResourceUtils", () => {
});

describe("#getValuesAtResourcePath()", () => {

it("should return array with values if path exists for a top level element", () => {
// execute
const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.gender");
Expand Down
Loading