All files / platform/core/src/DataSources IWebApiDataSource.js

63.63% Statements 7/11
70% Branches 7/10
16.66% Functions 1/6
63.63% Lines 7/11

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                                                    340x                                           340x       340x               340x   340x       340x                           34x          
import { DicomMetadataStore } from '../services/DicomMetadataStore';
// TODO: Use above to inject so dependent datasources don't need to import or
// depend on @ohif/core?
 
/**
 * Factory function that creates a new "Web API" data source.
 * A "Web API" data source is any source that fetches data over
 * HTTP. This function serves as an "adapter" to wrap those calls
 * so that all "Web API" data sources have the same interface and can
 * be used interchangeably.
 *
 * It's worth noting that a single implementation of this interface
 * can define different underlying sources for "read" and "write" operations.
 */
function create({
  query,
  retrieve,
  store,
  reject,
  initialize,
  deleteStudyMetadataPromise,
  getImageIdsForDisplaySet,
  getImageIdsForInstance,
  getConfig,
  getStudyInstanceUIDs,
}) {
  const defaultQuery = {
    studies: {
      /**
       * @param {string} params.patientName
       * @param {string} params.mrn
       * @param {object} params.studyDate
       * @param {string} params.description
       * @param {string} params.modality
       * @param {string} params.accession
       * @param {string} params.sortBy
       * @param {string} params.sortDirection -
       * @param {number} params.page
       * @param {number} params.resultsPerPage
       */
      mapParams: params => params,
      requestResults: () => {},
      processResults: results => results,
    },
    series: {},
    instances: {},
  };
 
  const defaultRetrieve = {
    series: {},
  };
 
  const defaultStore = {
    dicom: async naturalizedDataset => {
      throw new Error(
        'store.dicom(naturalizedDicom, StudyInstanceUID) not implemented for dataSource.'
      );
    },
  };
 
  const defaultReject = {};
 
  const defaultGetConfig = () => {
    return { dicomUploadEnabled: false };
  };
 
  return {
    query: query || defaultQuery,
    retrieve: retrieve || defaultRetrieve,
    reject: reject || defaultReject,
    store: store || defaultStore,
    initialize,
    deleteStudyMetadataPromise,
    getImageIdsForDisplaySet,
    getImageIdsForInstance,
    getConfig: getConfig || defaultGetConfig,
    getStudyInstanceUIDs: getStudyInstanceUIDs,
  };
}
 
const IWebApiDataSource = {
  create,
};
 
export default IWebApiDataSource;