Node.js client for Redix Universal Healthcare Conversion API
npm install redix-clientsh
npm install redix-client
`
Quick Start
`javascript
const { RedixClient } = require('redix-client');
// Initialize client
const client = new RedixClient({
baseUrl: 'https://demo.redix.com',
apiKey: 'YOUR_API_KEY'
});
// Health check
const health = await client.get('/');
console.log(health); // { status: 'healthy', version: '2.1.1' }
// List staging files
const files = await client.get('/api/v2/staging-files');
console.log(files);
// Upload a file to staging
const result = await client.post('/api/v2/staging/upload', {
files: { file: '/path/to/input.txt' }
});
// Convert HL7 to FHIR
const fhir = await client.post('/api/v2/convert/hl7-to-fhir', {
files: { file: '/path/to/message.hl7' }
});
`
API Methods
The client provides simple HTTP methods that work with any API endpoint:
| Method | Description |
|--------|-------------|
| client.get(endpoint, options) | GET request |
| client.post(endpoint, options) | POST request |
| client.put(endpoint, options) | PUT request |
| client.patch(endpoint, options) | PATCH request |
| client.delete(endpoint, options) | DELETE request |
| client.download(endpoint, destPath, options) | Download file |
$3
`javascript
{
params: {}, // Query parameters
data: {}, // Form data fields
json: {}, // JSON body
files: {}, // Files to upload (path strings or streams)
headers: {}, // Additional headers
timeout: 120000 // Request timeout in ms
}
`
Examples
$3
`javascript
// Convert with file upload
const result = await client.post('/api/v2/convert/file-upload', {
files: {
Input_File: '/path/to/input.txt',
IFD_File: '/path/to/rules/835.ifd',
OFD_File: '/path/to/rules/835.ofd'
},
data: {
Conversion_Flag: 'e - UN/EDIFACT/RMap',
WarningLevel: 1,
User_Data: '0\\:?'
}
});
// View output file
const output = await client.get(/api/v2/view-file/output/${result.filename_base}.out);
console.log(output.content);
`
$3
`javascript
// HL7 to FHIR
const result = await client.post('/api/v2/convert/hl7-to-fhir', {
files: { file: '/path/to/message.hl7' }
});
// CDA to FHIR
const result = await client.post('/api/v2/convert/cda-to-fhir', {
files: { file: '/path/to/document.xml' }
});
// HIPAA X12 to FHIR
const result = await client.post('/api/v2/convert/hipaa-to-fhir', {
files: { file: '/path/to/835.x12' }
});
// Smart convert (auto-detect format)
const result = await client.post('/api/v2/convert/smart', {
files: { file: '/path/to/unknown_format.dat' }
});
`
$3
`javascript
// Start batch conversion
const job = await client.post('/api/v2/batch-convert/folder', {
data: {
Input_Subfolder: 'incoming',
Config_Profile: '835_to_rmap'
}
});
const jobId = job.Job_Id;
// Check status
const status = await client.get(/api/v2/batch-status/${jobId});
console.log(status);
// List all batch jobs
const jobs = await client.get('/api/v2/batch-jobs', {
params: { Limit: 10 }
});
`
$3
`javascript
// Upload to staging
await client.post('/api/v2/staging/upload', {
files: { file: 'data.txt' }
});
// List staging files
const files = await client.get('/api/v2/staging-files');
// Delete from staging
await client.delete('/api/v2/staging/myfile.txt');
// Download converted file
await client.download('/api/v2/download-file/output/result.out', './downloads/');
`
$3
`javascript
// List users
const users = await client.get('/api/v2/admin/users');
// Create user
await client.post('/api/v2/admin/users', {
json: {
username: 'newuser',
password: 'secure123',
role: 'user'
}
});
// Get statistics
const stats = await client.get('/api/v2/statistics');
// Get conversion history
const history = await client.get('/api/v2/history', {
params: { limit: 50 }
});
`
Configuration
$3
`bash
export REDIX_API_URL=https://demo.redix.com
export REDIX_API_KEY=your-api-key
`
Then initialize without parameters:
`javascript
const client = new RedixClient({});
`
$3
For self-signed certificates in development:
`javascript
const client = new RedixClient({
baseUrl: 'https://localhost:8080',
apiKey: 'your-key',
rejectUnauthorized: false
});
`
Error Handling
`javascript
const { RedixClient, RedixAPIError } = require('redix-client');
const client = new RedixClient({
baseUrl: 'https://demo.redix.com',
apiKey: 'your-key'
});
try {
const result = await client.get('/api/v2/batch-status/invalid_id');
} catch (error) {
if (error instanceof RedixAPIError) {
console.log(Error ${error.statusCode}: ${error.message});
}
}
``