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