Skip to content

Commit

Permalink
Updated with the clean code to remove 100% dependency on MCC API Java
Browse files Browse the repository at this point in the history
  • Loading branch information
svalluripalli committed Mar 27, 2023
1 parent a416700 commit 99e6c1b
Show file tree
Hide file tree
Showing 25 changed files with 1,270 additions and 2,075 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ npm link e-care-common-data-services
- Release a tag, e.g `v1.0.0`
- in mcc-provider or mcc-care-planner app, run
```
npm i [email protected]:chronic-care/e-care-common-data-services.git#v1.0.0
npm i ssh://[email protected]:XXGITHUB_ORG_NAMEXX/e-care-common-data-services.git#v1.0.0
```

## Code structure explanation
Expand Down Expand Up @@ -63,7 +63,7 @@ This is where we store our modules, inside will be having each module, e.g `obse
This is where we put testing specific to observation

#### mapping
This is where we put resource mapping from fhir localised to our module, e.g on `vital-mapping` when we get `ckd`, we will try to query data for
This is the where we put resource mapping from fhir localised to our module, e.g on `vital-mapping` when we get `ckd`, we will try to query data for
- Cognitive Status (MoCA)
- Fatigue (PROMIS T-score)
- Functional Status (PROMIS raw score)
Expand Down
2,356 changes: 450 additions & 1,906 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
"test": "run-s build test:*",
"test:lint": "eslint source --ext .ts",
"test:prettier": "prettier \"source/**/*.ts\" --list-different",
"test:unit": "nyc --silent ava",
"check-cli": "run-s test diff-integration-tests check-integration-tests",
"check-integration-tests": "run-s check-integration-test:*",
"diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "nyc --silent ava --watch",
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
Expand All @@ -33,7 +30,6 @@
"doc": "run-s doc:html && open-cli build/docs/index.html",
"doc:html": "typedoc source/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
"doc:json": "typedoc source/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
"version": "standard-version",
"reset-hard": "git clean -dfx && git reset --hard && npm i",
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
Expand All @@ -49,12 +45,10 @@
"dayjs": "^1.11.5",
"fhirclient": "^2.5.2",
"http": "^0.0.1-security",
"loglevel": "^1.8.0",
"papaparse": "^5.3.2"
"loglevel": "^1.8.0"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/node": "^18.7.17",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
Expand All @@ -67,9 +61,7 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"gh-pages": "^3.1.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^7.0.1",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
Expand Down Expand Up @@ -106,12 +98,6 @@
"prettier": {
"singleQuote": true
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"exclude": [
"**/*.spec.js"
]
},
"copyFiles": [
{
"from": "source/resources/*",
Expand Down
9 changes: 8 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ export * from './lib/authorize/authorize';
export * from './lib/questionnaire/questionnaire';
export * from './lib/careplan/careplan';
export * from './lib/condition/condition';
export * from './lib/contact/contact';
export * from './lib/counseling/counseling';
export * from './lib/education/education';
export * from './lib/goal/goal';
export * from './lib/medication-request/medication-request';
export * from './lib/patient/patient';
export * from './lib/referral/referral';
export * from './lib/social-concern/social-concern';
export * from './query/json';
export * from './lib/patient/patient';
69 changes: 47 additions & 22 deletions source/lib/careplan/careplan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CarePlan, Condition } from 'fhir/r4';
import FHIR from 'fhirclient';
import { fhirclient } from 'fhirclient/lib/types';

import { MccCarePlan, MccCondition } from '../../types/mcc-types';
import log from '../../utils/loglevel';

import {
Expand All @@ -12,7 +13,7 @@ import {
resourcesFromObject,
} from './careplan.util';

export const getCareplans = async (sort?: string, max?: string): Promise<CarePlan[]> => {
export const getCareplans = async (sort?: string, max?: string): Promise<MccCarePlan[]> => {
const sortType = sort === 'descending' ? '-date' : 'date';

const client = await FHIR.oauth2.ready();
Expand All @@ -22,9 +23,9 @@ export const getCareplans = async (sort?: string, max?: string): Promise<CarePla
queryPath
);

const filteredCareplans: CarePlan[] = resourcesFrom(
const filteredCareplans: MccCarePlan[] = resourcesFrom(
careplanRequest
) as CarePlan[];
) as MccCarePlan[];

log.info(
`getCareplans - successful with status ${filteredCareplans[0]?.status}`
Expand All @@ -33,10 +34,10 @@ export const getCareplans = async (sort?: string, max?: string): Promise<CarePla
return filteredCareplans;
};

export const getCareplan = async (id: string): Promise<CarePlan> => {
export const getCareplan = async (id: string): Promise<MccCarePlan> => {
if (!id) {
log.error('getCareplan - id not found');
return notFoundResponse as unknown as CarePlan;
return notFoundResponse as unknown as MccCarePlan;
}

const client = await FHIR.oauth2.ready();
Expand All @@ -46,9 +47,9 @@ export const getCareplan = async (id: string): Promise<CarePlan> => {
queryPath
);

const filteredCareplan: CarePlan = resourcesFromObject(
const filteredCareplan: MccCarePlan = resourcesFromObject(
careplanRequest
) as CarePlan;
) as MccCarePlan;

log.info(
`getCareplan - successful with id ${id} - with status ${filteredCareplan?.status}`
Expand All @@ -60,7 +61,7 @@ export const getCareplan = async (id: string): Promise<CarePlan> => {
export const getCareplansByStatusAndCategory = async (
status: string,
category: string[],
): Promise<CarePlan[]> => {
): Promise<MccCarePlan[]> => {
if (!status || !category) {
log.error('getCareplansByStatusAndCategory - status or category not found');
return [notFoundResponse] as unknown as CarePlan[];
Expand All @@ -74,9 +75,9 @@ export const getCareplansByStatusAndCategory = async (
queryPath
);

const filteredCareplans: CarePlan[] = resourcesFrom(
const filteredCareplans: MccCarePlan[] = resourcesFrom(
careplanRequest
) as CarePlan[];
) as MccCarePlan[];

log.info(
`getCareplansByStatusAndCategory - successful with pre-response ${filteredCareplans[0]?.toString()} - with status ${filteredCareplans[0]?.status}`
Expand All @@ -85,10 +86,10 @@ export const getCareplansByStatusAndCategory = async (
return filteredCareplans;
};

export const getConditionFromUrl = async (urlPath: string): Promise<Condition> => {
export const getConditionFromUrl = async (urlPath: string): Promise<MccCondition> => {
if (!urlPath) {
log.error('getCondition - urlPath not found');
return {} as unknown as Condition;
return {} as unknown as MccCondition;
}

const client = await FHIR.oauth2.ready();
Expand All @@ -100,9 +101,9 @@ export const getConditionFromUrl = async (urlPath: string): Promise<Condition> =
queryPath
);

const filteredCondition: Condition = resourcesFromObject(
const filteredCondition: MccCondition = resourcesFromObject(
conditionRequest
) as Condition;
) as MccCondition;

log.info(`getCondition - successful with urlPath ${urlPath}`);
log.debug({ serviceName: 'getCondition', result: filteredCondition });
Expand All @@ -112,10 +113,10 @@ export const getConditionFromUrl = async (urlPath: string): Promise<Condition> =
export const getBestCareplan = async (
subject: string,
matchScheme?: string
): Promise<CarePlan[]> => {
): Promise<MccCarePlan[]> => {
if (!subject) {
log.error('getBestCareplan - subject not found');
return [] as CarePlan[];
return [] as MccCarePlan[];
}

const matchSchemeParam = matchScheme ?? 'profiles';
Expand All @@ -129,11 +130,11 @@ export const getBestCareplan = async (
fhirOptions
);

const careplanResource: CarePlan[] = resourcesFrom(
const careplanResource: MccCarePlan[] = resourcesFrom(
careplanRequest
) as CarePlan[];
) as MccCarePlan[];

const filteredCareplans: CarePlan[] = careplanResource.filter(
const filteredCareplans: MccCarePlan[] = careplanResource.filter(
(v) =>
v !== undefined && v.resourceType === 'CarePlan' && v.status === 'active'
// filter for address condition not needed by mcc-provider
Expand All @@ -142,7 +143,7 @@ export const getBestCareplan = async (
// fallback
if (!filteredCareplans.length) {
log.error('getBestCareplan - empty careplan');
return [{ id: 'NOID' }] as CarePlan[];
return [{ id: 'NOID' }] as MccCarePlan[];
}

// sorting
Expand Down Expand Up @@ -182,8 +183,8 @@ export const getBestCareplan = async (
});

// filter out addresses by condition reference
const responseCarePlans: CarePlan[] = await Promise.all(
filteredCareplans.map(async (careplan: CarePlan) => {
const responseCarePlans: MccCarePlan[] = await Promise.all(
filteredCareplans.map(async (careplan: MccCarePlan) => {
const addresses = await Promise.all(
careplan.addresses.map(async (address) => {
const condition: Condition = await getConditionFromUrl(address.reference);
Expand All @@ -205,3 +206,27 @@ export const getBestCareplan = async (
log.debug({ serviceName: 'getBestCareplan', result: responseCarePlans });
return responseCarePlans;
};

// TODO: supported careplan with valueset integration on profilemap
export const getSupportedCarePlans = async (sort?: string, max?: string): Promise<MccCarePlan[]> => {
const sortType = sort === 'descending' ? '-date' : 'date';

const client = await FHIR.oauth2.ready();

const queryPath = `CarePlan?&_sort=${sortType}&_count=${max ?? 100}`;
const careplanRequest: fhirclient.JsonArray = await client.patient.request(
queryPath
);

const filteredCareplans: MccCarePlan[] = resourcesFrom(
careplanRequest
) as MccCarePlan[];

const activeCareplans = filteredCareplans.filter((carePlan => carePlan.status === 'active'))

log.info(
`getSupportedCarePlans - successful with status ${activeCareplans[0]?.status}`
);
log.debug({ serviceName: 'getSupportedCarePlans', result: activeCareplans });
return activeCareplans;
};
Loading

0 comments on commit 99e6c1b

Please sign in to comment.