# Clinical Trial Results Table QA (`sapphire_headwind/clinical-trial-results-table-qa`) Actor

Audit normalized ClinicalTrials.gov-style study and outcome CSVs before joins, analysis or delivery. Detect invalid NCT IDs, duplicate keys, broken joins, missing fields and malformed dates. No scraping, AI, repairs or clinical accuracy claims.

- **URL**: https://apify.com/sapphire_headwind/clinical-trial-results-table-qa.md
- **Developed by:** [chris zannetti](https://apify.com/sapphire_headwind) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$250.00 / 1,000 completed audits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Clinical Trial Results Table QA

Check normalized clinical-trial exports before a join, analysis or buyer delivery. Supply two CSV strings; receive a deterministic audit with missing fields, invalid NCT identifiers, duplicate keys, orphan outcomes and malformed result dates. No AI key, web scraping or source credentials required.

### Input contract

- `studiesCsv`: `trial_id,condition,phase`; one row per study.
- `outcomesCsv`: `trial_id,outcome_id,outcome_type,primary_endpoint,result_status,results_first_post_date`; one row per normalized outcome.
- Identifiers must match `NCT` followed by eight digits. Outcomes join exactly to studies on `trial_id`. Outcome identity is the compound `(trial_id,outcome_id)`.
- Outcome type: `PRIMARY`, `SECONDARY`, or `OTHER_PRE_SPECIFIED`. Despite its name, `primary_endpoint` is the endpoint text column for every outcome type in this export contract.
- Date: a valid full `YYYY-MM-DD` date. Partial dates need explicit upstream handling, never guessed here.
- Phase and result status are checked for presence, not assigned clinical meaning. Use this profile only for posted-results exports; it intentionally fails incomplete result rows.
- UTF-8, comma delimiter, standard quoted CSV, optional BOM. Whitespace around cell values is ignored for checks. Additional columns are allowed and not interpreted. Headers are exact and case-sensitive.

This is a normalized two-table contract, **not a native ClinicalTrials.gov JSON/CSV parser**. Map source columns explicitly before running. The Actor does not fetch data, repair it, reinterpret outcomes or verify trial existence.

### Output

The default dataset contains one audit; the default key-value store has `REPORT`. `report.schema.json` defines the JSON result. `PASS` means every implemented structural check passed. `FAIL` is a completed audit with data defects; inspect `issueCounts` and `issues`. Invalid configuration, malformed CSV or exceeded limits fail the Actor run.

Findings contain table name, one-based data-record number, field name and issue code, never cell values. Coverage is the non-empty fraction for each required column. Hashes bind the exact submitted CSV bytes. At most 1,000 detailed findings are returned; aggregate counts remain complete. `issuesTruncated` signals truncation.

### Example and local run

The bundled example is synthetic and contains no patient or production submission data.

```sh
python3 validator.py < examples/input.json
python3 -m unittest discover -s tests -v
## Python 3.12, dedicated virtual environment recommended:
pip install -r requirements.txt
## Apify CLI, after putting examples/input.json in local INPUT storage:
apify run
```

See `examples/output.json` for the matching successful audit. A malformed date or unknown parent study gives a failing audit, not an invented replacement.

### Limits, privacy and resource use

Maximum combined CSV size: 5 MiB. Maximum 10,000 rows per table, 40 columns, approximately 128 KiB per CSV field. The local CLI also caps JSON transport input at 6 MiB. Recommended cloud configuration: 256 MiB memory, 60-second timeout, limited permissions, no standby mode. The image runs as a non-root user. There are zero external source requests, retries or source rate-limit consumption; only Apify storage/event operations occur on-platform. No user-supplied URL is fetched. Logs contain only counts, status and elapsed time.

Input and output follow the customer's Apify storage/access/retention settings. Do not provide individual patient data or secrets. Source values are not echoed in audit output, but the customer's INPUT record still contains the submitted CSV. Whole-file hashes are integrity metadata, not anonymization.

### Pricing proposal

Proposed price: **$0.25 per completed audit**, up to the stated limits. A `FAIL` report is chargeable because finding defects is the service. Input errors are not charged by the custom `audit-completed` event. The event hook is implemented; no paid listing or price has been activated. Configure this custom event as one-time per run and remove default per-dataset-item charging before publication. Disable usage pass-through. Platform start fees, if imposed, must be disclosed in the final listing.

A private cloud billing smoke test must verify the configured event and spending cap before public publication. No automatic run resurrection is proposed. See `monetization-proposal.json` for the budget and approval boundary.

### Rights and limitations

Original validator code draws on DataForge's prior clinical export QA patterns; it copies no buyer dataset or competitor code. The customer must be entitled to process their input. This service neither licenses nor redistributes a source dataset and does not certify clinical accuracy, source authenticity, recency, statistical validity, legal reuse or regulatory compliance. It is not affiliated with NIH/ClinicalTrials.gov.

For reproducible issues provide the run ID and a minimal synthetic example through the Actor Issues tab. Do not post confidential CSVs or tokens.

# Actor input Schema

## `studiesCsv` (type: `string`):

UTF-8 CSV: trial_id, condition, phase. One study per row.

## `outcomesCsv` (type: `string`):

UTF-8 CSV: trial_id, outcome_id, outcome_type, primary_endpoint, result_status, results_first_post_date. One outcome per row.

## Actor input object example

```json
{
  "studiesCsv": "trial_id,condition,phase\nNCT00000001,Example condition,PHASE2\n",
  "outcomesCsv": "trial_id,outcome_id,outcome_type,primary_endpoint,result_status,results_first_post_date\nNCT00000001,primary-1,PRIMARY,Example endpoint,POSTED,2026-01-15\n"
}
```

# Actor output Schema

## `report` (type: `string`):

No description

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "studiesCsv": `trial_id,condition,phase
NCT00000001,Example condition,PHASE2`,
    "outcomesCsv": `trial_id,outcome_id,outcome_type,primary_endpoint,result_status,results_first_post_date
NCT00000001,primary-1,PRIMARY,Example endpoint,POSTED,2026-01-15`
};

// Run the Actor and wait for it to finish
const run = await client.actor("sapphire_headwind/clinical-trial-results-table-qa").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "studiesCsv": """trial_id,condition,phase
NCT00000001,Example condition,PHASE2
""",
    "outcomesCsv": """trial_id,outcome_id,outcome_type,primary_endpoint,result_status,results_first_post_date
NCT00000001,primary-1,PRIMARY,Example endpoint,POSTED,2026-01-15
""",
}

# Run the Actor and wait for it to finish
run = client.actor("sapphire_headwind/clinical-trial-results-table-qa").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "studiesCsv": "trial_id,condition,phase\\nNCT00000001,Example condition,PHASE2\\n",
  "outcomesCsv": "trial_id,outcome_id,outcome_type,primary_endpoint,result_status,results_first_post_date\\nNCT00000001,primary-1,PRIMARY,Example endpoint,POSTED,2026-01-15\\n"
}' |
apify call sapphire_headwind/clinical-trial-results-table-qa --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,sapphire_headwind/clinical-trial-results-table-qa"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/XJ7kfLMisQbBjk1k4/builds/ZdYbOWLwC0haCAYwU/openapi.json
