Skip to content

Commit

Permalink
Update code by clean up unused objects
Browse files Browse the repository at this point in the history
  • Loading branch information
svalluripalli committed Jan 30, 2023
1 parent 064091d commit dcecc86
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example Contributing Guidelines

This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information.
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- **I'm submitting a ...**
[ ] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project

- **Summary**

- **Other information** (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)

- **What is the current behavior?** (You can also link to an open issue here)

- **What is the new behavior (if this is a feature change)?**

- **Other information**:
1 change: 1 addition & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './lib/observation/observation';
export * from './lib/authorize/authorize';
export * from './lib/questionnaire/questionnaire';
export * from './lib/careplan/careplan';
export * from './query/json';
2 changes: 1 addition & 1 deletion source/lib/careplan/careplan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const getCareplansByStatusAndCategory = async (
) as CarePlan[];

log.info(
`getCareplansByStatusAndCategory - successful with pre-response ${filteredCareplans[0].toString()} - with status ${filteredCareplans[0]?.status}`
`getCareplansByStatusAndCategory - successful with pre-response ${filteredCareplans[0]?.toString()} - with status ${filteredCareplans[0]?.status}`
);
log.debug({ serviceName: 'getCareplansByStatusAndCategory', result: filteredCareplans });
return filteredCareplans;
Expand Down
56 changes: 52 additions & 4 deletions source/lib/observation/observation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FHIR from 'fhirclient';
import { fhirclient } from 'fhirclient/lib/types';

import { EccMode } from '../../constants/mode';
import { getAllCodes } from '../../query/json';
import { getAllCodes, getCodesFromValueSetCode } from '../../query/json';
import type { ObservationMode } from '../../types';
import log from '../../utils/loglevel';

Expand Down Expand Up @@ -65,9 +65,8 @@ export const getObservations = async (
log.info(
`getObservations - start with code - ${code} - ${mode} ${sort} ${max}`
);
const queryPath = `Observation?${
EccMode[mode] ?? EccMode.code
}=http://loinc.org|${code}&_sort=${sortType}&_count=${max ?? 100}`;
const queryPath = `Observation?${EccMode[mode] ?? EccMode.code
}=http://loinc.org|${code}&_sort=${sortType}&_count=${max ?? 100}`;
const observationRequest: fhirclient.JsonArray = await client.patient.request(
queryPath,
fhirOptions
Expand Down Expand Up @@ -199,3 +198,52 @@ export const getObservationsByCategory = async (
});
return filteredObservations;
};

export const getLatestObservation = async (code: string, translate: boolean, mode?: string): Promise<Observation> => {
if (!code) {
log.error('getLatestObservation - code not found');
return notFoundResponse() as unknown as Observation;
}

const client = await FHIR.oauth2.ready();
let codeValueSets = code;

if (translate) {
if (code.includes('|')) {
const codeArray = code.split('|')
codeValueSets = await getCodesFromValueSetCode(codeArray[0], codeArray[1]);
} else {
codeValueSets = await getCodesFromValueSetCode('http://loinc.org', code);
}
}

log.info(`getLatestObservation - start with code - ${code}`);
const queryPath = `Observation?${EccMode[mode] ?? EccMode.code}=http://loinc.org|${codeValueSets}&_sort=-date&_count=1`;
const observationRequest: fhirclient.JsonArray = await client.patient.request(
queryPath,
fhirOptions
);

const observationResource: Observation[] = resourcesFrom(
observationRequest
) as Observation[];

const filteredObservations: Observation[] = observationResource.filter(
(v) => v !== undefined && v.resourceType === 'Observation'
);

if (!filteredObservations.length) {
log.error('getObservation - empty observation');
return notFoundResponse(code) as unknown as Observation;
}

log.info(
`getObservation - successful with code ${code} - with status ${filteredObservations[0].status}`
);
log.debug({ serviceName: 'getObservation', result: filteredObservations[0] });
return filteredObservations[0];
};

// TODO add query observation segmented

// TODO add check for isBlackEgfr
2 changes: 0 additions & 2 deletions source/query/convertCsvToJson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// README: This is only to convert CSV to JSON, to run this, change it to js and simply run node convertCsvToJson.js

// const fs = require('fs')
// const path = require('path')
// let csvToJson = require('convert-csv-to-json');
Expand Down
18 changes: 18 additions & 0 deletions source/query/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ export const getAllCodes = async (valueName: string): Promise<string[]> => {

return mappedCodes;
};

// check for getAllValueSet name from code
export const getCodesFromValueSetCode = async (system: string, code: string) => {
const valueSetsList = await import(
`../resources/valueset_loadlist.json`
);


const valueSetsListParsed = await Promise.all(valueSetsList.map(async (v) => ({ fileName: v.Oid, valueSets: await import(`${v.Oid}.json`) })));

const foundValueSets = valueSetsListParsed.filter(v => v.valueSets.some(v => v['System'] === system && v['Code'] === code));

const valueSetCodes = getAllCodes(foundValueSets[0].fileName)

const joinedSetCodes = (await valueSetCodes).join(',');

return joinedSetCodes;
}
Loading

0 comments on commit dcecc86

Please sign in to comment.