Skip to content

@univ-lehavre/crf ​

Case Report Form - Unified package for interacting with the REDCap API.

About ​

This package provides a typed TypeScript client for the REDCap API, an HTTP REST server, and CLI tools. It uses an OpenAPI-first architecture with types generated from the specs/redcap.yaml specification.

Features ​

  • REDCap Client: Typed Effect client for the REDCap API
  • HTTP Server: REST microservice with Hono
  • CLI: Command-line tools for testing connectivity
  • Generated Types: TypeScript types generated from OpenAPI
  • Branded Types: Runtime validation of identifiers

Installation ​

bash
pnpm add @univ-lehavre/crf effect

Usage ​

REDCap Client ​

typescript
import { createRedcapClient, RedcapUrl, RedcapToken, RecordId } from '@univ-lehavre/crf/redcap';
import { Effect } from 'effect';

const client = createRedcapClient({
  url: RedcapUrl('https://redcap.example.com/api/'),
  token: RedcapToken('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'),
});

// Get REDCap version
const version = await Effect.runPromise(client.getVersion());
console.log('REDCap version:', version);

// Export records
const records = await Effect.runPromise(
  client.exportRecords({
    fields: ['record_id', 'first_name', 'last_name'],
    filterLogic: '[age] >= 18',
  })
);

CRF Server ​

bash
# Required environment variables
export REDCAP_API_URL=https://redcap.example.com/api/
export REDCAP_API_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
export PORT=3000

# Start the server
pnpm -F @univ-lehavre/crf start

Server API ​

EndpointDescription
GET /healthHealth check
GET /api/v1/project/versionREDCap version
GET /api/v1/project/infoProject information
GET /api/v1/recordsExport records
POST /api/v1/recordsImport records
GET /api/v1/users/:emailFind a user
GET /openapi.jsonOpenAPI specification
GET /docsScalar documentation

Scripts ​

bash
pnpm -F @univ-lehavre/crf dev            # Development
pnpm -F @univ-lehavre/crf build          # Production build
pnpm -F @univ-lehavre/crf test           # Unit tests
pnpm -F @univ-lehavre/crf generate:types # Regenerate types
pnpm -F @univ-lehavre/crf mock:redcap    # Mock REDCap (Prism)
pnpm -F @univ-lehavre/crf start          # Start the server
pnpm -F @univ-lehavre/crf test:api       # API tests (Schemathesis)

Branded Types ​

The package uses branded types for runtime validation:

typescript
import { RedcapToken, RecordId, InstrumentName, Email } from '@univ-lehavre/crf/redcap';

const token = RedcapToken('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); // OK
const recordId = RecordId('abc12345678901234567'); // OK (20+ chars)

Documentation ​

Organization ​

This package is part of Atlas, a set of tools developed by Le Havre Normandie University to facilitate research and collaboration between researchers.

Atlas is developed as part of two projects led by Le Havre Normandie University:


Le Havre Normandie University     Campus Polytechnique des Territoires Maritimes et Portuaires     EUNICoast

License ​

MIT

CRF Service - HTTP microservice for REDCap.

Interfaces ​

InterfaceDescription
CreateAppOptionsConfiguration options for creating the CRF app.

Functions ​

FunctionDescription
createAppCreates and configures the Hono application.