Health Engine
@loop/health-engine is a pure TypeScript engine for clinical health analysis. It provides qualification assessment, contraindication checking, lab panel completeness evaluation, health scoring, risk flagging, and recommendation generation.
Installation
pnpm add @loop/health-engineQualification Assessment
assessQualification(patient, biomarkers, peptideSlug?, options?)
Comprehensive qualification check that runs contraindication screening, cancer history assessment, biomarker analysis, and risk flagging.
import { assessQualification } from '@loop/health-engine';
const result = assessQualification(
{
age: 35,
sex: 'male',
conditions: ['type-2-diabetes'],
medications: ['metformin'],
cancerHistory: undefined,
},
[
{ code: 'testosterone-total', value: 650, unit: 'ng/dL' },
{ code: 'hba1c', value: 5.8, unit: '%' },
],
'bpc-157'
);
if (result.ok) {
console.log(result.value.status); // 'qualified' | 'conditional' | 'disqualified'
console.log(result.value.score); // 0-100
console.log(result.value.flags); // Risk flags
console.log(result.value.recommendations); // Next steps
}Return type:
interface QualificationResult {
status: 'qualified' | 'conditional' | 'disqualified';
score: number; // 0-100
contraindications: ContraindicationResult;
cancerScreening?: CancerScreeningResult;
flags: string[];
recommendations: string[];
}Qualification Scores
| Status | Minimum Score | Meaning |
|---|---|---|
qualified | 70 | Cleared for therapy |
conditional | 1 | Requires additional review or monitoring |
disqualified | 0 | Not eligible due to safety concerns |
Contraindication Checking
checkPeptideContraindications(patient, biomarkers, peptideSlug)
Check if a specific peptide is safe for a patient given their conditions, medications, and biomarker values.
import { checkPeptideContraindications } from '@loop/health-engine';
const result = checkPeptideContraindications(
{
age: 45,
sex: 'female',
conditions: ['pregnancy'],
medications: [],
},
[],
'bpc-157'
);
if (result.ok) {
console.log(result.value.allowed); // false
console.log(result.value.blocked); // ['pregnancy']
console.log(result.value.cautions); // []
}checkMultiplePeptides(patient, biomarkers, peptideSlugs)
Check multiple peptides at once:
import { checkMultiplePeptides } from '@loop/health-engine';
const results = checkMultiplePeptides(
patient,
biomarkers,
['bpc-157', 'tb-500', 'ipamorelin']
);
// Map<string, Result<ContraindicationResult>>
for (const [slug, result] of results) {
console.log(`${slug}: ${result.ok ? result.value.allowed : 'error'}`);
}filterAllowedPeptides(patient, biomarkers, peptideSlugs)
Get only the peptides that have no absolute contraindications:
import { filterAllowedPeptides } from '@loop/health-engine';
const allowed = filterAllowedPeptides(patient, biomarkers, ['bpc-157', 'tb-500', 'mk-677']);
// ['bpc-157', 'tb-500'] (mk-677 blocked for this patient)Cancer Screening
assessCancerHistory(cancerHistory, peptideCategory?)
Evaluates cancer history for peptide therapy safety.
import { assessCancerHistory } from '@loop/health-engine';
const result = assessCancerHistory({
type: 'breast',
status: 'remission',
diagnosisDate: '2020-01-15',
treatmentComplete: true,
});
if (result.ok) {
console.log(result.value.eligible); // false (high-risk cancer type)
console.log(result.value.requiresClearance); // true (needs oncologist clearance)
console.log(result.value.reason); // 'High-risk cancer type: breast'
}Rules:
- Active cancer: always disqualified
- High-risk cancer types (breast, prostate, colorectal, lung, pancreatic, melanoma): requires oncologist clearance
- Growth-promoting peptides + any cancer history: requires clearance
Lab Panel Completeness
assessPanelCompleteness(biomarkers, peptideId?)
Evaluate whether a patient’s lab work is sufficient for therapy.
import { assessPanelCompleteness } from '@loop/health-engine';
const result = assessPanelCompleteness(
[
{ code: 'testosterone-total', value: 650, unit: 'ng/dL' },
{ code: 'cbc', value: 14.5, unit: 'g/dL' },
],
'bpc-157'
);
if (result.ok) {
console.log(result.value.level); // 'complete' | 'partial' | 'insufficient'
console.log(result.value.score); // 0-100 completeness percentage
console.log(result.value.missing); // Missing biomarker codes
}isSufficientForTherapy(completeness)
import { isSufficientForTherapy } from '@loop/health-engine';
const sufficient = isSufficientForTherapy(result.value);
// true if 'complete' or ('partial' with score >= 80)getRequiredPanelsForPeptide(peptideId)
Get the required lab panels for a specific peptide:
import { getRequiredPanelsForPeptide } from '@loop/health-engine';
const result = getRequiredPanelsForPeptide('ipamorelin');
if (result.ok) {
console.log(result.value.required); // Required panel IDs
console.log(result.value.optional); // Recommended panel IDs
console.log(result.value.minimumBiomarkers); // Minimum required biomarkers
}getRecommendedPanelsForGoals(goals, sex)
Get recommended panels based on health goals:
import { getRecommendedPanelsForGoals } from '@loop/health-engine';
const result = getRecommendedPanelsForGoals(['longevity', 'performance'], 'male');
// Returns panels relevant to these goalsMonitoring Checks
import { requiresGHMonitoring, requiresMetabolicMonitoring } from '@loop/health-engine';
requiresGHMonitoring('ipamorelin'); // true (GH secretagogue)
requiresMetabolicMonitoring('semaglutide'); // true (GLP-1)Health Scoring
computeHealthScore(biomarkers)
Calculate a 0–100 health score from biomarker assessments.
import { computeHealthScore } from '@loop/health-engine';
const result = computeHealthScore([
{ code: 'testosterone-total', value: 650, unit: 'ng/dL', status: 'optimal', category: 'hormones' },
{ code: 'tsh', value: 2.1, unit: 'mIU/L', status: 'optimal', category: 'thyroid' },
{ code: 'glucose', value: 95, unit: 'mg/dL', status: 'normal', category: 'metabolic' },
]);
if (result.ok) {
console.log(result.value.overall); // 85 (0-100)
console.log(result.value.grade); // 'B+'
console.log(result.value.categories); // { hormones: 90, thyroid: 95, metabolic: 80 }
console.log(result.value.interpretation); // 'Good overall health with room for optimization'
}getHealthScoreGrade(score)
Map a numeric score to a letter grade:
| Score Range | Grade |
|---|---|
| 90–100 | A |
| 80–89 | B |
| 70–79 | C |
| 60–69 | D |
| 0–59 | F |
Risk Flags
deriveRiskFlags(patient, biomarkers)
Identify clinical risk patterns from patient profile and biomarker data.
import { deriveRiskFlags } from '@loop/health-engine';
const result = deriveRiskFlags(patient, biomarkers);
if (result.ok) {
for (const flag of result.value) {
console.log(flag.category); // 'cardiovascular', 'metabolic', 'hormonal', etc.
console.log(flag.severity); // 'low', 'moderate', 'high', 'critical'
console.log(flag.description); // Human-readable description
console.log(flag.biomarkers); // Related biomarker codes
}
}Risk Categories:
- Cardiovascular — lipid panel abnormalities, hsCRP elevation
- Metabolic — glucose, insulin, HbA1c patterns
- Hormonal — testosterone, estrogen, thyroid imbalances
- Organ — liver enzymes, kidney function markers
- Inflammation — CRP, ESR, ferritin patterns
- Thyroid — TSH, T3, T4 patterns
Recommendations
generateRecommendations(patient, biomarkers, riskFlags?, options?)
Generate personalized health recommendations based on biomarker data and risk flags.
import { generateRecommendations } from '@loop/health-engine';
const result = generateRecommendations(patient, biomarkers, riskFlags);
if (result.ok) {
for (const rec of result.value) {
console.log(rec.type); // 'lifestyle', 'supplementation', 'testing', 'specialist'
console.log(rec.priority); // 'high', 'medium', 'low'
console.log(rec.description); // Human-readable recommendation
console.log(rec.goal); // Related health goal
}
}Recommendation Types:
- Lifestyle — Diet, exercise, sleep modifications
- Supplementation — Vitamin/mineral suggestions based on deficiencies
- Testing — Additional lab panels recommended
- Specialist — Referral suggestions for concerning patterns