Encounter
Encounter¶
encounter_dto ¶
VitalSign ¶
Bases: BaseModel
Represents a single vital sign measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
The value of the vital sign. |
unit |
str
|
The unit of the vital sign. |
MedicalHistoryItem ¶
Bases: BaseModel
Represents a single item in the patient's medical history.
Attributes:
| Name | Type | Description |
|---|---|---|
condition |
Optional[str]
|
A medical condition in the patient's history. |
procedure |
Optional[str]
|
A medical procedure in the patient's history. |
FamilyHistoryItem ¶
Bases: BaseModel
Represents a single item in the patient's family history.
Attributes:
| Name | Type | Description |
|---|---|---|
relation |
str
|
The relation to the patient. |
condition |
str
|
The medical condition of the relative. |
ProcedureItem ¶
Bases: BaseModel
Represents a single procedure performed on the patient.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
Description of the procedure. |
complications |
Optional[str]
|
Any complications during the procedure. |
InvestigationItem ¶
Bases: BaseModel
Represents a single investigation record.
Attributes:
| Name | Type | Description |
|---|---|---|
observations |
list[str]
|
Observed vital signs. |
status |
str
|
Status of the investigation. |
recordedDate |
str
|
Date when the investigation was recorded. |
LabReportItem ¶
Bases: BaseModel
Represents a single lab report.
Attributes:
| Name | Type | Description |
|---|---|---|
observations |
list[str]
|
Observed vital signs. |
status |
str
|
Status of the lab report. |
recordedDate |
str
|
Date when the lab report was recorded. |
category |
str
|
Category of the lab report. |
conclusion |
str
|
Conclusion of the lab report. |
PatientDetails ¶
Bases: BaseModel
Represents patient demographic and admission details.
Attributes:
| Name | Type | Description |
|---|---|---|
first_name |
str
|
Patient's first name. |
middle_name |
Optional[str]
|
Patient's middle name. |
last_name |
str
|
Patient's last name. |
birth_date |
str
|
Patient's date of birth in ISO format (YYYY-MM-DD). |
gender |
Gender
|
Patient's gender, represented as an enum. |
mobile_number |
str
|
Patient's mobile number. |
email_id |
Optional[str]
|
Patient's email address. |
address |
str
|
Patient's residential address. |
pincode |
str
|
Patient's postal code. |
state |
str
|
Patient's state of residence. |
wants_to_link_whatsapp |
Optional[bool]
|
Indicates if the patient wants to link their WhatsApp number. |
photo |
Optional[str]
|
Base64 encoded string of the patient's photo. |
id_number |
str
|
Unique identifier for the patient (e.g., Aadhar number). |
id_type |
str
|
Type of the ID number (e.g., "Aadhar", "PAN"). |
abha_address |
Optional[str]
|
ABHA address for the patient, if available. |
resource_id |
Optional[str]
|
Resource ID for the patient in the system. |
DoctorDetails ¶
Bases: BaseModel
Represents doctor information.
Attributes:
| Name | Type | Description |
|---|---|---|
first_name |
str
|
Doctor's first name. |
middle_name |
Optional[str]
|
Doctor's middle name. |
last_name |
str
|
Doctor's last name. |
birth_date |
str
|
Doctor's date of birth in ISO format (YYYY-MM-DD). |
gender |
str
|
Doctor's gender, represented as an enum. |
mobile_number |
str
|
Doctor's mobile number. |
email_id |
Optional[str]
|
Doctor's email address. |
address |
str
|
Doctor's residential address. |
pincode |
str
|
Doctor's postal code. |
state |
str
|
Doctor's state of residence. |
wants_to_link_whatsapp |
Optional[bool]
|
Indicates if the doctor wants to link their WhatsApp number. |
photo |
Optional[str]
|
Base64 encoded string of the doctor's photo. |
designation |
str
|
Doctor's designation (e.g., "Cardiologist"). |
joining_date |
Optional[str]
|
Date when the doctor joined the organization in ISO format (YYYY-MM-DD). |
department |
str
|
Department of the doctor (e.g., "Cardiology"). |
registration_id |
str
|
Doctor's registration ID. |
hpr_id |
Optional[str]
|
HPR ID of the doctor, if available. |
resource_id |
Optional[str]
|
Resource ID for the doctor in the system. |
CommonHealthInformationDTO ¶
Bases: BaseModel
Base DTO for common health information sections.
Attributes:
| Name | Type | Description |
|---|---|---|
chief_complaints |
str
|
The patient's chief complaints. |
physical_examination |
str
|
Patient's physical examination. |
medical_history |
Optional[list[MedicalHistoryItem]]
|
Patient's medical history. |
family_history |
Optional[list[FamilyHistoryItem]]
|
Patient's family history. |
condtions |
Optional[list[str]]
|
Patient's conditions. |
current_procedures |
Optional[list[ProcedureItem]]
|
Patient's procedures. |
current_medications |
Optional[list[str]]
|
Patient's medications. |
prescribed_medications |
Optional[list[str]]
|
Patient's prescribed medications. |
allergies |
Optional[list[str]]
|
Patient's allergies. |
immunizations |
Optional[list[str]]
|
Patient's immunizations. |
advisory_notes |
Optional[list[str]]
|
Patient's advisory notes. |
care_plan |
Optional[list[str]]
|
Patient's care plan. |
follow_up |
Optional[list[str]]
|
Patient's follow-up plan. |
OPConsultationSections ¶
Bases: CommonHealthInformationDTO
Represents the OP consultation section, inheriting common health information from CommonHealthInformationDTO.
DischargeSummarySections ¶
Bases: CommonHealthInformationDTO
Represents the discharge summary section, inheriting common health information.
Attributes:
| Name | Type | Description |
|---|---|---|
investigations |
InvestigationItem
|
Patient's investigations. |
PrescriptionSections ¶
Bases: BaseModel
Represents the prescription section.
Attributes:
| Name | Type | Description |
|---|---|---|
prescribed_medications |
list[str]
|
Patient's prescribed medications. |
WellnessRecordSections ¶
Bases: BaseModel
Represents the wellness record section.
Attributes:
| Name | Type | Description |
|---|---|---|
vital_signs |
Optional[list[str]]]
|
Patient's vital signs. |
body_measurements |
Optional[list[str]]]
|
Patient's body measurements. |
physical_activities |
Optional[list[str]]]
|
Patient's physical activities. |
women_health |
Optional[list[str]]]
|
Women's health data. |
life_style |
Optional[list[str]]]
|
Lifestyle data. |
others |
Optional[list[str]]]
|
Other health data. |
ImmunizationRecordSections ¶
Bases: BaseModel
Represents the immunization record section.
Attributes:
| Name | Type | Description |
|---|---|---|
immunizations |
list[str]
|
Patient's immunizations. |
DiagnosticReportSections ¶
Bases: BaseModel
Represents the diagnostic report section.
Attributes:
| Name | Type | Description |
|---|---|---|
lab_reports |
LabReportItem
|
Patient's lab reports. |
OPConsultationDTO ¶
Bases: BaseModel
Data Transfer Object for OP Consultation. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient. payload (Optional[OPConsultationSections]): The raw data for the OP consultation.
DischargeSummaryDTO ¶
Bases: BaseModel
Data Transfer Object for Discharge Summary. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient. payload (Optional[DischargeSummarySections]): The raw data for the discharge summary.
PrescriptionRecordDTO ¶
Bases: BaseModel
Data Transfer Object for Prescription Record. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient. payload (Optional[PrescriptionSections]): The raw data for the prescription record.
WellnessRecordDTO ¶
Bases: BaseModel
Data Transfer Object for Wellness Record. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient. payload (Optional[WellnessRecordSections]): The raw data for the wellness record.
ImmunizationRecordDTO ¶
Bases: BaseModel
Data Transfer Object for Immunization Record.
Attributes:
| Name | Type | Description |
|---|---|---|
case_sheets |
Optional[list[str]]
|
List of case sheets associated with the patient. |
payload |
Optional[ImmunizationRecordSections]
|
The raw data for the immunization record. |
DiagnosticReportDTO ¶
Bases: BaseModel
Data Transfer Object for Diagnostic Report. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient. payload (Optional[DiagnosticReportSections]): The raw data for the diagnostic report.
GenerateFhirFromExtractedDataDto ¶
Bases: BaseModel
Data Transfer Object for generating a FHIR bundle from extracted data.
Attributes:
case_type (str): The type of case (e.g., OPConsultation, DischargeSummary). Serialized as caseType.
record_id (Optional[str]): Identifier for the record, if available. Serialized as recordId.
extracted_data (dict[str, Any]): Extracted clinical data for the bundle.
document_references (Optional[list[str]]): List of document references to be included in the bundle.
HealthDocumentRecordDTO ¶
Bases: BaseModel
Data Transfer Object for Health Document Record. Attributes: case_sheets (Optional[list[str]]): List of case sheets associated with the patient.
EncounterRequestDTO ¶
Bases: BaseModel
Data Transfer Object for Encounter Request.
Attributes:
| Name | Type | Description |
|---|---|---|
case_type |
str
|
The type of health information case (e.g., |
enable_extraction |
bool
|
Flag to enable data extraction from the provided documents. |
patient_details |
PatientDetails
|
Patient's information. |
doctor_details |
list[DoctorDetails]
|
List of doctors involved in the case. |
dto |
HealthInformationDTOUnion
|
The health information data, which can be one of the specific DTOs. |
document_references |
Optional[list[str]]
|
List of document references to be included in the request. |
Encounter ¶
Encounter(config: ClientConfig)
Bases: BaseService
Service for orchestrating healthcare encounter workflows, FHIR bundle and discharge summary generation.
This service provides a unified interface to create FHIR bundles or discharge summaries based on provided encounter data. It handles validation, encryption, and orchestrates AI-powered healthcare processing endpoints.
Key Features
- Validates incoming encounter request data thoroughly.
- Supports both file-based and payload-based FHIR bundle generation workflows.
- Handles discharge summary generation from encrypted data.
- Encrypts sensitive patient data and associated files before transmission.
- Robust error handling with clear logging for diagnosis.
Methods:
| Name | Description |
|---|---|
create |
Creates a FHIR bundle or discharge summary based on encounter data. |
generate_fhir_from_sections |
Generates FHIR bundle from provided clinical sections (payload). |
generate_fhir_from_files |
Generates FHIR bundle from case sheet files and optional lab reports. |
generate_discharge_summary |
Calls AI endpoint to generate discharge summary. |
generate_fhir_bundle |
Calls AI endpoint to generate FHIR bundle from extracted data and files. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ClientConfig
|
API credentials and settings for service initialization. |
required |
Example
config = ClientConfig(
api_key="your_api_key",
)
encounter_service = Encounter(config)
request = EncounterRequestDTO(
case_type=CaseType.OP_CONSULTATION,
dto=OPConsultationDTO(payload=OPConsultationSections(...))
)
bundle = await encounter_service.create(request)
print(bundle["resourceType"])
create
async
¶
create(request_body: EncounterRequestDTO) -> dict[str, Any]
Main entrypoint: creates a FHIR bundle or discharge summary for the given encounter data.
Determines workflow: file-based (case sheets), section-based (payload), and manages FHIR bundle and summary extraction/encryption as required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
EncounterRequestDTO
|
All data for FHIR/document generation, including case type, files, payload, patient/practitioner info, etc. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Serialized FHIR-compliant bundle or discharge summary document. |
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On validation or any underlying process failure. |
Example
encounter_request = EncounterRequestDTO(
case_type=CaseType.OP_CONSULTATION,
enable_extraction=True,
record_id="12345",
patient_details=PatientDetails(name="John Doe", ...),
doctor_details=[DoctorDetails(name="Dr. Smith", ...)],
document_references=["lab_report_1.pdf"],
dto=OPConsultationDTO(
caseSheets=None,
payload=OPConsultationSections(
chief_complaints="Fever and cough",
physical_examination=PhysicalExamination(...),
...
)
),
)
or
encounter_request = EncounterRequestDTO(
case_type=CaseType.OP_CONSULTATION,
enable_extraction=False,
record_id="12345",
patient_details=PatientDetails(name="John Doe", ...),
doctor_details=[DoctorDetails(name="Dr. Smith", ...)],
document_references=["lab_report_1.pdf"],
dto=OPCONSULTATIONDTO(
caseSheets=["case_sheet_1.pdf", "case_sheet_2.pdf"],
),
)
response = await encounter_service.create(encounter_request)
print(response)
Response:¶
Sample Output for the given example:
{
"resourceType": "Bundle",
"type": "document",
"entry": [ ...FHIR resources... ]
}
generate_discharge_summary
async
¶
generate_discharge_summary(case_type: str, encrypted_data: str) -> DischargeSummaryResponse
Generates a discharge summary from encrypted case sheet data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case_type
|
str
|
The caseType for AI endpoint (e.g., 'inpatient'). |
required |
encrypted_data
|
str
|
Encryption result for case sheets. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DischargeSummaryResponse |
DischargeSummaryResponse
|
Extracted summary with meta data. |
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On API or process failures. |
Example
summary = await encounter_service._generate_discharge_summary("inpatient", encrypted_files) print(summary.dischargeSummary)
generate_fhir_from_files
async
¶
generate_fhir_from_files(case_type: str, enable_extraction: bool, case_sheets: list[str], document_references: list[str], record_id: Optional[str] = None, patient_details: Optional[PatientDetails] = None, doctor_details: Optional[list[DoctorDetails]] = None) -> dict[str, Any]
Generates a FHIR bundle from provided case sheet files and any document references.
Workflow: 1. Optionally encrypts document references (lab reports, scans, etc) 2. If extraction enabled: a. Encrypts case sheets. b. Extracts discharge summary & data. c. Encrypts extracted summary data for FHIR. 3. If extraction disabled: requires patient and practitioner details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case_type
|
str
|
Case type code. |
required |
enable_extraction
|
bool
|
Whether to extract summary from the files. |
required |
case_sheets
|
list[str]
|
Source case files (URLs, filenames, etc). |
required |
document_references
|
list[str]
|
Any supporting doc refs (base64-encoded files). |
required |
patient_details
|
Optional[PatientDetails]
|
Demographic data, if used. |
None
|
doctor_details
|
Optional[list[DoctorDetails]]
|
Provider/practitioner data, if used. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The parsed FHIR-compliant document. |
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On API/encryption/validation failure. |
Example
``` bundle = await encounter_service._generate_fhir_from_files( case_type="SURGERY", enable_extraction=True, case_sheets=["cs1.pdf", "cs2.pdf"], document_references=["lab1.pdf"], patient_details=details, doctor_details=[doctor], ) print(bundle["resourceType"])
Response:¶
{
"resourceType": "Bundle",
"type": "document",
"entry": [ ...FHIR resources... ]
}
```
generate_fhir_from_sections
async
¶
generate_fhir_from_sections(case_type: str, enabled_extraction: bool, sections: dict[str, Any], document_references: list[str] = [], record_id: Optional[str] = None, patient_details: Optional[PatientDetails] = None, doctor_details: Optional[list[DoctorDetails]] = None) -> dict[str, Any]
Generates a FHIR-compliant bundle using provided section (payload) data and optional supporting docs.
When extraction is enabled, the entire sections/payload dict is encrypted and included in the FHIR call. When disabled, requires explicit patient and practitioner metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case_type
|
str
|
Encounter/case type. |
required |
enabled_extraction
|
bool
|
Whether to encrypt/process sections for extraction. |
required |
sections
|
dict
|
Clinical sections, e.g. consultation notes, as dict. |
required |
document_references
|
list[str]
|
Doc references (e.g. lab reports). |
[]
|
patient_details
|
Optional[PatientDetails]
|
Patient metadata, required if extraction is off. |
None
|
doctor_details
|
Optional[list[DoctorDetails]]
|
Provider metadata, required if extraction is off. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
FHIR-compliant bundle resource. |
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On validation or API failure. |
Example
``` bundle = await encounter_service._generate_fhir_from_sections( case_type="OP_CONSULTATION", enabled_extraction=True, sections=payload, document_references=[], patient_details=details, doctor_details=[doctor], )
Response:¶
{
"resourceType": "Bundle",
"type": "document",
"entry": [ ...FHIR resources... ]
}
```