File size: 1,355 Bytes
063458c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Constants for API endpoints
export const HEALTHGOV_API_BASE = "https://health.gov/myhealthfinder/api/v3";
export const FDA_API_BASE = "https://api.fda.gov/drug";
export const NIH_MED_API_BASE = "https://clinicaltables.nlm.nih.gov/api/conditions/v3/search";
export const USER_AGENT = "healthcare-assistant/1.0";

// Helper function for making API requests
export async function makeApiRequest<T>(url: string): Promise<T | null> {
    const headers = {
        "User-Agent": USER_AGENT,
        Accept: "application/json",
    };

    try {
        const response = await fetch(url, { headers });
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        }
        return (await response.json()) as T;
    } catch (error) {
        console.error("Error making API request:", error);
        return null;
    }
}

// Format health recommendation data
export function formatHealthRecommendation(recommendation: any): string {
    return [
        `Title: ${recommendation.Title || "Unknown"}`,
        `Target Population: ${recommendation.PopulationData?.PopulationGroup || "General population"}`,
        `Summary: ${recommendation.RecommendationSummary || "No summary available"}`,
        `Description: ${recommendation.MyHFDescription || "No description available"}`,
        "---",
    ].join("\n");
}