001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2025 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.fhirgw.svc; 011 012import ca.cdr.api.fhirgw.model.CreateRequest; 013import ca.cdr.api.fhirgw.model.DeleteRequest; 014import ca.cdr.api.fhirgw.model.HistoryRequest; 015import ca.cdr.api.fhirgw.model.OperationRequest; 016import ca.cdr.api.fhirgw.model.OperationResponse; 017import ca.cdr.api.fhirgw.model.ReadRequest; 018import ca.cdr.api.fhirgw.model.ReadResponse; 019import ca.cdr.api.fhirgw.model.SearchPageRequest; 020import ca.cdr.api.fhirgw.model.SearchRequest; 021import ca.cdr.api.fhirgw.model.SearchSingleTargetResponse; 022import ca.cdr.api.fhirgw.model.TransactionRequest; 023import ca.cdr.api.fhirgw.model.UpdateRequest; 024import ca.uhn.fhir.rest.api.MethodOutcome; 025import ca.uhn.fhir.rest.api.StringOutcome; 026import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; 027import ca.uhn.fhir.util.monad.Either; 028import org.apache.http.auth.AuthenticationException; 029import org.hl7.fhir.r4.model.Bundle; 030import org.hl7.fhir.r4.model.OperationOutcome; 031 032import java.io.IOException; 033import java.net.URISyntaxException; 034import java.util.List; 035 036public interface IFhirEndpointGatewayTarget { 037 038 /** 039 * Fetch the ID for this target 040 */ 041 String getId(); 042 043 /** 044 * This method will be called prior to {@link #start()} 045 */ 046 void setConnectTimeout(int theConnectTimeoutSeconds); 047 048 /** 049 * This method will be called prior to {@link #start()} 050 */ 051 void setSocketTimeout(int theSocketTimeoutSeconds); 052 053 /** 054 * This method will only be called if HTTP Basic credentials are configured for this endpoint 055 * <p> 056 * This method will be called prior to {@link #start()} 057 */ 058 void setHttpBasicCredentials(String theUsername, String thePassword); 059 060 /** 061 * Provides a prefix to prepend to resource IDs 062 * <p> 063 * This method will be called prior to {@link #start()} 064 */ 065 void setResourceIdPrefix(String theResourceIdPrefix); 066 067 /** 068 * Provides a prefix to prepend to resource IDs 069 */ 070 String getResourceIdPrefix(); 071 072 /** 073 * This method will be automatically called once before any invoke methods 074 */ 075 void start(); 076 077 /** 078 * This method will be automatically called when the gateway is shutting down 079 */ 080 void stop(); 081 082 /** 083 * Invoked to perform a type level search 084 * 085 * @param theRequest The details of the search request 086 */ 087 SearchSingleTargetResponse invokeTypeSearch(SearchRequest theRequest); 088 089 /** 090 * Invoked to fetch a page of results 091 */ 092 SearchSingleTargetResponse invokePageRequest(SearchPageRequest theRequest); 093 094 /** 095 * Invoked to perform a read or vread operation 096 */ 097 ReadResponse invokeRead(ReadRequest theRequest); 098 099 /** 100 * Invoked to perform a fhir operation 101 */ 102 OperationResponse invokeOperation(OperationRequest theRequest); 103 104 /** 105 * Invoked to perform a GraphQL operation 106 */ 107 String invokeGraphQLOperation(OperationRequest theRequest, String theGraphQLQuery) 108 throws IOException, URISyntaxException, AuthenticationException; 109 110 /** 111 * Invoked to perform a fhir update operation 112 */ 113 MethodOutcome invokeUpdate(UpdateRequest theRequest, ServletRequestDetails theRequestDetails); 114 115 /** 116 * Invoked to perform a fhir delete operation 117 */ 118 MethodOutcome invokeDelete(DeleteRequest theRequest, ServletRequestDetails theRequestDetails); 119 120 /** 121 * Invoked to perform a fhir CREATE operation 122 */ 123 MethodOutcome invokeCreate(CreateRequest theRequest, ServletRequestDetails theRequestDetails); 124 125 /** 126 * Invoked to perform a FHIR TRANSACTION operation 127 */ 128 MethodOutcome invokeTransaction(TransactionRequest theRequest, ServletRequestDetails theRequestDetails); 129 130 /** 131 * Invoked to perform a FHIR HISTORY INSTANCE operation 132 */ 133 Bundle invokeHistoryInstance(HistoryRequest theRequest, ServletRequestDetails theRequestDetails); 134 135 /** 136 * Invoked for any operation returning either an OperationOutcome, as an error return or 137 * a MethodOutcome as a successful return 138 * 139 * @return Either (but not both) of an OperationOutcome, as an error return or a MethodOutcome as a successful return 140 */ 141 Either<OperationOutcome, MethodOutcome> invokeForMethodOutcome(OperationRequest theRequest); 142 143 /** 144 * Invoked for any operation returning either an OperationOutcome, as an error return or 145 * a StringOutcome as a successful return 146 * 147 * @return Either (but not both) of an OperationOutcome, as an error return or a StringOutcome as a successful return 148 */ 149 Either<OperationOutcome, StringOutcome> invokeForStringOutcome(OperationRequest theRequest); 150 151 /** 152 * Return the base URL for the server 153 */ 154 String getBaseUrl(); 155 156 /** 157 * This method will be called prior to {@link #start()} 158 */ 159 void setBaseUrl(String theBaseUrl); 160 161 /** 162 * Get headers to be copied from the incoming client request and added to requests to the target server 163 */ 164 List<String> getHeadersToForward(); 165 166 /** 167 * Return headers to be copied from the incoming client request and added to requests to the target server 168 */ 169 void setHeadersToForward(List<String> theHeadersToForward); 170 171 /** 172 * Should this target use HTTP POST for all search operations 173 * <p> 174 * Default is <code>false</code> 175 */ 176 boolean isUseHttpPostForAllSearches(); 177 178 /** 179 * Should this target use HTTP POST for all search operations 180 * <p> 181 * Default is <code>false</code> 182 */ 183 void setUseHttpPostForAllSearches(boolean theUseHttpPostForAllSearches); 184 185 /** 186 * If the downstream target uses a fixed endpoint URL which does not match the defined {@link #getBaseUrl()}, set this value 187 * to the target's Fixed URL in order to have gateway trust bundle links which originate from this URL. 188 * 189 * @param theTargetFixedUrl The fixed URL of the downstream target. 190 */ 191 void setTargetFixedUrl(String theTargetFixedUrl); 192 193 /** 194 * If the downstream target uses a fixed endpoint URL which does not match the defined {@link #getBaseUrl()}, set this value 195 * to the target's Fixed URL in order to have gateway trust bundle links which originate from this URL. 196 * 197 * @return the fixed URL of the downstream target. 198 */ 199 String getTargetFixedUrl(); 200 201 /** 202 * Should FHIR Gateway validate the target server's CapabilityStatement with a request to /metadata 203 * <p> 204 * Default is <code>true</code> 205 */ 206 void setServerCapabilityStatementValidationEnabled(boolean theServerCapabilityStatementValidationEnabled); 207 208 /** 209 * Should FHIR Gateway validate the target server's CapabilityStatement with a request to /metadata 210 * <p> 211 * Default is <code>true</code> 212 */ 213 boolean isServerCapabilityStatementValidationEnabled(); 214 215 /** 216 * Should FHIR Gateway permit this target to fail on search routes? Does not apply to read routes. 217 * <p> 218 * Default is <code>false</code> 219 */ 220 void setAllowedToFail(boolean theAllowedToFail); 221 222 /** 223 * Should FHIR Gateway permit this target to fail on search routes? Does not apply to read routes. 224 * <p> 225 * Default is <code>false</code> 226 */ 227 boolean isAllowedToFail(); 228}