diff --git a/src/site/stages/build/drupal/static-data-files/config.js b/src/site/stages/build/drupal/static-data-files/config.js index 113f927a54..07dfec0733 100644 --- a/src/site/stages/build/drupal/static-data-files/config.js +++ b/src/site/stages/build/drupal/static-data-files/config.js @@ -3,6 +3,11 @@ const { postProcess: postProcessVamcEhrSystem, } = require('./vamcEhrSystem'); +const { + query: queryVaHealthcareServices, + postProcess: postProcessVaHealthcareServices, +} = require('./vaHealthcareServices'); + const { query: queryVamcFacilitySupplementalStatus, postProcess: postProcessVamcFacilitySupplementalStatus, @@ -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', diff --git a/src/site/stages/build/drupal/static-data-files/generate.js b/src/site/stages/build/drupal/static-data-files/generate.js index e0d651e59d..e23821d250 100644 --- a/src/site/stages/build/drupal/static-data-files/generate.js +++ b/src/site/stages/build/drupal/static-data-files/generate.js @@ -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 = ( diff --git a/src/site/stages/build/drupal/static-data-files/vaHealthcareServices/index.js b/src/site/stages/build/drupal/static-data-files/vaHealthcareServices/index.js new file mode 100644 index 0000000000..5e046b3561 --- /dev/null +++ b/src/site/stages/build/drupal/static-data-files/vaHealthcareServices/index.js @@ -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(`${str}`); + 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, +}; diff --git a/src/site/tests/static-files/static-files-exist.cypress.spec.js b/src/site/tests/static-files/static-files-exist.cypress.spec.js index f1696ae535..6f0e0ace2d 100644 --- a/src/site/tests/static-files/static-files-exist.cypress.spec.js +++ b/src/site/tests/static-files/static-files-exist.cypress.spec.js @@ -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, @@ -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', + ); + }); });