Skip to content

Commit

Permalink
add new checks and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoTrabach committed Sep 4, 2023
1 parent 42cc71f commit 5e769ea
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 67 deletions.
47 changes: 39 additions & 8 deletions fhir_utils/fhir/patient/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __post_init__(self):
self.check_gender()
self.check_address()
self.check_telecom()
self.check_nationality
self.check_race()
self.check_ethnicity()

# calculate register quality
self.calculate_register_quality()
Expand Down Expand Up @@ -121,14 +124,13 @@ def check_cns(self):
return True

def check_birth_country(self):
if self.birth_country not in ["B", "E", "N"]:
if not 2 <= len(keep_numeric_characters(self.birth_country)) <= 3:
self._is_valid = False
self._invalid_elements.append("birth_country")
return False
else:
return True


def check_birth_date(self):
is_valid = True
if not is_valid_date_format(self.birth_date):
Expand Down Expand Up @@ -214,6 +216,32 @@ def check_telecom(self):
self._invalid_elements.append("telecom")
return False

def check_race(self):
if self.race != "" and len(self.race) != 2:
self._is_valid = False
self._invalid_elements.append("race")
return False
else:
return True

def check_ethnicity(self):
if self.ethnicity != "" and len(self.ethnicity) != 4:
self._is_valid = False
self._invalid_elements.append("ethnicity")
return False
else:
return True

def check_nationality(self):
if self.nationality not in ["B", "E", "N"]:
self._is_valid = False
self._invalid_elements.append("nationality")
return False
else:
return True

#def check_naturalization(self):
# TODO: check natualization

def calculate_register_quality(self):
counter = 0
Expand All @@ -222,13 +250,16 @@ def calculate_register_quality(self):
"active", "address", "birth_city", "deceased", "nationality",
"naturalization", "mother", "father", "protected_person",
"race", "ethnicity","telecom"]
print(self._invalid_elements)
for p in self.__dict__.items():
if p[0] in quality_properties:
if p[0] in ["address", "telecom"]:
if len(p[1]) > 0 and p[0] not in self._invalid_elements:
counter += 1
print(p[0])
elif p[1] != "" and p[1] != None and p[0] not in self._invalid_elements:
counter += 1
print(p[0])

self.register_quality = int(counter/len(quality_properties) * 100)

Expand Down Expand Up @@ -326,24 +357,24 @@ def to_fhir(self):

# mother
if self.mother != "":
mother = {"extension": [{"url": "relationship",
mother = {"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0",
"extension": [{"url": "relationship",
"valueCode": "mother"},
{"url": "parent",
"valueHumanName": {
"use": "official",
"text": self.mother}}],
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0"}
"text": self.mother}}]}
extension.append(mother)

# father
if self.father != "":
father = {"extension": [{"url": "relationship",
father = {"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0",
"extension": [{"url": "relationship",
"valueCode": "father"},
{"url": "parent",
"valueHumanName": {
"use": "official",
"text": self.father}}],
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0"}
"text": self.father}}]}
extension.append(father)

# race and ethnicity
Expand Down
174 changes: 174 additions & 0 deletions tests/unit/fhir/resource/test_data/patient_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "TAX"
}
]
},
"system": "https://rnds-fhir.saude.gov.br/NamingSystem/cpf",
"value": "87877669810"
},
{
"use": "official",
"type": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v2-0203",
"code": "HC"
}
]
},
"system": "https://rnds-fhir.saude.gov.br/NamingSystem/cns",
"value": "123456789012345"
}
],
"active": true,
"name": {
"use": "official",
"text": "John Doe"
},
"telecom": [
{
"system": "phone",
"value": "5521123456789",
"use": "home"
}
],
"gender": "male",
"birthDate": "2000-01-01",
"deceasedBoolean": false,
"address": [
{
"use": "home",
"type": "postal",
"line": [
"081",
"SQN BLOCO M",
"604",
"APARTAMENTO",
"ASA NORTE"
],
"city": "315780",
"state": "53",
"postalCode": "70752130"
}
],
"extension": [
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRQualidadeCadastroIndividuo-1.0",
"valuePositiveInt": 100
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0",
"extension": [
{
"url": "relationship",
"valueCode": "mother"
},
{
"url": "parent",
"valueHumanName": {
"use": "official",
"text": "Jane Doe"
}
}
]
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRParentesIndividuo-1.0",
"extension": [
{
"url": "relationship",
"valueCode": "father"
},
{
"url": "parent",
"valueHumanName": {
"use": "official",
"text": "John Doe Sr"
}
}
]
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRRacaCorEtnia-1.0",
"extension": [
{
"url": "race",
"valueCodeableConcept": {
"coding": [
{
"system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BRRacaCor-1.0",
"code": "05"
}
]
}
},
{
"url": "indigenousEthnicity",
"valueCodeableConcept": {
"coding": [
{
"system": "http://www.saude.gov.br/fhir/r4/CodeSystem/BREtniaIndigena-1.0",
"code": "X405"
}
]
}
}
]
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRMunicipio-1.0",
"valueCodeableConcept": {
"coding": [
{
"system": "https://rnds-fhir.saude.gov.br/CodeSystem/BRMunicipio-1.0",
"code": "315780"
}
]
}
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRPais-1.0",
"valueCodeableConcept": {
"coding": [
{
"system": "https://rnds-fhir.saude.gov.br/CodeSystem/BRPais-1.0",
"code": "10"
}
]
}
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRNacionalidade",
"valueCodeableConcept": {
"coding": [
{
"system": "https://rnds-fhir.saude.gov.br/CodeSystem/BRNacionalidade",
"code": "10"
}
]
}
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRNaturalizacao-1.0",
"valueCodeableConcept": {
"coding": [
{
"system": "https://rnds-fhir.saude.gov.br/CodeSystem/BRNaturalizacao-1.0",
"code": "10"
}
]
}
},
{
"url": "http://www.saude.gov.br/fhir/r4/StructureDefinition/BRIndividuoProtegido-1.0",
"valueBoolean": false
}
]
}
Loading

0 comments on commit 5e769ea

Please sign in to comment.