Quick Start Guide
This tutorial shows you how to implement AHI's MultiScan SDK for Web. The example will include a full FaceScan process.
Environment
Before you start building your web form, you will need to set up your development environment.
You will need:
- an IDE/text editor,
- a web server
- a web browser
Prepare
To get started we will create several files in the development folder.
For health details input form, SDK Setup, and initializing the SDK:
- index.html - Not included in guide (create your own form UI)
- indexscript.js - Instructions provided below
Note: Refer to FaceScan Schemas to view the user input requirements for the form page.
For handling and displaying results from the SDK output:
- results.html - Not included in guide (create your own results UI)
- resultsScript.js - Instructions provided below
For styling:
- styles.css - Not included in guide (create your own styles)
There are three parts to implementing MultiScan Web SDK:
- Setting up the system
- Initializing the service and integrating ScanControl API
- Handling the results
The form input and results display pages are not a part of this SDK. We recommend that developers build these pages according to their use case and include a scan guide for users to achieve best results.
1. Setup MultiScan SDK
In the first instance we will configure our code to call the AHI service and set-up MultiScan. This is done by adding the following code to index.html before the closing BODY tag
With the javascipt now being loaded we need to turn our attention to indexscript.js
The following code needs to be added to the file:
The above code requires that you add a <TOKEN> to the MultiScan set up.
Please ensure that you have a valid MultiScan token prior to continuing. If you do not have a token please contact AHI via your primary contact to arrange.
It also requires that you supply: <userID>, <salt>, and <claims>. More information on this can be found here: Authorization vs. Authentication
An example may look like:
Where USER1234 is the user's id, Company12345 represents your company (generally this should always be the same), and 13101978 (D/M/Y) represents the user's join date (helps to harden the security, and should be a value unique to the user but not changeable).
Note to Developer: User Claims
An array of user claims is needed for user authorization in order to provide additional information about the user beyond their username and identifier. These claims can be used to verify that the user is who they claim to be.
Here are a few examples of user claims that do not change and can be used for user authorization:
- dateCreated: The date an account was created can not change.
- dateOfBirth: A user's birthday can not change.
It is recommended to use claims that do not change over time such as an email address, as it can result in authorization issues if the user updates their information.
Now that the script for MultiScan setup has been added, proceed to add onload event to your body tag in index.html:
2. Initialize the Scan
One you have a MultiScan Object and your user is authorized you are ready to initialize a FaceScan.
FaceScan has a set of requirements that need to be adhered to in order for a successful Scan session. The following schema specifies the expected parameters that the web form must pass to MultiScan initiateScan() method:
Validation
It is important to note that the schema gives the type and validation rules required for each field.
Implementing the validation for these requirements is left to the developer for a production system.
For our example we will use HTML5's built in validation. We recommend you do not solely rely on this method and implement additional validation as per your preferred framework.
Submitting Form
To initalize the scan an onSubmit action will need to be added to the opening tag of the input form in index.html.
In this instance we call postValidateForm as we want to satisfy the MIN / MAX requirements for BMI in the schema. As we can't easily achieve this using the HTML5 validation we call our own custom code.
Add the custom code for postValidateForm function to indexscript.js. This is for example purposes and we recommend that the developer implement validation according to their own use case and error messaging system as required.
postValidateForm pulls validated height and weight values from the form to calculate BMI. If this is not within range it will alert the user.
This is for example purposes and we recommend that the developer implement validation according to their own use case and error messaging system as required.
If the form passes all validation tests then callScan(event) is actioned.
Calling FaceScan
Add the code for callScan() into indexscript.js. It should include all the params listed in the FaceScan schema.
It is important to note that params contains a callback url key cb in addition to the metrics required for the scan.
This is the URL that you wish results to be returned to. Once returned, it is the developer's responsibility to decode and interpret these results.
At this point we submit the form and hand control over to the MultiScan SDK and allow the user to complete their scan.
Assuming the scan process is successful we will expect a callback from the service.
Integrating ScanControl API
The ScanControl API is required for initializing scans. This API helps to track and manage the usage of scans.
This stage can be completed after pricing and subscription schemes have been contractually agreed. There will be a handover of the API KEY and a list of relevant PRODUCT ID for calling the API.
See Using ScanControl System to learn how to implement this service.
3. Handling Results
See FaceScan Schemas - Output for definitions of the results output.
Scan results are returned as a Base64 queryString within the URL.
The developer has to extrapolate and intepret these raw outputs according to their needs.
The sample code below is added to resultsScript.js. It simply iterates through the returned results and outputs them to the page.
Demo
View the AHI styled demo for an example of the full FaceScan Web process.
Note: You may need to request access to the demo. Also the form input, scan guide and results pages are only examples. The developer has to build the these pages according to their use case.