DEV Community

Cover image for Validating Medical Device Specs in Python: A Stone Basket Example
SPG Medisafe
SPG Medisafe

Posted on Originally published at spgmedisafe.com

Validating Medical Device Specs in Python: A Stone Basket Example

If you maintain a product catalogue or ERP feed for medical devices, bad specification data is a quiet source of errors. A basket listed with the wrong length or a missing diameter can end up in a tender or an order. Here is a small, practical approach to validating device specs before they are published.

The problem

A ureteroscopic stone retrieval basket has a handful of attributes that buyers filter on: shaft diameter (Fr), working length (cm), cage style, wire count and sterility. Suppliers send these in spreadsheets with inconsistent units and spellings, such as 1.9F, 1.9 Fr or 1.9 french.

Model the data

from dataclasses import dataclass
from typing import Literal

Cage = Literal["helical", "flat-wire", "tipless", "fixed-tip"]

@dataclass
class BasketSpec:
    sku: str
    shaft_fr: float
    length_cm: int
    cage: Cage
    wires: int
    sterile: bool
Enter fullscreen mode Exit fullscreen mode

Normalise before you validate

import re

def parse_fr(value: str) -> float:
    m = re.search(r"(\d+(?:\.\d+)?)", value)
    if not m:
        raise ValueError(f"No diameter in {value!r}")
    return float(m.group(1))
Enter fullscreen mode Exit fullscreen mode

Add sanity checks

def validate(spec: BasketSpec) -> list[str]:
    errors = []
    if not 1.0 <= spec.shaft_fr <= 4.0:
        errors.append("shaft_fr outside expected range")
    if not 50 <= spec.length_cm <= 150:
        errors.append("length_cm outside expected range")
    if spec.wires < 2:
        errors.append("wires must be 2 or more")
    if not spec.sterile:
        errors.append("sterile flag missing")
    return errors
Enter fullscreen mode Exit fullscreen mode

The ranges are placeholders. Take the real limits from each manufacturer's specification sheet rather than hard-coding assumptions.

Fail loudly in your pipeline

Run the validator in CI or in your import job, and reject the batch if any row returns errors. A report listing the SKU and the failing field is much easier for a catalogue team to fix than a silent bad record.

Why it matters

Buyers compare devices on exactly these fields, so clean data means fewer wrong orders and faster quotes. If you want the buyer's side of the story, including cage designs and quality checks, see the full guide: stone retrieval basket guide for buyers.

Note: this is general software advice and not clinical guidance.

Top comments (0)