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

100% Statements 15/15
83.33% Branches 5/6
100% Functions 2/2
100% Lines 15/15

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 4010x   10x 10x 10x 10x             10x 305x 305x   222x   2x   76x   5x                 10x 99x     10x        
const { VERSIONS } = require('../../constants');
 
const schemasR401 = require('../resources/4_0_1/schemas');
const schemasR4 = require('../resources/4_0_0/schemas');
const schemas3 = require('../resources/3_0_1/schemas');
const schemas1 = require('../resources/1_0_2/schemas');
 
/**
 *
 * @param {String} version
 * @param {String} schema
 */
const resolveSchema = (version = '4_0_1', schema = '') => {
  const lowercaseSchema = schema.toLowerCase();
  switch (version) {
    case '4_0_1':
      return schemasR401[lowercaseSchema];
    case '4_0_0':
      return schemasR4[lowercaseSchema];
    case '3_0_1':
      return schemas3[lowercaseSchema];
    case '1_0_2':
      return schemas1[lowercaseSchema];
  }
};
 
/**
 * Utility helpful for checking if a given string is a valid FHIR version
 * within node-fhir-server-core
 * @param {String} version
 */
const isValidVersion = (version) => {
  return Object.keys(VERSIONS).includes(version);
};
 
module.exports = {
  resolveSchema,
  isValidVersion,
};