code wiki / (root) / nx_prodready.nx

nx_prodready.nx source

↩ module page · 263 lines · 9774 B

1// nx_prodready.nx -- GTM SUITE / PRODUCTION-READINESS ENGINE. The capstone 2// that recombinates every earlier rung into ONE answer: given a product 3// concept, what is blocking it from market, in the order that actually kills 4// products. This is the "help us get a plan on what we need to do" the 5// operator asked for, made mechanical. 6// 7// THE ORDERING IS THE INSIGHT. Readiness is not a checklist you can do in 8// any order -- the dimensions have a kill-order, and reporting them out of 9// order wastes effort. A legally-impossible product needs no formulation 10// work; a product that cannot fit a dosage form needs no cost model; a 11// product that cannot clear a margin needs no cGMP audit yet. So pr_first_gap 12// walks the dimensions in the order that a product dies, and returns the FIRST 13// blocker -- the one thing to fix next -- rather than a flat list that invites 14// working on rung 6 while rung 1 is still broken. 15// 16// 1. LEGAL every ingredient sellable in the target market 17// 2. FORMAT the clinical doses fit a saleable dosage form 18// 3. ECONOMICS the price clears the target margin 19// 4. IDENTITY 21 CFR 111 100% identity testing is in place 20// 5. MANUFACTURING an EU-GMP / cGMP facility is qualified 21// 6. CLAIMS the marketing claims are reviewed + compliant 22// 7. COA a certificate of analysis is on file per lot 23// 24// 1-3 are COMPUTED from the earlier libraries (ingredient class, jurisdiction, 25// formulation, economics). 4-7 are OPERATOR ATTESTATIONS -- things a person 26// must actually do, which the engine cannot verify itself and therefore does 27// not pretend to; it tracks whether they are declared done, and refuses to 28// call a product ready while any is open. 29// 30// The readiness score is the fraction of dimensions passed, per-mil -- a 31// progress bar toward market, not a marketing number. 32// 33// Grounding: composes nx_supp_ingredient (class) + nx_supp_jurisdiction 34// (market pathway) + nx_supp_formula (format + economics) + nx_supp_claims 35// + the 21 CFR 111 identity-testing requirement nx_qc_svc serves. 36// 37// genealogy_id: supplement_gtm + service_infrastructure 38 39import "nx_syscalls.nx" 40import "nx_supp_ingredient.nx" 41import "nx_supp_formula.nx" 42import "nx_supp_jurisdiction.nx" 43 44// ===== Readiness dimensions (sealed, in KILL ORDER) =================== 45 46const PR_LEGAL: i64 = 0 47const PR_FORMAT: i64 = 1 48const PR_ECONOMICS: i64 = 2 49const PR_IDENTITY: i64 = 3 50const PR_MANUFACTURING: i64 = 4 51const PR_CLAIMS: i64 = 5 52const PR_COA: i64 = 6 53const PR_N_DIM: i64 = 7 54 55const PR_READY: i64 = 0 - 1 // pr_first_gap returns this when nothing blocks 56 57func pr_dim_name(d: i64) -> *u8 { 58 if d == PR_LEGAL { return "legal: every ingredient sellable in the target market" as *u8 } 59 if d == PR_FORMAT { return "format: clinical doses fit a saleable dosage form" as *u8 } 60 if d == PR_ECONOMICS { return "economics: price clears the target margin" as *u8 } 61 if d == PR_IDENTITY { return "identity: 21 CFR 111 100% identity testing in place" as *u8 } 62 if d == PR_MANUFACTURING { return "manufacturing: an EU-GMP/cGMP facility is qualified" as *u8 } 63 if d == PR_CLAIMS { return "claims: marketing claims reviewed and compliant" as *u8 } 64 if d == PR_COA { return "coa: certificate of analysis on file per lot" as *u8 } 65 return "unknown dimension" as *u8 66} 67 68// The concrete NEXT ACTION for a blocking dimension -- the plan line. 69func pr_action(d: i64) -> *u8 { 70 if d == PR_LEGAL { return "remove the unlawful ingredient(s) or change target market" as *u8 } 71 if d == PR_FORMAT { return "switch to powder/stick-pack or reduce the ingredient count" as *u8 } 72 if d == PR_ECONOMICS { return "raise price, cut COGS, or accept a lower margin" as *u8 } 73 if d == PR_IDENTITY { return "stand up incoming-ingredient identity testing (LC-MS/FTIR)" as *u8 } 74 if d == PR_MANUFACTURING { return "qualify a cGMP contract manufacturer + quality agreement" as *u8 } 75 if d == PR_CLAIMS { return "route all label claims through structure/function review" as *u8 } 76 if d == PR_COA { return "require a CoA per lot from the manufacturer" as *u8 } 77 return "no action" as *u8 78} 79 80// ===== The product concept ============================================ 81// 82// ingredient_mask: bit i set => ingredient id i is in the product. Bitmask 83// rather than a list so a concept is one integer, trivially passed and stored. 84 85struct NxProduct { 86 market: i64, // SJ_* 87 ingredient_mask: i64, 88 format: i64, // SF_FORMAT_* 89 retail_cents: i64, 90 target_margin_permil: i64, 91 servings: i64, 92 max_units: i64, // saleable dosage-form ceiling (e.g. 2 capsules) 93 identity_ready: i64, // operator attestations (0/1) ... 94 gmp_qualified: i64, 95 claims_reviewed: i64, 96 coa_on_file: i64, 97} 98 99func nx_product_new() -> *NxProduct { 100 let p: *NxProduct = (sys_mmap(96)) as *NxProduct 101 p.market = SJ_US 102 p.ingredient_mask = 0 103 p.format = SF_FORMAT_CAPSULE 104 p.retail_cents = 0 105 p.target_margin_permil = 700 106 p.servings = 30 107 p.max_units = 2 108 p.identity_ready = 0 109 p.gmp_qualified = 0 110 p.claims_reviewed = 0 111 p.coa_on_file = 0 112 return p 113} 114 115func pr_add_ingredient(p: *NxProduct, id: i64) -> i64 { 116 if si_valid_id(id) != 1 { return 0 } 117 let bit: i64 = 1 << id 118 p.ingredient_mask = p.ingredient_mask | bit 119 return 1 120} 121 122func pr_has_ingredient(p: *NxProduct, id: i64) -> i64 { 123 if si_valid_id(id) != 1 { return 0 } 124 let bit: i64 = 1 << id 125 let m: i64 = p.ingredient_mask & bit 126 if m != 0 { return 1 } 127 return 0 128} 129 130// Build a clinical-dose formula from the mask -- the bridge to the format + 131// economics libraries. 132func pr_build_formula(p: *NxProduct) -> *NxSuppFormula { 133 let f: *NxSuppFormula = nx_supp_formula_new() 134 var i: i64 = 0 135 while i < SI_N { 136 if pr_has_ingredient(p, i) == 1 { sf_set_clinical(f, i) } 137 i = i + 1 138 } 139 return f 140} 141 142// ===== Dimension predicates =========================================== 143 144// LEGAL: every ingredient in the mask is sellable in the target market. 145// An empty product is NOT legal (nothing to sell). 146func pr_legal_ok(p: *NxProduct) -> i64 { 147 if p.ingredient_mask == 0 { return 0 } 148 var i: i64 = 0 149 var ok: i64 = 1 150 while i < SI_N { 151 if pr_has_ingredient(p, i) == 1 { 152 if sj_is_sellable(p.market, i) != 1 { ok = 0 } 153 } 154 i = i + 1 155 } 156 return ok 157} 158 159// The first unlawful ingredient id, for a precise plan line (or SI_INVALID). 160func pr_first_unlawful(p: *NxProduct) -> i64 { 161 var i: i64 = 0 162 var found: i64 = SI_INVALID 163 while i < SI_N { 164 if found == SI_INVALID { 165 if pr_has_ingredient(p, i) == 1 { 166 if sj_is_sellable(p.market, i) != 1 { found = i } 167 } 168 } 169 i = i + 1 170 } 171 return found 172} 173 174// FORMAT: a powder always fits; a capsule product must stay within max_units. 175func pr_format_ok(p: *NxProduct) -> i64 { 176 if p.format == SF_FORMAT_POWDER { return 1 } 177 let f: *NxSuppFormula = pr_build_formula(p) 178 return sf_fits_in_capsules(f, SI_CAP_00, p.max_units) 179} 180 181// ECONOMICS: the actives budget at the target price/margin is non-negative 182// AND the achieved margin at real COGS clears the target. 183func pr_economics_ok(p: *NxProduct) -> i64 { 184 if p.retail_cents <= 0 { return 0 } 185 let f: *NxSuppFormula = pr_build_formula(p) 186 let cogs: i64 = sf_cogs_per_bottle_cents(f, p.servings, p.format, SI_CAP_00) 187 if cogs == SI_INVALID { return 0 } 188 let margin: i64 = sf_gross_margin_permil(p.retail_cents, cogs) 189 if margin == SI_INVALID { return 0 } 190 if margin >= p.target_margin_permil { return 1 } 191 return 0 192} 193 194func pr_dim_ok(p: *NxProduct, d: i64) -> i64 { 195 if d == PR_LEGAL { return pr_legal_ok(p) } 196 if d == PR_FORMAT { return pr_format_ok(p) } 197 if d == PR_ECONOMICS { return pr_economics_ok(p) } 198 if d == PR_IDENTITY { return p.identity_ready } 199 if d == PR_MANUFACTURING { return p.gmp_qualified } 200 if d == PR_CLAIMS { return p.claims_reviewed } 201 if d == PR_COA { return p.coa_on_file } 202 return 0 203} 204 205// ===== The plan ======================================================= 206 207// The FIRST blocking dimension in kill order, or PR_READY if none block. 208// This is the single "do this next" answer. 209func pr_first_gap(p: *NxProduct) -> i64 { 210 var d: i64 = 0 211 var gap: i64 = PR_READY 212 while d < PR_N_DIM { 213 if gap == PR_READY { 214 if pr_dim_ok(p, d) != 1 { gap = d } 215 } 216 d = d + 1 217 } 218 return gap 219} 220 221// How many dimensions pass, and the readiness as per-mil of the total. 222func pr_dims_passed(p: *NxProduct) -> i64 { 223 var d: i64 = 0 224 var n: i64 = 0 225 while d < PR_N_DIM { 226 n = n + pr_dim_ok(p, d) 227 d = d + 1 228 } 229 return n 230} 231 232func pr_readiness_permil(p: *NxProduct) -> i64 { 233 let n: i64 = pr_dims_passed(p) 234 return n * 1000 / PR_N_DIM 235} 236 237func pr_is_production_ready(p: *NxProduct) -> i64 { 238 if pr_first_gap(p) == PR_READY { return 1 } 239 return 0 240} 241 242// How many of the OPEN gaps are operator attestations (dims 3..6) vs computed 243// blockers (0..2). Tells whether the remaining work is "do a thing" or 244// "the concept itself needs changing". 245func pr_open_attestations(p: *NxProduct) -> i64 { 246 var d: i64 = PR_IDENTITY 247 var n: i64 = 0 248 while d < PR_N_DIM { 249 if pr_dim_ok(p, d) != 1 { n = n + 1 } 250 d = d + 1 251 } 252 return n 253} 254 255func pr_open_computed_blockers(p: *NxProduct) -> i64 { 256 var d: i64 = 0 257 var n: i64 = 0 258 while d < PR_IDENTITY { 259 if pr_dim_ok(p, d) != 1 { n = n + 1 } 260 d = d + 1 261 } 262 return n 263}