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