Overview
TheHl7Service class provides high-level methods for executing HL7 transactions with the Connectivity Providers API. It handles request serialization, HTTP communication, response validation, and error classification.
Class Definition
Constructor
Hl7Service instance.
The API client to use for HTTP requests. Must not be null.
NullPointerException if apiClient is null
Example:
Public Methods
consultarElegibilidad
Eligibility query request containing patient and service information
Hl7Result<ElegibilidadResponse> with one of these statuses:
OK- Patient is eligibleREJECTED- Patient is not eligible (with reason inissue)ERROR- Technical error occurred
consultarRegistracion
Registration request containing patient, service, and benefit information
Hl7Result<RegistracionResponse> with one of these statuses:
OK- All items registered successfullyPARTIAL- Some items failed (details indetailslist)REJECTED- Entire request rejected (reason inissue)ERROR- Technical error occurred
Registration can return
PARTIAL status when the header is accepted but some detail items fail validation. Check result.getDetails() for item-level errors.cancelarPrestacion
Cancellation request with transaction IDs to cancel
Hl7Result<CancelacionResponse> with one of these statuses:
OK- All items cancelled successfullyPARTIAL- Some items failed to cancel (details indetailslist)REJECTED- Entire cancellation rejected (reason inissue)ERROR- Technical error occurred
Internal Implementation
postHl7 (Core Method)
-
Session Validation: Checks if user is authenticated
- Returns
Hl7Result.error(Hl7Error.sessionExpired())if not authenticated
- Returns
-
Request Serialization: Converts request object to JSON using
JsonUtil -
HTTP Request: Sends POST request via
ApiClient -
HTTP Status Validation:
- Response Parsing: Deserializes JSON response to the target type
- Business Validation: Calls the appropriate validator function
- Exception Handling: Catches any parsing errors and returns technical error
Validator Pattern
The service uses a functional interface for validation logic:validarElegibilidad()- ChecksrechaCabecerafieldvalidarRegistracion()- Checks header and detail-level errorsvalidarCancelacion()- Checks header and detail-level errors
Result Status Types
All methods returnHl7Result<T> with these possible statuses:
Success: Transaction completed successfully.
data: Contains the response objectissue: Emptydetails: Empty list
Partial Success: Header accepted but some detail items failed.
data: Contains the response object (with both successful and failed items)issue: Emptydetails: List of item-level errors (Hl7ItemError)
consultarRegistracion and cancelarPrestacionBusiness Rejection: HL7 system rejected the entire request for functional reasons.
data: Contains the response objectissue: Business error with code and descriptiondetails: Empty list
Technical Error: System error occurred (network, parsing, HTTP error).
data: Emptyissue: Technical error with origin (TRANSPORTE, PARSEO, SESION)details: Empty list
Error Origins
Technical errors are classified by origin:TRANSPORTE: “Error técnico del servidor HL7 (HTTP 500)”PARSEO: “Error técnico procesando respuesta HL7”SESION: “Sesión expirada”
Usage Pattern
Typical workflow for handling HL7 results:Related Types
- ApiClient - HTTP client for API communication
- Hl7Result - Result wrapper with status and error information
- ElegibilidadRequest - Eligibility query request
- RegistracionRequest - Registration request
- CancelacionRequest - Cancellation request
Thread Safety
Hl7Service itself is stateless and thread-safe, but it depends on SessionContext which is a global singleton. Ensure proper synchronization when using from multiple threads.