Java - API Examples

Simple Java classes to query the 1upHealth FHIR Analytics server

Bulk Data Analytics APIs are currently available in the 1up development environment. View the examples below to test in dev.

JDBC Requirement

You need the JDBC driver for Athena connectivity to run the examples



Code

List FHIR Resources

public class ListFHIRresources {

    // JDBC configuration and output area
    private static final String ATHENA_JDBC_CLASS = "com.simba.athena.jdbc.Driver";
    private static final String ATHENA_JDBC_DRIVER = "jdbc:awsathena://AwsRegion=us-east-1";
    private static final String ATHENA_OUTPUT_BUCKET = "s3://1uphealth-bulkdata-analytics-dev-output/";

    // 1uphealth-bulkdata user credentials
    private static final String AWS_ACCESS_KEY_ID = "**CONTACT-1UPHEALTH-FOR-ACCESS**";
    private static final String AWS_SECRET_ACCESS_KEY = "**CONTACT-1UPHEALTH-FOR-ACCESS**";

    public static void main(String args[]) {

        // Measure response time
        long start = System.currentTimeMillis();
        System.out.println("Starting query...");
        disableWarnings();

        // JDBC query variables
        Connection conn;
        Statement stmt;
        ResultSet res;

        // Result counter
        int rowCount = 0;

        // JDBC connection properties
        Properties properties = new Properties();
        properties.put("User", AWS_ACCESS_KEY_ID);
        properties.put("Password", AWS_SECRET_ACCESS_KEY);
        properties.put("S3OutputLocation", ATHENA_OUTPUT_BUCKET);

        try {

            // Set up the connection
            Class.forName(ATHENA_JDBC_CLASS);
            conn = DriverManager.getConnection(ATHENA_JDBC_DRIVER, properties);

            // Prepare the sql statement
            String sql = "SHOW TABLES FROM 1uphealthbulkdataanalytics";
            System.out.println("Query = " + sql);

            // Run the query
            stmt = conn.createStatement();
            res = stmt.executeQuery(sql);

            // Output FHIR resources
            System.out.println("FHIR Resource List");
            while (res.next()) {
                System.out.println(++rowCount + " - " + res.getObject(1).toString());
            }

            // Clean up
            conn.close();
            stmt.close();
            res.close();

        } catch (Exception e)  {
            e.printStackTrace();
        }

        // Output metrics
        System.out.println("End query...");
        System.out.println("Execution time: " + (System.currentTimeMillis() - start)*0.001);
        System.out.println("Number of resources = " + rowCount);

    }



Immunization Report

Query = 13 year old children in Boston who have been immunized for chickenpox (vaccine Code: 21)

Same connection code - Different SQL statement (& output processing)

public class ImmunizationReport {

    // JDBC definitions and AWS output area
    private static final String ATHENA_JDBC_CLASS = "com.simba.athena.jdbc.Driver";
    private static final String ATHENA_JDBC_DRIVER = "jdbc:awsathena://AwsRegion=us-east-1";
    private static final String ATHENA_OUTPUT_BUCKET = "s3://1uphealth-bulkdata-analytics-dev-output/";

    // 1uphealth-bulkdata user credentials
    private static final String AWS_ACCESS_KEY_ID = "**CONTACT-1UPHEALTH-FOR-ACCESS**";
    private static final String AWS_SECRET_ACCESS_KEY = "**CONTACT-1UPHEALTH-FOR-ACCESS**";

    public static void main(String args[]) {

        // Measure response time
        long start = System.currentTimeMillis();
        System.out.println("Starting query...");
        disableWarnings();

        // JDBC query variables
        Connection conn;
        Statement stmt;
        ResultSet res;

        // Result counter
        int rowCount = 0;

        // JDBC connection properties
        Properties properties = new Properties();
        properties.put("User", AWS_ACCESS_KEY_ID);
        properties.put("Password", AWS_SECRET_ACCESS_KEY);
        properties.put("S3OutputLocation", ATHENA_OUTPUT_BUCKET);

        try {

            // Set up the connection
            Class.forName(ATHENA_JDBC_CLASS);
            conn = DriverManager.getConnection(ATHENA_JDBC_DRIVER, properties);

            // Prepare the sql statement
            String sql = "SELECT p.id AS PID, " +
                    "p.name[1].family[1] AS LastName, " +
                    "p.name[1].given[1] AS FirstName, " +
                    "p.birthdate AS DOB, " +
                    "i.vaccineCode.coding[1].code AS iCode, " +
                    "i.vaccineCode.coding[1].display AS iType, " +
                    "split_part(i.date,'T',1) AS iDate " +
                    "FROM 1uphealthbulkdataanalytics.patient p, 1uphealthbulkdataanalytics.immunization i " +
                    "WHERE p.id = (split_part(i.patient.reference, ':', 3)) " +
                    " AND i.vaccineCode.coding[1].code = '21' " +
                    " AND p.birthdate > '2015-01-01' " +
                    " AND p.birthdate < '2015-12-31' " +
                    " AND p.address[1].city = 'Boston' " +
                    "ORDER BY LastName, FirstName";
            System.out.println("Query = " + sql);

            // run the query
            stmt = conn.createStatement();
            res = stmt.executeQuery(sql);

            // Go through query results
            while (res.next()) {
                rowCount++;
                System.out.print("PID - ");
                System.out.println(res.getObject(1));           // patient id
                System.out.print(res.getObject(2) + ", ");      // last name
                System.out.print(res.getObject(3) + " ");       // first name
                System.out.print(res.getObject(4) + " ");       // date of birth
                System.out.print(res.getObject(5) + " ");       // vaccine code
                System.out.print(res.getObject(6) + " ");       // vaccine text
                System.out.println(res.getObject(7));           // vaccine date
            }

            // Clean-up
            conn.close();
            stmt.close();
            res.close();

        } catch (Exception e)  {
            e.printStackTrace();
        }

        // Output metrics
        System.out.println("End query...");
        System.out.println("Execution time: " + (System.currentTimeMillis() - start)*0.001);
        System.out.println("Number of records = " + rowCount);
    }