Skip to content

Commit

Permalink
Remove Gender matching Feature [Executive Order 14168] (#185)
Browse files Browse the repository at this point in the history
## Description
Removing the Gender matching field per [Executive Order
14168](https://www.chcoc.gov/content/initial-guidance-regarding-president-trump%E2%80%99s-executive-order-defending-women).
  • Loading branch information
ericbuckley authored Jan 31, 2025
1 parent 5bff4d1 commit 9942907
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 97 deletions.
4 changes: 0 additions & 4 deletions docs/site/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ linkage evaluation phase. The following features are supported:

: The patient's sex (normalized to `M`, `F`, or `U` for unknown).

`GENDER`

: The gender the patient identifies with in the format of "FEMALE", "MALE", "NON_BINARY", "ASKED_DECLINED" or "UNKNOWN".

`RACE`

: The patient's race in the format of "AMERICAN_INDIAN", "ASIAN", "BLACK", "HAWAIIAN", "WHITE", "OTHER", "ASKED_UNKNOWN" or "UNKNOWN".
Expand Down
2 changes: 0 additions & 2 deletions scripts/gen_seed_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from recordlinker import schemas
from recordlinker.schemas.identifier import Identifier
from recordlinker.schemas.pii import Address
from recordlinker.schemas.pii import Gender
from recordlinker.schemas.pii import Name
from recordlinker.schemas.pii import Race
from recordlinker.schemas.pii import Sex
Expand Down Expand Up @@ -77,7 +76,6 @@ def _generate_random_pii_record(faker):
)
],
race=random.choice(list(Race)),
gender=random.choice(list(Gender)),
identifiers=list(_generate_random_identifiers(random.randint(1, 3), faker)),
)

Expand Down
6 changes: 0 additions & 6 deletions src/recordlinker/hl7/fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def fhir_record_to_pii_record(fhir_record: dict) -> schemas.PIIRecord:
"sex": fhir_record.get("gender"),
"address": fhir_record.get("address", []),
"race": None,
"gender": None,
"telecom": fhir_record.get("telecom", []),
"identifiers": [],
}
Expand All @@ -59,11 +58,6 @@ def fhir_record_to_pii_record(fhir_record: dict) -> schemas.PIIRecord:
for ext in extension.get("extension", []):
if ext.get("url") == "ombCategory":
val["race"] = ext.get("valueCoding", {}).get("display")
if extension.get("url") == "http://hl7.org/fhir/StructureDefinition/individual-genderIdentity":
for ext in extension.get("extension", []):
if ext.get("url") == "value":
for coding in ext.get("valueCodeableConcept", {}).get("coding", []):
val["gender"] = coding.get("display")

return schemas.PIIRecord(**val)

Expand Down
43 changes: 0 additions & 43 deletions src/recordlinker/schemas/pii.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FeatureAttribute(enum.Enum):
STATE = "STATE"
ZIP = "ZIP"
RACE = "RACE"
GENDER = "GENDER"
TELECOM = "TELECOM"
PHONE = "PHONE"
EMAIL = "EMAIL"
Expand Down Expand Up @@ -126,24 +125,6 @@ def __str__(self):
return self.value


class Gender(enum.Enum):
"""
Enum for the Gender field.
"""

FEMALE = "FEMALE"
MALE = "MALE"
NON_BINARY = "NON_BINARY"
ASKED_DECLINED = "ASKED_DECLINED"
UNKNOWN = "UNKNOWN"

def __str__(self):
"""
Return the value of the enum as a string.
"""
return self.value


class Name(pydantic.BaseModel):
"""
The schema for a name record.
Expand Down Expand Up @@ -224,7 +205,6 @@ class PIIRecord(pydantic.BaseModel):
name: typing.List[Name] = []
telecom: typing.List[Telecom] = []
race: typing.Optional[Race] = None
gender: typing.Optional[Gender] = None
identifiers: typing.List[Identifier] = []

@classmethod
Expand Down Expand Up @@ -298,26 +278,6 @@ def parse_race(cls, value):
return race
return Race.OTHER

@pydantic.field_validator("gender", mode="before")
def parse_gender(cls, value):
"""
Prase the gender string into a gender enum
"""
if value:
val = str(value).lower().strip()
try:
return Gender(val)
except ValueError:
if "female" in val:
return Gender.FEMALE
elif "male" in val:
return Gender.MALE
elif "nonbinary" in val:
return Gender.NON_BINARY
elif "declined" in val or "asked" in val:
return Gender.ASKED_DECLINED
return Gender.UNKNOWN

def to_json(self, prune_empty: bool = False) -> str:
"""
Convert the PIIRecord object to a JSON string.
Expand Down Expand Up @@ -388,9 +348,6 @@ def feature_iter(self, feature: Feature) -> typing.Iterator[str]:
elif attribute == FeatureAttribute.RACE:
if self.race:
yield str(self.race)
elif attribute == FeatureAttribute.GENDER:
if self.gender:
yield str(self.gender)
elif attribute == FeatureAttribute.TELECOM:
for telecom in self.telecom:
if telecom.value:
Expand Down
1 change: 0 additions & 1 deletion tests/unit/hl7/test_fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def test_fhir_record_to_pii_record():
assert pii_record.telecom[0].value == "123-456-7890"
assert pii_record.telecom[0].system == "phone"
assert str(pii_record.race) == "WHITE"
assert str(pii_record.gender) == "FEMALE"

# identifiers
assert pii_record.identifiers[0].value == "1234567890"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/test_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def test_record_setter(self):
assert patient.data == {}
patient.record = pii.PIIRecord(birthDate="1980-01-01", sex="male")
assert patient.data == {"birth_date": "1980-01-01", "sex": "M"}
patient.record = pii.PIIRecord(birthDate="1980-01-01", sex="male", mrn="", name=[], gender=None)
patient.record = pii.PIIRecord(birthDate="1980-01-01", sex="male", mrn="", name=[])
assert patient.data == {"birth_date": "1980-01-01", "sex": "M", "mrn": "", "name": []}
40 changes: 0 additions & 40 deletions tests/unit/schemas/test_pii.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,51 +181,12 @@ def test_parse_race(self):
record = pii.PIIRecord()
assert record.race is None

def test_parse_gender(self):
# testing verbose genders
record = pii.PIIRecord(gender="identifies as female gender (finding)")
assert record.gender == pii.Gender.FEMALE
record = pii.PIIRecord(gender="identifies as male gender (finding)")
assert record.gender == pii.Gender.MALE
record = pii.PIIRecord(gender="identifies as gender nonbinary")
assert record.gender == pii.Gender.NON_BINARY
record = pii.PIIRecord(gender="asked but declined")
assert record.gender == pii.Gender.ASKED_DECLINED
record = pii.PIIRecord(gender="unknown")
assert record.gender == pii.Gender.UNKNOWN

# testing less verbose genders
record = pii.PIIRecord(gender="Female")
assert record.gender == pii.Gender.FEMALE
record = pii.PIIRecord(gender="identifies female")
assert record.gender == pii.Gender.FEMALE
record = pii.PIIRecord(gender="Male")
assert record.gender == pii.Gender.MALE
record = pii.PIIRecord(gender="identifies male")
assert record.gender == pii.Gender.MALE
record = pii.PIIRecord(gender="nonbinary")
assert record.gender == pii.Gender.NON_BINARY
record = pii.PIIRecord(gender="declined")
assert record.gender == pii.Gender.ASKED_DECLINED

# testing capitalization and leading/trailing spaces
record = pii.PIIRecord(gender=" Unknown ")
assert record.gender == pii.Gender.UNKNOWN

# testing none result
record = pii.PIIRecord(gender="invalid gender")
assert record.gender is pii.Gender.UNKNOWN

record = pii.PIIRecord()
assert record.gender is None

def test_feature_iter(self):
record = pii.PIIRecord(
external_id="99",
birth_date="1980-2-1",
sex="male",
race="unknown",
gender="unknown",
address=[
pii.Address(
line=["123 Main St"],
Expand Down Expand Up @@ -282,7 +243,6 @@ def test_feature_iter(self):
assert list(record.feature_iter(pii.Feature(attribute=pii.FeatureAttribute.FIRST_NAME))) == ["John", "Jane"]
assert list(record.feature_iter(pii.Feature(attribute=pii.FeatureAttribute.LAST_NAME))) == ["Doe", "Smith"]
assert list(record.feature_iter(pii.Feature(attribute=pii.FeatureAttribute.RACE))) == ["UNKNOWN"]
assert list(record.feature_iter(pii.Feature(attribute=pii.FeatureAttribute.GENDER))) == ["UNKNOWN"]
assert list(record.feature_iter(pii.Feature(attribute=pii.FeatureAttribute.TELECOM))) == [
"555-123-4567",
"(555) 987-6543",
Expand Down

0 comments on commit 9942907

Please sign in to comment.