Sharing is caring!
I have worked on many API integrations of Salesforce to other 3rd parties and here I will be sharing my coding experience with Salesforce to Dr. Chrono API integration. One my end clients requested this plugin/ app to be created in Salesforce which will do the Doctors, Patients and other information syncs between the two platforms.
Below image shows “integration mind mapping” used by me. I use it to consider some major aspects while discussing integration approaches for this project.
In this post, we will discuss how Dr. Chrono API can be used to integrate with Salesforce™. But before moving forward let’s discuss the requirement of the project.
Data flow diagram :
App development strategy:
The project requirements encurtail following. We have to integrate the Dr. Chrono API with Salesforce™ and create a plugin exclusively, it is a free Healthcare API and SDK built by developers, for developers. Leverage health data, an EHR, practice management and medical billing platform, beside it Dr. Chrono gets 22 Million API calls per month.
What is Dr. Chrono API?
A company that helps people find quality care providers nearby, is using the Dr.Chrono API to integrate patient records into the service. This vastly improves the search experience, as patients are connected with doctors based on their medical history and set of conditions. There API uses a common web-based authentication system. It provides a straightforward way for a provider to grant access to their data to your application.
There are three main steps in the OAuth 2.0 authentication workflow.
- Redirect the provider to the authorization page.
- The provider authorizes your application and is redirected back to your web application.
Your application exchanges the authorization_code that came with the redirect into a pair of access_token and refresh_token.
Step 1: Redirect to Dr. Chrono
The first step is redirecting your user to Dr. Chrono, typically with a button labeled “Connect to Dr. Chrono” or “Login with Dr. Chrono”.
Step 2: Token exchange
Below code is used to obtain a pair of the access token and refresh token like this:
return customsetting;
Main API Usage
Getting user information
In cases where Dr.Chrono is used for single sign-on, often the first request that’s made is to /api/users/current to get information about the currently logged in user:
Roadblock (2): DML and Callout
DML: DML provides a straightforward way to manage records by providing simple statements to insert, update, merge, delete, and restore records. Because Apex is a data-focused language and is saved on the Lightning Platform, it has direct access to your data in Salesforce™.
Callout: An Apex callout lets you tightly integrate Apex code with an external service by making a call to an external Web service or sending an HTTP request from Apex code and then receiving the response. Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services (RESTful services).
As discussed above they were using an OAuth tool(2.0 version) which generates a fresh token and after every 1 hour it gets expire, so it was a big question for us that how can we stop token to get expire?
So after a discussion, we finally come up with a solution. Now what we did is every time for their custom setting we tried to check whether the token is expired or not and if we find the token is of before time then it is expired. That’s why instead of doing callout DML callout, we did call out and without inserting it into the custom setting we again did callout and then DML. Using callout DML approach we resolved this problem.
Read Also : Challenges of Undertaking Salesforce Integration
Ajay Dubedi
CEO | Founder
Ajay Dubedi, the founder and CEO of Cloud Analogy, is a prominent Salesforce Sales, Service, and Marketing cloud Consultant with a rich expertise in handling challenging business models. Ajay has assisted and implemented solutions in industries comprising Banking, Health Care, Networking, Education, Telecommunication and Manufacturing. Ajay is globally acclaimed for his extensive experience in APEX Programming, VisualForce pages, Triggers, Workflows, Page Layouts, Roles, Profiles, Reports & Dashboards.Hire the best Salesforce Implementation Partner. Choose Cloud Analogy, the world's most preferred Salesforce Implementation Company that provides custom CRM Implementation services.