1.0.2 • Published 4 years ago

cliniasearch v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

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 or prefix_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 or prefix_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 nameTypeDescriptionPossible Values
resultsIndexResponse[]Contains the results from all indexes

IndexResponse

Field nameTypeDescriptionPossible Values
indexstringName of the indexprofessionalhealth_facility
recordsRecord[]Contains the records matching the search
metaMetadataMetadata of the search

Single index response Object

Field nameTypeDescriptionPossible Values
recordsRecord[]Contains the records matching the search
metaMetadataMetadata of the search

Query suggestions response Array

Field nameTypeDescriptionPossible Values
suggestionstringSuggested query
facetstringType of the suggestion
highlightstringAugmented suggestion

Place suggestions response Array

Field nameTypeDescriptionPossible Values
idstringIdentifier.
typestringType of location.postcodeplaceneighborhood
formattedAddressstringFormatted address, ready to display.
suitestringSuite, door, appartment number.
routestringStreet name of the location.
postalCodestringPostal code.
neighborhoodstringNeighborhood.
localitystringLocality.
placestringCity.
districtstringDistrict.
regionstringName of the region.
regionCodestringISO 3166-2 region code.
countrystringName of the country.
countryCodestringISO 3166 country code
geometryGeometryGeographical information of the location.
timeZoneIdstringTimezone.
translationsMap<string, LocationTranslation>Translatable elements, if applicable.

Shared

Record (health_facility)

Field nameTypeDescriptionPossible Values
documentTypestringType of document.health_facility
idstringIdentifier of the resource.
typestringType of resource.
addressAddressAddress.
geoPointGeoPointCoordinate of the resource, if applicable.
onlineBookingUrlstringOnline booking url.
distancedoubleDistance (in meters) from the center of the location search parameter.
openingHoursMap<string, Interval[]>Opening hours.The keys are strings from 1 to 7.1: Monday2: Tuesday3: Wednesday4: Thursday5: Friday6: Saturday7: Sunday
namestringName of the resource.
phonesPhone[]Name of the resource.
ownerstringOwner of the resource (mainly used internally)

Record (professional)

Field nameTypeDescriptionPossible Values
documentTypestringType of document.professional
idstringIdentifier of the resource.
titlestringTitle of the resourceMRMSDRDRE
practiceNumberstringPractice number of the resource.
namestringName.
phonesPhone[]Phones.
ownerstringOwner of the resource (mainly used internally)

Phone

Field nameTypeDescriptionPossible Values
countryCodestringCountry code.
numberstringPhone number.
extensionstringExtension.
typestringType of phone.UNKNOWNMAINALTERNATERECEPTIONFAXTEXT_TELEPHONE_TTYINFOTOOL_FREEPAGERMOBILEHOMEWORKPERSONALOTHER

Address

Field nameTypeDescriptionPossible Values
streetAddressstringStreet number plus route name.
suiteNumberstringSuite, door, appartment number.
postalCodestringPostal code.
neighborhoodstringNeighborhood.
localitystringLocality.
placestringCity.
regionstringName of the region.
regionCodestringISO 3166-2 region code.
countrystringName of the country.
countryCodestringISO 3166 country code

Interval

Field nameTypeDescriptionPossible Values
startstringStart time of the time interval.Format is HH:mm
endstringEnd time of the time interval.Format is HH:mm

Metadata

Field nameTypeDescriptionPossible Values
querystringQuery.
pagenumberCurrent page.
numPagesnumberTotal number of available pages.
perPagenumberNumber of records per page.
totalnumberTotal number of records matching the query.
aroundLatLngstringCoordinate around which the search is geographically centered.e.g. '45.5016889,-73.567256'
insideBoundingBoxstringBounding box inside which the search was applied.e.g. '45.739653,-73.472354,45.5016889,-73.567256'

Geometry

Field nameTypeDescriptionPossible Values
boundsBoundsBounds of the location.
locationGeoPointBest coordinate to locate the location.

Bounds

Field nameTypeDescriptionPossible Values
northEastGeoPointNorth-east coordinate delimiting the bounds of the location.
southWestGeoPointSouth-west coordinate delimiting the bounds of the location.

GeoPoint

Field nameTypeDescriptionPossible Values
latdoubleLatitude
lngdoubleLongitude

LocationTranslation

Field nameTypeDescriptionPossible Values
formattedAddressstringFormatted address, ready to display.
routestringStreet name of the location.
neighborhoodstringNeighborhood.
localitystringLocality.
placestringLocality.
districtstringDistrict.
regionstringName of the region.
countrystringName of the country.

📄 License

Clinia JavaScript API Client is an open-sourced software licensed under the MIT license.