mirror of
https://github.com/Sudo-JHare/FHIRFLARE-IG-Toolkit.git
synced 2025-11-05 13:35:15 +00:00
hotfix
This commit is contained in:
parent
ffeef91166
commit
a76180fd48
45
app.py
45
app.py
@ -1905,7 +1905,49 @@ def proxy_hapi(subpath):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Unexpected proxy error for {final_url}: {str(e)}", exc_info=True)
|
logger.error(f"Unexpected proxy error for {final_url}: {str(e)}", exc_info=True)
|
||||||
return jsonify({'resourceType': 'OperationOutcome', 'issue': [{'severity': 'error', 'code': 'exception', 'diagnostics': 'An unexpected error occurred within the FHIR proxy.', 'details': {'text': str(e)}}]}), 500
|
return jsonify({'resourceType': 'OperationOutcome', 'issue': [{'severity': 'error', 'code': 'exception', 'diagnostics': 'An unexpected error occurred within the FHIR proxy.', 'details': {'text': str(e)}}]}), 500
|
||||||
# --- End of corrected proxy_hapi function ---
|
|
||||||
|
|
||||||
|
@app.route('/api/stream-retrieve', methods=['GET'])
|
||||||
|
def stream_retrieve_bundles():
|
||||||
|
"""
|
||||||
|
Handles streaming FHIR bundle retrieval. This endpoint directly calls the service function,
|
||||||
|
bypassing the proxy to avoid conflicts. It receives the target URL,
|
||||||
|
resources, and other parameters from the front-end via URL query parameters.
|
||||||
|
"""
|
||||||
|
def generate_stream():
|
||||||
|
# Push the application context manually for the generator's lifetime
|
||||||
|
with app.app_context():
|
||||||
|
# Extract parameters from query string
|
||||||
|
fhir_server_url = request.args.get('fhir_server_url')
|
||||||
|
resources = request.args.getlist('resources')
|
||||||
|
validate_references = request.args.get('validate_references', 'false').lower() == 'true'
|
||||||
|
fetch_reference_bundles = request.args.get('fetch_reference_bundles', 'false').lower() == 'true'
|
||||||
|
|
||||||
|
# Extract authentication headers
|
||||||
|
auth_token = request.headers.get('Authorization')
|
||||||
|
auth_type = 'bearer' if auth_token and auth_token.lower().startswith('bearer') else 'basic' if auth_token and auth_token.lower().startswith('basic') else 'none'
|
||||||
|
|
||||||
|
temp_dir = tempfile.gettempdir()
|
||||||
|
zip_filename = f"retrieved_bundles_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}.zip"
|
||||||
|
output_zip = os.path.join(temp_dir, zip_filename)
|
||||||
|
|
||||||
|
try:
|
||||||
|
yield from services.retrieve_bundles(
|
||||||
|
fhir_server_url=fhir_server_url,
|
||||||
|
resources=resources,
|
||||||
|
output_zip=output_zip,
|
||||||
|
validate_references=validate_references,
|
||||||
|
fetch_reference_bundles=fetch_reference_bundles,
|
||||||
|
auth_type=auth_type,
|
||||||
|
auth_token=auth_token
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in retrieve_bundles: {e}", exc_info=True)
|
||||||
|
yield json.dumps({"type": "error", "message": f"Unexpected error: {str(e)}"}) + "\n"
|
||||||
|
|
||||||
|
response = Response(generate_stream(), mimetype='application/x-ndjson')
|
||||||
|
response.headers['X-Zip-Path'] = os.path.join('/tmp', zip_filename)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/load-ig-to-hapi', methods=['POST'])
|
@app.route('/api/load-ig-to-hapi', methods=['POST'])
|
||||||
@ -2338,7 +2380,6 @@ def retrieve_split_data():
|
|||||||
now=datetime.datetime.now(), app_mode=app.config['APP_MODE'],
|
now=datetime.datetime.now(), app_mode=app.config['APP_MODE'],
|
||||||
api_key=app.config['API_KEY'])
|
api_key=app.config['API_KEY'])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/retrieve-bundles', methods=['POST'])
|
@app.route('/api/retrieve-bundles', methods=['POST'])
|
||||||
@csrf.exempt
|
@csrf.exempt
|
||||||
@swag_from({
|
@swag_from({
|
||||||
|
|||||||
@ -4583,13 +4583,11 @@ def retrieve_bundles(fhir_server_url, resources, output_zip, validate_references
|
|||||||
else:
|
else:
|
||||||
yield json.dumps({"type": "info", "message": "Reference fetching OFF"}) + "\n"
|
yield json.dumps({"type": "info", "message": "Reference fetching OFF"}) + "\n"
|
||||||
|
|
||||||
# Determine Base URL and Headers for the requests.
|
# Determine the final base URL for requests.
|
||||||
|
final_base_url = fhir_server_url.rstrip('/') if fhir_server_url and fhir_server_url != '/fhir' else app.config.get('HAPI_FHIR_URL', 'http://localhost:8080/fhir')
|
||||||
headers = {'Accept': 'application/fhir+json, application/fhir+xml;q=0.9, */*;q=0.8'}
|
headers = {'Accept': 'application/fhir+json, application/fhir+xml;q=0.9, */*;q=0.8'}
|
||||||
|
|
||||||
is_custom_url = fhir_server_url != '/fhir' and fhir_server_url is not None and fhir_server_url.startswith('http')
|
is_custom_url = fhir_server_url != '/fhir' and fhir_server_url is not None and fhir_server_url.startswith('http')
|
||||||
|
|
||||||
final_base_url = fhir_server_url.rstrip('/') if fhir_server_url else '/fhir'
|
|
||||||
|
|
||||||
if is_custom_url:
|
if is_custom_url:
|
||||||
if auth_type in ['bearer', 'basic'] and auth_token:
|
if auth_type in ['bearer', 'basic'] and auth_token:
|
||||||
auth_display = 'Basic <redacted>' if auth_type == 'basic' else (auth_token[:10] + '...' if len(auth_token) > 10 else auth_token)
|
auth_display = 'Basic <redacted>' if auth_type == 'basic' else (auth_token[:10] + '...' if len(auth_token) > 10 else auth_token)
|
||||||
@ -4600,7 +4598,7 @@ def retrieve_bundles(fhir_server_url, resources, output_zip, validate_references
|
|||||||
logger.debug(f"Will send requests directly to: {final_base_url}")
|
logger.debug(f"Will send requests directly to: {final_base_url}")
|
||||||
else:
|
else:
|
||||||
yield json.dumps({"type": "info", "message": "Using no authentication for local HAPI server"}) + "\n"
|
yield json.dumps({"type": "info", "message": "Using no authentication for local HAPI server"}) + "\n"
|
||||||
logger.debug("Will use proxy targeting local HAPI server")
|
logger.debug("Will use local HAPI server")
|
||||||
|
|
||||||
# Fetch Initial Bundles
|
# Fetch Initial Bundles
|
||||||
initial_bundle_files = []
|
initial_bundle_files = []
|
||||||
|
|||||||
@ -384,7 +384,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentFhirServerUrl = useLocalHapi ? '/fhir' : fhirServerUrlInput.value.trim().replace(/\/+$/, '');
|
const currentFhirServerUrl = useLocalHapi ? null : fhirServerUrlInput.value.trim().replace(/\/+$/, '');
|
||||||
if (!useLocalHapi && !currentFhirServerUrl) {
|
if (!useLocalHapi && !currentFhirServerUrl) {
|
||||||
alert('Custom FHIR Server URL is required.');
|
alert('Custom FHIR Server URL is required.');
|
||||||
fhirServerUrlInput.classList.add('is-invalid');
|
fhirServerUrlInput.classList.add('is-invalid');
|
||||||
@ -407,7 +407,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (currentFhirServerUrl) {
|
if (currentFhirServerUrl) {
|
||||||
url.searchParams.set('proxy-target', currentFhirServerUrl);
|
url.searchParams.set('proxy-target', currentFhirServerUrl);
|
||||||
}
|
}
|
||||||
selectedResources.forEach(res => url.searchParams.append('resource_type', res));
|
selectedResources.forEach(res => url.searchParams.append('resources', res));
|
||||||
url.searchParams.set('validate_references', validateReferences);
|
url.searchParams.set('validate_references', validateReferences);
|
||||||
url.searchParams.set('fetch_reference_bundles', fetchReferenceBundles);
|
url.searchParams.set('fetch_reference_bundles', fetchReferenceBundles);
|
||||||
|
|
||||||
@ -428,7 +428,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
console.log(`Submitting retrieve request. URL: ${url.toString()}, Headers: ${JSON.stringify(headers)}`);
|
console.log(`Submitting retrieve request. URL: ${url.toString()}, Headers: ${JSON.stringify(headers)}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url.toString(), { method: 'POST', headers: headers });
|
const response = await fetch(url.toString(), { method: 'GET', headers: headers });
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch(() => ({ message: 'Failed to parse error response.' }));
|
const errorData = await response.json().catch(() => ({ message: 'Failed to parse error response.' }));
|
||||||
@ -661,8 +661,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
alert("Download error: No file path available.");
|
alert("Download error: No file path available.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Initial Setup Calls ---
|
|
||||||
updateBundleSourceUI();
|
updateBundleSourceUI();
|
||||||
updateServerToggleUI();
|
updateServerToggleUI();
|
||||||
toggleFetchReferenceBundles();
|
toggleFetchReferenceBundles();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user