Java SDK
The Telesoft Healthcare AI Java SDK provides a convenient way to integrate with our API from your Java applications. This SDK handles authentication, request formatting, and response parsing so you can focus on building your healthcare application.
Installation
Add the Telesoft SDK to your Java project using Maven or Gradle:
Maven
<dependency>
<groupId>com.telesoft.healthcare</groupId>
<artifactId>telesoft-ai</artifactId>
<version>1.2.0</version>
</dependency>
Gradle
implementation 'com.telesoft.healthcare:telesoft-ai:1.2.0'
Getting Started
To use the SDK, you'll need an API key from the Telesoft Developer Portal:
Authentication
import com.telesoft.healthcare.TelesoftAI;
import com.telesoft.healthcare.TelesoftConfig;
// Initialize the client with your API key
TelesoftConfig config = TelesoftConfig.builder()
.apiKey("YOUR_API_KEY")
.build();
TelesoftAI telesoft = new TelesoftAI(config);
// Alternatively, load from environment variable
String apiKey = System.getenv("TELESOFT_API_KEY");
TelesoftAI telesoft = new TelesoftAI(TelesoftConfig.builder()
.apiKey(apiKey)
.build());
⚠️ API Key Security
Never hardcode your API key directly in your source code. Use environment variables or a secure configuration management system.
Basic Usage
Here's a simple example of using the SDK to analyze patient symptoms:
import com.telesoft.healthcare.TelesoftAI;
import com.telesoft.healthcare.TelesoftConfig;
import com.telesoft.healthcare.diagnostics.DiagnosticAnalysis;
import com.telesoft.healthcare.diagnostics.DiagnosticRequest;
import com.telesoft.healthcare.diagnostics.DiagnosticOptions;
import com.telesoft.healthcare.models.Patient;
import java.util.Arrays;
import java.util.List;
public class DiagnosticsExample {
public static void main(String[] args) {
// Initialize the Telesoft client
String apiKey = System.getenv("TELESOFT_API_KEY");
TelesoftAI telesoft = new TelesoftAI(TelesoftConfig.builder()
.apiKey(apiKey)
.build());
try {
// Create a patient with symptoms
Patient patient = Patient.builder()
.age(45)
.sex("female")
.symptoms(Arrays.asList("cough", "fever", "shortness of breath"))
.duration("5 days")
.medicalHistory(Arrays.asList("hypertension", "type 2 diabetes"))
.medications(Arrays.asList("lisinopril", "metformin"))
.build();
// Set analysis options
DiagnosticOptions options = DiagnosticOptions.builder()
.includeConfidenceScores(true)
.includeDifferentialDiagnosis(true)
.includeRecommendations(true)
.includeEvidence(true)
.build();
// Create the request
DiagnosticRequest request = DiagnosticRequest.builder()
.patient(patient)
.options(options)
.build();
// Call the API
DiagnosticAnalysis analysis = telesoft.getDiagnosticsService().analyze(request);
// Process the results
System.out.println("Primary diagnosis: " + analysis.getPrimaryDiagnosis().getCondition());
System.out.println("Confidence: " +
String.format("%.2f", analysis.getPrimaryDiagnosis().getConfidenceScore()));
System.out.println("
Differential diagnoses:");
analysis.getDifferentialDiagnoses().forEach(diagnosis -> {
System.out.println("- " + diagnosis.getCondition() + " (" +
String.format("%.2f", diagnosis.getConfidenceScore()) + ")");
});
System.out.println("
Recommended tests:");
analysis.getRecommendations().getDiagnosticTests().forEach(test -> {
System.out.println("- " + test.getName() + ": " + test.getRationale());
});
} catch (Exception e) {
System.err.println("Error analyzing patient symptoms: " + e.getMessage());
e.printStackTrace();
}
}
}
Key Features
Diagnostic Analysis
Analyze patient symptoms, medical history, and demographics to generate diagnostic insights.
Medical Imaging Analysis
Analyze various medical images including X-rays, CT scans, MRIs, and more.
Treatment Recommendations
Generate evidence-based treatment recommendations based on patient data.
Medical Document Processing
Extract structured information from medical documents, reports, and notes.
Advanced Examples
Analyzing Medical Images
import com.telesoft.healthcare.TelesoftAI;
import com.telesoft.healthcare.TelesoftConfig;
import com.telesoft.healthcare.imaging.ImagingAnalysis;
import com.telesoft.healthcare.imaging.ImagingRequest;
import com.telesoft.healthcare.imaging.ImagingOptions;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ImagingExample {
public static void main(String[] args) {
// Initialize the Telesoft client
String apiKey = System.getenv("TELESOFT_API_KEY");
TelesoftAI telesoft = new TelesoftAI(TelesoftConfig.builder()
.apiKey(apiKey)
.build());
try {
// Path to the image file
String imagePath = "path/to/chest_xray.dcm";
byte[] imageData = Files.readAllBytes(Paths.get(imagePath));
// Set analysis options
ImagingOptions options = ImagingOptions.builder()
.includeAnnotations(true)
.includeHeatmap(true)
.confidenceThreshold(0.5f)
.build();
// Create the request
ImagingRequest request = ImagingRequest.builder()
.imagingType("chest-xray")
.imageData(imageData)
.options(options)
.build();
// Call the API
ImagingAnalysis analysis = telesoft.getImagingService().analyze(request);
// Process the results
System.out.println("Found " + analysis.getFindings().size() + " findings:");
analysis.getFindings().forEach(finding -> {
System.out.println("- " + finding.getDescription() +
" (confidence: " + String.format("%.2f", finding.getConfidence()) + ")");
System.out.println(" Location: " + finding.getLocation());
});
// Save the annotated image if provided
if (analysis.getAnnotatedImage() != null) {
try (FileOutputStream fos = new FileOutputStream("annotated_xray.png")) {
fos.write(analysis.getAnnotatedImage());
}
System.out.println("Annotated image saved as annotated_xray.png");
}
} catch (Exception e) {
System.err.println("Error analyzing medical image: " + e.getMessage());
e.printStackTrace();
}
}
}
Using with Spring Boot
import com.telesoft.healthcare.TelesoftAI;
import com.telesoft.healthcare.TelesoftConfig;
import com.telesoft.healthcare.diagnostics.DiagnosticAnalysis;
import com.telesoft.healthcare.diagnostics.DiagnosticRequest;
import com.telesoft.healthcare.diagnostics.DiagnosticOptions;
import com.telesoft.healthcare.exceptions.TelesoftException;
import com.telesoft.healthcare.models.Patient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
// Configuration class to set up the Telesoft client
@Configuration
public class TelesoftConfig {
@Value("${telesoft.api.key}")
private String apiKey;
@Bean
public TelesoftAI telesoftAI() {
return new TelesoftAI(com.telesoft.healthcare.TelesoftConfig.builder()
.apiKey(apiKey)
.build());
}
}
// Data transfer objects
class PatientDTO {
private int age;
private String sex;
private List<String> symptoms;
private String duration;
private List<String> medicalHistory;
private List<String> medications;
// Getters and setters omitted for brevity
public Patient toPatient() {
return Patient.builder()
.age(age)
.sex(sex)
.symptoms(symptoms)
.duration(duration)
.medicalHistory(medicalHistory)
.medications(medications)
.build();
}
}
class AnalysisResponse {
private Map<String, Object> primaryDiagnosis;
private List<Map<String, Object>> differentialDiagnoses;
private Map<String, Object> recommendations;
// Getters and setters omitted for brevity
}
// Controller to expose the API
@RestController
public class DiagnosticsController {
private final TelesoftAI telesoftAI;
public DiagnosticsController(TelesoftAI telesoftAI) {
this.telesoftAI = telesoftAI;
}
@PostMapping("/api/analyze")
public ResponseEntity<?> analyzeSymptoms(@RequestBody PatientDTO patientDTO) {
try {
// Validate input
if (patientDTO.getSymptoms() == null || patientDTO.getSymptoms().isEmpty()) {
return ResponseEntity.badRequest().body(Map.of("error", "Symptoms are required"));
}
// Convert to Patient model
Patient patient = patientDTO.toPatient();
// Set options
DiagnosticOptions options = DiagnosticOptions.builder()
.includeConfidenceScores(true)
.includeDifferentialDiagnosis(true)
.includeRecommendations(true)
.build();
// Create request
DiagnosticRequest request = DiagnosticRequest.builder()
.patient(patient)
.options(options)
.build();
// Call the API
DiagnosticAnalysis analysis = telesoftAI.getDiagnosticsService().analyze(request);
// Convert to response DTO
AnalysisResponse response = new AnalysisResponse();
// Map primary diagnosis
Map<String, Object> primaryDiagnosis = new HashMap<>();
primaryDiagnosis.put("condition", analysis.getPrimaryDiagnosis().getCondition());
primaryDiagnosis.put("confidenceScore", analysis.getPrimaryDiagnosis().getConfidenceScore());
response.setPrimaryDiagnosis(primaryDiagnosis);
// Map differential diagnoses
List<Map<String, Object>> differentialDiagnoses = analysis.getDifferentialDiagnoses().stream()
.map(diagnosis -> {
Map<String, Object> diagnosisMap = new HashMap<>();
diagnosisMap.put("condition", diagnosis.getCondition());
diagnosisMap.put("confidenceScore", diagnosis.getConfidenceScore());
return diagnosisMap;
})
.collect(Collectors.toList());
response.setDifferentialDiagnoses(differentialDiagnoses);
// Map recommendations
Map<String, Object> recommendations = new HashMap<>();
recommendations.put("diagnosticTests", analysis.getRecommendations().getDiagnosticTests().stream()
.map(test -> {
Map<String, Object> testMap = new HashMap<>();
testMap.put("name", test.getName());
testMap.put("rationale", test.getRationale());
return testMap;
})
.collect(Collectors.toList()));
response.setRecommendations(recommendations);
return ResponseEntity.ok(response);
} catch (TelesoftException e) {
return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
} catch (Exception e) {
return ResponseEntity.internalServerError().body(Map.of("error", "Internal server error"));
}
}
}