Repository: NeurodataWithoutBorders/nwbinspector (language: python)

Issue:
[Add Check]: cell and sample id
### What would you like to see added to the NWBInspector?

@satra has requested checks for more complete metadata associated with intracellular electrophysiology patch clamp experiments, including checking for cell and sample ids.

### Pseudocode or other logic of the check

_No response_

### Do you have any interest in helping implement the check function?

Yes, but I would need guidance.

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/NeurodataWithoutBorders/nwbinspector/blob/dev/.github/CODE_OF_CONDUCT.rst)
- [X] Have you ensured this check was not already [requested](https://github.com/neurodatawithoutborders/nwbinspector/issues)?


Discussion / hints:
One tricky thing for this is I think it relies on the dandi icephys extension, so not entirely sure if it ought to be included in our core offering (through fancier autoloading for extensions) or if it all ought to exist on the DANDI side.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6dcdd8c85..61c6391a7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,3 +2,4 @@
 
 ### Improvements
 * Enhanced human-readability of the return message from `check_experimenter_form`. [PR #254](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/254)
+* Add check for existence of ``IntracellularElectrode.cell_id`` (#256)
diff --git a/nwbinspector/__init__.py b/nwbinspector/__init__.py
index d8a1c8d26..a3eb0e290 100644
--- a/nwbinspector/__init__.py
+++ b/nwbinspector/__init__.py
@@ -12,3 +12,4 @@
 from .checks.ophys import *
 from .checks.tables import *
 from .checks.time_series import *
+from .checks.icephys import *
diff --git a/nwbinspector/checks/icephys.py b/nwbinspector/checks/icephys.py
new file mode 100644
index 000000000..0358e6530
--- /dev/null
+++ b/nwbinspector/checks/icephys.py
@@ -0,0 +1,10 @@
+from pynwb.icephys import IntracellularElectrode
+
+from ..register_checks import register_check, Importance, InspectorMessage
+
+
+@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=IntracellularElectrode)
+def check_intracellular_electrode_cell_id_exists(intracellular_electrode: IntracellularElectrode):
+    """Check if the IntracellularElectrode contains a cell_id."""
+    if intracellular_electrode.cell_id is None:
+        return InspectorMessage(message="Please include a unique cell_id associated with this IntracellularElectrode.")


Test patch:
diff --git a/tests/unit_tests/test_icephys.py b/tests/unit_tests/test_icephys.py
new file mode 100644
index 000000000..59e4ee6fa
--- /dev/null
+++ b/tests/unit_tests/test_icephys.py
@@ -0,0 +1,23 @@
+from pynwb.icephys import IntracellularElectrode
+from pynwb.device import Device
+
+from nwbinspector import InspectorMessage, Importance, check_intracellular_electrode_cell_id_exists
+
+
+def test_pass_check_intracellular_electrode_cell_id_exists():
+    device = Device(name="device")
+    ielec = IntracellularElectrode(name="ielec", cell_id="123", device=device, description="an intracellular electrode")
+    assert check_intracellular_electrode_cell_id_exists(ielec) is None
+
+
+def test_fail_check_intracellular_electrode_cell_id_exists():
+    device = Device(name="device")
+    ielec = IntracellularElectrode(name="ielec", device=device, description="an intracellular electrode")
+    assert check_intracellular_electrode_cell_id_exists(ielec) == InspectorMessage(
+        message="Please include a unique cell_id associated with this IntracellularElectrode.",
+        importance=Importance.BEST_PRACTICE_VIOLATION,
+        check_function_name="check_intracellular_electrode_cell_id_exists",
+        object_type="IntracellularElectrode",
+        object_name="ielec",
+        location="/",
+    )