legit-health / medical-device-sdk
SDK for integrate with the Medical Device API
Requires
- php: ^8.2
- symfony/http-client: ^7.1
Requires (Dev)
- ekino/phpstan-banned-code: ^1.0
- friendsofphp/php-cs-fixer: ^3.37
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/php-code-coverage: 10.1.*
- phpunit/phpunit: 10.4.*
- vlucas/phpdotenv: ^5.5
This package is not auto-updated.
Last update: 2024-11-13 05:52:58 UTC
README
Official SDK for integrating with Legit.Health's Medical Device API 🩺🤖
Before You Start
Ensure that you have a registered username and password for our API before making any requests.
Instructions
To start sending requests to Legit.Health's Dermatology API, create an instance of the LegitHealth\MedicalDevice\MedicalDeviceClient
class. There are several ways to instantiate this object, but the simplest is by using the createWithBaseUri
method. This static method accepts a single argument: the API's base URL, which varies depending on the environment you're working in. For development purposes, use https://medical-device-pre.legit.health
.
The MedicalDeviceClient
class provides three main methods:
-
login
: Requires your username and password, returning an access token that must be included in subsequent requests. -
diagnosisSupport
: Sends a diagnosis support request to the API. Use this method to analyze a set of images to determine the probability of detected pathologies, or to retrieve metrics such as malignancy or the need for referral. -
severityAssessment
: Sends a severity assessment request to evaluate the severity of a known condition. For example, you can use this method to assess the severity of a psoriasis lesion and calculate the correspondingAPASI
score
Login Request
Before invoking the diagnosis support or severity assessment methods, you need to obtain an access token. This is done by calling the login
method of the MedicalDeviceClient
class. This method expects a username and a password and returns an AccessToken
object. This object contains the access token and its expiration time in minutes.
$medicalDeviceClient = MedicalDeviceClient::createWithBaseUri('url'); $accessToken = $medicalDeviceClient->login('username', 'password'); $bearerToken = new BearerToken($accessToken->value);
Diagnosis Support Request
The diagnosisSupport
method of the MedicalDeviceClient
class accepts three arguments:
- An object of the
DiagnosisSupportArguments
class, containing the images to analyze. Important: The maximum allowed length for themedias
argument is 3. - A bearer token obtained by invoking the
login
method. - An object containing request options such as
timeout
.
$fileToUpload1 = $this->currentDir . '/tests/resources/psoriasis_01.png'; $image1 = file_get_contents($fileToUpload1); $fileToUpload2 = $this->currentDir . '/tests/resources/psoriasis_02.png'; $image2 = file_get_contents($fileToUpload2); $fileToUpload3 = $this->currentDir . '/tests/resources/psoriasis_03.png'; $image3 = file_get_contents($fileToUpload3); $diagnosisSupportArguments = new DiagnosisSupportArguments( // three images at most medias: [ base64_encode($image1), base64_encode($image2), base64_encode($image3) ] );
Once you've created a DiagnosisSupportArguments
object, you can send the request as follows:
$medicalDeviceClient = MedicalDeviceClient::createWithBaseUri('https://...'); $response = $medicalDeviceClient->diagnosisSupport( $diagnosisSupportArguments, $bearerToken );
The response object, which is an instance of DiagnosisSupportResponse
, contains several properties with the information returned by the API about the analyzed images:
clinicalIndicators
: an object of theClinicalIndicators
class with the probabilities of different suspicions, such ashasCondition
ormalignancy
.performanceIndicators
: contains the sensitivity, specificity, and entropy values.conclusions
: an array ofConclusion
objects with the detected pathologies and their probabilities. The total probability is distributed among the detected pathologies.imagingStudySeries
: an array ofImagingStudySeriesInstance
objects with information related to each image, such as conclusions, performance indicators, and clinical indicators. It also contains amedia
object that includes the modality of the image and whether it passed our Dermatology Image Quality Assessment (DIQA).analysisDuration
: the time spent by the AI model analyzing the image.effectiveDateTime
: the date and time of the report.
Severity Assessment Requests
The severityAssessment
method of the MedicalDeviceClient
class accepts three arguments:
- An object of the
SeverityAssessmentArguments
class, containing the image whose severity is to be assessed along with the related questionnaires. - A bearer token obtained by invoking the
login
method. - An object containing request options such as
timeout
.
Example: Severity Assessment Request for Psoriasis
Here’s how to send a severity assessment request for a patient diagnosed with psoriasis.
First, create the objects representing the questionnaires used to track the evolution of psoriasis:
use LegitHealth\MedicalDevice\MedicalDeviceArguments\Params\ApasiLocalQuestionnaire; use LegitHealth\Dapi\MediaAnalyzerArguments\Questionnaires\Questionnaires; // ... $apasiLocal = new ApasiLocalQuestionnaire(3); $questionnaires = new Questionnaires([$apasiLocal]);
Then, create an object of the SeverityAssessmentArguments
class:
$fileToUpload = $this->currentDir . '/tests/resources/psoriasis_02.png'; $image = file_get_contents($fileToUpload); $apasiLocal = new ApasiLocalQuestionnaire(3); $questionnaires = new Questionnaires([$apasiLocal]); $severityAssessmentArguments = new SeverityAssessmentArguments( base64_encode($image), scoringSystems: array_map( fn (Questionnaire $questionnaire) => $questionnaire->getName(), $questionnaires->questionnaires ), questionnaires: $questionnaires, knownCondition: new KnownCondition('Psoriasis'), bodySiteCode: ParamsBodySiteCode::ArmLeft );
Unlike diagnosis support requests, severity assessment requests support the following additional arguments:
-
scoringSystems
: an array of strings with the names of the scoring systems to be calculated. It supports all codes returned by theQuestionnaire
classes within theLegitHealth\MedicalDevice\MedicalDeviceArguments\Params
namespace. -
questionnaires
: an object of theQuestionnaires
class with the answers required for practitioner or patient input. For psoriasis, thesurface
value is needed when creating anApasiLocalQuestionnaire
object.
Once the SeverityAssessmentArguments
object is created, send the request as follows:
$medicalDeviceClient = MedicalDeviceClient::createWithBaseUri('https://...'); $response = $medicalDeviceClient->severityAssessment( $severityAssessmentArguments, $bearerToken );
The response object contains several properties with information returned by the API about the analyzed image:
media
: contains the image modality and its validity, including whether it passed the Dermatology Image Quality Assessment (DIQA).patientEvolution
: an array ofPatientEvolutionInstance
objects containing the score for each calculated scoring system along with its corresponding items.analysisDuration
: the time spent by the AI model analyzing the image.
The PatientEvolutionInstance
Class
The PatientEvolutionInstance
contains all the information about a scoring system, for example, APASI_LOCAL
.
You can access the value of a scoring system using the getPatientEvolutionInstance
method:
$apasiLocalScoringSystemValue = $response->getPatientEvolutionInstance(ScoringSystemCode::ApasiLocal);
This object contains the following properties:
scoringSystemCode
score
: the calculated score for the scoring system.items
: an array ofEvolutionItem
objects representing each item used to calculate the scoring system.attachments
: an array of images that contain an overlay with detections made by the AI model.detections
: an array ofDetection
objects representing each box identifying a lesion detected in the image.
Once you have a PatientEvolutionInstance
object, you can access the value of each item using the getEvolutionItem(string $itemCode)
method. Each item contains its code and the calculated value. For example, the APASI_LOCAL
scoring system includes 4 items: desquamation, erythema, induration, and surface.
Full example:
$apasiLocalScoringSystemValue = $response->getPatientEvolutionInstance(ScoringSystemCode::ApasiLocal); // score $apasiLocalScoringSystemValue->score->value // score interpretation $apasiLocalScoringSystemValue->score->interpretation // accessing desquamation item $apasiLocalScoringSystemValue->getEvolutionItem('desquamation'); $apasiLocalScoringSystemValue->getEvolutionItem('desquamation')->value; // raw values output by the AI model $apasiLocalScoringSystemValue->getEvolutionItem('desquamation')->additionalData;