nx_chem_report_json.nx
buildroot/runtime/nx_chem_report_json.nx
about
nx_chem_report_json.nx -- C6.0 milestone: structured JSON report
emitter for LIMS (Laboratory Information Management System) integration.
Real lab workflow:
1. Lab runs adulterant-detection pipeline
2. Substrate emits JSON report to a file or stdout
3. LIMS ingests JSON, applies business rules:
- banned_count > 0 -> auto-reject lot, alert QA
- restricted_count > 0 + label_doesnt_mention -> escalate
- unknown_count > threshold -> retest with method 2
4. Audit trail: JSON archived with sample record + citation
Format (one-line; nx_chem_report_emit_json):
{"sample_id":"...","method":"...","tolerance_ppm":N,
"peaks_analyzed":N,
"matches":[
{"mz":NNN.NNNN,"rt_seconds":N,"compound_id":N,
"name":"...","regulatory":"...","delta_ppm":N,
"citation":"..."},
...
],
"verdict":{"banned":N,"restricted":N,"approved":N,
"unknown":N,"recommendation":"..."}}
Bits-up emitter:
- No JSON library; manual byte emission to caller-provided buffer
- String escape: handles " and \ ; control chars not expected in
citations or compound names
- Q4 decimal -> "DDD.MMMM" zero-padded form
- All emit_* functions return bytes written
dependencies 4 imports · 7 importers
imports: nx_chem.nxnx_chem_molecule.nxnx_chem_adulterant_db.nxnx_chem_peak_list.nx
imported by: nx_chem_report_csv.nxnx_chem_report_csv_test.nxnx_chem_report_json_test.nxnx_supplement.nxnx_supplement_batch.nxnx_supplement_check.nxnx_supplement_csv.nx
structs
| none |
consts
| none |
functions
| 41 | func nx_chem_emit_str(buf: *u8, offset: nx_int, src: *u8) -> nx_int |
| 60 | func nx_chem_emit_str_escaped(buf: *u8, offset: nx_int, src: *u8) -> nx_int |
| 91 | func nx_chem_emit_int(buf: *u8, offset: nx_int, value: nx_int) -> nx_int |
| 128 | func nx_chem_emit_q4(buf: *u8, offset: nx_int, value: nx_int) -> nx_int called by 4: nx_chem_emit_csv_rownx_chem_emit_report_jsond_emit_q4e_emit_q4_padded calls 1: nx_chem_emit_int |
| 154 | func nx_chem_emit_char(buf: *u8, offset: nx_int, ch: nx_int) -> nx_int called by 1: nx_chem_emit_report_json |
| 164 | func nx_chem_emit_regulatory(buf: *u8, offset: nx_int, reg: nx_int) -> nx_int |
| 172 | func nx_chem_verdict_recommendation(n_banned: nx_int, n_restricted: nx_int, n_unknown: nx_int) -> *u8 |
| 189 | func nx_chem_emit_report_json(buf: *u8, peaks: *PeakList, db: *AdulterantDB, sample_id: *u8, tolerance_ppm: nx_int) -> nx_int |
| 286 | func nx_chem_buf_find(haystack: *u8, len: nx_int, needle: *u8) -> nx_int |