-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS 18909 KISS autosuggest data for services from taxonomies (#2248)
* creates va-healthcare-services.json * remove spaces from JSONs * process the processed HTML to text * simplify
- Loading branch information
Showing
4 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/site/stages/build/drupal/static-data-files/vaHealthcareServices/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters