Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (astm-nestjs-module) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ASTM NestJS Module
Module NestJS nhận và xử lý kết quả từ các máy xét nghiệm thông qua giao thức ASTM và các protocol khác.
Tính năng
- Multi-Protocol Support: ASTM, HL7, LIS2A2, Raw data
- Real-time Communication: WebSocket gateway cho real-time monitoring
- MongoDB Logging: Tự động log tất cả dữ liệu vào MongoDB
- Device Management: Tự động nhận dạng thiết bị dựa trên IP/Port mapping
- Session Logging: Tạo log file riêng cho mỗi session kết nối
- Error Handling: Xử lý lỗi và response tự động cho các protocol
Cài đặt
# Install dependencies
npm install
# Build project
npm run build
# Start development server
npm run start:dev
# Start production server
npm run start:prodCấu hình
Tạo file .env hoặc cấu hình environment variables:
PORT=1008
HOST=0.0.0.0
DEBUG=true
TIMEOUT=30000
LOG_DIRECTORY=./logs
MONGODB_URI=mongodb://localhost:27017/astm-lab-data
MONGODB_DB_NAME=astm-lab-dataCấu trúc dự án
src/
├── common/
│ ├── interfaces/ # Interfaces chung
│ └── utils/ # Utilities
├── config/
│ └── app.config.ts # Cấu hình ứng dụng
├── gateway/
│ └── protocol.gateway.ts # WebSocket gateway cho TCP server
├── modules/
│ ├── mongodb/ # MongoDB service
│ └── protocol/ # Protocol handlers
│ ├── handlers/ # Các protocol handlers
│ ├── interfaces/ # Protocol interfaces
│ └── dto/ # Data Transfer Objects
├── app.module.ts # Root module
└── main.ts # Bootstrap fileProtocol Handlers
ASTM Protocol
- Xử lý ENQ/ACK handshake
- Parse STX/ETX frames với checksum
- Tự động response ACK/NAK
HL7 Protocol
- Parse HL7 messages và segments
- Tạo ACK/NACK responses
- Hỗ trợ MSH segment parsing
LIS2A2 Protocol
- Xử lý SOH/EOT messages
- STX/ETX frame với sequence numbers
- Checksum validation
Raw Protocol
- Phân tích raw data
- Detect encoding và characteristics
- Protocol detection hints
Device Mapping
Cấu hình mapping thiết bị trong app.config.ts:
labDeviceMapping: [
{ ip: '192.168.25.107', name: 'Máy XN HbA1c AdamA1C', port: 10001 },
{ ip: '192.168.25.107', name: 'Máy Cobas6000 số 1', port: 10008 },
// ...thêm các thiết bị khác
]WebSocket Events
Client có thể lắng nghe các events:
server_started- Server đã khởi độngclient_connected- Thiết bị kết nốiprotocol_detected- Phát hiện protocoldata_processed- Dữ liệu đã được xử lýclient_disconnected- Thiết bị ngắt kết nốiserver_error- Lỗi server
Logs
- Session Logs: File log riêng cho mỗi kết nối tại
./logs/ - MongoDB Logs: Tất cả dữ liệu được log vào collection
lab_data_logs - Console Logs: Real-time logging với NestJS Logger
Scripts
# Development
npm run start:dev
# Production build và start
npm run build
npm run start:prod
# Testing
npm run test
npm run test:watch
npm run test:cov
# Linting và formatting
npm run lint
npm run formatMigration từ phiên bản cũ
Dự án này được convert từ Node.js thuần sang NestJS architecture:
- Modular Structure: Tách thành modules rõ ràng
- Dependency Injection: Sử dụng DI container của NestJS
- Type Safety: Full TypeScript với interfaces
- Testing Support: Built-in testing framework
- Configuration Management: Centralized config với validation
- WebSocket Integration: Real-time communication capability
Môi trường phát triển
- Node.js >= 16.0.0
- TypeScript
- NestJS Framework
- MongoDB
- Socket.io (cho WebSocket)