@openhealth/oht-custom-parser-lib 0.5.4 → 0.5.6
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/service/fileUploadErrorHandler.service.d.ts +2 -2
- package/dist/service/fileUploadErrorHandler.service.js +23 -31
- package/dist/service/fileUploadErrorHandler.service.js.map +1 -1
- package/dist/service/processingLogger.service.d.ts +6 -1
- package/dist/service/processingLogger.service.js +31 -1
- package/dist/service/processingLogger.service.js.map +1 -1
- package/dist/util-ts/extractionUtils.js +6 -5
- package/dist/util-ts/extractionUtils.js.map +1 -1
- package/package.json +36 -36
- package/readme.md +115 -115
- package/dist/service/ohtAgnosticMeasurementsExtractor.service.d.ts +0 -59
- package/dist/service/ohtAgnosticMeasurementsExtractor.service.js +0 -603
- package/dist/service/ohtAgnosticMeasurementsExtractor.service.js.map +0 -1
package/readme.md
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
# oht-custom-parser-lib
|
|
2
|
-
|
|
3
|
-
`oht-custom-parser-lib` is a shared library designed for use across multiple Node.js cloud functions. It contains common MongoDB connectors and data utilities that can be reused to avoid code duplication and ensure consistency.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Installation](#installation)
|
|
8
|
-
- [Usage](#usage)
|
|
9
|
-
- [Development](#development)
|
|
10
|
-
- [Patch Versions](#patch-versions)
|
|
11
|
-
- [Publish to npm Registry](#publish-to-npm-registry)
|
|
12
|
-
- [Using the Library in Cloud Functions](#using-the-library-in-cloud-functions)
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
To install `oht-custom-parser-lib`, you can add it as a dependency in your project using npm:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install oht-custom-parser-lib
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Or, if you want to install a specific version:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install oht-custom-parser-lib@<version>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
After installing, you can import and use the library in your cloud functions:
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
const { connectToMongoDB } = require('oht-custom-parser-lib');
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Logging
|
|
37
|
-
|
|
38
|
-
- **Production / GCP**: Logs are emitted as JSON (one line per log) for Cloud Logging.
|
|
39
|
-
- **Local / development**: When `NODE_ENV !== 'production'`, logs are pretty-printed in the terminal (colors, timestamps, readable structure). You can override: `LOG_PRETTY=true` to force pretty output, or `LOG_PRETTY=false` to force JSON when not in production.
|
|
40
|
-
|
|
41
|
-
### Processing logger: request-scoped state
|
|
42
|
-
|
|
43
|
-
The processing logger (`processingLogger`, `runWithContextAsync`, `getRequestIdFromContext`) uses a **registry + facade** so each request has isolated state and logs never leak context between concurrent invocations (e.g. in Cloud Functions).
|
|
44
|
-
|
|
45
|
-
- **Registry**: One `ProcessingState` per request, keyed by request id (`fileUploadId ?? messageId ?? cloudEventId ?? generatedId`). The same id is used for the whole request.
|
|
46
|
-
- **AsyncLocalStorage**: Holds only the current request id; state is resolved via `registry.get(id)`.
|
|
47
|
-
- **Entry point**: Wrap your handler in `runWithContextAsync(context, async () => { ... })`. The lib creates a registry entry, runs your callback with the id in AsyncLocalStorage, and removes the entry in a `finally` block.
|
|
48
|
-
- **Clear-state rule**: If there is no request id or the id is not in the registry (e.g. logging outside `runWithContextAsync` or after teardown), the logger uses a **transient empty state** for that call only (never stored). That way one request never overwrites another’s context.
|
|
49
|
-
|
|
50
|
-
Use `processingLogger.logInfo`, `logWarn`, `logError`, `logProgress`, etc. inside the callback so logs include the same context and are searchable by `fileUploadId` / filename.
|
|
51
|
-
|
|
52
|
-
## Development
|
|
53
|
-
|
|
54
|
-
### Patch Versions
|
|
55
|
-
|
|
56
|
-
When making changes to the `oht-custom-parser-lib`, you need to update the version number before publishing. Follow these steps:
|
|
57
|
-
|
|
58
|
-
1. **Update the version number**: Use npm's version command to bump the version:
|
|
59
|
-
- **Patch** for bug fixes:
|
|
60
|
-
```bash
|
|
61
|
-
npm version patch
|
|
62
|
-
```
|
|
63
|
-
- **Minor** for new features:
|
|
64
|
-
```bash
|
|
65
|
-
npm version minor
|
|
66
|
-
```
|
|
67
|
-
- **Major** for breaking changes:
|
|
68
|
-
```bash
|
|
69
|
-
npm version major
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
This command will automatically update the version in the `package.json` and create a git tag.
|
|
73
|
-
|
|
74
|
-
2. **Commit Changes**: Ensure your changes and the version bump are committed to the repository.
|
|
75
|
-
|
|
76
|
-
### Publish to npm Registry
|
|
77
|
-
|
|
78
|
-
After updating the version, you can publish the library to the npm registry:
|
|
79
|
-
|
|
80
|
-
1. **Login to npm** (if you haven't already):
|
|
81
|
-
```bash
|
|
82
|
-
npm login
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
2. **Publish the package**:
|
|
86
|
-
```bash
|
|
87
|
-
npm publish
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
If this is a private package, use:
|
|
91
|
-
```bash
|
|
92
|
-
npm publish --access restricted
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
3. **Verify the publish**: You can check the package on [npmjs.com](https://www.npmjs.com/) to verify that the new version is available.
|
|
96
|
-
|
|
97
|
-
## Using the Library in Cloud Functions
|
|
98
|
-
|
|
99
|
-
To use `oht-custom-parser-lib` in your cloud functions:
|
|
100
|
-
|
|
101
|
-
1. **Install the Library**: Add `oht-custom-parser-lib` as a dependency in the cloud function's `package.json`:
|
|
102
|
-
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"dependencies": {
|
|
106
|
-
"oht-custom-parser-lib": "^1.0.0"
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Replace `^1.0.0` with the appropriate version as needed.
|
|
112
|
-
|
|
113
|
-
2. **Install Dependencies**: Run `npm install` to install the library along with other dependencies.
|
|
114
|
-
|
|
115
|
-
3. **Deploy Your Function**: Deploy your cloud function as usual, ensuring that the updated dependencies are included.
|
|
1
|
+
# oht-custom-parser-lib
|
|
2
|
+
|
|
3
|
+
`oht-custom-parser-lib` is a shared library designed for use across multiple Node.js cloud functions. It contains common MongoDB connectors and data utilities that can be reused to avoid code duplication and ensure consistency.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Development](#development)
|
|
10
|
+
- [Patch Versions](#patch-versions)
|
|
11
|
+
- [Publish to npm Registry](#publish-to-npm-registry)
|
|
12
|
+
- [Using the Library in Cloud Functions](#using-the-library-in-cloud-functions)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install `oht-custom-parser-lib`, you can add it as a dependency in your project using npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install oht-custom-parser-lib
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or, if you want to install a specific version:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install oht-custom-parser-lib@<version>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
After installing, you can import and use the library in your cloud functions:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const { connectToMongoDB } = require('oht-custom-parser-lib');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Logging
|
|
37
|
+
|
|
38
|
+
- **Production / GCP**: Logs are emitted as JSON (one line per log) for Cloud Logging.
|
|
39
|
+
- **Local / development**: When `NODE_ENV !== 'production'`, logs are pretty-printed in the terminal (colors, timestamps, readable structure). You can override: `LOG_PRETTY=true` to force pretty output, or `LOG_PRETTY=false` to force JSON when not in production.
|
|
40
|
+
|
|
41
|
+
### Processing logger: request-scoped state
|
|
42
|
+
|
|
43
|
+
The processing logger (`processingLogger`, `runWithContextAsync`, `getRequestIdFromContext`) uses a **registry + facade** so each request has isolated state and logs never leak context between concurrent invocations (e.g. in Cloud Functions).
|
|
44
|
+
|
|
45
|
+
- **Registry**: One `ProcessingState` per request, keyed by request id (`fileUploadId ?? messageId ?? cloudEventId ?? generatedId`). The same id is used for the whole request.
|
|
46
|
+
- **AsyncLocalStorage**: Holds only the current request id; state is resolved via `registry.get(id)`.
|
|
47
|
+
- **Entry point**: Wrap your handler in `runWithContextAsync(context, async () => { ... })`. The lib creates a registry entry, runs your callback with the id in AsyncLocalStorage, and removes the entry in a `finally` block.
|
|
48
|
+
- **Clear-state rule**: If there is no request id or the id is not in the registry (e.g. logging outside `runWithContextAsync` or after teardown), the logger uses a **transient empty state** for that call only (never stored). That way one request never overwrites another’s context.
|
|
49
|
+
|
|
50
|
+
Use `processingLogger.logInfo`, `logWarn`, `logError`, `logProgress`, etc. inside the callback so logs include the same context and are searchable by `fileUploadId` / filename.
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
### Patch Versions
|
|
55
|
+
|
|
56
|
+
When making changes to the `oht-custom-parser-lib`, you need to update the version number before publishing. Follow these steps:
|
|
57
|
+
|
|
58
|
+
1. **Update the version number**: Use npm's version command to bump the version:
|
|
59
|
+
- **Patch** for bug fixes:
|
|
60
|
+
```bash
|
|
61
|
+
npm version patch
|
|
62
|
+
```
|
|
63
|
+
- **Minor** for new features:
|
|
64
|
+
```bash
|
|
65
|
+
npm version minor
|
|
66
|
+
```
|
|
67
|
+
- **Major** for breaking changes:
|
|
68
|
+
```bash
|
|
69
|
+
npm version major
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This command will automatically update the version in the `package.json` and create a git tag.
|
|
73
|
+
|
|
74
|
+
2. **Commit Changes**: Ensure your changes and the version bump are committed to the repository.
|
|
75
|
+
|
|
76
|
+
### Publish to npm Registry
|
|
77
|
+
|
|
78
|
+
After updating the version, you can publish the library to the npm registry:
|
|
79
|
+
|
|
80
|
+
1. **Login to npm** (if you haven't already):
|
|
81
|
+
```bash
|
|
82
|
+
npm login
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
2. **Publish the package**:
|
|
86
|
+
```bash
|
|
87
|
+
npm publish
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
If this is a private package, use:
|
|
91
|
+
```bash
|
|
92
|
+
npm publish --access restricted
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
3. **Verify the publish**: You can check the package on [npmjs.com](https://www.npmjs.com/) to verify that the new version is available.
|
|
96
|
+
|
|
97
|
+
## Using the Library in Cloud Functions
|
|
98
|
+
|
|
99
|
+
To use `oht-custom-parser-lib` in your cloud functions:
|
|
100
|
+
|
|
101
|
+
1. **Install the Library**: Add `oht-custom-parser-lib` as a dependency in the cloud function's `package.json`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"dependencies": {
|
|
106
|
+
"oht-custom-parser-lib": "^1.0.0"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Replace `^1.0.0` with the appropriate version as needed.
|
|
112
|
+
|
|
113
|
+
2. **Install Dependencies**: Run `npm install` to install the library along with other dependencies.
|
|
114
|
+
|
|
115
|
+
3. **Deploy Your Function**: Deploy your cloud function as usual, ensuring that the updated dependencies are included.
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { LabToOhtContract, LabToOhtMapper, RangeExtractionResponse, SynonymUnit, UnknownUnits, TransformationRulesChains } from "../types/custom-parser.types";
|
|
2
|
-
import { Biomarker, BiomarkerValueType, Measurement, MeasurementValueComparator, PatientInfo, UnknownMeasurement, Exam } from "../types/oht.types";
|
|
3
|
-
/**
|
|
4
|
-
* Extracts unit from rawData (OhtExam object)
|
|
5
|
-
* @param rawData - OhtExam object (not a JSON string)
|
|
6
|
-
* @param ohtBiomarker - Biomarker information
|
|
7
|
-
* @param synonymUnits - Synonym units for unit resolution
|
|
8
|
-
* @param partnerId - Partner ID for synonym resolution
|
|
9
|
-
*/
|
|
10
|
-
declare function agnosticExtractUnit(rawData: any, ohtBiomarker: Biomarker, synonymUnits?: SynonymUnit[] | null, partnerId?: string | null | undefined): {
|
|
11
|
-
unit: string;
|
|
12
|
-
isUnitParsedCorrectly: boolean;
|
|
13
|
-
originalUnit: string;
|
|
14
|
-
isArbitraryUnit: boolean;
|
|
15
|
-
unknownUnit: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Extracts reference annotation from rawExam (OhtExam object)
|
|
19
|
-
* @param labToOhtMapper - Lab to OHT mapper configuration
|
|
20
|
-
* @param rawExam - OhtExam object (not a JSON string)
|
|
21
|
-
* @param patientInfo - Patient information
|
|
22
|
-
* @param documentDate - Document date
|
|
23
|
-
* @param exams - Array of exams for appended mappings
|
|
24
|
-
*/
|
|
25
|
-
declare function agnosticExtractReferenceAnnotation(labToOhtMapper: LabToOhtMapper, rawExam: any, patientInfo: PatientInfo, documentDate?: Date, exams?: Exam[]): string;
|
|
26
|
-
/**
|
|
27
|
-
* Extracts reference ranges from rawData (OhtExam object)
|
|
28
|
-
* Always uses parseRange function from extractionUtils for range extraction
|
|
29
|
-
*/
|
|
30
|
-
declare function agnosticExtractReferenceRanges(labToOhtMapper: LabToOhtMapper, rawData: any, patientInfo: PatientInfo, documentDate?: Date): RangeExtractionResponse;
|
|
31
|
-
declare function agnosticExtractValueFromGreaterLowerThan(value: string): {
|
|
32
|
-
extractedValue: number | null;
|
|
33
|
-
extractedValueComparator: MeasurementValueComparator | null;
|
|
34
|
-
valueParsedCorrectly: boolean;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Parses exam value from rawExamObj (OhtExam object)
|
|
38
|
-
* Now uses value directly from ohtExam
|
|
39
|
-
*/
|
|
40
|
-
declare function agnosticParseExamValue(rawExamObj: any, ohtBiomarker: Biomarker): {
|
|
41
|
-
valueType: BiomarkerValueType;
|
|
42
|
-
alphanumericalValue: string | null;
|
|
43
|
-
numberValue: number | null;
|
|
44
|
-
valueComparator: MeasurementValueComparator;
|
|
45
|
-
isValueParsedCorrectly: boolean;
|
|
46
|
-
};
|
|
47
|
-
declare function agnosticCheckValueForPlausibleValues(labToOhtMapper: LabToOhtMapper, ohtBiomarker: Biomarker, unit: string, value: number, isUnitParsedCorrectly: boolean): boolean;
|
|
48
|
-
type ApplyTransformationRulesResult = {
|
|
49
|
-
transformedExams: Exam[];
|
|
50
|
-
applicationErrorMessages: string[];
|
|
51
|
-
};
|
|
52
|
-
declare function ohtAgnosticMeasurementsExtractor(labToOhtContract: LabToOhtContract, exams: Exam[], transformationRules: TransformationRulesChains, ohtCoreApiKey: string, partnerId?: string | null | undefined): Promise<{
|
|
53
|
-
measurements: Measurement[];
|
|
54
|
-
unknownMeasurements: UnknownMeasurement[];
|
|
55
|
-
unknownUnits: UnknownUnits[];
|
|
56
|
-
isReportCorrectlyParsed: boolean;
|
|
57
|
-
transformationRulesErrors: string[];
|
|
58
|
-
}>;
|
|
59
|
-
export { ApplyTransformationRulesResult, ohtAgnosticMeasurementsExtractor, agnosticCheckValueForPlausibleValues, agnosticExtractReferenceRanges, agnosticExtractReferenceAnnotation, agnosticParseExamValue, agnosticExtractUnit, agnosticExtractValueFromGreaterLowerThan };
|