@medplum/core 0.9.11 → 0.9.14
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/dist/cjs/index.js +184 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +176 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/client.d.ts +8 -22
- package/dist/types/utils.d.ts +71 -1
- package/package.json +2 -2
- package/document.pdf +0 -0
- package/test.pdf +0 -1
- package/test2.pdf +0 -1
- package/test3.pdf.txt +0 -1
- package/test4.pdf +0 -1
- package/test5.pdf +0 -0
- package/test7-2.pdf +0 -1
- package/test7.pdf +0 -1
- package/test8-2.pdf +0 -0
- package/test8.pdf +0 -0
- package/test9-2.pdf +0 -0
- package/test9-3.pdf +0 -0
- package/test9-4.pdf +0 -0
- package/test9.pdf +0 -0
package/dist/esm/index.js
CHANGED
|
@@ -566,6 +566,165 @@ function capitalize(word) {
|
|
|
566
566
|
function isLowerCase(c) {
|
|
567
567
|
return c === c.toLowerCase();
|
|
568
568
|
}
|
|
569
|
+
/**
|
|
570
|
+
* Tries to find a code string for a given system within a given codeable concept.
|
|
571
|
+
* @param concept The codeable concept.
|
|
572
|
+
* @param system The system string.
|
|
573
|
+
* @returns The code if found; otherwise undefined.
|
|
574
|
+
*/
|
|
575
|
+
function getCodeBySystem(concept, system) {
|
|
576
|
+
var _a, _b;
|
|
577
|
+
return (_b = (_a = concept === null || concept === void 0 ? void 0 : concept.coding) === null || _a === void 0 ? void 0 : _a.find((coding) => coding.system === system)) === null || _b === void 0 ? void 0 : _b.code;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Sets a code for a given system within a given codeable concept.
|
|
581
|
+
* @param concept The codeable concept.
|
|
582
|
+
* @param system The system string.
|
|
583
|
+
* @param code The code value.
|
|
584
|
+
*/
|
|
585
|
+
function setCodeBySystem(concept, system, code) {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
if (!concept.coding) {
|
|
588
|
+
concept.coding = [];
|
|
589
|
+
}
|
|
590
|
+
const coding = (_a = concept.coding) === null || _a === void 0 ? void 0 : _a.find((c) => c.system === system);
|
|
591
|
+
if (coding) {
|
|
592
|
+
coding.code = code;
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
(_b = concept.coding) === null || _b === void 0 ? void 0 : _b.push({ system, code });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Tries to find an observation interval for the given patient and value.
|
|
600
|
+
* @param definition The observation definition.
|
|
601
|
+
* @param patient The patient.
|
|
602
|
+
* @param value The observation value.
|
|
603
|
+
* @returns The observation interval if found; otherwise undefined.
|
|
604
|
+
*/
|
|
605
|
+
function findObservationInterval(definition, patient, value, category) {
|
|
606
|
+
var _a;
|
|
607
|
+
return (_a = definition.qualifiedInterval) === null || _a === void 0 ? void 0 : _a.find((interval) => {
|
|
608
|
+
var _a;
|
|
609
|
+
return observationIntervalMatchesPatient(interval, patient) &&
|
|
610
|
+
observationIntervalMatchesValue(interval, value, (_a = definition.quantitativeDetails) === null || _a === void 0 ? void 0 : _a.decimalPrecision) &&
|
|
611
|
+
(category === undefined || interval.category === category);
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Returns true if the patient matches the observation interval.
|
|
616
|
+
* @param interval The observation interval.
|
|
617
|
+
* @param patient The patient.
|
|
618
|
+
* @returns True if the patient matches the observation interval.
|
|
619
|
+
*/
|
|
620
|
+
function observationIntervalMatchesPatient(interval, patient) {
|
|
621
|
+
return observationIntervalMatchesGender(interval, patient) && observationIntervalMatchesAge(interval, patient);
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Returns true if the patient gender matches the observation interval.
|
|
625
|
+
* @param interval The observation interval.
|
|
626
|
+
* @param patient The patient.
|
|
627
|
+
* @returns True if the patient gender matches the observation interval.
|
|
628
|
+
*/
|
|
629
|
+
function observationIntervalMatchesGender(interval, patient) {
|
|
630
|
+
return !interval.gender || interval.gender === patient.gender;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Returns true if the patient age matches the observation interval.
|
|
634
|
+
* @param interval The observation interval.
|
|
635
|
+
* @param patient The patient.
|
|
636
|
+
* @returns True if the patient age matches the observation interval.
|
|
637
|
+
*/
|
|
638
|
+
function observationIntervalMatchesAge(interval, patient) {
|
|
639
|
+
return !interval.age || matchesRange(calculateAge(patient.birthDate).years, interval.age);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Returns true if the value matches the observation interval.
|
|
643
|
+
* @param interval The observation interval.
|
|
644
|
+
* @param value The observation value.
|
|
645
|
+
* @param precision Optional precision in number of digits.
|
|
646
|
+
* @returns True if the value matches the observation interval.
|
|
647
|
+
*/
|
|
648
|
+
function observationIntervalMatchesValue(interval, value, precision) {
|
|
649
|
+
return !!interval.range && matchesRange(value, interval.range, precision);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Returns true if the value is in the range accounting for precision.
|
|
653
|
+
* @param value The numeric value.
|
|
654
|
+
* @param range The numeric range.
|
|
655
|
+
* @param precision Optional precision in number of digits.
|
|
656
|
+
* @returns True if the value is within the range.
|
|
657
|
+
*/
|
|
658
|
+
function matchesRange(value, range, precision) {
|
|
659
|
+
var _a, _b;
|
|
660
|
+
return ((((_a = range.low) === null || _a === void 0 ? void 0 : _a.value) === undefined || preciseGreaterThanOrEquals(value, range.low.value, precision)) &&
|
|
661
|
+
(((_b = range.high) === null || _b === void 0 ? void 0 : _b.value) === undefined || preciseLessThanOrEquals(value, range.high.value, precision)));
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Returns true if the two numbers are equal to the given precision.
|
|
665
|
+
* @param a The first number.
|
|
666
|
+
* @param b The second number.
|
|
667
|
+
* @param precision Optional precision in number of digits.
|
|
668
|
+
* @returns True if the two numbers are equal to the given precision.
|
|
669
|
+
*/
|
|
670
|
+
function preciseEquals(a, b, precision) {
|
|
671
|
+
if (precision) {
|
|
672
|
+
return Math.abs(a - b) < Math.pow(10, -precision);
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
return a === b;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Returns true if the first number is less than the second number to the given precision.
|
|
680
|
+
* @param a The first number.
|
|
681
|
+
* @param b The second number.
|
|
682
|
+
* @param precision Optional precision in number of digits.
|
|
683
|
+
* @returns True if the first number is less than the second number to the given precision.
|
|
684
|
+
*/
|
|
685
|
+
function preciseLessThan(a, b, precision) {
|
|
686
|
+
if (precision) {
|
|
687
|
+
return a < b && Math.abs(a - b) > Math.pow(10, -precision);
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
return a < b;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Returns true if the first number is greater than the second number to the given precision.
|
|
695
|
+
* @param a The first number.
|
|
696
|
+
* @param b The second number.
|
|
697
|
+
* @param precision Optional precision in number of digits.
|
|
698
|
+
* @returns True if the first number is greater than the second number to the given precision.
|
|
699
|
+
*/
|
|
700
|
+
function preciseGreaterThan(a, b, precision) {
|
|
701
|
+
if (precision) {
|
|
702
|
+
return a > b && Math.abs(a - b) > Math.pow(10, -precision);
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
return a > b;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Returns true if the first number is less than or equal to the second number to the given precision.
|
|
710
|
+
* @param a The first number.
|
|
711
|
+
* @param b The second number.
|
|
712
|
+
* @param precision Optional precision in number of digits.
|
|
713
|
+
* @returns True if the first number is less than or equal to the second number to the given precision.
|
|
714
|
+
*/
|
|
715
|
+
function preciseLessThanOrEquals(a, b, precision) {
|
|
716
|
+
return preciseLessThan(a, b, precision) || preciseEquals(a, b, precision);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Returns true if the first number is greater than or equal to the second number to the given precision.
|
|
720
|
+
* @param a The first number.
|
|
721
|
+
* @param b The second number.
|
|
722
|
+
* @param precision Optional precision in number of digits.
|
|
723
|
+
* @returns True if the first number is greater than or equal to the second number to the given precision.
|
|
724
|
+
*/
|
|
725
|
+
function preciseGreaterThanOrEquals(a, b, precision) {
|
|
726
|
+
return preciseGreaterThan(a, b, precision) || preciseEquals(a, b, precision);
|
|
727
|
+
}
|
|
569
728
|
|
|
570
729
|
/**
|
|
571
730
|
* Returns a cryptographically secure random string.
|
|
@@ -1218,7 +1377,7 @@ const PATCH_CONTENT_TYPE = 'application/json-patch+json';
|
|
|
1218
1377
|
* Search for a `Patient` by name:
|
|
1219
1378
|
*
|
|
1220
1379
|
* ```typescript
|
|
1221
|
-
* const bundle = await medplum.search('Patient
|
|
1380
|
+
* const bundle = await medplum.search('Patient', 'name=Alice');
|
|
1222
1381
|
* console.log(bundle.total);
|
|
1223
1382
|
* ```
|
|
1224
1383
|
*/
|
|
@@ -1500,7 +1659,9 @@ class MedplumClient extends EventTarget {
|
|
|
1500
1659
|
*/
|
|
1501
1660
|
fhirSearchUrl(resourceType, query) {
|
|
1502
1661
|
const url = this.fhirUrl(resourceType);
|
|
1503
|
-
|
|
1662
|
+
if (query) {
|
|
1663
|
+
url.search = query.toString();
|
|
1664
|
+
}
|
|
1504
1665
|
return url;
|
|
1505
1666
|
}
|
|
1506
1667
|
/**
|
|
@@ -1509,21 +1670,7 @@ class MedplumClient extends EventTarget {
|
|
|
1509
1670
|
* Example using a FHIR search string:
|
|
1510
1671
|
*
|
|
1511
1672
|
* ```typescript
|
|
1512
|
-
* const bundle = await client.search('Patient
|
|
1513
|
-
* console.log(bundle);
|
|
1514
|
-
* ```
|
|
1515
|
-
*
|
|
1516
|
-
* Example using a structured search:
|
|
1517
|
-
*
|
|
1518
|
-
* ```typescript
|
|
1519
|
-
* const bundle = await client.search({
|
|
1520
|
-
* resourceType: 'Patient',
|
|
1521
|
-
* filters: [{
|
|
1522
|
-
* code: 'name',
|
|
1523
|
-
* operator: 'eq',
|
|
1524
|
-
* value: 'Alice',
|
|
1525
|
-
* }]
|
|
1526
|
-
* });
|
|
1673
|
+
* const bundle = await client.search('Patient', 'name=Alice');
|
|
1527
1674
|
* console.log(bundle);
|
|
1528
1675
|
* ```
|
|
1529
1676
|
*
|
|
@@ -1568,7 +1715,7 @@ class MedplumClient extends EventTarget {
|
|
|
1568
1715
|
* Example using a FHIR search string:
|
|
1569
1716
|
*
|
|
1570
1717
|
* ```typescript
|
|
1571
|
-
* const patient = await client.searchOne('Patient
|
|
1718
|
+
* const patient = await client.searchOne('Patient', 'identifier=123');
|
|
1572
1719
|
* console.log(patient);
|
|
1573
1720
|
* ```
|
|
1574
1721
|
*
|
|
@@ -1602,7 +1749,7 @@ class MedplumClient extends EventTarget {
|
|
|
1602
1749
|
* Example using a FHIR search string:
|
|
1603
1750
|
*
|
|
1604
1751
|
* ```typescript
|
|
1605
|
-
* const patients = await client.searchResources('Patient
|
|
1752
|
+
* const patients = await client.searchResources('Patient', 'name=Alice');
|
|
1606
1753
|
* console.log(patients);
|
|
1607
1754
|
* ```
|
|
1608
1755
|
*
|
|
@@ -1657,7 +1804,13 @@ class MedplumClient extends EventTarget {
|
|
|
1657
1804
|
*/
|
|
1658
1805
|
getCachedReference(reference) {
|
|
1659
1806
|
const refString = reference.reference;
|
|
1807
|
+
if (!refString) {
|
|
1808
|
+
return undefined;
|
|
1809
|
+
}
|
|
1660
1810
|
const [resourceType, id] = refString.split('/');
|
|
1811
|
+
if (!resourceType || !id) {
|
|
1812
|
+
return undefined;
|
|
1813
|
+
}
|
|
1661
1814
|
return this.getCached(resourceType, id);
|
|
1662
1815
|
}
|
|
1663
1816
|
/**
|
|
@@ -1703,6 +1856,9 @@ class MedplumClient extends EventTarget {
|
|
|
1703
1856
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
1704
1857
|
}
|
|
1705
1858
|
const [resourceType, id] = refString.split('/');
|
|
1859
|
+
if (!resourceType || !id) {
|
|
1860
|
+
return new ReadablePromise(Promise.reject(new Error('Invalid reference')));
|
|
1861
|
+
}
|
|
1706
1862
|
return this.readResource(resourceType, id);
|
|
1707
1863
|
}
|
|
1708
1864
|
/**
|
|
@@ -5361,5 +5517,5 @@ function simplifyExpression(input) {
|
|
|
5361
5517
|
return result;
|
|
5362
5518
|
}
|
|
5363
5519
|
|
|
5364
|
-
export { COMPONENT_SEPARATOR, DEFAULT_SEARCH_COUNT, FIELD_SEPARATOR, Hl7Field, Hl7Message, Hl7Segment, LRUCache, MedplumClient, OperationOutcomeError, Operator, PropertyType, ReadablePromise, SEGMENT_SEPARATOR, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals$1 as deepEquals, evalFhirPath, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getExtensionValue, getIdentifier, getImageSrc, getPropertyDisplayName, getQuestionnaireAnswers, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isObject$1 as isObject, isOk, isProfileResource, isStringArray, isUUID, notFound, notModified, parseFhirPath, parseSearchDefinition, resolveId, stringify, tokenize };
|
|
5520
|
+
export { COMPONENT_SEPARATOR, DEFAULT_SEARCH_COUNT, FIELD_SEPARATOR, Hl7Field, Hl7Message, Hl7Segment, LRUCache, MedplumClient, OperationOutcomeError, Operator, PropertyType, ReadablePromise, SEGMENT_SEPARATOR, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, calculateAge, calculateAgeString, capitalize, createReference, createSchema, createTypeSchema, created, deepEquals$1 as deepEquals, evalFhirPath, findObservationInterval, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getCodeBySystem, getDateProperty, getDisplayString, getExpressionForResourceType, getExtensionValue, getIdentifier, getImageSrc, getPropertyDisplayName, getQuestionnaireAnswers, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isObject$1 as isObject, isOk, isProfileResource, isStringArray, isUUID, matchesRange, notFound, notModified, parseFhirPath, parseSearchDefinition, preciseEquals, preciseGreaterThan, preciseGreaterThanOrEquals, preciseLessThan, preciseLessThanOrEquals, resolveId, setCodeBySystem, stringify, tokenize };
|
|
5365
5521
|
//# sourceMappingURL=index.js.map
|