From 0e3c70f710bf755fb2f69a86db8366302868ba38 Mon Sep 17 00:00:00 2001 From: Occumed79 Date: Sun, 16 Aug 2026 23:19:17 -0700 Subject: [PATCH 1/4] Constrain Tango discovery to Occu-Med scope --- api-server/src/lib/providers/tango.ts | 222 +++++++++++++++++++++++++- 1 file changed, 214 insertions(+), 8 deletions(-) diff --git a/api-server/src/lib/providers/tango.ts b/api-server/src/lib/providers/tango.ts index 32268a87..b4e21f7d 100644 --- a/api-server/src/lib/providers/tango.ts +++ b/api-server/src/lib/providers/tango.ts @@ -20,6 +20,132 @@ const DEFAULT_MAX_PAGES = 5; const DEFAULT_MAX_RETRIES = 2; const MAX_RECORD_LIMIT = 500; const MAX_PAGE_SIZE = 100; +const DEFAULT_TANGO_SEARCH = "occupational health"; + +// Tango is a useful secondary federal index, but its full opportunity feed is far +// broader than Occu-Med's addressable scope. These source-specific guards run +// before the shared structured-opportunity judge so generic federal medical +// records never consume judge budget or reach persistence. +const TANGO_STRONG_OCCUMED_SIGNALS = [ + "occupational health", + "occupational medicine", + "occupational medical", + "medical surveillance", + "pre-employment physical", + "pre employment physical", + "pre-placement physical", + "pre placement physical", + "fitness for duty", + "fit for duty", + "return to work physical", + "return-to-work physical", + "respirator medical evaluation", + "respirator medical clearance", + "hearing conservation", + "dot physical", + "dot medical examination", + "fmcsa physical", + "49 cfr part 40", + "dot part 40", + "nfpa 1582", + "firefighter medical examination", + "public safety physical", + "deployment medical", + "pre-deployment medical", + "pre deployment medical", + "contractor personnel medical", + "periodic health assessment", + "employee health services", + "workforce health", +]; + +const TANGO_CONTEXT_REQUIRED_CLINICAL_SIGNALS = [ + "drug testing", + "drug screening", + "alcohol testing", + "breath alcohol", + "audiogram", + "audiometric", + "hearing test", + "spirometry", + "pulmonary function", + "fit testing", + "respirator fit testing", + "vaccination", + "immunization", + "tb testing", + "tuberculosis testing", + "medical examination", + "medical examinations", + "physical examination", + "physical examinations", + "medical screening", + "health screening", + "vision testing", + "laboratory testing", + "lab testing", +]; + +const TANGO_WORKFORCE_CONTEXT_SIGNALS = [ + "employee", + "employees", + "employer", + "workforce", + "worker", + "workers", + "worksite", + "work site", + "workplace", + "occupational", + "pre-employment", + "pre employment", + "pre-placement", + "pre placement", + "new hire", + "new hires", + "applicant", + "applicants", + "fitness for duty", + "fit for duty", + "return to work", + "return-to-work", + "return to duty", + "safety-sensitive", + "safety sensitive", + "osha", + "hazwoper", + "respirator", + "respiratory protection", + "hearing conservation", + "nfpa 1582", + "fmcsa", + "49 cfr part 40", + "dot part 40", + "contractor personnel", + "contractor employees", + "firefighter", + "firefighters", + "law enforcement", + "deployment", + "pre-deployment", +]; + +const TANGO_NON_OCCUPATIONAL_PATIENT_SIGNALS = [ + "patient care", + "clinic patients", + "hospital patients", + "community residents", + "general public", + "community vaccination", + "community testing", + "student health", + "students", + "school children", + "medicaid members", + "medicare beneficiaries", + "inmates", + "treatment services", +]; interface TangoOpportunity { opportunity_id: string; @@ -58,6 +184,66 @@ interface TangoListResponse { results: TangoOpportunity[]; } +function normalizePrecisionText(value: string): string { + return ` ${value + .toLowerCase() + .replace(/[^a-z0-9]+/g, " ") + .replace(/\s+/g, " ") + .trim()} `; +} + +function includesPrecisionSignal(text: string, signal: string): boolean { + return text.includes(normalizePrecisionText(signal)); +} + +/** + * Tango-only fail-closed relevance gate. + * + * Generic clinical services such as vaccinations, TB testing, audiograms, + * spirometry, medical exams, or drug testing are only accepted when they are + * explicitly tied to employees/workforce, employment screening, public-safety, + * deployment, or occupational/regulatory programs. + */ +export function passesTangoOccumedPrecisionGate(value: string): boolean { + const text = normalizePrecisionText(value); + const strong = TANGO_STRONG_OCCUMED_SIGNALS.some((signal) => + includesPrecisionSignal(text, signal), + ); + if (strong) return true; + + const clinical = TANGO_CONTEXT_REQUIRED_CLINICAL_SIGNALS.some((signal) => + includesPrecisionSignal(text, signal), + ); + if (!clinical) return false; + + const workforce = TANGO_WORKFORCE_CONTEXT_SIGNALS.some((signal) => + includesPrecisionSignal(text, signal), + ); + if (workforce) return true; + + const patientOnly = TANGO_NON_OCCUPATIONAL_PATIENT_SIGNALS.some((signal) => + includesPrecisionSignal(text, signal), + ); + if (patientOnly) return false; + + // Generic clinical scope with no explicit occupational context fails closed. + return false; +} + +function tangoPrecisionText(opportunity: TangoOpportunity): string { + return [ + opportunity.title, + opportunity.description, + opportunity.office?.agency_name, + opportunity.office?.department_name, + opportunity.meta?.notice_type?.type, + opportunity.naics_code, + opportunity.psc_code, + ] + .filter(Boolean) + .join(" "); +} + function parsedDate(value?: string): Date | undefined { if (!value) return undefined; const parsed = new Date(value); @@ -152,20 +338,23 @@ export class TangoProvider implements DataSourceProvider { providerName: this.name, rawData: { providerName: "tango", - providerFamily: "direct_procurement_api", + providerFamily: "secondary_procurement_index", providerType: "tango_makegov_api", discoveryMethod: "direct_api", - sourceConfidence: "high", + evidenceType: "aggregator", + sourceConfidence: "medium", dateUnknown: !postedDate, listingPageNumber: pageNumber, paginationMode: "bounded_api_next_link", tags: [ "direct-api", + "secondary-source", "tango", + "tango-precision-gated", ...(!postedDate ? ["date-unknown"] : []), ], notes: - "Collected directly from the configured Tango by MakeGov opportunity API using bounded pagination.", + "Collected from Tango by MakeGov as a secondary federal opportunity index and retained only after the Tango-specific Occu-Med precision gate.", tango: opportunity, }, }; @@ -272,6 +461,7 @@ export class TangoProvider implements DataSourceProvider { 0, 5, ); + const search = options.keywords?.trim() || DEFAULT_TANGO_SEARCH; endpoint.searchParams.set( "first_notice_date_after", @@ -304,9 +494,9 @@ export class TangoProvider implements DataSourceProvider { endpoint.searchParams.set("limit", String(pageSize)); endpoint.searchParams.set("page", "1"); endpoint.searchParams.set("ordering", "-first_notice_date"); - if (options.keywords?.trim()) { - endpoint.searchParams.set("search", options.keywords.trim()); - } + // Never ask Tango for the unbounded federal firehose. Blank manual searches + // use a focused occupational-health seed; custom searches remain supported. + endpoint.searchParams.set("search", search); const records: NormalizedOpportunity[] = []; const errors: string[] = []; @@ -315,6 +505,7 @@ export class TangoProvider implements DataSourceProvider { let currentUrl: URL | null = endpoint; let pageNumber = 0; let reportedTotal = 0; + let precisionRejected = 0; while ( currentUrl && @@ -353,6 +544,10 @@ export class TangoProvider implements DataSourceProvider { if (!opportunity?.opportunity_id) continue; if (seenOpportunityIds.has(opportunity.opportunity_id)) continue; seenOpportunityIds.add(opportunity.opportunity_id); + if (!passesTangoOccumedPrecisionGate(tangoPrecisionText(opportunity))) { + precisionRejected += 1; + continue; + } records.push(this.normalize(opportunity, pageNumber)); if (records.length >= recordLimit) break; } @@ -369,9 +564,20 @@ export class TangoProvider implements DataSourceProvider { ); } + console.info( + JSON.stringify({ + event: "tango_occumed_precision_gate", + search, + upstreamReportedTotal: reportedTotal, + pagesScanned: pageNumber, + retained: records.length, + precisionRejected, + }), + ); + return { records, - total: reportedTotal || records.length, + total: records.length, errors, }; } @@ -386,4 +592,4 @@ export class TangoProvider implements DataSourceProvider { } } -export const tangoProvider = new TangoProvider(); +export const tangoProvider = new TangoProvider(); \ No newline at end of file From 300cd3430b4a04f1a5f8b974d17de6c78d3d47ac Mon Sep 17 00:00:00 2001 From: Occumed79 Date: Sun, 16 Aug 2026 23:19:45 -0700 Subject: [PATCH 2/4] Add Tango precision regression coverage --- .../__tests__/tangoPrecision.test.ts | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 api-server/src/lib/providers/__tests__/tangoPrecision.test.ts diff --git a/api-server/src/lib/providers/__tests__/tangoPrecision.test.ts b/api-server/src/lib/providers/__tests__/tangoPrecision.test.ts new file mode 100644 index 00000000..ecf3b5b2 --- /dev/null +++ b/api-server/src/lib/providers/__tests__/tangoPrecision.test.ts @@ -0,0 +1,89 @@ +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; +import { passesTangoOccumedPrecisionGate } from "../tango"; + +describe("Tango Occu-Med precision gate", () => { + it("keeps core occupational-health scopes", () => { + assert.equal( + passesTangoOccumedPrecisionGate( + "RFP for occupational health services including employee physical examinations, drug testing, audiograms, spirometry, and medical surveillance.", + ), + true, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "NFPA 1582 firefighter medical examinations and annual fitness-for-duty services.", + ), + true, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "Respirator medical evaluation and fit testing for public works employees under the respiratory protection program.", + ), + true, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "Pre-employment physical examinations and DOT drug and alcohol testing for agency applicants and employees.", + ), + true, + ); + }); + + it("keeps generic clinical components only when tied to workforce context", () => { + assert.equal( + passesTangoOccumedPrecisionGate( + "Audiometric testing, spirometry and vaccinations for employees assigned to hazardous worksites.", + ), + true, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "TB testing and immunization services for contractor personnel before deployment.", + ), + true, + ); + }); + + it("rejects ordinary patient and community medical procurements", () => { + assert.equal( + passesTangoOccumedPrecisionGate( + "Community vaccination services for residents and the general public.", + ), + false, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "Hospital seeks laboratory testing and medical screening services for clinic patients.", + ), + false, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "Student health TB testing and immunization program for university students.", + ), + false, + ); + }); + + it("rejects unrelated federal solicitations containing incidental medical words", () => { + assert.equal( + passesTangoOccumedPrecisionGate( + "Construction contract. Contractor must maintain a drug testing policy for its own staff.", + ), + false, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "IT support services. Personnel must complete a medical screening before receiving site access.", + ), + false, + ); + assert.equal( + passesTangoOccumedPrecisionGate( + "Purchase of laboratory testing equipment and medical supplies.", + ), + false, + ); + }); +}); From 6b1c7ebe31bfff2148fe68c78c79818f140742b3 Mon Sep 17 00:00:00 2001 From: Occumed79 Date: Sun, 16 Aug 2026 23:20:39 -0700 Subject: [PATCH 3/4] Use focused SAM query on blank discovery runs --- api-server/src/lib/providers/samGovQuality.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api-server/src/lib/providers/samGovQuality.ts b/api-server/src/lib/providers/samGovQuality.ts index 2a22c347..e6f8d50f 100644 --- a/api-server/src/lib/providers/samGovQuality.ts +++ b/api-server/src/lib/providers/samGovQuality.ts @@ -68,6 +68,7 @@ const SAM_TITLE_PROFILES = [ const CUSTOM_QUERY_NOISE = /\b(?:active|bid|bids|city|contract|contracts|county|due|federal|find|government|open|opportunities|opportunity|procurement|proposal|proposals|request|rfp|rfq|services?|solicitation|state)\b/gi; const BID_READY_TYPE_RE = /^(?:solicitation|combined synopsis\/solicitation)$/i; +const DEFAULT_AUTONOMOUS_SAM_TITLE = "occupational health"; export function buildSamGovTitleQueries(keywords?: string): string[] { const normalized = (keywords ?? "") @@ -76,9 +77,10 @@ export function buildSamGovTitleQueries(keywords?: string): string[] { .replace(/[^a-z0-9]+/g, " ") .replace(/\s+/g, " ") .trim(); - // Blank autonomous runs retrieve broadly once; the Occu-Med ontology then - // classifies notices locally instead of spending a call per service title. - if (!normalized) return []; + // Keep autonomous SAM usage to one API call, but make that call useful. + // A broad blank search returns thin metadata for many unrelated notices and + // routinely produces zero usable Occu-Med records after local classification. + if (!normalized) return [DEFAULT_AUTONOMOUS_SAM_TITLE]; const matched = SAM_TITLE_PROFILES.filter((profile) => profile.aliases.some((alias) => normalized.includes(alias)), @@ -111,4 +113,4 @@ export function isBidReadySamOpportunity( : null; if (!deadline || Number.isNaN(deadline.getTime())) return false; return deadline.getTime() > now.getTime(); -} +} \ No newline at end of file From afd13198496f5b40c3bf0f89c03363a46dd6a65e Mon Sep 17 00:00:00 2001 From: Occumed79 Date: Sun, 16 Aug 2026 23:20:48 -0700 Subject: [PATCH 4/4] Cover focused autonomous SAM query --- .../src/lib/providers/__tests__/samGovQuality.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api-server/src/lib/providers/__tests__/samGovQuality.test.ts b/api-server/src/lib/providers/__tests__/samGovQuality.test.ts index e85cfe22..aa8790c6 100644 --- a/api-server/src/lib/providers/__tests__/samGovQuality.test.ts +++ b/api-server/src/lib/providers/__tests__/samGovQuality.test.ts @@ -29,8 +29,8 @@ describe("SAM.gov bid-ready query policy", () => { ); }); - it("uses one broad structured retrieval when no query is supplied", () => { - assert.deepEqual(buildSamGovTitleQueries(), []); + it("uses one focused occupational-health title request when no query is supplied", () => { + assert.deepEqual(buildSamGovTitleQueries(), ["occupational health"]); }); it("accepts only active bid notices with a future response deadline", () => { @@ -61,4 +61,4 @@ describe("SAM.gov bid-ready query policy", () => { false, ); }); -}); +}); \ No newline at end of file