@medplum/core 0.9.12 → 0.9.13
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 +177 -0
- 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 +169 -1
- 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/utils.d.ts +71 -1
- package/package.json +2 -2
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.
|
|
@@ -1645,7 +1804,13 @@ class MedplumClient extends EventTarget {
|
|
|
1645
1804
|
*/
|
|
1646
1805
|
getCachedReference(reference) {
|
|
1647
1806
|
const refString = reference.reference;
|
|
1807
|
+
if (!refString) {
|
|
1808
|
+
return undefined;
|
|
1809
|
+
}
|
|
1648
1810
|
const [resourceType, id] = refString.split('/');
|
|
1811
|
+
if (!resourceType || !id) {
|
|
1812
|
+
return undefined;
|
|
1813
|
+
}
|
|
1649
1814
|
return this.getCached(resourceType, id);
|
|
1650
1815
|
}
|
|
1651
1816
|
/**
|
|
@@ -1691,6 +1856,9 @@ class MedplumClient extends EventTarget {
|
|
|
1691
1856
|
return new ReadablePromise(Promise.reject(new Error('Missing reference')));
|
|
1692
1857
|
}
|
|
1693
1858
|
const [resourceType, id] = refString.split('/');
|
|
1859
|
+
if (!resourceType || !id) {
|
|
1860
|
+
return new ReadablePromise(Promise.reject(new Error('Invalid reference')));
|
|
1861
|
+
}
|
|
1694
1862
|
return this.readResource(resourceType, id);
|
|
1695
1863
|
}
|
|
1696
1864
|
/**
|
|
@@ -5349,5 +5517,5 @@ function simplifyExpression(input) {
|
|
|
5349
5517
|
return result;
|
|
5350
5518
|
}
|
|
5351
5519
|
|
|
5352
|
-
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 };
|
|
5353
5521
|
//# sourceMappingURL=index.js.map
|