Skip to content

Commit

Permalink
refactor(ccdaservice): test and refactor populateProvider function (o…
Browse files Browse the repository at this point in the history
…penemr#6859)

* refactor(ccdaservice): test and refactor populateProvider function

* refactor(ccdaservice): use extracted populateProvider function

* test(ccdaservice): improve test description
  • Loading branch information
raskolnikov-rodion authored Sep 24, 2023
1 parent 9cd423d commit 658135c
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 52 deletions.
56 changes: 4 additions & 52 deletions ccdaservice/serveccda.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
getNpiFacility,
populateDemographics,
} = require('./utils/demographics/populate-demographics');
const { populateProvider } = require('./utils/providers/providers');

var conn = ''; // make our connection scope global to script
var oidFacility = "";
Expand All @@ -37,67 +38,18 @@ var webRoot = "";
var authorDateTime = '';
var documentLocation = '';

function populateProvider(provider) {
// The provider role is a maybe and will only be provided for physicians as a
// primary care role. All other team members will id via taxonomy only and if not physicians.
return {
"function_code": provider.physician_type ? "PP" : "",
"date_time": {
"low": {
"date": provider.provider_since ? fDate(provider.provider_since) : fDate(""),
"precision": "tz"
}
},
"identity": [
{
"root": provider.npi ? "2.16.840.1.113883.4.6" : oidFacility,
"extension": provider.npi || provider.table_id || "NI"
}
],
"type": [
{
"name": provider.taxonomy_description || "",
"code": cleanCode(provider.taxonomy) || "",
"code_system": "2.16.840.1.113883.6.101",
"code_system_name": "NUCC Health Care Provider Taxonomy"
}
],
"name": [
{
"last": provider.lname || "",
"first": provider.fname || ""
}
],
"address": [
{
"street_lines": [
all.encounter_provider.facility_street
],
"city": all.encounter_provider.facility_city,
"state": all.encounter_provider.facility_state,
"zip": all.encounter_provider.facility_postal_code,
"country": all.encounter_provider.facility_country_code || "US"
}
],

"phone": [{
"number": all.encounter_provider.facility_phone || ""
}]
}
}

function populateProviders(all) {
let providerArray = [];
// primary provider
let provider = populateProvider(all.primary_care_provider.provider);
let provider = populateProvider(all.primary_care_provider.provider, all);
providerArray.push(provider);
let count = countEntities(all.care_team.provider);
if (count === 1) {
provider = populateProvider(all.care_team.provider);
provider = populateProvider(all.care_team.provider, all);
providerArray.push(provider);
} else if (count > 1) {
for (let i in all.care_team.provider) {
provider = populateProvider(all.care_team.provider[i]);
provider = populateProvider(all.care_team.provider[i], all);
providerArray.push(provider);
}
}
Expand Down
59 changes: 59 additions & 0 deletions ccdaservice/utils/providers/providers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { fDate } = require('../date/date');
const { cleanCode } = require('../clean-code/clean-code');
const { NOT_INFORMED } = require('../constants');

function populateProvider(provider, documentData) {
const oidFacility =
documentData?.encounter_provider?.facility_oid ||
'2.16.840.1.113883.19.5.99999.1';
// The provider role is a maybe and will only be provided for physicians as a
// primary care role. All other team members will id via taxonomy only and if not physicians.
return {
function_code: provider.physician_type ? 'PP' : '',
date_time: {
low: {
date: fDate(provider.provider_since || ''),
precision: 'tz',
},
},
identity: [
{
root: provider.npi ? '2.16.840.1.113883.4.6' : oidFacility,
extension: provider.npi || provider.table_id || NOT_INFORMED,
},
],
type: [
{
name: provider.taxonomy_description || '',
code: cleanCode(provider.taxonomy) || '',
code_system: '2.16.840.1.113883.6.101',
code_system_name: 'NUCC Health Care Provider Taxonomy',
},
],
name: [
{
last: provider.lname || '',
first: provider.fname || '',
},
],
address: [
{
street_lines: [documentData.encounter_provider.facility_street],
city: documentData.encounter_provider.facility_city,
state: documentData.encounter_provider.facility_state,
zip: documentData.encounter_provider.facility_postal_code,
country:
documentData.encounter_provider.facility_country_code ||
'US',
},
],

phone: [
{
number: documentData.encounter_provider.facility_phone || '',
},
],
};
}

exports.populateProvider = populateProvider;
157 changes: 157 additions & 0 deletions ccdaservice/utils/providers/providers.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
const { NOT_INFORMED, NULL_FLAVOR } = require("../constants");

const TODAY = '2021-04-10T18:55:55.301Z';

const documentData = {
encounter_provider: {
facility_oid: 'mock_facility_oid',
facility_street: 'mock_facility_street',
facility_city: 'mock_facility_city',
facility_state: 'mock_facility_state',
facility_postal_code: 'mock_facility_postal_code',
facility_country_code: 'mock_facility_country_code',
facility_phone: 'mock_facility_phone',
},
};

const provider = {
physician_type: 'mock_physician_type',
provider_since: '07/05/2010',
npi: 'mock_npi',
taxonomy: 'mock_taxonomy',
taxonomy_description: 'mock_taxonomy_description',
fname: 'mock_provider_fname',
lname: 'mock_provider_lname',
};

const providerResult = {
address: [
{
city: documentData.encounter_provider.facility_city,
country: documentData.encounter_provider.facility_country_code,
state: documentData.encounter_provider.facility_state,
street_lines: [documentData.encounter_provider.facility_street],
zip: documentData.encounter_provider.facility_postal_code,
},
],
date_time: {
low: {
date: '2010-07-05',
precision: 'tz',
},
},
function_code: 'PP',
identity: [
{
extension: provider.npi,
root: '2.16.840.1.113883.4.6',
},
],
name: [
{
first: provider.fname,
last: provider.lname,
},
],
phone: [
{
number: documentData.encounter_provider.facility_phone,
},
],
type: [
{
code: provider.taxonomy,
code_system: '2.16.840.1.113883.6.101',
code_system_name: 'NUCC Health Care Provider Taxonomy',
name: provider.taxonomy_description,
},
],
};

const PROVIDER_TEST_DATA = [
[
// INPUT
provider,
documentData,
// RESULT
providerResult,
],
[
// INPUT
{
...provider,
npi: undefined,
table_id: undefined,
},
documentData,
// RESULT
{
...providerResult,
identity: [
{
extension: NOT_INFORMED,
root: documentData.encounter_provider.facility_oid,
},
],
},
],
[
// INPUT
{
...provider,
table_id: 'mock_table_id',
physician_type: undefined,
provider_since: undefined,
npi: undefined,
taxonomy: undefined,
taxonomy_description: undefined,
fname: undefined,
lname: undefined,
},
{
encounter_provider: {
...documentData.encounter_provider,
facility_oid: undefined,
facility_country_code: undefined,
facility_phone: undefined,
},
},
// RESULT
{
address: [
{
city: documentData.encounter_provider.facility_city,
country: 'US',
state: documentData.encounter_provider.facility_state,
street_lines: [
documentData.encounter_provider.facility_street,
],
zip: documentData.encounter_provider.facility_postal_code,
},
],
date_time: {
low: { date: TODAY, precision: 'tz' },
},
function_code: '',
identity: [
{
extension: 'mock_table_id',
root: '2.16.840.1.113883.19.5.99999.1',
},
],
name: [{ first: '', last: '' }],
phone: [{ number: '' }],
type: [
{
code: NULL_FLAVOR,
code_system: '2.16.840.1.113883.6.101',
code_system_name: 'NUCC Health Care Provider Taxonomy',
name: '',
},
],
},
],
];

exports.TODAY = TODAY;
exports.PROVIDER_TEST_DATA = PROVIDER_TEST_DATA;
19 changes: 19 additions & 0 deletions ccdaservice/utils/providers/providers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { populateProvider } = require('./providers');
const { PROVIDER_TEST_DATA, TODAY } = require('./providers.mock');

describe('populateProvider', () => {
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date(TODAY));
});

test.each(PROVIDER_TEST_DATA)(
'should map the input data to provider data object',
(provider, documentData, result) => {
expect(populateProvider(provider, documentData)).toEqual(result);
}
);

afterAll(() => {
jest.useRealTimers();
});
});

0 comments on commit 658135c

Please sign in to comment.