import { IAction } from 'types' ; import { availableTypes } from 'mockdata/mimic' ; import { ENGINE_BACKEND_URL } from '../../constants' ; export const fetchRecommendedColumns = ( fhirAttribute , type ) : IAction => { return ( dispatch , getState ) => { const url = `${ ENGINE_BACKEND_URL }/search/${ availableTypes [ type ] }` ; return fetch ( url ) . then ( ( response ) => { return response . json ( ) ; } ) . then ( ( response ) => { dispatch ( fetchRecommendedColumnsSuccess ( fhirAttribute , response ) ) ; } ) . catch ( ( err ) => { console . log ( err ) ; dispatch ( fetchRecommendedColumnsFailure ( err ) ) ; } ) ; } ; } ; export const fetchBetaRecommendedColumns = ( fhirAttribute , type , head_table , mot_clef ) : IAction => { return ( dispatch , getState ) => { const url = mot_clef == '' || ! mot_clef ? `${ ENGINE_BACKEND_URL }/beta/search/${ availableTypes [ type ] }/${ head_table }` : `${ ENGINE_BACKEND_URL }/beta/search/${ type ? availableTypes [ type ] : 'all' }/${ head_table }/${ mot_clef }` ; return fetch ( url ) . then ( ( response ) => { return response . json ( ) ; } ) . then ( ( response ) => { dispatch ( fetchRecommendedColumnsSuccess ( fhirAttribute , response ) ) ; } ) . catch ( ( err ) => { console . log ( err ) ; dispatch ( fetchRecommendedColumnsFailure ( err ) ) ; } ) ; } ; } ; export const fetchRecommendedColumnsSuccess = ( fhirAttribute , columns ) : IAction => { return { type : 'FETCH_RECOMMENDED_COLUMNS_SUCCESS' , payload : { fhirAttribute , columns } } ; } ; export const fetchRecommendedColumnsFailure = ( error ) : IAction => { return { type : 'FETCH_RECOMMENDED_COLUMNS_FAILURE' , payload : error } ; } ;