@smile-cdr/fhirts 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.5
4
+
5
+ * Fixed issue with `ResourceUtils.getValuesAtResourcePath` not being able to get an array with values if path exists for a top level element and is an array.
6
+
7
+ ## 2.2.4
8
+
9
+ ### Updates (R3)
10
+
11
+ * Added `Condition` resource definition.
12
+
3
13
  ## 2.2.2
4
14
 
5
15
  * Added `PatchUtils` for generating Parameters resource for `FHIR Patch`.
package/GETTINGSTARTED.md CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
  ## Setting Up Your First FHIR Resource
4
4
 
5
- FHIR.ts offers both classes & interfaces for various FHIR resources - which one(s) you choose to use will depend on what your use case is.
6
5
 
7
- > At the moment, the fhirR3 library only supports classes
6
+ > NOTE: At the moment, the fhirR3 library only supports classes
8
7
 
9
- To start, you'll need to first import the library:
8
+ #### Table of Contents
9
+
10
+ - [Class and Interface usage](#models-usage)
11
+ - [Resource Narrowing](#resource-narrowing)
12
+ - [Utilities](#utilities)
13
+ - [PatchUtils](#patchutils)
14
+ - [QueryBuilder](#querybuilder)
15
+ - [BundleUtils](#bundleutils)
16
+ - [ResourceUtils](#resourceutils)
17
+ - [Bundle Utilities (static BundleUtils)](#bundleutilities)
18
+ - [Resource Utilities (static ResourceUtils)](#resourceutilities)
19
+
20
+
21
+ ### Class and Interface usage
10
22
 
11
23
  ```js
12
24
 
@@ -51,29 +63,8 @@ let patient: fhirR5.Patient = {
51
63
 
52
64
  Fields in FHIR.ts have strict typing to them. For example, in `Patient`, you can only select a `gender` that's in the list of accepted values.
53
65
 
54
- ## Example
55
-
56
- Here's an example of setting up a `Patient` resource in R4 using classes:
57
-
58
- ```js
59
- import { fhirR4 } from '@smile-cdr/fhirts';
60
-
61
- const patient = new fhirR4.Patient();
62
- const identifer = new fhirR4.Identifier();
63
- const humanName = new fhirR4.HumanName();
64
-
65
- humanName.family = 'Doe'
66
- humanName.given = ['John', 'Edward'];
67
-
68
- identifer.system = 'https://smilecdr.com';
69
- identifer.value = '123';
70
-
71
- patient.resourceType = 'Patient';
72
- patient.identifier = [identifer];
73
- patient.name = [humanName]
74
- ```
75
66
 
76
- ## Type / Resource [Narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)
67
+ ### Resource Narrowing
77
68
 
78
69
  When working with Resources from a Bundle, by investigating the values and properties of those Resources Typescript will automatically infer the correct type. For example take the following code:
79
70
  ```js
@@ -85,33 +76,89 @@ function getResourceType(resource:Resource){
85
76
  ```
86
77
  If you try writing this out you will see that the variable `resource` inside the `if` block is of type `CarePlan`. This was inferred automatically using the `if` condition (since as per the specification the only resources which can have `resourceType:"CarePlan"` are `CarePlan` resources).
87
78
 
88
- ## Utilities
79
+ Read more about resource narrowing here : https://www.typescriptlang.org/docs/handbook/2/narrowing.html
89
80
 
90
- - There are 2 new utilities available starting `v2.0.0`.
81
+ ### Utilities
82
+
83
+ - There are 4 new utilities available :
91
84
  - BundleUtilities
92
85
  - ResourceUtilities
86
+ - PatchUtilities
87
+ - QueryBuilder
93
88
  - All of the above mentioned classes are currently in preliminary phase and will be refined in future as per needs.
94
89
  - The above utlity classes include common functionalities used by front end applications using FHIR.
95
- - All utilities functions are static right now, so, no need for instantiating classes. **Note: This is subject to change in future**
96
90
 
97
- ### `v2.1.0`
98
- #### BundleUtils usage
91
+ #### PatchUtils
92
+ - Published in `v2.2.0`.
93
+ - Example usage demonstrated below.
94
+ ```js
95
+ import { PatchUtils } from '@smile-cdr/fhirts';
96
+
97
+ const patchUtils = new PatchUtils();
98
+ // returns patch parameters
99
+ const patchParameters = patchUtils.createDeleteParameters("Patient.identifier[3]").getPatchParameters();
100
+ console.log(patchParameters)
101
+ // console logs
102
+ /*
103
+ * {
104
+ "resourceType": "Parameters",
105
+ "parameter": [
106
+ {
107
+ "name": "operation",
108
+ "part": [
109
+ {
110
+ "name": "type",
111
+ "valueCode": "delete"
112
+ },
113
+ {
114
+ "name": "path",
115
+ "valueString": "Patient.identifier[3]"
116
+ }
117
+ ]
118
+ }
119
+ ]
120
+ }
121
+ */
122
+ ```
123
+
124
+ #### QueryBuilder
125
+ - Published in `v2.1.2`.
126
+ - Example usage demonstrated below.
127
+ ```js
128
+ import { QueryBuilder } from '@smile-cdr/fhirts';
129
+
130
+ const queryBuilder = new QueryBuilder();
131
+ // returns encoded url
132
+ const query = queryBuilder.setBaseResource("Observation")
133
+ .revincludeAll()
134
+ .include("based-on")
135
+ .sort("status", SORT_ORDER.ASCENDING)
136
+ .getCompleteUrl();
137
+ console.log(query)
138
+ // console logs
139
+ // "Observation?_revinclude=*&_include=Observation%3Abased-on&_sort=status"
140
+ ```
141
+
142
+
143
+ #### BundleUtils
144
+ - Published in `v2.1.0`.
145
+ - Example usage demonstrated below.
99
146
  ```js
100
147
  import { BundleUtils } from '@smile-cdr/fhirts';
101
148
 
102
149
  const bundleUtils = new BundleUtils();
103
150
  // returns arrayof Claim resources from Bundle.entry
104
- const claimsList = bundleUtils.getResourcesFromBundle(Bundle.entry, 'Claim');
151
+ const claimsList = bundleUtils.getResources(Bundle.entry, 'Claim');
105
152
  // returns a single resource with ID 123 from Bundle.entry
106
- const resource = bundleUtils.getResourceFromBundle(Bundle.entry, '123');
153
+ const resource = bundleUtils.getResource(Bundle.entry, '123');
107
154
  ```
108
155
 
109
- #### ResourceUtils usage
156
+ #### ResourceUtils
157
+ - Published in `v2.1.0`.
158
+ - Example usage demonstrated below.
110
159
  ```js
111
160
  import { ResourceUtils } from '@smile-cdr/fhirts';
112
161
  const resourceUtils = new ResourceUtils();
113
- // returns deserialized Patient resource
114
- const deserializedPatientResource = resourceUtils.deserializeResource(jsonPatientPayload, new Patient());
115
162
 
116
163
  // returns Patient.gender
117
164
  const patientGender = resourceUtils.getResourceProperty(jsonPatientPayload, 'gender');
@@ -133,8 +180,9 @@ const references = resourceUtils.getAllReferencesFromResource(resourcePayload);
133
180
 
134
181
 
135
182
 
136
- ### `v2.0.0`
137
- #### BundleUtilities usage
183
+ #### BundleUtilities
184
+ - Published in `v2.0.0`.
185
+ - Example usage demonstrated below.
138
186
  ```js
139
187
  import { BundleUtilities } from '@smile-cdr/fhirts';
140
188
 
@@ -142,13 +190,12 @@ import { BundleUtilities } from '@smile-cdr/fhirts';
142
190
  const claimsList = BundleUtilities.getResourcesFromBundle(Bundle.entry, 'Claim');
143
191
  ```
144
192
 
145
- #### ResourceUtilities usage
193
+ #### ResourceUtilities
194
+ - Published in `v2.0.0`.
195
+ - Example usage demonstrated below.
146
196
  ```js
147
197
  import { ResourceUtilities } from '@smile-cdr/fhirts';
148
198
 
149
- // returns deserialized Patient resource
150
- const deserializedPatientResource = ResourceUtilities.deserializeResource(jsonPatientPayload, new Patient());
151
-
152
199
  // returns Patient.gender
153
200
  const patientGender = ResourceUtilities.getResourceProperty(jsonPatientPayload, 'gender');
154
201
 
package/dist/FHIR-R3.d.ts CHANGED
@@ -655,6 +655,40 @@ export declare class ProcessRequest extends BaseResource {
655
655
  provider: Reference;
656
656
  request: Reference;
657
657
  }
658
+ export declare class Condition extends BaseResource {
659
+ resourceType: "Condition";
660
+ identifier?: Identifier[];
661
+ clinicalStatus?: "active" | "recurrence" | "inactive" | "remission" | "resolved";
662
+ verificationStatus?: "provisional" | "differential" | "confirmed" | "refuted" | "entered-in-error" | "unknown";
663
+ category?: CodeableConcept[];
664
+ severity?: CodeableConcept;
665
+ code?: CodeableConcept;
666
+ bodySite?: CodeableConcept[];
667
+ subject: Reference;
668
+ context?: Reference;
669
+ onsetDateTime?: string | Date;
670
+ onsetAge?: Age;
671
+ onsetPeriod?: Period;
672
+ onsetRange?: Range;
673
+ onsetString?: string;
674
+ abatementDateTime?: string | Date;
675
+ abatementAge?: Age;
676
+ abatementBoolean?: boolean;
677
+ abatementPeriod?: Period;
678
+ abatementRange?: Range;
679
+ abatementString?: string;
680
+ assertedDate?: string | Date;
681
+ asserter?: Reference;
682
+ stage?: {
683
+ summary?: CodeableConcept;
684
+ assessment?: Reference[];
685
+ };
686
+ evidence?: {
687
+ code?: CodeableConcept[];
688
+ detail?: Reference[];
689
+ }[];
690
+ note?: Annotation[];
691
+ }
658
692
  export declare class Encounter extends BaseResource {
659
693
  resourceType: "Encounter";
660
694
  identifier: Identifier[];
@@ -1185,5 +1219,5 @@ export declare class ValueSetContains extends BackboneElement {
1185
1219
  designation?: ValueSetDesignation[];
1186
1220
  contains?: ValueSetContains[];
1187
1221
  }
1188
- export type Resource = AllergyIntolerance | ClinicalImpression | Schedule | HealthcareService | Bundle | AuditEvent | CommunicationRequest | Immunization | Observation | Device | Practitioner | PractitionerRole | ProcedureRequest | Task | Communication | CarePlan | EpisodeOfCare | CareTeam | Encounter | ProcessRequest | Account | Location | Organization | AppointmentResponse | Appointment | QuestionnaireResponse | Questionnaire | Slot | Patient | DocumentReference | ValueSet;
1222
+ export type Resource = AllergyIntolerance | ClinicalImpression | Condition | Schedule | HealthcareService | Bundle | AuditEvent | CommunicationRequest | Immunization | Observation | Device | Practitioner | PractitionerRole | ProcedureRequest | Task | Communication | CarePlan | EpisodeOfCare | CareTeam | Encounter | ProcessRequest | Account | Location | Organization | AppointmentResponse | Appointment | QuestionnaireResponse | Questionnaire | Slot | Patient | DocumentReference | ValueSet;
1189
1223
  export {};
package/dist/FHIR-R3.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Restriction = exports.SampledData = exports.Output = exports.Input = exports.Range = exports.Ratio = exports.Component = exports.Timing = exports.Activity = exports.EncounterParticipant = exports.Participant = exports.ReferenceRange = exports.Context = exports.ContextRelated = exports.Annotation = exports.FHIROption = exports.Answer = exports.EnableWhen = exports.Network = exports.Payload = exports.Identifier = exports.Reference = exports.ContactDetail = exports.ContactPoint = exports.Contact = exports.PatientCommunication = exports.Link = exports.Content = exports.Qualification = exports.Attachment = exports.VaccinationProtocol = exports.ImmunizationReaction = exports.ImmunizationExplaination = exports.PractitionerForImmunization = exports.UsageContext = exports.Quantity = exports.Period = exports.CodeableConcept = exports.Meta = exports.Address = exports.Extension = exports.HumanName = exports.DoseCoding = exports.Coding = exports.Code = exports.Narrative = exports.BaseResource = exports.DomainResource = exports.BackboneElement = exports.FHIRElement = void 0;
4
- exports.ClinicalImpressionFinding = exports.ClinicalImpressionInvestigation = exports.ClinicalImpression = exports.Slot = exports.Schedule = exports.HealthcareService = exports.Bundle = exports.AuditEvent = exports.CommunicationRequest = exports.Immunization = exports.Observation = exports.Device = exports.Practitioner = exports.PractitionerRole = exports.ProcedureRequest = exports.Task = exports.Communication = exports.CarePlan = exports.EpisodeOfCare = exports.CareTeam = exports.CareTeamParticipant = exports.Encounter = exports.ProcessRequest = exports.Account = exports.Location = exports.Organization = exports.AppointmentResponse = exports.Appointment = exports.DocumentReference = exports.Patient = exports.Questionnaire = exports.QuestionnaireResponse = exports.Udi = exports.Entity = exports.EntityDetail = exports.Source = exports.Agent = exports.Item = exports.QuestionnaireResponseItem = exports.Requester = exports.Position = exports.ActivityDetail = exports.BundleEntry = exports.BundleResponse = exports.BundleRequest = exports.Search = exports.BundleSignature = exports.BundleLink = exports.NotAvailable = exports.AvailableTime = void 0;
5
- exports.ValueSetContains = exports.ValueSetParameter = exports.ValueSetExpansion = exports.ValueSetFilter = exports.ValueSetDesignation = exports.ValueSetConcept = exports.ValueSetInclude = exports.ValueSetCompose = exports.ValueSet = exports.Age = exports.AllergyIntoleranceReaction = exports.AllergyIntolerance = void 0;
4
+ exports.ClinicalImpressionInvestigation = exports.ClinicalImpression = exports.Slot = exports.Schedule = exports.HealthcareService = exports.Bundle = exports.AuditEvent = exports.CommunicationRequest = exports.Immunization = exports.Observation = exports.Device = exports.Practitioner = exports.PractitionerRole = exports.ProcedureRequest = exports.Task = exports.Communication = exports.CarePlan = exports.EpisodeOfCare = exports.CareTeam = exports.CareTeamParticipant = exports.Encounter = exports.Condition = exports.ProcessRequest = exports.Account = exports.Location = exports.Organization = exports.AppointmentResponse = exports.Appointment = exports.DocumentReference = exports.Patient = exports.Questionnaire = exports.QuestionnaireResponse = exports.Udi = exports.Entity = exports.EntityDetail = exports.Source = exports.Agent = exports.Item = exports.QuestionnaireResponseItem = exports.Requester = exports.Position = exports.ActivityDetail = exports.BundleEntry = exports.BundleResponse = exports.BundleRequest = exports.Search = exports.BundleSignature = exports.BundleLink = exports.NotAvailable = exports.AvailableTime = void 0;
5
+ exports.ValueSetContains = exports.ValueSetParameter = exports.ValueSetExpansion = exports.ValueSetFilter = exports.ValueSetDesignation = exports.ValueSetConcept = exports.ValueSetInclude = exports.ValueSetCompose = exports.ValueSet = exports.Age = exports.AllergyIntoleranceReaction = exports.AllergyIntolerance = exports.ClinicalImpressionFinding = void 0;
6
6
  /* This is base class from which other elements are derived */
7
7
  class FHIRElement {
8
8
  }
@@ -314,6 +314,9 @@ exports.Account = Account;
314
314
  class ProcessRequest extends BaseResource {
315
315
  }
316
316
  exports.ProcessRequest = ProcessRequest;
317
+ class Condition extends BaseResource {
318
+ }
319
+ exports.Condition = Condition;
317
320
  class Encounter extends BaseResource {
318
321
  }
319
322
  exports.Encounter = Encounter;
@@ -72,7 +72,7 @@ class ResourceUtils {
72
72
  let resultSet = [];
73
73
  for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
74
74
  const subPathValue = resourcePathValue[subPathIndex];
75
- if (this.isPrimitive(subPathValue)) {
75
+ if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
76
76
  resultSet.push(subPathValue);
77
77
  }
78
78
  else {
@@ -190,6 +190,28 @@ describe("ResourceUtils", () => {
190
190
  expect(pathValues.length).toEqual(1);
191
191
  expect(pathValues[0]).toEqual("male");
192
192
  });
193
+ it("should return array with values if path exists for a top level element and is a array", () => {
194
+ // setup
195
+ const expected = [
196
+ {
197
+ use: "usual",
198
+ family: "van de Heuvel",
199
+ given: ["Pieter", "Peter"],
200
+ suffix: ["MSc"],
201
+ },
202
+ {
203
+ use: "usual",
204
+ family: "van de Heuvel",
205
+ given: ["Pieter"],
206
+ suffix: ["MSc"],
207
+ },
208
+ ];
209
+ // execute
210
+ const actual = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name");
211
+ // validate
212
+ expect(actual.length).toEqual(2);
213
+ expect(actual).toEqual(expected);
214
+ });
193
215
  it("should return array with values for a array under object", () => {
194
216
  // execute
195
217
  const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smile-cdr/fhirts",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "Fhir ts/js library for frontend apps",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
package/src/FHIR-R3.ts CHANGED
@@ -809,6 +809,41 @@ export class ProcessRequest extends BaseResource {
809
809
  request: Reference;
810
810
  }
811
811
 
812
+ export class Condition extends BaseResource {
813
+ resourceType: "Condition";
814
+ identifier?: Identifier[];
815
+ clinicalStatus?: "active" | "recurrence" | "inactive" | "remission" | "resolved";
816
+ verificationStatus?: "provisional" | "differential" | "confirmed" | "refuted" | "entered-in-error" | "unknown";
817
+ category?: CodeableConcept[];
818
+ severity?: CodeableConcept;
819
+ code?: CodeableConcept;
820
+ bodySite?: CodeableConcept[];
821
+ subject: Reference;
822
+ context?: Reference;
823
+ onsetDateTime?: string | Date;
824
+ onsetAge?: Age;
825
+ onsetPeriod?: Period;
826
+ onsetRange?: Range;
827
+ onsetString?: string;
828
+ abatementDateTime?: string | Date;
829
+ abatementAge?: Age;
830
+ abatementBoolean?: boolean;
831
+ abatementPeriod?: Period;
832
+ abatementRange?: Range;
833
+ abatementString?: string;
834
+ assertedDate?: string | Date;
835
+ asserter?: Reference;
836
+ stage?: {
837
+ summary?: CodeableConcept;
838
+ assessment?: Reference[];
839
+ };
840
+ evidence?: {
841
+ code?: CodeableConcept[];
842
+ detail?: Reference[];
843
+ }[];
844
+ note?: Annotation[]
845
+ }
846
+
812
847
  export class Encounter extends BaseResource {
813
848
  resourceType: "Encounter";
814
849
  identifier: Identifier[];
@@ -1376,4 +1411,4 @@ export class ValueSetContains extends BackboneElement {
1376
1411
  }
1377
1412
 
1378
1413
 
1379
- export type Resource = AllergyIntolerance | ClinicalImpression | Schedule | HealthcareService | Bundle | AuditEvent | CommunicationRequest | Immunization | Observation | Device | Practitioner | PractitionerRole | ProcedureRequest | Task | Communication | CarePlan | EpisodeOfCare | CareTeam | Encounter | ProcessRequest | Account | Location | Organization | AppointmentResponse | Appointment | QuestionnaireResponse | Questionnaire | Slot | Patient | DocumentReference | ValueSet;
1414
+ export type Resource = AllergyIntolerance | ClinicalImpression | Condition | Schedule | HealthcareService | Bundle | AuditEvent | CommunicationRequest | Immunization | Observation | Device | Practitioner | PractitionerRole | ProcedureRequest | Task | Communication | CarePlan | EpisodeOfCare | CareTeam | Encounter | ProcessRequest | Account | Location | Organization | AppointmentResponse | Appointment | QuestionnaireResponse | Questionnaire | Slot | Patient | DocumentReference | ValueSet;
@@ -255,6 +255,32 @@ describe("ResourceUtils", () => {
255
255
  expect(pathValues[0]).toEqual("male");
256
256
  });
257
257
 
258
+ it("should return array with values if path exists for a top level element and is a array", () => {
259
+ // setup
260
+ const expected = [
261
+ {
262
+ use: "usual",
263
+ family: "van de Heuvel",
264
+ given: ["Pieter", "Peter"],
265
+ suffix: ["MSc"],
266
+ },
267
+ {
268
+ use: "usual",
269
+ family: "van de Heuvel",
270
+ given: ["Pieter"],
271
+ suffix: ["MSc"],
272
+ },
273
+ ];
274
+ // execute
275
+ const actual = resourceUtils.getValuesAtResourcePath(
276
+ patientPayload,
277
+ "Patient.name"
278
+ );
279
+ // validate
280
+ expect(actual.length).toEqual(2);
281
+ expect(actual).toEqual(expected);
282
+ });
283
+
258
284
  it("should return array with values for a array under object", () => {
259
285
  // execute
260
286
  const pathValues = resourceUtils.getValuesAtResourcePath(patientPayload, "Patient.name.given");
@@ -82,9 +82,10 @@ export class ResourceUtils {
82
82
  let resultSet = [];
83
83
  for (let subPathIndex = 0; subPathIndex < resourcePathValue.length; subPathIndex++) {
84
84
  const subPathValue = resourcePathValue[subPathIndex];
85
- if (this.isPrimitive(subPathValue)) {
85
+ if (this.isPrimitive(subPathValue) || pathSections.length === 2) {
86
86
  resultSet.push(subPathValue);
87
- } else {
87
+ }
88
+ else {
88
89
  resultSet.push(...this.getValuesAtResourcePath(subPathValue,
89
90
  pathSections.slice(index).join(".")));
90
91
  }