cliniasearch v1.0.2
Features
- Thin & minimal low-level HTTP client to interact with Clinia's API
- Works both on the browser and node.js
- UMD compatible, you can use it with any module loader
- Contains type definitions: @types/cliniasearch
Getting Started
First, install Clinia JavaScript API Client via the npm package manager:
npm install --save cliniasearch
OR
yarn add cliniasearch
Quickstart
Let's search using the search
method, targeting a single index:
const cliniasearch = require('cliniasearch');
const client = cliniasearch('YourApplicationID', 'YourAPIKey');
const index = client.initIndex('your_index_name');
index
.search('Foo')
.then(({ results }) => {
console.log(results);
})
.catch(err => {
console.log(err);
});
More details...
The client allows to use the following Clinia APIs:
- Single index search
- Multiple indexes search
- Query suggestions (Autocomplete)
- Location suggestions (Autocomplete)
Single index search
For use cases where one wants to search through a single index, the client provides the Index
interface. The current possible index
values are :
professional
: Represents people working in the health industry like doctors, physiotherapists and other health professionals.health_facility
: Represents health establishments like clinics, hospitals, pharmacies and other health facilities.
Multiple indexes search
For use cases where one wants to search through all indexes, the client provides methods to search directly, without using the Index
interface.
Query suggestions (Autocomplete)
For use cases where one wants to get query suggestions based on a user input, the client provides methods to autocomplete queries based on the content of one's database. Typical use cases usually follow query suggestions with an actual search using the provided suggestion as search query.
Place suggestions (Autocomplete)
For use cases where one wants to get place suggestions based on a user input, the client provides methods to autocomplete queries based Clinia's Location API. Typical use cases usually follow place suggestions with an actual search using the provided place as parameter to a search query.
API
Client
Initialization
const client = cliniasearch('YourApplicationID', 'YourAPIKey');
client.initIndex(indexName)
Get the Index
object initialized .
Arguments
- indexName (string) -- Name of the targeted index.
Returns
Returns an instance of Index
.
client.initPlaces()
Get the Places object initialized.
Returns
Returns an instance of Places
.
client.setExtraHeader(name, value)
Add an extra field to the HTTP request.
Arguments
- name (string) -- The header field name.
- value (string) -- The header field value.
client.getExtraHeader(name)
Get the value of an extra HTTP header.
Arguments
- name (string) -- The header field name.
Returns
A string
of the field value.
client.unsetExtraHeader(name)
Remove an extra field from the HTTP request.
Arguments
- name (string) -- The header field name.
client.suggest(query, args, callback)
Get query suggestions based on a query.
Arguments
- query (string) -- The query to get suggestions for.
- args (Object) -- The query parameters.
- highlightPreTag (string) -- The pre tag used to highlight matched query parts.
- highlightPostTag (string) -- The post tag used to highlight matched query parts.
- size (number) -- Max number of suggestions to receive.
- callback (Function) -- Callback to be called.
Returns
Returns a Promise
if no callback given.
Example
client.suggest('Foo', { highlightPreTag: "<strong>", highlightPostTag: "</strong>" }, function(err, suggestions) {
if (err) {
throw err;
}
console.log(suggestions)
})
client.search(queries, callback)
Search through multiple indices at the same time.
Arguments
- queries (Object[]) -- An array of queries you want to run.
- indexName (string) -- The name of the index you want to target.
- query (string) -- The query to issue on this index. Can also be passed into
params
. - params (Object) -- Search params.
- page (string) -- Page offset.
- perPage (string) -- Page size.
- queryType (string) -- Strategy for the query. Possible values are
prefix_last
orprefix_none
.prefix_last
will return partial word match.prefix_none
will return exact word match. - searchFields (string[]) -- Fields in which to search.
- location (string) -- A postal code, the name of a city or a region.
- callback (Function) -- Callback to be called.
Returns
Returns a Promise
if no callback given.
Example
var queries = [
{
indexName: 'health_facility',
query: 'sons',
params: {
queryType: 'prefixLast',
searchFields: ['name'],
},
},
{
indexName: 'professional',
query: 'sons',
params: {
queryType: 'prefixLast',
searchFields: ['name'],
},
},
];
client.search(queries, function(err, response) {
if (err) {
throw err;
}
console.log(response);
});
Index
Initialization
const index = client.initIndex(indexName);
The current possible indexName
values are :
professional
: Represents people working in the health industry like doctors, physiotherapists and other health professionals.health_facility
: Represents health establishments like clinics, hospitals, pharmacies and other health facilities.
index.search(query, args, callback)
Search through a single index.
Arguments
- query (Object) -- The query to issue on this index. Can also be passed into
args
. - args (Object) -- The query parameters.
- page (string) -- Page offset.
- perPage (string) -- Page size.
- queryType (string) -- Strategy for the query. Possible values are
prefix_last
orprefix_none
.prefix_last
will return partial word match.prefix_none
will return exact word match. - searchFields (string[]) -- Fields in which to search.
- location (string) -- A postal code, the name of a city or a region.
- callback (Function) -- Callback to be called.
Returns
Returns a Promise
if no callback given.
Example
index.search('Foo', { queryType: 'prefix_last', filters: { location: 'Bar' }}, function(err, results) {
if (err) {
throw err;
}
console.log(results)
});
Places
Initialization
const places = client.initPlaces();
places.suggest(query, args, callback)
Get place suggestions based on a query.
Arguments
- query (Object) -- The query to issue. Can also be passed into
args
. - args (Object) -- The query parameters.
- limit (number) -- Max number of suggestions to receive.
- country (string) -- ISO3166 Alpha-2 country code (e.g. 'CA'). Limits the suggestions to this country.
- callback (Function) -- Callback to be called.
Returns
Returns a Promise
if no callback given.
Example
places.search('3578 rue Dorion Montréal', { country: 'CA', limit: 5 }, function(err, suggestions) {
if (err) {
throw err;
}
console.log(suggestions)
});
List of object properties
Multiple indexes response Object
Field name | Type | Description | Possible Values |
---|---|---|---|
results | IndexResponse[] | Contains the results from all indexes |
IndexResponse
Field name | Type | Description | Possible Values |
---|---|---|---|
index | string | Name of the index | professional health_facility |
records | Record[] | Contains the records matching the search | |
meta | Metadata | Metadata of the search |
Single index response Object
Field name | Type | Description | Possible Values |
---|---|---|---|
records | Record[] | Contains the records matching the search | |
meta | Metadata | Metadata of the search |
Query suggestions response Array
Field name | Type | Description | Possible Values |
---|---|---|---|
suggestion | string | Suggested query | |
facet | string | Type of the suggestion | |
highlight | string | Augmented suggestion |
Place suggestions response Array
Field name | Type | Description | Possible Values |
---|---|---|---|
id | string | Identifier. | |
type | string | Type of location. | postcode place neighborhood |
formattedAddress | string | Formatted address, ready to display. | |
suite | string | Suite, door, appartment number. | |
route | string | Street name of the location. | |
postalCode | string | Postal code. | |
neighborhood | string | Neighborhood. | |
locality | string | Locality. | |
place | string | City. | |
district | string | District. | |
region | string | Name of the region. | |
regionCode | string | ISO 3166-2 region code. | |
country | string | Name of the country. | |
countryCode | string | ISO 3166 country code | |
geometry | Geometry | Geographical information of the location. | |
timeZoneId | string | Timezone. | |
translations | Map<string, LocationTranslation> | Translatable elements, if applicable. |
Shared
Record (health_facility
)
Field name | Type | Description | Possible Values |
---|---|---|---|
documentType | string | Type of document. | health_facility |
id | string | Identifier of the resource. | |
type | string | Type of resource. | |
address | Address | Address. | |
geoPoint | GeoPoint | Coordinate of the resource, if applicable. | |
onlineBookingUrl | string | Online booking url. | |
distance | double | Distance (in meters) from the center of the location search parameter. | |
openingHours | Map<string, Interval[]> | Opening hours. | The keys are strings from 1 to 7 .1: Monday 2: Tuesday 3: Wednesday 4: Thursday 5: Friday 6: Saturday 7: Sunday |
name | string | Name of the resource. | |
phones | Phone[] | Name of the resource. | |
owner | string | Owner of the resource (mainly used internally) |
Record (professional
)
Field name | Type | Description | Possible Values |
---|---|---|---|
documentType | string | Type of document. | professional |
id | string | Identifier of the resource. | |
title | string | Title of the resource | MR MS DR DRE |
practiceNumber | string | Practice number of the resource. | |
name | string | Name. | |
phones | Phone[] | Phones. | |
owner | string | Owner of the resource (mainly used internally) |
Phone
Field name | Type | Description | Possible Values |
---|---|---|---|
countryCode | string | Country code. | |
number | string | Phone number. | |
extension | string | Extension. | |
type | string | Type of phone. | UNKNOWN MAIN ALTERNATE RECEPTION FAX TEXT_TELEPHONE_TTY INFO TOOL_FREE PAGER MOBILE HOME WORK PERSONAL OTHER |
Address
Field name | Type | Description | Possible Values |
---|---|---|---|
streetAddress | string | Street number plus route name. | |
suiteNumber | string | Suite, door, appartment number. | |
postalCode | string | Postal code. | |
neighborhood | string | Neighborhood. | |
locality | string | Locality. | |
place | string | City. | |
region | string | Name of the region. | |
regionCode | string | ISO 3166-2 region code. | |
country | string | Name of the country. | |
countryCode | string | ISO 3166 country code |
Interval
Field name | Type | Description | Possible Values |
---|---|---|---|
start | string | Start time of the time interval. | Format is HH:mm |
end | string | End time of the time interval. | Format is HH:mm |
Metadata
Field name | Type | Description | Possible Values |
---|---|---|---|
query | string | Query. | |
page | number | Current page. | |
numPages | number | Total number of available pages. | |
perPage | number | Number of records per page. | |
total | number | Total number of records matching the query. | |
aroundLatLng | string | Coordinate around which the search is geographically centered. | e.g. '45.5016889,-73.567256' |
insideBoundingBox | string | Bounding box inside which the search was applied. | e.g. '45.739653,-73.472354,45.5016889,-73.567256' |
Geometry
Field name | Type | Description | Possible Values |
---|---|---|---|
bounds | Bounds | Bounds of the location. | |
location | GeoPoint | Best coordinate to locate the location. |
Bounds
Field name | Type | Description | Possible Values |
---|---|---|---|
northEast | GeoPoint | North-east coordinate delimiting the bounds of the location. | |
southWest | GeoPoint | South-west coordinate delimiting the bounds of the location. |
GeoPoint
Field name | Type | Description | Possible Values |
---|---|---|---|
lat | double | Latitude | |
lng | double | Longitude |
LocationTranslation
Field name | Type | Description | Possible Values |
---|---|---|---|
formattedAddress | string | Formatted address, ready to display. | |
route | string | Street name of the location. | |
neighborhood | string | Neighborhood. | |
locality | string | Locality. | |
place | string | Locality. | |
district | string | District. | |
region | string | Name of the region. | |
country | string | Name of the country. |
📄 License
Clinia JavaScript API Client is an open-sourced software licensed under the MIT license.
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago