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

Transferring Jsonata functions to Js #58

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ea45031
jsonataFuncs after testing
itayshavitOB Mar 7, 2024
7ac7a61
isEmpty
itayshavitOB Mar 7, 2024
3f74c7b
Merge remote-tracking branch 'origin' into itay/transform_jsonata_to_js
itayshavitOB Mar 11, 2024
372d722
Merge remote-tracking branch 'origin' into first_batch_fix_commit
itayshavitOB Mar 13, 2024
1d74909
Merge remote-tracking branch 'origin' into final_batch
itayshavitOB Mar 14, 2024
b791e05
fix: isEmpty
itayshavitOB Mar 16, 2024
f8c91ef
fix: another batch
itayshavitOB Mar 17, 2024
0ecad11
fix: more functions
itayshavitOB Mar 17, 2024
65d631f
fix: more
itayshavitOB Mar 23, 2024
a19d590
fix: more
itayshavitOB Mar 23, 2024
1c74ef7
Merge branch 'final_batch' of https://github.com/itayshavitOB/fume-co…
itayshavitOB Mar 23, 2024
0c92a2f
fix: initcap
itayshavitOB Mar 24, 2024
5625456
fix: v2normalizeKey
itayshavitOB Mar 24, 2024
fd759af
fix: more functions
itayshavitOB Mar 27, 2024
93bcd52
fix: structureMapsToMappingObject
itayshavitOB Mar 28, 2024
67fe812
fix: remove structureMapsToMappingObject from file
itayshavitOB Mar 28, 2024
4bbbfa6
fix: change function name
itayshavitOB Mar 28, 2024
b9ccb06
Merge remote-tracking branch 'origin' into final_batch
itayshavitOB Mar 29, 2024
2894096
fix: cr
itayshavitOB Mar 31, 2024
d594661
fix: version.split
itayshavitOB Mar 31, 2024
14ce994
fix: _.split
itayshavitOB Mar 31, 2024
7891502
fix: reverse createRawPackageIndexObject
itayshavitOB Mar 31, 2024
f753b25
fix: packageIndexObject undefined
itayshavitOB Mar 31, 2024
bfddb67
fix: split
itayshavitOB Mar 31, 2024
f2ef5e5
fix: url
itayshavitOB Mar 31, 2024
35f5030
fix: bundleToArrayOfResources
itayshavitOB Mar 31, 2024
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
154 changes: 77 additions & 77 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
# Contributing to FUME Community
## Bug reports
If you think you have found a bug in FUME Community, first make sure that you are testing against the latest version - your issue may already have been fixed. If not, search our [issues list on GitHub](https://github.com/Outburn-IL/fume-community/issues) in case a similar issue has already been opened.
It is very helpful if you can prepare a reproduction of the bug. In other words, provide a small test case which we can run to confirm your bug. It makes it easier to find the problem and to fix it. For example:
```
EXAMPLE CODE
```
## Feature requests
If you find yourself wishing for a feature that doesn't exist in FUME Community, please let us know. Check the [issues list on GitHub](https://github.com/Outburn-IL/fume-community/issues) to see if a similar feature has already been requested. If no,open an issue on our issues list on GitHub which describes the feature you would like to see, why you need it, and how it should work.
## Contributing code and documentation changes
If you would like to contribute a new feature or a bug fix to FUME Community, please **discuss your idea first on the GitHub issue**. If there is no GitHub issue for your idea, please open one. It may be that somebody is already working on it, or that there are particular complexities that you should know about before starting the implementation. There are often a number of ways to fix a problem and it is important to find the right approach before spending time on a PR that cannot be merged.
### Fork and clone the repository
To make changes, you will need to fork this repository and clone it to your local machine. See [GitHub help page](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) for help.
Once you forked the repository, clone it to your local work station and open it in your preferred editor.
### Running the server
1. Install the recommended version as listed in the `.nvmrc` file. (Or use `nvm` or an equivalent version management tool).
2. Go to the `fume-community` folder
3. Install all dependencies
```
npm install
```
4. Run the development server
```
npm run dev
```
This will start the server in development mode on `localhost:42420` (the default port).
5. To change the default port or any other environment variable, you should create a file named `.env`. You can find two sample templates in the repository ([Stateful](https://github.com/Outburn-IL/fume-community/blob/main/.env.example.stateful) \ [Stateless](https://github.com/Outburn-IL/fume-community/blob/main/.env.example.stateless)).
### Testing your changes
1. Run unit tests by running the `npm run test:unit` command.
2. Run integration tests by running the `npm run test:integration` command. This will start a local FHIR service
### Submitting your changes
1. Comitting changes
Code goes through a linting check every time you commit. It will automatically fix any issues it can and fail if there are issues that can't be resolved. Please refrain from using `eslint-disable` and if you absolutely must, explain the reasoning behind doing so.
Commit messages in the repository pass `commitlint` validation. We use the default `Angular` style commit messages. You can read about them [here](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional#type-enum).
2. Test your changes
Make sure to add unit and integration tests (where applicable) to verify your changes.
3. Rebase your changes
Update your local repository with the most recent code from the main Outburn-IL repository, and rebase your branch on top of the latest main branch.
3. Push your changes
Push changes to the repository you forked and create a pull requst to the `Outburn-IL/fume-community` repo.
The first time you make a PR, one of our maintainers will have to approve tests to run on your PR. After that tests are automatically run for every PR. PRs can be merged only if all tests pass.
4. Sign the Contributor License Agreement
If you haven't done so before, our `CLAassistant` will ask you to sign the CLA.
At this stage, we might ask you for clarifications or changes and once all are resolved we will gladly merge your contribution!
---
© 2022-2024 Outburn Ltd. All Rights Reserved.
# Contributing to FUME Community

## Bug reports

If you think you have found a bug in FUME Community, first make sure that you are testing against the latest version - your issue may already have been fixed. If not, search our [issues list on GitHub](https://github.com/Outburn-IL/fume-community/issues) in case a similar issue has already been opened.

It is very helpful if you can prepare a reproduction of the bug. In other words, provide a small test case which we can run to confirm your bug. It makes it easier to find the problem and to fix it. For example:

```
EXAMPLE CODE
```

## Feature requests

If you find yourself wishing for a feature that doesn't exist in FUME Community, please let us know. Check the [issues list on GitHub](https://github.com/Outburn-IL/fume-community/issues) to see if a similar feature has already been requested. If no,open an issue on our issues list on GitHub which describes the feature you would like to see, why you need it, and how it should work.

## Contributing code and documentation changes

If you would like to contribute a new feature or a bug fix to FUME Community, please **discuss your idea first on the GitHub issue**. If there is no GitHub issue for your idea, please open one. It may be that somebody is already working on it, or that there are particular complexities that you should know about before starting the implementation. There are often a number of ways to fix a problem and it is important to find the right approach before spending time on a PR that cannot be merged.

### Fork and clone the repository

To make changes, you will need to fork this repository and clone it to your local machine. See [GitHub help page](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) for help.

Once you forked the repository, clone it to your local work station and open it in your preferred editor.

### Running the server

1. Install the recommended version as listed in the `.nvmrc` file. (Or use `nvm` or an equivalent version management tool).
2. Go to the `fume-community` folder
3. Install all dependencies
```
npm install
```
4. Run the development server
```
npm run dev
```
This will start the server in development mode on `localhost:42420` (the default port).

5. To change the default port or any other environment variable, you should create a file named `.env`. You can find two sample templates in the repository ([Stateful](https://github.com/Outburn-IL/fume-community/blob/main/.env.example.stateful) \ [Stateless](https://github.com/Outburn-IL/fume-community/blob/main/.env.example.stateless)).

### Testing your changes

1. Run unit tests by running the `npm run test:unit` command.
2. Run integration tests by running the `npm run test:integration` command. This will start a local FHIR service

### Submitting your changes

1. Comitting changes

Code goes through a linting check every time you commit. It will automatically fix any issues it can and fail if there are issues that can't be resolved. Please refrain from using `eslint-disable` and if you absolutely must, explain the reasoning behind doing so.

Commit messages in the repository pass `commitlint` validation. We use the default `Angular` style commit messages. You can read about them [here](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional#type-enum).

2. Test your changes

Make sure to add unit and integration tests (where applicable) to verify your changes.

3. Rebase your changes

Update your local repository with the most recent code from the main Outburn-IL repository, and rebase your branch on top of the latest main branch.

3. Push your changes

Push changes to the repository you forked and create a pull requst to the `Outburn-IL/fume-community` repo.

The first time you make a PR, one of our maintainers will have to approve tests to run on your PR. After that tests are automatically run for every PR. PRs can be merged only if all tests pass.

4. Sign the Contributor License Agreement

If you haven't done so before, our `CLAassistant` will ask you to sign the CLA.

At this stage, we might ask you for clarifications or changes and once all are resolved we will gladly merge your contribution!

---
© 2022-2024 Outburn Ltd. All Rights Reserved.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/helpers/conformance/loadFhirPackageIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import fs from 'fs-extra';
import path from 'path';

import { expressions as expressionsNew } from '../jsonataExpr';
import expressions from '../jsonataExpression';
import { getLogger } from '../logger';
import { omitKeys } from '../objectFunctions';
import { isNumeric } from '../stringFunctions';
import { getCachedPackageDirs, getCachePackagesPath, getFumeIndexFilePath } from './getCachePath';

Expand Down Expand Up @@ -68,7 +68,7 @@ const buildFhirCacheIndex = async () => {
});

const bindings = {
omitKeys,
omitKeys: expressionsNew.omitKeys,
pathJoin: path.join,
require: (filePath: string) => {
try {
Expand All @@ -82,9 +82,10 @@ const buildFhirCacheIndex = async () => {
},
isNumeric
};

const packageIndexObject = await expressions.createRawPackageIndexObject.evaluate(packageIndexArray, bindings);

const fixedIndex = await expressions.fixPackageIndexObject.evaluate(packageIndexObject, { isNumeric });
const fixedIndex = expressionsNew.fixPackageIndexObject(packageIndexObject);
return fixedIndex;
};

Expand All @@ -95,8 +96,8 @@ const parseFhirPackageIndex = async (): Promise<IFhirPackageIndex> => {
const dirList: string[] = getCachedPackageDirs();
// eslint-disable-next-line @typescript-eslint/no-var-requires
const currentIndex = require(fumeIndexPath);
const currentPackages = await expressions.extractCurrentPackagesFromIndex.evaluate(currentIndex);
const diff: string[] = await expressions.checkPackagesMissingFromIndex.evaluate({ dirList, packages: currentPackages });
const currentPackages = Object.keys(currentIndex?.packages);
const diff: string[] = expressionsNew.checkPackagesMissingFromIndex(dirList, currentPackages);
if (diff.length === 0) {
getLogger().info('Global package index file is up-to-date');
return require(fumeIndexPath);
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/conformance/recacheFromServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import config from '../../config';
import { getCache } from '../cache';
import { getFhirClient } from '../fhirServer';
import expressions from '../jsonataExpression';
import { expressions } from '../jsonataExpr';
import { transform } from '../jsonataFunctions';
import { getLogger } from '../logger';

Expand Down Expand Up @@ -36,7 +36,7 @@ const getNextBundle = async (bundle: Record<string, any>) => {
throw new Error('FUME running in stateless mode. Cannot get next page of search results bundle.');
};
let nextBundle;
const nextLink = await expressions.extractNextLink.evaluate(bundle);
const nextLink = expressions.extractNextLink(bundle);
if (typeof nextLink === 'string' && nextLink > '') {
nextBundle = await getFhirClient().read(nextLink);
}
Expand All @@ -54,7 +54,7 @@ const fullSearch = async (query: string, params?: Record<string, any>) => {
bundleArray.push(page);
page = await getNextBundle(page);
};
const resourceArray = await expressions.bundleToArrayOfResources.evaluate({}, { bundleArray });
const resourceArray = expressions.bundleToArrayOfResources(bundleArray);
return resourceArray;
};

Expand Down Expand Up @@ -100,12 +100,12 @@ const getAliases = async (createFunc?: Function) => {
let aliasResource = await getAliasResource();
if (typeof aliasResource === 'object') {
if (typeof aliasResource.resourceType === 'string' && aliasResource.resourceType === 'ConceptMap') {
aliasObject = await expressions.aliasResourceToObject.evaluate(aliasResource);
aliasObject = expressions.aliasResourceToObject(aliasResource);
} else {
if (createFunc !== undefined) {
logger.info('Creating new alias resource...');
aliasResource = await createFunc();
aliasObject = await expressions.aliasResourceToObject.evaluate(aliasResource);
aliasObject = expressions.aliasResourceToObject(aliasResource);
}
}
};
Expand All @@ -120,7 +120,7 @@ const getAllMappings = async (): Promise<Record<string, string>> => {
return {};
};
const allStructureMaps = await fullSearch('StructureMap/', { context: 'http://codes.fume.health|fume' });
const mappingDict: Record<string, string> = await expressions.structureMapsToMappingObject.evaluate(allStructureMaps);
const mappingDict: Record<string, string> = expressions.structureMapsToMappingObject(allStructureMaps);
if (Object.keys(mappingDict).length > 0) {
logger.info('Loaded the following mappings from server: ' + Object.keys(mappingDict).join(', '));
};
Expand Down
9 changes: 2 additions & 7 deletions src/helpers/fhirFunctions/literal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
import expressions from '../jsonataExpression';
import { searchSingle } from './searchSingle';
import { expressions } from '../jsonataExpr';

export const literal = async (query: string, params?: Record<string, any>): Promise<string | undefined> => {
const res = await expressions.literal.evaluate({}, { query, searchSingle, params });
const res = await expressions.literal(query);
return res;
};
4 changes: 2 additions & 2 deletions src/helpers/fhirFunctions/resourceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
import { searchSingle } from './searchSingle';

export const resourceId = async (query: string, params?: Record<string, any>): Promise<string | undefined> => {
export const resourceId = (query: string, params?: Record<string, any>): string | undefined => {
// fork: os
const resource = await searchSingle(query, params);
const resource: any = searchSingle(query, params);
let resourceId: string | undefined;
if (resource === undefined) {
resourceId = undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/fhirFunctions/searchSingle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project name: FUME-COMMUNITY
*/
import { getFhirClient } from '../fhirServer';
import expressions from '../jsonataExpression';
import { expressions } from '../jsonataExpr';

export const searchSingle = async (query: string, params?: Record<string, any>): Promise<any | undefined> => {
const url: string = encodeURI(query);
Expand All @@ -18,6 +18,6 @@ export const searchSingle = async (query: string, params?: Record<string, any>):
};

const bundle = await getFhirClient().search(url, options);
const res = await expressions.searchSingle.evaluate({}, { bundle });
const res = expressions.searchSingle(bundle);
return res;
};
4 changes: 2 additions & 2 deletions src/helpers/fhirFunctions/translateCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { getCache } from '../cache';
import { getTable } from '../conformance';
import expressions from '../jsonataExpression';
import { expressions } from '../jsonataExpr';
import { getLogger } from '../logger';

export const translateCode = async (input: string, tableId: string) => {
Expand All @@ -27,7 +27,7 @@ export const translateCode = async (input: string, tableId: string) => {
if (mapFiltered.length === 1) {
result = mapFiltered[0].code;
} else {
result = await expressions.translateCodeExtract.evaluate({}, { mapFiltered });
result = expressions.translateCodeExtract(mapFiltered);
}
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/fhirFunctions/translateCoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project name: FUME-COMMUNITY
*/
import { getCache } from '../cache';
import expressions from '../jsonataExpression';
import { expressions } from '../jsonataExpr';
import { getLogger } from '../logger';

export const translateCoding = async (input, tableId) => {
Expand All @@ -22,7 +22,7 @@ export const translateCoding = async (input, tableId) => {
}
}

const coding = await expressions.translateCodingExtract.evaluate({}, { result, input });
const coding = expressions.translateCodingExtract(result, input);
return coding;
} catch (error) {
getLogger().error({ error });
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/hl7v2/v2normalizeKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ describe('v2normalizeKey', () => {
});

test('normalizes key', async () => {
const res = await v2normalizeKey('hello');
const res = v2normalizeKey('hello');
expect(res).toBe('Hello');
});

test('stores normalized key', async () => {
await v2normalizeKey('hello');
v2normalizeKey('hello');
expect(v2keyMap.get('hello')).toBe('Hello');
});

test('returns from cache, if exists in cache.v2keyMap', async () => {
v2keyMap.set('hello', 'Hello2');
const res = await v2normalizeKey('hello');
const res = v2normalizeKey('hello');
expect(res).toBe('Hello2');
});
});
18 changes: 3 additions & 15 deletions src/helpers/hl7v2/v2normalizeKey.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
import { getCache } from '../cache';
import expressions from '../jsonataExpression';
import { initCap } from '../stringFunctions';
import { registerV2key } from './registerV2key';
import { expressions } from '../jsonataExpr';

export const v2normalizeKey = async (key: string) => {
const bindings = {
initCap,
keyMap: getCache().v2keyMap.getDict(),
registerV2key
};
const res = await expressions.v2normalizeKey.evaluate(key, bindings);
export const v2normalizeKey = (key: string) => {
const res = expressions.v2normalizeKey(key);
return res;
};
Loading
Loading