Skip to content

Commit

Permalink
updates for entity gender/birthsex/race
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Aug 17, 2023
1 parent b7e5edc commit 07a7b55
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/engine/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ private Map<String, Object> pickDemographics(RandomNumberGenerator random, Demog
gender = "F";
}
}
demographicsOutput.put(Person.BIRTH_SEX, gender);
demographicsOutput.put(Person.GENDER, gender);

// Pick the person's socioeconomic variables of education/income/occupation based on location.
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,26 @@ private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long

Extension birthSexExtension = new Extension(
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
if (person.attributes.get(Person.GENDER).equals("M")) {
patientResource.setGender(AdministrativeGender.MALE);
if (person.attributes.get(Person.BIRTH_SEX).equals("M")) {
birthSexExtension.setValue(new CodeType("M"));
} else if (person.attributes.get(Person.GENDER).equals("F")) {
patientResource.setGender(AdministrativeGender.FEMALE);
} else if (person.attributes.get(Person.BIRTH_SEX).equals("F")) {
birthSexExtension.setValue(new CodeType("F"));
} else if (person.attributes.get(Person.GENDER).equals("UNK")) {
} else if (person.attributes.get(Person.BIRTH_SEX).equals("UNK")) {
patientResource.setGender(AdministrativeGender.UNKNOWN);
}
if (USE_US_CORE_IG) {
patientResource.addExtension(birthSexExtension);
}

if (person.attributes.get(Person.GENDER).equals("M")) {
patientResource.setGender(AdministrativeGender.MALE);
} else if (person.attributes.get(Person.GENDER).equals("F")) {
patientResource.setGender(AdministrativeGender.FEMALE);
} else if (person.attributes.get(Person.GENDER).equals("UNK")) {
patientResource.setGender(AdministrativeGender.UNKNOWN);
}


String state = (String) person.attributes.get(Person.STATE);
if (USE_US_CORE_IG) {
if (state.length() > 2) {
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/mitre/synthea/identity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class Entity implements Serializable {
private List<Seed> seeds;
private LocalDate dateOfBirth;
private String gender;
private String sexAtBirth;
private String ombRaceCategory;
private String socioeconomicLevel;
private String individualId;
private String housingStatus;

Expand Down Expand Up @@ -102,4 +105,62 @@ public String getHousingStatus() {
public void setHousingStatus(String housingStatus) {
this.housingStatus = housingStatus;
}

public String getSexAtBirth() {
return sexAtBirth;
}

public void setSexAtBirth(String sexAtBirth) {
this.sexAtBirth = sexAtBirth;
}

public String getOmbRaceCategory() {
return ombRaceCategory;
}

public String getSyntheaRace() {
if (ombRaceCategory == null || ombRaceCategory.trim().isEmpty()) {
return null;
}
switch (ombRaceCategory) {
case "American Indian/Alaska Native":
return "native";
case "Asian":
return "asian";
case "Black/African American":
return "black";
case "Hispanic/Latino":
// TODO
return "white";
case "Multiple races":
return "other";
case "White":
return "white";
default:
throw new IllegalArgumentException("Unexpected ombRaceCategory: " + ombRaceCategory);
}

}

public String getSyntheaEthnicity() {
if (ombRaceCategory == null) {
return null;
} else if (ombRaceCategory.equals("Hispanic/Latino")) {
return "hispanic";
} else {
return "nonhispanic";
}
}

public void setOmbRaceCategory(String ombRaceCategory) {
this.ombRaceCategory = ombRaceCategory;
}

public String getSocioeconomicLevel() {
return socioeconomicLevel;
}

public void setSocioeconomicLevel(String socioeconomicLevel) {
this.socioeconomicLevel = socioeconomicLevel;
}
}
15 changes: 12 additions & 3 deletions src/main/java/org/mitre/synthea/identity/EntityDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class EntityDeserializer implements JsonDeserializer<Entity> {
@Override
public Entity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
Entity entity = new Entity();
JsonObject entityObject = json.getAsJsonObject();
entity.setIndividualId(entityObject.getAsJsonPrimitive("individualId").getAsString());
entity.setGender(entityObject.getAsJsonPrimitive("gender").getAsString());

Function<String, String> getString = (fieldName) -> {
if (!entityObject.has(fieldName)) return null;
return entityObject.getAsJsonPrimitive(fieldName).getAsString();
};
entity.setIndividualId(getString.apply("individualId"));
entity.setGender(getString.apply("gender"));
entity.setSexAtBirth(getString.apply("sexAtBirth"));
entity.setOmbRaceCategory(getString.apply("ombRaceCategory"));
entity.setSocioeconomicLevel(getString.apply("socioeconomicLevel"));
entity.setDateOfBirth(LocalDate.parse(
entityObject.getAsJsonPrimitive("dateOfBirth").getAsString(),
getString.apply("dateOfBirth"),
DateTimeFormatter.ISO_LOCAL_DATE));
List<Seed> seeds = new ArrayList<>();
entityObject.getAsJsonArray("seeds").forEach(seedElement -> {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/mitre/synthea/identity/Seed.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Seed implements IdentityRecord, Serializable {
private Period period;
private String givenName;
private String familyName;
private String gender;
private String phone;
private List<String> addressLines;
private String city;
Expand Down Expand Up @@ -59,6 +60,10 @@ public void setGivenName(String givenName) {
public void setFamilyName(String familyName) {
this.familyName = familyName;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setPhone(String phone) {
this.phone = phone;
Expand Down Expand Up @@ -108,7 +113,7 @@ public LocalDate getDateOfBirth() {

@Override
public String getGender() {
return entity.getGender();
return gender;
}

@Override
Expand Down Expand Up @@ -177,6 +182,15 @@ public Map<String, Object> demographicAttributesForPerson() {
attributes.put(Person.NAME, this.givenName + " " + this.familyName);
attributes.put(Person.TELECOM, this.getPhone());
attributes.put(Person.GENDER, this.getGender());
attributes.put(Person.BIRTH_SEX, this.entity.getSexAtBirth());

// TODO
// attributes.put(Person.SOCIOECONOMIC_CATEGORY, ???)
// this.entity.getSocioeconomicLevel()

attributes.put(Person.RACE, this.entity.getSyntheaRace());
attributes.put(Person.ETHNICITY, this.entity.getSyntheaEthnicity());

attributes.put(Person.STATE, this.state);
attributes.put(Person.CITY, WordUtils.capitalizeFully(this.city));
attributes.put(Person.ADDRESS, this.addressLines.stream()
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/mitre/synthea/world/agents/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class Person implements Serializable, RandomNumberGenerator, QuadTreeElem
public static final String ETHNICITY = "ethnicity";
public static final String FIRST_LANGUAGE = "first_language";
public static final String GENDER = "gender";
public static final String BIRTH_SEX = "birth_sex";

public static final String MULTIPLE_BIRTH_STATUS = "multiple_birth_status";
public static final String TELECOM = "telecom";
public static final String ID = "id";
Expand Down

0 comments on commit 07a7b55

Please sign in to comment.