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