All files / src/server/utils conformance.utils.js

86.66% Statements 13/15
55.55% Branches 5/9
60% Functions 3/5
92.3% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 985x                                               40x 930x                                 5x                                                                   5x 40x       40x 930x     930x 930x       40x     5x        
const { getSearchParameters } = require('./params.utils');
 
// /**
//  * @description Reduce function for removing duplicates from the search params array
//  * @param {Object} collection - Cumulutaive array for reduce function
//  * @param {Object} route_arg - route argument
//  * @return {Object} collection
//  */
// let conformanceSearchParamsReduce = (collection, route_arg) => {
// 	console.log(collection);
// 	// Use the name to find duplicates, we should not have arguments with the same name
// 	if (!collection.find(item => item.name === route_arg.name)) {
// 		collection.push(route_arg);
// 	}
// 	return collection;
// };
 
/**
 * @description Filter function for determining which searchParam fields are needed
 * for conformance/capability statements
 * @param {Object} route_arg - route argument
 * @param {string} base_version - which version (not necessary now, but may be in the future)
 * @return {function} filter function for array.filter
 */
let conformanceSearchParamsFilter = (base_version) => (route_arg) => {
  return route_arg.conformance_hide
    ? // If the conformance_hide property is true, always remove this element
      false
    : // Else check our versions property, there are two possible cases
      // If no versions are provided, it is available for all versions
      !route_arg.versions ||
        // If versions are provided, make sure this arg is meant for this version
        (route_arg.versions && route_arg.versions.indexOf(base_version) > -1);
};
 
/**
 * @description Map function for taking a router argument and mapping it
 * into the searchParam field needed for conformance/capability statements
 * @param {string} version - which version (not necessary now, but may be in the future)
 * @return {function} map function for array.map
 */
/* eslint-disable no-unused-vars */
let conformanceSearchParamsMap = (version) => (route_arg) => {
  // The router adds extra arguments and those need to be discarded
  // these are the only fields we currently care about
  return {
    name: route_arg.name,
    type: route_arg.type,
    definition: route_arg.definition,
    documentation: route_arg.documentation || route_arg.description,
  };
};
 
// /**
//  * Function to take the routes and the FHIR version and return an array of search parameters
//  * @param {Array<Object>} routes - an array of routes from the profile config files
//  * @param {string} version - Which FHIR version was hit
//  * @return {Array<Object>} an array of filtered and mapped routes to show in the conformance statement
//  */
// let generateSearchParamsForConformance = (routes, version) => {
// 	return (
// 		routes
// 			// Get a flat list of all of our router arguments
// 			.reduce((all, route) => all.concat(route.args), [])
// 			// Filter parameters that should be excluded from this conformance
// 			// statement based on version or if it is a route parameter (e.g. version or id)
// 			// route parameters will have a conformance_hide property
// 			.filter(conformanceSearchParamsFilter(version))
// 			// Remove any duplicates from the array based on their name
// 			.reduce(conformanceSearchParamsReduce, [])
// 			// Route arguments have additional parameters necessary for generating routes
// 			// map over the routes and remove those parameters
// 			.map(conformanceSearchParamsMap(version))
// 	);
// };
 
let getSearchParams = (profileKey, version) => {
  let params = getSearchParameters(profileKey, version).filter(
    conformanceSearchParamsFilter(version)
  );
 
  for (let key of Object.keys(params)) {
    let param = params[key];
 
    // don't show version
    Eif (param.versions) {
      delete param.versions;
    }
  }
 
  return params;
};
 
module.exports = {
  // generateSearchParamsForConformance,
  getSearchParams,
};