legit-health / medical-device-sdk
SDK for integrate with the Medical Device API
Installs: 138
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/legit-health/medical-device-sdk
Requires
- php: ^8.4
- symfony/http-client: ^7.1
Requires (Dev)
- brianium/paratest: ^7.9
- ekino/phpstan-banned-code: ^3.0
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/php-code-coverage: ^12.0
- phpunit/phpunit: ^12.0
- vlucas/phpdotenv: ^5.6
This package is auto-updated.
Last update: 2025-11-07 15:08:17 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 correspondingAPASIscore
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
DiagnosisSupportArgumentsclass, containing the images to analyze. Important: The maximum allowed length for themediasargument is 3. - A bearer token obtained by invoking the
loginmethod. - 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 theClinicalIndicatorsclass with the probabilities of different suspicions, such ashasConditionormalignancy.performanceIndicators: contains the sensitivity, specificity, and entropy values.conclusions: an array ofConclusionobjects with the detected pathologies and their probabilities. The total probability is distributed among the detected pathologies.imagingStudySeries: an array ofImagingStudySeriesInstanceobjects with information related to each image, such as conclusions, performance indicators, and clinical indicators. It also contains amediaobject 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
SeverityAssessmentArgumentsclass, containing the image whose severity is to be assessed along with the related questionnaires. - A bearer token obtained by invoking the
loginmethod. - 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\Arguments\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 theQuestionnaireclasses within theLegitHealth\MedicalDevice\Arguments\Paramsnamespace. -
questionnaires: an object of theQuestionnairesclass with the answers required for practitioner or patient input. For psoriasis, thesurfacevalue is needed when creating anApasiLocalQuestionnaireobject.
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 ofPatientEvolutionInstanceobjects 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:
scoringSystemCodescore: the calculated score for the scoring system.items: an array ofEvolutionItemobjects 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 ofDetectionobjects 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;