mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): fix editable regions in medical data validator workshop (#65460)
Co-authored-by: Dario <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
+3
-3
@@ -41,9 +41,9 @@ assert medical_records[0].get("patient_id", None) == "P1001"
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
medical_records = [
|
||||
|
||||
]
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
]
|
||||
```
|
||||
|
||||
+1
@@ -87,6 +87,7 @@ medical_records = [
|
||||
'last_visit_id': 'V2304',
|
||||
}
|
||||
]
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
+2
-1
@@ -88,9 +88,10 @@ medical_records = [
|
||||
'last_visit_id': 'V2304',
|
||||
}
|
||||
]
|
||||
--fcc-editable-region--
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+3
-2
@@ -48,11 +48,12 @@ assert medical_records[0].get("patient_id", None) == "P1001"
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
medical_records = [
|
||||
{
|
||||
--fcc-editable-region--
|
||||
'patient_id': 'P1001'
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
]
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+3
-2
@@ -68,13 +68,14 @@ assert medical_records[0].get("gender", None) == "Female"
|
||||
## --seed-contents--
|
||||
|
||||
```py
|
||||
--fcc-editable-region--
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
'age': 34,
|
||||
--fcc-editable-region--
|
||||
'gender': 'Female'
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
]
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -60,6 +60,7 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
--fcc-editable-region--
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -80,5 +81,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+1
-1
@@ -62,6 +62,7 @@ medical_records = """[
|
||||
}
|
||||
]"""
|
||||
--fcc-editable-region--
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -82,5 +83,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+4
-5
@@ -50,7 +50,6 @@ medical_records = [
|
||||
'medications': ['Albuterol'],
|
||||
'last_visit_id': 'V2303',
|
||||
},
|
||||
--fcc-editable-region--
|
||||
{
|
||||
'patient_id': 'P1004',
|
||||
'age': 56,
|
||||
@@ -59,10 +58,11 @@ medical_records = [
|
||||
'medications': ['Ibuprofen', 'Physical Therapy'],
|
||||
'last_visit_id': 'V2304',
|
||||
},
|
||||
|
||||
|
||||
]
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
]
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -83,5 +83,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+3
-3
@@ -51,7 +51,6 @@ medical_records = [
|
||||
'medications': ['Albuterol'],
|
||||
'last_visit_id': 'V2303',
|
||||
},
|
||||
--fcc-editable-region--
|
||||
{
|
||||
'patient_id': 'P1004',
|
||||
'age': 56,
|
||||
@@ -60,10 +59,12 @@ medical_records = [
|
||||
'medications': ['Ibuprofen', 'Physical Therapy'],
|
||||
'last_visit_id': 'V2304',
|
||||
},
|
||||
--fcc-editable-region--
|
||||
"spam",
|
||||
42
|
||||
]
|
||||
--fcc-editable-region--
|
||||
]
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -84,5 +85,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+1
-2
@@ -76,7 +76,6 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -88,6 +87,7 @@ def validate(data):
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
for index, dictionary in enumerate(data):
|
||||
if not isinstance(dictionary, dict):
|
||||
print(f'Invalid format: expected a dictionary at position {index}.')
|
||||
@@ -99,5 +99,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+1
-4
@@ -123,7 +123,6 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -144,13 +143,11 @@ def validate(data):
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
if is_invalid:
|
||||
return False
|
||||
print('Valid format.')
|
||||
return True
|
||||
|
||||
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
-3
@@ -61,7 +61,6 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -90,7 +89,5 @@ def validate(data):
|
||||
print('Valid format.')
|
||||
return True
|
||||
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
-2
@@ -95,7 +95,6 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -125,5 +124,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
-1
@@ -119,5 +119,4 @@ def validate(data):
|
||||
return True
|
||||
|
||||
validate(medical_records)
|
||||
|
||||
```
|
||||
|
||||
+3
-5
@@ -61,17 +61,15 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
+1
-3
@@ -29,6 +29,7 @@ assert _Node(_code).has_import("import re")
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -64,17 +65,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
|
||||
+3
-7
@@ -38,7 +38,6 @@ assert _Node(_code).find_function("find_invalid_records").find_variable("constra
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -74,17 +73,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+1
-1
@@ -108,8 +108,8 @@ def validate(data):
|
||||
|
||||
is_invalid = False
|
||||
|
||||
--fcc-editable-region--
|
||||
for index, dictionary in enumerate(data):
|
||||
--fcc-editable-region--
|
||||
pass
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
+1
-1
@@ -82,9 +82,9 @@ def validate(data):
|
||||
print(f'Invalid format: expected a dictionary at position {index}.')
|
||||
is_invalid = True
|
||||
|
||||
--fcc-editable-region--
|
||||
if is_invalid:
|
||||
return False
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
-2
@@ -77,7 +77,6 @@ def find_invalid_records(
|
||||
constraints = {
|
||||
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
@@ -108,7 +107,6 @@ def validate(data):
|
||||
print('Valid format.')
|
||||
return True
|
||||
|
||||
|
||||
validate(medical_records)
|
||||
--fcc-editable-region--
|
||||
|
||||
|
||||
+3
-7
@@ -45,7 +45,6 @@ _var.is_equivalent(_first) or _var.is_equivalent(_second)
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -81,17 +80,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p', patient_id)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p', patient_id)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+3
-7
@@ -36,7 +36,6 @@ assert _Node(_code).find_function("find_invalid_records").find_variable("constra
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -72,17 +71,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p', patient_id, re.IGNORECASE)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p', patient_id, re.IGNORECASE)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+3
-7
@@ -39,7 +39,6 @@ assert _Node(_code).find_function("find_invalid_records").find_variable("constra
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -75,17 +74,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p\d', patient_id, re.IGNORECASE)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p\d', patient_id, re.IGNORECASE)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+3
-7
@@ -40,7 +40,6 @@ assert _Node(_code).find_function("find_invalid_records").find_variable("constra
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,17 +75,14 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p\d+', patient_id, re.IGNORECASE)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str) and re.search('p\d+', patient_id, re.IGNORECASE)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+4
-7
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(age, int)")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,17 +75,15 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE)
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE)
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
-5
@@ -13,7 +13,6 @@ Using the `and` operator, add a second expression to the value of the `age` key
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
The `age` key of your `constraints` dictionary should have the value of `isinstance(age, int) and age >= 18`.
|
||||
|
||||
```js
|
||||
@@ -33,7 +32,6 @@ _Node(_val).is_equivalent("isinstance(age, int) and age >= 18")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -69,18 +67,15 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
--fcc-editable-region--
|
||||
'age': isinstance(age, int)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+4
-7
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(gender, str) and gender.lower() in ('male'
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,18 +75,16 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18
|
||||
|
||||
}
|
||||
--fcc-editable-region--
|
||||
'age': isinstance(age, int) and age >= 18
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+4
-7
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(diagnosis, str) or diagnosis is None")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,19 +75,17 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
'gender': isinstance(gender, str) and gender.lower() in ('male', 'female')
|
||||
|
||||
}
|
||||
--fcc-editable-region--
|
||||
'gender': isinstance(gender, str) and gender.lower() in ('male', 'female')
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+4
-6
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(medications, list)")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,19 +75,18 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
'gender': isinstance(gender, str) and gender.lower() in ('male', 'female'),
|
||||
'diagnosis': isinstance(diagnosis, str) or diagnosis is None
|
||||
}
|
||||
--fcc-editable-region--
|
||||
'diagnosis': isinstance(diagnosis, str) or diagnosis is None
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
-4
@@ -41,7 +41,6 @@ _Node(_val).is_equivalent("isinstance(medications, list) and [isinstance(i, str)
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -77,11 +76,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
@@ -91,7 +88,6 @@ def find_invalid_records(
|
||||
'medications': isinstance(medications, list)
|
||||
--fcc-editable-region--
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
-4
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(medications, list) and all([isinstance(i,
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,11 +75,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
@@ -90,7 +87,6 @@ def find_invalid_records(
|
||||
'medications': isinstance(medications, list) and [isinstance(i, str) for i in medications]
|
||||
--fcc-editable-region--
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+4
-6
@@ -40,7 +40,6 @@ _Node(_val).is_equivalent("isinstance(last_visit_id, str)")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -76,20 +75,19 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
--fcc-editable-region--
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
'gender': isinstance(gender, str) and gender.lower() in ('male', 'female'),
|
||||
'diagnosis': isinstance(diagnosis, str) or diagnosis is None,
|
||||
'medications': isinstance(medications, list) and all([isinstance(i, str) for i in medications])
|
||||
|
||||
}
|
||||
--fcc-editable-region--
|
||||
'medications': isinstance(medications, list) and all([isinstance(i, str) for i in medications])
|
||||
|
||||
--fcc-editable-region--
|
||||
}
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
-5
@@ -32,7 +32,6 @@ _Node(_val).is_equivalent("isinstance(last_visit_id, str) and re.fullmatch('v\\d
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -68,11 +67,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str) and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
'age': isinstance(age, int) and age >= 18,
|
||||
@@ -82,9 +79,7 @@ def find_invalid_records(
|
||||
--fcc-editable-region--
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
--fcc-editable-region--
|
||||
|
||||
}
|
||||
|
||||
return constraints
|
||||
|
||||
def validate(data):
|
||||
|
||||
+1
-3
@@ -47,7 +47,6 @@ _expr.is_equivalent("key")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -83,11 +82,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -102,6 +99,7 @@ def find_invalid_records(
|
||||
--fcc-editable-region--
|
||||
return constraints
|
||||
--fcc-editable-region--
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
|
||||
+1
-3
@@ -62,7 +62,6 @@ _expr.is_equivalent("key")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -98,11 +97,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -117,6 +114,7 @@ def find_invalid_records(
|
||||
--fcc-editable-region--
|
||||
return [key for key, value in constraints.items()]
|
||||
--fcc-editable-region--
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
|
||||
-5
@@ -26,7 +26,6 @@ not _Node(_code).has_call("print(find_invalid_records(**medical_records[0]))")
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -62,11 +61,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -78,10 +75,8 @@ def find_invalid_records(
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
and re.fullmatch('v\d+', last_visit_id, re.IGNORECASE)
|
||||
}
|
||||
|
||||
return [key for key, value in constraints.items() if not value]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
|
||||
+2
-5
@@ -36,7 +36,6 @@ assert _Node(_code).find_function("validate").find_for_loops()[0].find_bodies()[
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -72,11 +71,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -88,10 +85,8 @@ def find_invalid_records(
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
and re.fullmatch('v\d+', last_visit_id, re.IGNORECASE)
|
||||
}
|
||||
|
||||
return [key for key, value in constraints.items() if not value]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -114,9 +109,11 @@ def validate(data):
|
||||
f'Invalid format: {dictionary} at position {index} has missing and/or invalid keys.'
|
||||
)
|
||||
is_invalid = True
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
if is_invalid:
|
||||
return False
|
||||
print('Valid format.')
|
||||
|
||||
+1
-11
@@ -82,7 +82,6 @@ assert _Node(_code).find_function("validate").find_for_loops()[0].find_bodies()[
|
||||
`) })
|
||||
```
|
||||
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
@@ -90,7 +89,6 @@ assert _Node(_code).find_function("validate").find_for_loops()[0].find_bodies()[
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -126,11 +124,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -142,10 +138,8 @@ def find_invalid_records(
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
and re.fullmatch('v\d+', last_visit_id, re.IGNORECASE)
|
||||
}
|
||||
|
||||
return [key for key, value in constraints.items() if not value]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -175,6 +169,7 @@ def validate(data):
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
if is_invalid:
|
||||
return False
|
||||
print('Valid format.')
|
||||
@@ -188,7 +183,6 @@ validate(medical_records)
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -224,11 +218,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -240,10 +232,8 @@ def find_invalid_records(
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
and re.fullmatch('v\d+', last_visit_id, re.IGNORECASE)
|
||||
}
|
||||
|
||||
return [key for key, value in constraints.items() if not value]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
|
||||
+3
-7
@@ -30,7 +30,6 @@ _if_statements[0].find_bodies()[0].is_ordered("is_invalid = True", "continue") a
|
||||
```py
|
||||
import re
|
||||
|
||||
|
||||
medical_records = [
|
||||
{
|
||||
'patient_id': 'P1001',
|
||||
@@ -66,11 +65,9 @@ medical_records = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def find_invalid_records(
|
||||
patient_id, age, gender, diagnosis, medications, last_visit_id
|
||||
):
|
||||
|
||||
constraints = {
|
||||
'patient_id': isinstance(patient_id, str)
|
||||
and re.fullmatch('p\d+', patient_id, re.IGNORECASE),
|
||||
@@ -82,10 +79,8 @@ def find_invalid_records(
|
||||
'last_visit_id': isinstance(last_visit_id, str)
|
||||
and re.fullmatch('v\d+', last_visit_id, re.IGNORECASE)
|
||||
}
|
||||
|
||||
return [key for key, value in constraints.items() if not value]
|
||||
|
||||
|
||||
def validate(data):
|
||||
is_sequence = isinstance(data, (list, tuple))
|
||||
|
||||
@@ -99,18 +94,19 @@ def validate(data):
|
||||
)
|
||||
|
||||
for index, dictionary in enumerate(data):
|
||||
--fcc-editable-region--
|
||||
if not isinstance(dictionary, dict):
|
||||
print(f'Invalid format: expected a dictionary at position {index}.')
|
||||
is_invalid = True
|
||||
--fcc-editable-region--
|
||||
|
||||
|
||||
if set(dictionary.keys()) != key_set:
|
||||
print(
|
||||
f'Invalid format: {dictionary} at position {index} has missing and/or invalid keys.'
|
||||
)
|
||||
is_invalid = True
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
invalid_records = find_invalid_records(**dictionary)
|
||||
|
||||
if is_invalid:
|
||||
|
||||
Reference in New Issue
Block a user