import { FhirConfig , FhirVersion , stubs , BASE_R4_RESOURCES , BASE_STU3_RESOURCES , Validator , } from 'fhir-works-on-aws-interface' ; import { ElasticSearchService } from 'fhir-works-on-aws-search-es' ; import { RBACHandler } from 'fhir-works-on-aws-authz-rbac' ; import { DynamoDb , DynamoDbDataService , DynamoDbBundleService , S3DataService , DynamoDbUtil , } from 'fhir-works-on-aws-persistence-ddb' ; import JsonSchemaValidator from 'fhir-works-on-aws-routing/lib/router/validation/jsonSchemaValidator' ; import HapiFhirLambdaValidator from 'fhir-works-on-aws-routing/lib/router/validation/hapiFhirLambdaValidator' ; import RBACRules from './RBACRules' ; import { loadImplementationGuides } from './implementationGuides/loadCompiledIGs' ; const { IS_OFFLINE , ENABLE_MULTI_TENANCY } = process . env ; const enableMultiTenancy = ENABLE_MULTI_TENANCY === 'true' ; export const fhirVersion = '4.0.1' ; const baseResources = fhirVersion === '4.0.1' ? BASE_R4_RESOURCES : BASE_STU3_RESOURCES ; const authService = IS_OFFLINE ? stubs . passThroughAuthz : new RBACHandler ( RBACRules ( baseResources ) , fhirVersion ) ; const dynamoDbDataService = new DynamoDbDataService ( DynamoDb , false , { enableMultiTenancy } ) ; const dynamoDbBundleService = new DynamoDbBundleService ( DynamoDb , undefined , undefined , { enableMultiTenancy , } ) ; const validators = [ ] ; if ( process . env . VALIDATOR_LAMBDA_ALIAS && process . env . VALIDATOR_LAMBDA_ALIAS !== '[object Object]' ) { validators . push ( new HapiFhirLambdaValidator ( process . env . VALIDATOR_LAMBDA_ALIAS ) ) ; } else if ( process . env . OFFLINE_VALIDATOR_LAMBDA_ALIAS ) { validators . push ( new HapiFhirLambdaValidator ( process . env . OFFLINE_VALIDATOR_LAMBDA_ALIAS ) ) ; } else { validators . push ( new JsonSchemaValidator ( fhirVersion ) ) ; } const esSearch = new ElasticSearchService ( [ { key : 'documentStatus' , value : [ 'AVAILABLE' ] , comparisonOperator : '==' , logicalOperator : 'AND' , } , ] , DynamoDbUtil . cleanItem , fhirVersion , loadImplementationGuides ( 'fhir-works-on-aws-search-es' ) , undefined , { enableMultiTenancy } ) ; const s3DataService = new S3DataService ( dynamoDbDataService , fhirVersion , { enableMultiTenancy } ) ; const OAuthUrl = process . env . OAUTH2_DOMAIN_ENDPOINT === '[object Object]' || process . env . OAUTH2_DOMAIN_ENDPOINT === undefined ? 'https://OAUTH2.com' : process . env . OAUTH2_DOMAIN_ENDPOINT ; export const getFhirConfig = async ( ) : Promise < FhirConfig > => ( { configVersion : 1.0 , productInfo : { orgName : 'Organization Name' , } , auth : { authorization : authService , strategy : { service : 'OAuth' , oauthPolicy : { authorizationEndpoint : `${ OAuthUrl }/authorize` , tokenEndpoint : `${ OAuthUrl }/token` , } , } , } , server : { url : process . env . API_URL === '[object Object]' || process . env . API_URL === undefined ? 'https://API_URL.com' : process . env . API_URL , } , validators , profile : { systemOperations : [ 'transaction' ] , bundle : dynamoDbBundleService , compiledImplementationGuides : loadImplementationGuides ( 'fhir-works-on-aws-routing' ) , systemHistory : stubs . history , systemSearch : stubs . search , bulkDataAccess : dynamoDbDataService , fhirVersion , genericResource : { operations : [ 'create' , 'read' , 'update' , 'delete' , 'vread' , 'search-type' ] , fhirVersions : [ fhirVersion ] , persistence : dynamoDbDataService , typeSearch : esSearch , typeHistory : stubs . history , } , resources : { Binary : { operations : [ 'create' , 'read' , 'update' , 'delete' , 'vread' ] , fhirVersions : [ fhirVersion ] , persistence : s3DataService , typeSearch : stubs . search , typeHistory : stubs . history , } , } , } , multiTenancyConfig : enableMultiTenancy ? { enableMultiTenancy : true , useTenantSpecificUrl : true , tenantIdClaimPath : 'custom:tenantId' , } : undefined , } ) ; export const genericResources = baseResources ;