Introduction


This article will guide you through the process of using the LiveDDM REST API.  This article is intended for use by 3rd Party Vendors that wish to interact with the LiveDDM database..


Vendor Account


Before proceeding, please ensure that you have a Vendor Account and API Key.  Please email support@liveddm.com to register.


REST API


Access to LiveDDM data is controlled via a REST API that is exposed by the LiveDDM Management Client (LMC).  The LMC is installed at every office.  You will be able to obtain the specific end point for each office when you register for a Vendor Account.


For the purposes of testing, a sandboxed LMC is running in the cloud at https://liveddmmanagementclient.azurewebsites.net


Documentation


REST API Documentation is available online by navigating to https://liveddmmanagementclient.azurewebsites.net/api


Authentication


The REST API is secured using JSON Web Tokens (JWT).  Before calling any of the web methods, you must first authorize your Vendor API Key.  Upon success, you will receive a Token that must be passed in the request header in order to authorize access.


Sample Code


The code below is provided in C#.  The sample demonstrates how to connect to the REST API, authorize your vendor api key and then request a collection of Patient Info objects.


internal class Program
{
    static async Task Main(string[] args)
    {
        await Connect();
    }

    static async Task Connect()
    {
        //
        // create a new instance of HttpClient
        //
        var client = new HttpClient();
        //
        // set the base Uri for the Api
        //
        var baseUri = new Uri("https://liveddmmanagementclient.azurewebsites.net");
        //
        // authenticate using your vendor Api key
        //
        var apiKey = "{your_api_key}";
        var uri = new Uri(baseUri, $"api/authentication/authenticatevendor/{apiKey}");
        //
        // get your Jwt token
        //
        var response = await client.GetAsync(uri);
        response.EnsureSuccessStatusCode();
        var content = await response.Content.ReadAsStringAsync();
        var vendorToken = JsonSerializer.Deserialize<VendorAuthenticationToken>(content);
        //
        // call the GetPatient end point to get the first 20 patients,
        // remembering to add your token to the header
        //
        uri = new Uri(baseUri, $"api/liveddm/patients/getpatientinfo/0/20");
        var request = new HttpRequestMessage(HttpMethod.Get, uri.ToString());
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", vendorToken.Token);
        //
        // get the response Json object
        //
        response = await client.SendAsync(request);
        var json = await response.Content.ReadAsStringAsync();


        var patients = JsonSerializer.Deserialize<List<PatientInfo>>(json);
    }
}


internal class VendorAuthenticationToken
{
    [JsonPropertyName("vendorName")]
    public string VendorName { get; set; }

    [JsonPropertyName("token")]
    public string Token { get; set; }

    [JsonPropertyName("expiresOn")]
    public DateTime ExpiresOn { get; set; }
}
enum GenderTypes
{
    NotSpecified, Male, Female, Other
}
internal class PatientInfo
{

    [JsonPropertyName("id")]
    public int Id { get; set; }

    [JsonPropertyName("firstName")]
    public string FirstName { get; set; }

    [JsonPropertyName("lastName")]
    public string LastName { get; set; }

    [JsonPropertyName("birthDate")]
    public DateTime BirthDate { get; set; }

    [JsonPropertyName("gender")]
    public GenderTypes Gender { get; set; }

    [JsonPropertyName("phoneNumber")]
    public string PhoneNumber { get; set; }

    [JsonPropertyName("email")]
    public string Email { get; set; }

    [JsonPropertyName("cellNumber")]
    public string CellNumber { get; set; }

    [JsonPropertyName("isActive")]
    public bool IsActive { get; set; }

    [JsonPropertyName("street1")]
    public string Street1 { get; set; }

    [JsonPropertyName("street2")]
    public string Street2 { get; set; }

    [JsonPropertyName("city")]
    public string City { get; set; }

    [JsonPropertyName("province")]
    public string Province { get; set; }

    [JsonPropertyName("postalCode")]
    public string PostalCode { get; set; }

    [JsonPropertyName("rfmId")]
    public int RfmId { get; set; }

    [JsonPropertyName("responsibleFamilyMember")]
    public string ResponsibleFamilyMember { get; set; }

    public override string ToString()
    {
        return $"{FirstName} {LastName}";
    }


}