PHP Client
The sadv-client library lets you:
- generate a health profile form to personalize vaccination recommendations for a given patient;
- query the vaccination recommendation service to obtain vaccination recommendations for a given patient.
PHP
Prerequisites
- The Composer tool must be installed;
- An authentication token must be provided by Syadem (contact developers@mesvaccins.net to obtain an authentication token);
- PHP 7.4 or later.
Examples
The following example displays the health profile form content as follows:
Retrieving and Displaying a Health Profile Form
Loading the Health Profile Nomenclature and Initializing the Client
# Load the health profile nomenclature
# Required to display the conditions referenced in the health profile form
$profileNomenclature = Syadem\VaccinationProfile\Container::init();
# Obtain an access token to query the vaccination recommendation service
$token_client = new GuzzleHttp\Client();
$response = $token_client->request(
'POST',
'https://auth.integration.mesvaccins.net/realms/professional/protocol/openid-connect/token',
[
'auth' => [$_ENV['CLIENT_ID'], $_ENV['CLIENT_SECRET']],
'form_params' => ['grant_type' => 'client_credentials']
]
);
$access_token = json_decode($response->getBody()->getContents())->access_token;
# Instantiate a configuration object
$api_config = new \Syadem\SadvClient\Configuration();
$api_config->setHost('https://api.fr.sad.mesvaccins.net');
$api_config->setAccessToken($access_token);
# Instantiate an API client object
$api = new Syadem\SadvClient\Api\SadvApi(
new GuzzleHttp\Client(),
$api_config
);
Retrieving the Health Profile Form
# Retrieve the health profile form
$profil_questionnaire_body = new \Syadem\SadvClient\Model\ProfilQuestionnaireBody(
[
'patient' => [
'birthdate' => '2000-01-01',
'gender' => 'm',
'prevention_acts' => [],
'conditions' => []
]
]
);
try {
$questionnaire_sections = $api->profilQuestionnaire($profil_questionnaire_body);
} catch (Exception $e) {
echo 'Exception when calling SadvApi->profilQuestionnaire: ', $e->getMessage(), PHP_EOL;
exit(1);
}
Displaying the Health Profile Form
We recursively iterate over the health profile form sections and display the conditions associated with each section.
function print_questionnaire_section(FilteredSection $section)
{
global $profileNomenclature;
$title = $section->getTitle();
$titleEn = isset($title['en']) ? $title['en'] : "[Missing title]";
echo '<b>' . $titleEn . "</b> <span>(id=" . $section->getId() . ')</span>';
echo '<ul>';
if (count($section->getConditions()) > 0) {
echo '<li>';
echo '<b>Conditions</b>';
echo '<ul>';
foreach ($section->getConditions() as $condition) {
$full_condition = $profileNomenclature->getConditions()->find($condition->getId());
echo '<li>';
echo $full_condition->getLabel()->getEn() ?? '[missing label]';
echo ' (id=' . $full_condition->getId() . ', type=' . \Syadem\VaccinationProfile\Type::to($full_condition->getType()) . ')';
echo '</li>';
}
echo '</ul>';
echo '</li>';
}
if (count($section->getSections()) > 0) {
foreach ($section->getSections() as $subSection) {
echo '<li>';
print_questionnaire_section($subSection);
echo '</li>';
}
}
echo '</ul>';
}
echo '<h1>Health profile questionnaire</h1>';
echo '<ul>';
foreach ($questionnaire_sections as $section) {
echo '<li>';
print_questionnaire_section($section);
echo '</li>';
}
echo '</ul>';