Exemplo n.º 1
0
    /*
     *  ////////////////////////////////////////////////////////////////////////////////////////////////
     *  // Testing token refresh
     *  //
     *  // NOTE: this test takes an hour, so it's disabled by default. Change false to true to run.
     *  ////////////////////////////////////////////////////////////////////////////////////////////////
     */
    public static void TestTokenRefresh()
    {
        TestingConfig config = new TestingConfig();
        APIConnection api    = config.Connection;

        string oldToken = api.GetToken();

        Console.WriteLine("Old token: " + oldToken);

        api.GET("/departments");

        // Wait 3600 seconds = 1 hour for token to expire.
        Thread.Sleep(3600 * 1000);

        api.GET("/departments");

        Console.WriteLine("New token: " + api.GetToken());
    }
Exemplo n.º 2
0
    // Procedure to send the pdf:
    public string SendPDFToAthena(string practiceID, string patientID, string appointmentID, string departmentID, string internalNote, bool attachPDFToVisit, byte[] data)
    {
        string version = "{yourVersionHere}"; // preview1, v1, etc
        string key     = "{yourKeyHere}";
        string secret  = "{yourSecretHere}";

        // This references an api that is pretty much exactly like that found on the
        // athena website for asp.net examples.  Get a token for authentication:
        APIConnection api   = new APIConnection(version, key, secret, practiceID);
        string        token = api.GetToken();

        // Generate post objects
        Dictionary <string, object> postParameters = new Dictionary <string, object>();

        postParameters.Add("appointmentid", appointmentID);
        postParameters.Add("internalnote", internalNote);

        //automatically close these docs (or leave out if you want them to be open for review)
        postParameters.Add("autoclose", "true");

        //where to attach? You should modify these for your use case
        if (attachPDFToVisit)
        {
            postParameters.Add("documentsubclass", "ENCOUNTERDOCUMENT_PROGRESSNOTE");
        }
        else
        {
            postParameters.Add("documentsubclass", "CLINICALDOCUMENT");
        }

        postParameters.Add("file", new FormUpload.FileParameter(data, appointmentID + ".pdf", "application/pdf"));

        // Create request and receive response
        string postURL     = Config.MDPUrl.Uri.ToString() + version + "/" + practiceID + "/patients/" + patientID + "/documents";
        string userAgent   = "Someone"; // The secret sauce: seems meaningless, but userAgent apparently must have a value
        string webResponse = FormUpload.MultipartFormDataPost(postURL, userAgent, postParameters, token);

        return(webResponse);
    }
Exemplo n.º 3
0
    static public void Main()
    {
        ////////////////////////////////////////////////////////////////////////////////////////////////
        // Setup
        ////////////////////////////////////////////////////////////////////////////////////////////////
        string key        = "CHANGEME: YOUR_API_KEY";
        string secret     = "CHANGEME: YOUR_API_SECRET";
        string version    = "preview1";
        string practiceid = "000000";

        APIConnection api = new APIConnection(version, key, secret, practiceid);

        // If you want to set the practice ID after construction, this is how.
        // api.PracticeID = "000000";


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // GET without parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        JsonValue customfields = api.GET("/customfields");

        Console.WriteLine("Custom fields:");
        foreach (JsonValue field in customfields)
        {
            Console.WriteLine("\t" + field["name"]);
        }

        ////////////////////////////////////////////////////////////////////////////////////////////////
        // GET with parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        string   format   = "MM/dd/yyyy";
        DateTime today    = DateTime.Now;
        DateTime nextyear = today.AddYears(1);

        Dictionary <string, string> search = new Dictionary <string, string>()
        {
            { "departmentid", "82" },
            { "startdate", today.ToString(format) },
            { "enddate", nextyear.ToString(format) },
            { "appointmenttypeid", "2" },
            { "limit", "1" },
        };

        JsonValue open_appts = api.GET("/appointments/open", search);

        Console.WriteLine(open_appts.ToString());
        JsonValue appt = open_appts["appointments"][0];

        Console.WriteLine("Open appointment:");
        Console.WriteLine(appt.ToString());

        Dictionary <string, string> newAppt = new Dictionary <string, string>();

        foreach (KeyValuePair <string, JsonValue> kvp in appt)
        {
            newAppt[kvp.Key] = kvp.Value.ToString();
        }


        // add keys to make appt usable for scheduling
        appt["appointmenttime"] = appt["starttime"];
        appt["appointmentdate"] = appt["date"];


        // Thread.Sleep(1000);      // NOTE: Uncomment this line if you keep getting "Over QPS" errors
        ////////////////////////////////////////////////////////////////////////////////////////////////
        // POST with parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        Dictionary <string, string> patientInfo = new Dictionary <string, string>()
        {
            { "departmentid", "1" },
            { "lastname", "Foo" },
            { "firstname", "Jason" },
            { "address1", "123 Any Street" },
            { "city", "Cambridge" },
            { "countrycode3166", "US" },
            { "dob", "6/18/1987" },
            { "language6392code", "declined" },
            { "maritalstatus", "S" },
            { "race", "declined" },
            { "sex", "M" },
            { "ssn", "*****1234" },
            { "zip", "02139" },
        };

        JsonValue newPatient = api.POST("/patients", patientInfo);

        Console.WriteLine(newPatient.ToString());
        string newPatientID = newPatient[0]["patientid"];

        Console.WriteLine("New patient id:");
        Console.WriteLine(newPatientID);


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // PUT with parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        Dictionary <string, string> appointmentInfo = new Dictionary <string, string>()
        {
            { "appointmenttypeid", "82" },
            { "departmentid", "1" },
            { "patientid", newPatientID },
        };

        JsonValue booked = api.PUT("/appointments/" + appt["appointmentid"], appointmentInfo);

        Console.WriteLine("Booked:");
        Console.WriteLine(booked.ToString());


        // Thread.Sleep(1000);      // NOTE: Uncomment this line if you keep getting "Over QPS" errors
        ////////////////////////////////////////////////////////////////////////////////////////////////
        // POST without parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        JsonValue checked_in = api.POST(string.Format("/appointments/{0}/checkin", appt["appointmentid"]));

        Console.WriteLine("Check-in:");
        Console.WriteLine(checked_in.ToString());


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // DELETE with parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        Dictionary <string, string> deleteParams = new Dictionary <string, string>()
        {
            { "departmentid", "1" },
        };
        JsonValue chartAlert = api.DELETE(string.Format("/patients/{0}/chartalert", newPatientID), deleteParams);

        Console.WriteLine("Removed chart alert:");
        Console.WriteLine(chartAlert.ToString());


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // DELETE without parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////
        JsonValue photo = api.DELETE(string.Format("/patients/{0}/photo", newPatientID));

        Console.WriteLine("Removed photo:");
        Console.WriteLine(photo.ToString());


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // There are no PUTs without parameters
        ////////////////////////////////////////////////////////////////////////////////////////////////


        // Thread.Sleep(1000);      // NOTE: Uncomment this line if you keep getting "Over QPS" errors
        ////////////////////////////////////////////////////////////////////////////////////////////////
        // Error conditions
        ////////////////////////////////////////////////////////////////////////////////////////////////
        JsonValue badPath = api.GET("/nothing/at/this/path");

        Console.WriteLine("GET /nothing/at/this/path:");
        Console.WriteLine(badPath.ToString());
        JsonValue missingParameters = api.GET("/appointments/open");

        Console.WriteLine("Missing parameters:");
        Console.WriteLine(missingParameters.ToString());


        ////////////////////////////////////////////////////////////////////////////////////////////////
        // Testing token refresh
        //
        // NOTE: this test takes an hour, so it's disabled by default. Change false to true to run.
        ////////////////////////////////////////////////////////////////////////////////////////////////
        if (false)
        {
            string oldToken = api.GetToken();
            Console.WriteLine("Old token: " + oldToken);

            api.GET("/departments");

            // Wait 3600 seconds = 1 hour for token to expire.
            Thread.Sleep(3600 * 1000);

            api.GET("/departments");

            Console.WriteLine("New token: " + api.GetToken());
        }
    }