Opium Quality Checker — Quality control of Opium (poppy latex)
⚠️ FOR LICENSED PHARMACEUTICAL USE ONLY
ℹ️ The utility checks morphine, codeine, thebaine content, loss on drying, and total ash.
ℹ️ Related to universal utilities: HerbalDrugQualityChecker, ImpurityThresholdChecker.
Usage:
OpiumQualityChecker.exe → demo mode (console output)
OpiumQualityChecker.exe input.csv output.json → evaluate your data
Input format:
BatchNumber,Morphine_percent,Codeine_percent,Thebaine_percent,LossOnDrying_percent,TotalAsh_percent
Example:
OPI20250110,12.0,1.2,0.8,10.5,7.8
📌 Analytical method: HPLC or titrimetry. Ph. Eur. 1673 requirements:
- Morphine ≥10.0%,
- Codeine ≤3.0%,
- Thebaine ≤1.5%,
- Loss on drying ≤12.0%,
- Total ash ≤8.0%.
input.csv
BatchNumber,Morphine_percent,Codeine_percent,Thebaine_percent,LossOnDrying_percent,TotalAsh_percent OPI20250110,12.0,1.2,0.8,10.5,7.8
URS & FS — user requirements and functional specification
This document defines user requirements and functional specification for the quality-control utility. It supports deployment discussion, IQ/OQ preparation and QC workflow integration.
1. Scope
The Opium Quality Checker utility is used for Opium. The actual input.csv is the source of truth for the input structure; control criteria are defined by the executable and the domain description.
The utility does not use machine learning; decisions are produced by deterministic rules.
Categories: Herbal pharmacopoeia
Tags: ash, BHP, botanical, herbal, impurities, loss on drying, markers
2. Execution modes
OpiumQualityChecker.exe → demo mode (console output) OpiumQualityChecker.exe input.csv output.json → evaluate your data
3. Key controlled areas
- pH and physicochemical parameters
4. Domain limits and critical parameters
- ⚠️ FOR LICENSED PHARMACEUTICAL USE ONLY
- Morphine ≥10.0%,
- Codeine ≤3.0%,
- Thebaine ≤1.5%,
- Loss on drying ≤12.0%,
- Total ash ≤8.0%.
5. URS — user requirements
| ID | Requirement | Criticality | Acceptance criterion |
|---|---|---|---|
| URS-001 | The system shall accept an input.csv file for Opium with the exact columns listed in the “Input data contract” section. | High | A file with the correct header is processed without manual editing; missing mandatory columns produce FAIL/import error. |
| URS-002 | The system shall support execution without arguments in demo mode and execution with input.csv output.json for user data. | Medium | Both execution scenarios produce a predictable result or clear diagnostic error. |
| URS-003 | The system shall perform rule-based controls for: pH and physicochemical parameters. | High | Each controlled parameter receives a status and message; the result does not depend on hidden Excel formulas or ML. |
| URS-004 | The system shall preserve traceability between batch/lot, source values, applied rules and final verdict. | High | Output includes batch identifier, source values, parameter statuses and critical findings. |
| URS-005 | The system shall generate machine-readable output.json for LIMS/ELN/MES, batch record and QA/QC review. | High | JSON contains overall status, check array, warnings, failures and source-file reference. |
| URS-006 | The system shall support use in the client validation package: URS/FS, IQ/OQ preparation, installation and operational scenario checks. | High | The document, test scenarios and reproducible CSV/JSON flow are suitable for audit and internal approval. |
| URS-007 | The system shall clearly separate technical data errors from specification nonconformities. | Medium | Schema/type errors are not mixed with pharmacopoeial deviations and are reported separately. |
6. input.csv data contract
The source of truth for the input schema is the actual input.csv header. Column names are technical identifiers and are not translated.
| # | Column | Type | Unit | Description | Sample | Control rule |
|---|---|---|---|---|---|---|
| 1 | BatchNumber | identifier | as specified | Batch Number | OPI20250110 | mandatory field; used for batch/lot traceability |
| 2 | Morphine_percent | decimal | % | Morphine percent | 12.0 | mandatory numeric value; rule comparison is performed by the utility |
| 3 | Codeine_percent | decimal | % | Codeine percent | 1.2 | mandatory numeric value; rule comparison is performed by the utility |
| 4 | Thebaine_percent | decimal | % | Thebaine percent | 0.8 | mandatory numeric value; rule comparison is performed by the utility |
| 5 | LossOnDrying_percent | decimal | % | Loss On Drying percent | 10.5 | mandatory numeric value; rule comparison is performed by the utility |
| 6 | TotalAsh_percent | decimal | % | Total Ash percent | 7.8 | mandatory numeric value; rule comparison is performed by the utility |
CSV example
BatchNumber,Morphine_percent,Codeine_percent,Thebaine_percent,LossOnDrying_percent,TotalAsh_percent OPI20250110,12.0,1.2,0.8,10.5,7.8
7. FS — functional specification
| ID | Function | Implementation description |
|---|---|---|
| FS-001 | CLI entry point | The executable OpiumQualityChecker.exe supports demo mode and input.csv output.json processing mode. |
| FS-002 | CSV parser | The import module reads CSV, validates header, column presence/order, value count and encoding. Decimal values are expected with a dot separator. |
| FS-003 | Field conversion | Each column is converted to the expected type: identifier, text, decimal number, date/time or boolean flag. |
| FS-004 | Domain rule engine | For Opium, explicit rules are applied: range, minimum, maximum, absence of prohibited flag, data completeness or calculation-based check. |
| FS-005 | Criticality handling | Critical violations produce FAIL; non-critical deviations and incomplete data produce WARNING; full conformance produces PASS. |
| FS-006 | JSON writer | output.json stores overall status, per-parameter results, source values, warnings, failures and diagnostic messages. |
| FS-007 | Integration contract | The CSV → JSON format is stable for invocation from LIMS/ELN/MES, scheduled task or wrapper service. |
| FS-008 | Error handling | Schema error, missing file, non-numeric value or JSON write failure returns diagnosable error without silent PASS. |
8. output.json contract
The output file must be suitable for automated processing, audit review and correlation with the source input.csv row.
{
"utility": "OpiumQualityChecker",
"api": "Opium",
"batchNumber": "OPI20250110",
"overallStatus": "PASS|WARNING|FAIL",
"checkedAtUtc": "2026-05-18T00:00:00Z",
"checks": [
{
"parameter": "BatchNumber",
"value": "OPI20250110",
"unit": "as specified",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
},
{
"parameter": "Morphine_percent",
"value": "12.0",
"unit": "%",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
},
{
"parameter": "Codeine_percent",
"value": "1.2",
"unit": "%",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
},
{
"parameter": "Thebaine_percent",
"value": "0.8",
"unit": "%",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
},
{
"parameter": "LossOnDrying_percent",
"value": "10.5",
"unit": "%",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
},
{
"parameter": "TotalAsh_percent",
"value": "7.8",
"unit": "%",
"status": "PASS|WARNING|FAIL",
"message": "Rule-based check result"
}
],
"criticalFindings": [],
"sourceFile": "input.csv"
}9. OQ/PQ test scenarios
| ID | Scenario | Expected result |
|---|---|---|
| TC-001 | Valid CSV with expected header and sample row | All rows are processed; output contains PASS/WARNING/FAIL and parameter-level detail. |
| TC-002 | A mandatory input.csv column is missing | Import is rejected or the row receives FAIL with schema reference. |
| TC-003 | A numeric field contains text or a blank value | Type conversion error is recorded; the result is not hidden as PASS. |
| TC-004 | A parameter is outside specification or critical limit | Critical parameters produce FAIL; non-critical deviations produce WARNING according to the rule. |
10. QA/QC, CSV and change control
- Before production use, the client records executable version, checksum, specification/monograph version, test CSV, expected JSON and IQ/OQ results.
- Column names must not be changed without updating the validator and test scenarios.
- The source CSV, output.json and utility version should be stored together as an evidence package.
- Any change in control rules must go through change control and repeated OQ scenario verification.
Included in packages
Addiction Medicine & Controlled Substances QC Suite
QC utility package for addiction medicine and regulated medicinal products: addiction-treatment medicines, opioids, benzodiazepines, stimulants, sedatives, volatile impurities, assay/identity/dissolution/release checks.
OpenBritish Herbal Pharmacopoeia QC Suite
Large utility package for herbal drugs, botanicals and phytopharmaceutical monographs.
OpenNeurology QC Suite
QC package for neurology and neuropsychiatry: antiepileptics, antiparkinsonian medicines, antidepressants, antipsychotics, analgesics and neurological diagnostic radiopharmaceuticals.
Open