Skip to content

Commit

Permalink
VACMS 18909 KISS autosuggest data for services from taxonomies (#2248)
Browse files Browse the repository at this point in the history
* creates va-healthcare-services.json
* remove spaces from JSONs
* process the processed HTML to text
* simplify
  • Loading branch information
eselkin authored and GovCIOLiz committed Sep 3, 2024
1 parent e6b7722 commit f6a5589
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/site/stages/build/drupal/static-data-files/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const {
postProcess: postProcessVamcEhrSystem,
} = require('./vamcEhrSystem');

const {
query: queryVaHealthcareServices,
postProcess: postProcessVaHealthcareServices,
} = require('./vaHealthcareServices');

const {
query: queryVamcFacilitySupplementalStatus,
postProcess: postProcessVamcFacilitySupplementalStatus,
Expand Down Expand Up @@ -37,6 +42,13 @@ const DATA_FILES = [
queryType: 'graphql',
postProcess: postProcessVamcEhrSystem,
},
{
description: 'VA Healthcare Services',
filename: 'va-healthcare-services.json',
query: queryVaHealthcareServices,
queryType: 'graphql',
postProcess: postProcessVaHealthcareServices,
},
{
description: 'VAMC Facility Supplemental Status',
filename: 'vamc-facility-supplemental-status.json',
Expand Down
4 changes: 1 addition & 3 deletions src/site/stages/build/drupal/static-data-files/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ const writeProcessedDataFilesToBuild = (

const writeProcessedDataFileToCache = async (path, filename, data) => {
const filenameWithPath = `${path}/${filename}`;
fs.outputJSON(filenameWithPath, data, {
spaces: 2,
});
fs.outputJSON(filenameWithPath, data);
};

const writeProcessedDataFilesToCache = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const { JSDOM } = require('jsdom');

const query = `
query {
taxonomyTermQuery(
offset: 0
filter: {conditions: [{field: "vid", value: ["health_care_service_taxonomy"]}, {field: "status", value: ["1"]}]}
limit: 1000
) {
count
entities {
... on TaxonomyTermHealthCareServiceTaxonomy {
name
fieldAlsoKnownAs
fieldCommonlyTreatedCondition
fieldHealthServiceApiId
fieldServiceTypeOfCare
fieldShowForVetCenters
fieldShowForVbaFacilities
fieldShowForVamcFacilities
fieldTricareSpecificService
description {
processed
}
fieldTricareDescription
reverseFieldServiceNameAndDescriptiNode {
count
}
}
}
}
}
`;

function decodeEntities(str) {
// this prevents any overhead from creating the object each time
const dom = new JSDOM(`<!DOCTYPE html><body>${str}</body>`);
return dom.window.document.body.textContent || '';
}

const postProcess = queryResult => {
// [{
// name: 'name',
// fieldAlsoKnownAs: 'aka',
// fieldCommonlyTreatedCondition: 'commonconditions',
// fieldHealthServiceApiId: 'fieldHealthServiceApiId',
// fieldServiceTypeOfCare: 'typeOfCare',
// fieldShowForVetCenters: true,
// fieldShowForVbaFacilities: true,
// fieldShowForVamcFacilities: false,
// fieldTricareSpecificService: false,
// reverseFieldServiceNameAndDescriptiNode: { count: 0 },
// description: 'description',
// fieldTricareDescription: 'fieldTricareDescription'
// }]
// GraphQL query filter is pretty bad, so we'll do the filtering here (can't do a successful nested OR on the show for VetCenter,VAMC,VBA fields - it returns 3 elements)
// 1. Filter out services that are false for fieldShowForVetCenters, fieldShowForVbaFacilities, and fieldShowForVamcFacilities
// 2. Sort by frequency of use (revereFieldServiceNameAndDescriptiNode.count)
// 3. Convert to an array of arrays of ["name", "aka", "commonconditions", "fieldHealthServiceApiId", "typeOfCare", true, false, true, false, count]
const taxonomies = queryResult.data.taxonomyTermQuery.entities
.filter(
service =>
(service.fieldShowForVetCenters ||
service.fieldShowForVbaFacilities ||
service.fieldShowForVamcFacilities) &&
service.reverseFieldServiceNameAndDescriptiNode?.count,
)
.map(service => {
const {
name,
fieldAlsoKnownAs,
fieldCommonlyTreatedCondition,
fieldHealthServiceApiId,
fieldServiceTypeOfCare,
fieldShowForVetCenters,
fieldShowForVbaFacilities,
fieldShowForVamcFacilities,
fieldTricareSpecificService,
reverseFieldServiceNameAndDescriptiNode,
description,
fieldTricareDescription,
} = service;
return [
name,
fieldAlsoKnownAs,
fieldCommonlyTreatedCondition,
fieldHealthServiceApiId,
fieldServiceTypeOfCare,
fieldShowForVetCenters,
fieldShowForVbaFacilities,
fieldShowForVamcFacilities,
fieldTricareSpecificService,
reverseFieldServiceNameAndDescriptiNode.count, // i=9
decodeEntities(description?.processed || ''),
decodeEntities(fieldTricareDescription || ''),
];
});
// descending sort by frequency of use
taxonomies.sort((a, b) => b[9] - a[9]);
return taxonomies;
};

module.exports = {
query,
postProcess,
};
17 changes: 17 additions & 0 deletions src/site/tests/static-files/static-files-exist.cypress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('Static Data Files Test', () => {
cy.readFile('cypress/downloads/vamc-system.json').should('exist');
});
it('has the VAMC Police JSON static file', () => {
// relative to current working directory
cy.deleteFileOrDir('../cypress/downloads/vamc-police.json');
// relative to the cy task
cy.fileOrDirExists('cypress/downloads/vamc-police.json').should(
'eq',
false,
Expand All @@ -47,4 +49,19 @@ describe('Static Data Files Test', () => {
);
cy.readFile('cypress/downloads/vamc-police.json').should('exist');
});
it('has the VA Healthcare Services JSON static file', () => {
cy.deleteFileOrDir('../cypress/downloads/va-healthcare-services.json');
cy.fileOrDirExists('cypress/downloads/va-healthcare-services.json').should(
'eq',
false,
);
cy.downloadFile(
'http://localhost:3002/data/cms/va-healthcare-services.json',
'../cypress/downloads',
'va-healthcare-services.json',
);
cy.readFile('cypress/downloads/va-healthcare-services.json').should(
'exist',
);
});
});

0 comments on commit f6a5589

Please sign in to comment.