Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
What changed in OpenBGA Interface Engine, grouped by release with unreleased changes on
top, then by impact. Types follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased (2026-11-12 to 2026-11-24)
## Unreleased (2026-11-12 to 2026-11-25)

### High impact

Expand Down Expand Up @@ -173,6 +173,22 @@ top, then by impact. Types follow [Keep a Changelog](https://keepachangelog.com/

### Medium impact

- **Fixed:** Multi-page newborn screening reports and dates without a time are read (2026-11-25)

The newborn screening report preset now reads reports that run to two or more pages, where
the footer repeats the date of birth without its time, and reports that print the date of
birth or the collection date without a time. Such reports were refused as not matching the
template; now the HL7 message carries the date alone when the report prints no time.

Technical notes:

New PDF template field setting `first_page_only` (default `false`): the field is read on
page 1 only. Profile `pdf_newborn_screening_report`: `dob` has `first_page_only: true`;
`dob` and `collected` are `type: date` with formats `M/d/yyyy HH:mm` and `M/d/yyyy`.
Mapping `pdf_newborn_screening_to_hl7_oru`: PID-7, OBR-7 and SPM-17 are written as
`yyyyMMddHHmm` when the value has a time, otherwise `yyyyMMdd`. Channels created from the
earlier presets keep their settings; apply the presets again or make the same edits.

- **Changed:** PDF reports are filed by date inside their outcome folders (2026-11-24)

When a PDF report channel moves an incoming PDF after reading it, the engine now places the
Expand Down
20 changes: 20 additions & 0 deletions changelog.d/2026-11-25-pdf-report-pages-and-dates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
date: 2026-11-25
type: fixed
impact: medium
title: Multi-page newborn screening reports and dates without a time are read
area: Channels
---
The newborn screening report preset now reads reports that run to two or more pages, where
the footer repeats the date of birth without its time, and reports that print the date of
birth or the collection date without a time. Such reports were refused as not matching the
template; now the HL7 message carries the date alone when the report prints no time.

## Technical notes

New PDF template field setting `first_page_only` (default `false`): the field is read on
page 1 only. Profile `pdf_newborn_screening_report`: `dob` has `first_page_only: true`;
`dob` and `collected` are `type: date` with formats `M/d/yyyy HH:mm` and `M/d/yyyy`.
Mapping `pdf_newborn_screening_to_hl7_oru`: PID-7, OBR-7 and SPM-17 are written as
`yyyyMMddHHmm` when the value has a time, otherwise `yyyyMMdd`. Channels created from the
earlier presets keep their settings; apply the presets again or make the same edits.
4 changes: 4 additions & 0 deletions console/src/ipc/generated/PdfField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ position: FieldPosition,
* Which match of the label on a page: 0 the first, −1 the last; −1 to 20. Default 0.
*/
occurrence: number,
/**
* Read on page 1 only; the label on later pages is ignored. Default `false`.
*/
first_page_only: boolean,
/**
* `below` only: the block line, 1–20. Default 1.
*/
Expand Down
102 changes: 83 additions & 19 deletions crates/packie-config/profiles/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@
{
"name": "dob",
"label": "DOB:",
"type": "datetime",
"format": "M/d/yyyy HH:mm"
"first_page_only": true,
"type": "date",
"format": [
"M/d/yyyy HH:mm",
"M/d/yyyy"
]
},
{
"name": "birth_order",
Expand Down Expand Up @@ -163,8 +167,11 @@
{
"name": "collected",
"label": "Date Collected:",
"type": "datetime",
"format": "M/d/yyyy HH:mm"
"type": "date",
"format": [
"M/d/yyyy HH:mm",
"M/d/yyyy"
]
},
{
"name": "sample_id",
Expand Down Expand Up @@ -1416,11 +1423,30 @@
]
},
{
"op": "datetime",
"from": "field.dob",
"to": "PID.7",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
"op": "when",
"condition": {
"path": "field.dob",
"op": "matches",
"value": ":"
},
"then": [
{
"op": "datetime",
"from": "field.dob",
"to": "PID.7",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
}
],
"else": [
{
"op": "datetime",
"from": "field.dob",
"to": "PID.7",
"input": "M/d/yyyy",
"output": "yyyyMMdd"
}
]
},
{
"op": "lookup",
Expand Down Expand Up @@ -1650,11 +1676,30 @@
"to": "OBR.4.3"
},
{
"op": "datetime",
"from": "field.collected",
"to": "OBR.7",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
"op": "when",
"condition": {
"path": "field.collected",
"op": "matches",
"value": ":"
},
"then": [
{
"op": "datetime",
"from": "field.collected",
"to": "OBR.7",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
}
],
"else": [
{
"op": "datetime",
"from": "field.collected",
"to": "OBR.7",
"input": "M/d/yyyy",
"output": "yyyyMMdd"
}
]
},
{
"op": "datetime",
Expand Down Expand Up @@ -1779,11 +1824,30 @@
"to": "SPM.2"
},
{
"op": "datetime",
"from": "field.collected",
"to": "SPM.17",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
"op": "when",
"condition": {
"path": "field.collected",
"op": "matches",
"value": ":"
},
"then": [
{
"op": "datetime",
"from": "field.collected",
"to": "SPM.17",
"input": "M/d/yyyy HH:mm",
"output": "yyyyMMddHHmm"
}
],
"else": [
{
"op": "datetime",
"from": "field.collected",
"to": "SPM.17",
"input": "M/d/yyyy",
"output": "yyyyMMdd"
}
]
},
{
"op": "datetime",
Expand Down
3 changes: 3 additions & 0 deletions crates/packie-config/src/protocol/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub struct PdfField {
/// Which match of the label on a page: 0 the first, −1 the last; −1 to 20. Default 0.
#[serde(default)]
pub occurrence: i32,
/// Read on page 1 only; the label on later pages is ignored. Default `false`.
#[serde(default)]
pub first_page_only: bool,
/// `below` only: the block line, 1–20. Default 1.
#[serde(default)]
pub line: Option<u32>,
Expand Down
11 changes: 11 additions & 0 deletions crates/packie-config/tests/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,14 @@ fn an_oml_specimen_id_with_a_namespace_is_sent_as_the_bare_identifier() {
let sent = run_on(&preset, &input).expect("accepted");
assert!(sent.contains("O|1|SPEC1234|"), "{sent:?}");
}

#[test]
fn a_newborn_report_without_times_sends_dates() {
let preset = preset("pdf_newborn_screening_to_hl7_oru");
let input = changed(&preset.sample.input, "dob: 1/2/2026 08:05", "dob: 1/2/2026");
let input = changed(&input, "collected: 1/3/2026 10:00", "collected: 1/3/2026");
let sent = run_on(&preset, &input).expect("accepted");
assert!(sent.contains("|DOE^TEST BABY||20260102|F|"), "{sent:?}");
assert!(sent.contains("|INITIAL^Initial^L|||20260103|"), "{sent:?}");
assert!(sent.ends_with("|20260103|20260104\r"), "{sent:?}");
}
1 change: 1 addition & 0 deletions crates/packie-engine/src/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn field(field: &PdfField) -> packie_pdf::Field {
labels: field.label.to_vec(),
position,
occurrence: field.occurrence,
first_page_only: field.first_page_only,
required: field.required,
}
}
1 change: 1 addition & 0 deletions crates/packie-pdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
//! labels: vec!["Lab Number:".into()],
//! position: Position::Right,
//! occurrence: 0,
//! first_page_only: false,
//! required: true,
//! }],
//! ..Template::default()
Expand Down
7 changes: 6 additions & 1 deletion crates/packie-pdf/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct Field {
pub position: Position,
/// Which match of the label on a page: 0 the first, 1 the second, −1 the last.
pub occurrence: i32,
/// Read on page 1 only; the label on later pages (a footer repeating it) is ignored.
pub first_page_only: bool,
/// The label must be on page 1 with a value.
pub required: bool,
}
Expand Down Expand Up @@ -125,7 +127,10 @@ impl Template {
if number == 0 {
page.check_label_area(&hits, &ends)?;
}
for (index, value) in page.values(&hits, &self.fields) {
let fields = page.values(&hits, &self.fields).into_iter();
for (index, value) in
fields.filter(|(i, _)| number == 0 || !self.fields[*i].first_page_only)
{
found[index].push((number, value));
}
}
Expand Down
33 changes: 33 additions & 0 deletions crates/packie-pdf/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ fn right(name: &str, label: &str) -> Field {
labels: vec![label.into()],
position: Position::Right,
occurrence: 0,
first_page_only: false,
required: false,
}
}
Expand Down Expand Up @@ -321,6 +322,38 @@ fn conflicting_pages_are_refused() {
);
}

#[test]
fn a_first_page_field_ignores_its_label_on_later_pages() {
// Page 2 carries only the footer, which repeats the birth date without its time.
let footer = |page: &str| Run {
size: 8.0,
..run(400.0, 760.0, &format!("Page {page} of 2 DOB: 1/2/2026"))
};
let mut first = report_page();
first.runs.retain(|r| !r.text.starts_with("Page "));
first.runs.push(footer("1"));
let bytes = pdf(&[first, Page::new(vec![footer("2")])]);
let (reason, detail) = reason(read(&bytes));
assert_eq!(reason, Reason::TemplateMismatch);
assert_eq!(
detail,
"field \"dob\" has different values on pages 1 and 2"
);

let mut template = template();
let dob = template
.fields
.iter_mut()
.find(|f| f.name == "dob")
.unwrap();
dob.first_page_only = true;
let report = template
.read(&extract(&bytes, &Limits::default()).unwrap())
.unwrap();
assert_eq!(report.pages, 2);
assert_values(&report);
}

#[test]
fn unknown_label_in_the_label_area_is_refused() {
let mut page = report_page();
Expand Down
1 change: 1 addition & 0 deletions crates/packie-pdf/tests/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn template() -> Template {
labels: vec![label.into()],
position,
occurrence: 0,
first_page_only: false,
required: false,
};
Template {
Expand Down
1 change: 1 addition & 0 deletions docs/spec/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ Source only. Behavior, matching rules and the model are in [pdf-reports.md](pdf-
| `label` | string or array | none | 1–100 characters, or an array of 1–8 such strings. |
| `position` | string | `right` | `right` or `below`. |
| `occurrence` | integer | `0` | −1 to 20. |
| `first_page_only` | boolean | `false` | |
| `line` | integer | `1` | 1–20; only with `below`. |
| `phrase` | integer | `0` | −1 to 20 (−1 the last phrase of the line); only with `below`. |
| `indent` | number | `4` | 0–600 points, at most 2 decimal places; only with `below`. |
Expand Down
9 changes: 5 additions & 4 deletions docs/spec/pdf-reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ that follow them on the same line (a footer written as one run of text,
| `label` | One label, or 1–8 alternative labels; the first that is found on the page is used. |
| `position` | `right` (default): the value is on the label's line. `below`: the value is in the block of lines under the label. |
| `occurrence` | Which match of the label on a page: 0 the first in reading order (default), 1 the second, −1 the last. |
| `first_page_only` | `true`: the field is read on page 1 only and its label on later pages is ignored, for a label that a footer repeats with a different value (a grid's `DOB: 1/2/2026 08:05` and a footer's `DOB: 1/2/2026`). Default `false`. |
| `line`, `phrase`, `indent` | `below` only, see below. |
| `required` | `true`: the label is found on page 1 and its value is not empty; otherwise `template_mismatch`. `false` (default): a missing label or value is an empty field. |
| `type`, `format` | As delimited columns: `string` (default), `integer`, `decimal`, `date`, `datetime`; `format` is required for dates and may be an array of 1–4 formats, the first that matches the whole value wins. A non-empty value that matches no format, or is not an integer or decimal, is `field_invalid`. Values stay text in the model. |
Expand All @@ -107,8 +108,8 @@ default 1); a missing line or phrase is an empty value. The last phrase finds a
the right of a row whatever precedes it, such as a facility code after a name the report may
leave blank (give `indent` enough room for a row that starts at the code).

**Pages.** A field is evaluated on every page where its label occurs, with `occurrence`
counted on that page. Every page that yields a non-empty value must yield the same value;
**Pages.** A field is evaluated on every page where its label occurs (page 1 only with
`first_page_only`), with `occurrence` counted on that page. Every page that yields a non-empty value must yield the same value;
otherwise the report is `invalid` (`template_mismatch`, the field and pages named). A file
that holds several reports is refused this way, because their patient fields differ.

Expand Down Expand Up @@ -191,8 +192,8 @@ own reports before clinical use.

| Profile | Content |
| --- | --- |
| `pdf_newborn_screening_report` (connector, source) | Every label of the patient, specimen and collection grid as a `right` field, none required (`patient_name`, `gender`, `mother_name`, `dob`, `birth_order`, `mother_dob`, `race`, `birth_weight`, `mother_phone`, `medical_record`, `gestational_age`, `meconium_ileus`, `kit_number`, `nicu`, `collected`, `sample_id` = `Lab Number:`, `age_at_collection`, `received`, `specimen_type`, `transfusion_date`, `reported`, `food_source`, `collection_weight`, `printed`); the footer's `last_name` (`occurrence` −1), `accession_number` and `Reported Date:`; the report recipient's first line as a `below` field (`recipient`, `indent` 60; the rows after it vary between reports and are not read); the birth hospital, collection facility and physician or clinic (`Physician/Clinic`, printed without a colon) as `below` fields, each with its facility code as the last phrase of the row (`phrase` −1, `indent` 170: `birth_hospital_code`, `collection_facility_code`, `physician_facility_code`), which is found also when the report leaves the facility's name blank. `label_area_end`: `Results`. |
| `pdf_newborn_screening_to_hl7_oru` (mapping) | `ORU^R01^ORU_R01` for an `hl7_file` destination; the Lab Number identifies the patient and the order. `PID-2`, `PID-3` (`<Lab Number>^^^<assigning authority>^PI`), `PID-18` = `sample_id`; `PID-5` family name `last_name`, given names `patient_name` without it (`strip_suffix`); `PID-7` `dob`; `PID-8` through the `sex` table; `PID-10` through the `race` table; `PID-16` `S`. `NK1` when the report names the mother: `NK1-2` `mother_name`, `NK1-3` `MTH`, `NK1-5` `mother_phone`, `NK1-7` `N`. `PV1-2` `N`; `PV1-3.4` `birth_hospital_code`; `PV1-4` `N`; `PV1-7` and `PV1-8` the report recipient (the ordering provider); `PV1-19` `sample_id`; `PV1-44` `received`. `ORC-1` `RE`, `ORC-3` `sample_id`, `ORC-21` physician or clinic with its facility code, `ORC-23` the laboratory's phone. `OBR-3` `sample_id`; `OBR-4` the panel from `specimen_type`; `OBR-7` `collected`; `OBR-14` `received`; `OBR-16` the report recipient (name without NPI); `OBR-17` the laboratory's phone; `OBR-22` `reported`; `OBR-25` `F`. One `OBX` of type `ED`: `OBX-3` the panel, `OBX-5` `^AP^PDF^Base64^` with `report.file_base64`, `OBX-11` `F`, `OBX-14` `reported`. `SPM-2` `kit_number`, `SPM-17` `collected`, `SPM-18` `received`. The laboratory's phone, the assigning authority and the panel's coding system are constants a deployment fills in; MSH-3 to MSH-6 come from the destination settings. A field the report does not carry leaves its HL7 field empty: no rule is `required` and none writes the HL7 null `""`, which a receiver would read as "delete the stored value". |
| `pdf_newborn_screening_report` (connector, source) | Every label of the patient, specimen and collection grid as a `right` field, none required (`patient_name`, `gender`, `mother_name`, `dob`, `birth_order`, `mother_dob`, `race`, `birth_weight`, `mother_phone`, `medical_record`, `gestational_age`, `meconium_ileus`, `kit_number`, `nicu`, `collected`, `sample_id` = `Lab Number:`, `age_at_collection`, `received`, `specimen_type`, `transfusion_date`, `reported`, `food_source`, `collection_weight`, `printed`); `dob` and `collected` are dates printed with or without a time (`M/d/yyyy HH:mm` or `M/d/yyyy`), and `dob` is read on page 1 only (`first_page_only`), because the footer repeats `DOB:` without the time on every page; the footer's `last_name` (`occurrence` −1), `accession_number` and `Reported Date:`; the report recipient's first line as a `below` field (`recipient`, `indent` 60; the rows after it vary between reports and are not read); the birth hospital, collection facility and physician or clinic (`Physician/Clinic`, printed without a colon) as `below` fields, each with its facility code as the last phrase of the row (`phrase` −1, `indent` 170: `birth_hospital_code`, `collection_facility_code`, `physician_facility_code`), which is found also when the report leaves the facility's name blank. `label_area_end`: `Results`. |
| `pdf_newborn_screening_to_hl7_oru` (mapping) | `ORU^R01^ORU_R01` for an `hl7_file` destination; the Lab Number identifies the patient and the order. `PID-2`, `PID-3` (`<Lab Number>^^^<assigning authority>^PI`), `PID-18` = `sample_id`; `PID-5` family name `last_name`, given names `patient_name` without it (`strip_suffix`); `PID-7` `dob` (to the minute when the report prints a time, otherwise the date; likewise `OBR-7` and `SPM-17`); `PID-8` through the `sex` table; `PID-10` through the `race` table; `PID-16` `S`. `NK1` when the report names the mother: `NK1-2` `mother_name`, `NK1-3` `MTH`, `NK1-5` `mother_phone`, `NK1-7` `N`. `PV1-2` `N`; `PV1-3.4` `birth_hospital_code`; `PV1-4` `N`; `PV1-7` and `PV1-8` the report recipient (the ordering provider); `PV1-19` `sample_id`; `PV1-44` `received`. `ORC-1` `RE`, `ORC-3` `sample_id`, `ORC-21` physician or clinic with its facility code, `ORC-23` the laboratory's phone. `OBR-3` `sample_id`; `OBR-4` the panel from `specimen_type`; `OBR-7` `collected`; `OBR-14` `received`; `OBR-16` the report recipient (name without NPI); `OBR-17` the laboratory's phone; `OBR-22` `reported`; `OBR-25` `F`. One `OBX` of type `ED`: `OBX-3` the panel, `OBX-5` `^AP^PDF^Base64^` with `report.file_base64`, `OBX-11` `F`, `OBX-14` `reported`. `SPM-2` `kit_number`, `SPM-17` `collected`, `SPM-18` `received`. The laboratory's phone, the assigning authority and the panel's coding system are constants a deployment fills in; MSH-3 to MSH-6 come from the destination settings. A field the report does not carry leaves its HL7 field empty: no rule is `required` and none writes the HL7 null `""`, which a receiver would read as "delete the stored value". |

A channel that converts only some hospitals' reports adds a source filter on the birth
hospital's facility code, for example
Expand Down
Loading