Skip to content

Commit f29b5c6

Browse files
authored
Alphanumeric sep id 497 (#501)
* Getting there * SEP ID should now accept alphanumeric strings. Lowercaseness is enforced on creation and search. * Fixed backend tests and made sep id unique in model.
1 parent ff3398a commit f29b5c6

File tree

13 files changed

+51
-32
lines changed

13 files changed

+51
-32
lines changed

core/fixtures/participants.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
race: black (african american)
1010
date_of_birth: 1963-02-17
1111
start_date: 2019-04-21
12-
sep_id: 12345
12+
sep_id: abc12345
1313
maiden_name: momjordan
1414

1515
- model: core.participant
@@ -23,7 +23,7 @@
2323
race: white (caucasian)
2424
date_of_birth: 1961-01-26
2525
start_date: 2019-04-21
26-
sep_id: 12346
26+
sep_id: abr12346
2727
maiden_name: dwayne
2828

2929

@@ -38,7 +38,7 @@
3838
race: black (african american)
3939
date_of_birth: 1981-09-26
4040
start_date: 2019-04-21
41-
sep_id: 123
41+
sep_id: rooip123
4242
maiden_name: dunbar
4343

4444
- model: core.participant
@@ -52,5 +52,5 @@
5252
race: black (african american)
5353
date_of_birth: 1981-09-26
5454
start_date: 2019-04-19
55-
sep_id: 12347
55+
sep_id: ppeo12347
5656
maiden_name: baseball

core/management/commands/seed.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import random, pytz, datetime, json, re
1+
import random, pytz, datetime, json, re, string
22

33
from django.utils import timezone
44
from django.db import IntegrityError
@@ -154,12 +154,20 @@ def create_insurers(output=True):
154154
)
155155
)
156156

157+
def sep_id_generator(size=6, num_participants=10):
158+
chars=string.ascii_lowercase + string.digits
159+
participant_list = []
160+
for ind in range(num_participants):
161+
sepID = ''.join(random.choice(chars) for _ in range(size))
162+
participant_list.append(sepID)
163+
return participant_list
164+
157165
def create_participants():
158166
"""Create a fake participant, and optionally associated UDS and meds"""
159167
gender_list = list(Gender)
160168
race_list = list(Race)
161169
insurers = Insurer.objects.all()
162-
sep_ids = random.sample(range(1, 99999), DEFAULT_NUMBER_PARTICIPANTS)
170+
sep_ids = sep_id_generator(6, DEFAULT_NUMBER_PARTICIPANTS)
163171

164172
for index in range(DEFAULT_NUMBER_PARTICIPANTS):
165173
last_four = fake.ssn(taxpayer_identification_number_type="SSN")[-4:]

core/migrations/0001_initial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 2.2.13 on 2021-01-25 22:06
1+
# Generated by Django 2.2.13 on 2021-02-02 20:22
22

33
from django.db import migrations, models
44
import django.db.models.deletion
@@ -42,11 +42,11 @@ class Migration(migrations.Migration):
4242
('pp_id', models.CharField(db_index=True, max_length=200, verbose_name='Prevention Point ID')),
4343
('gender', models.CharField(choices=[('male', 'Male'), ('female', 'Female'), ('mtf', 'Mtf'), ('ftm', 'Ftm'), ('gender queer', 'Gender Queer'), ('other', 'Other')], max_length=12)),
4444
('race', models.CharField(choices=[('black (african american)', 'Black (African American)'), ('white (caucasian)', 'White (Caucasian)'), ('asian pi', 'Asian Pi'), ('native american', 'Native American'), ('latino', 'Latino'), ('other', 'Other')], max_length=24)),
45-
('date_of_birth', models.DateField()),
45+
('date_of_birth', models.DateField(db_index=True)),
4646
('start_date', models.DateField()),
4747
('is_insured', models.BooleanField(default=False)),
48-
('maiden_name', models.CharField(blank=True, max_length=100, null=True, verbose_name="Mother's Maiden Name")),
49-
('sep_id', models.IntegerField(null=True, unique=True)),
48+
('maiden_name', models.CharField(blank=True, db_index=True, max_length=100, null=True, verbose_name="Mother's Maiden Name")),
49+
('sep_id', models.CharField(blank=True, db_index=True, max_length=16, null=True, unique=True)),
5050
('insurer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Insurer')),
5151
],
5252
),

core/models/participant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class Participant(models.Model):
3434
)
3535
gender = models.CharField(choices=GENDER_CHOICES, max_length=12)
3636
race = models.CharField(choices=RACE_CHOICES, max_length=24)
37-
date_of_birth = models.DateField()
37+
date_of_birth = models.DateField(db_index=True)
3838
start_date = models.DateField()
3939
is_insured = models.BooleanField(default=False)
4040
insurer = models.ForeignKey(Insurer, on_delete=models.CASCADE, null=True, blank=True)
41-
maiden_name = models.CharField(
41+
maiden_name = models.CharField(db_index=True,
4242
null=True, blank=True, max_length=100, verbose_name="Mother's Maiden Name"
4343
)
44-
sep_id = models.IntegerField(null=True, unique=True)
44+
sep_id = models.CharField(db_index=True, null=True, blank=True, max_length=16, unique=True)
4545

4646
def __str__(self):
4747
return "%s %s" % (self.first_name, self.last_name)

core/tests/participants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_sep_filtered_response(self):
5353
ensure known sep id returned when entered completely
5454
"""
5555
headers = self.auth_headers_for_user("front_desk")
56-
known_sep_id = 12347
56+
known_sep_id = 'abr12346'
5757

5858
response = self.client.get(
5959
f"/api/participants?sep_id={known_sep_id}", follow=True, **headers
@@ -68,7 +68,7 @@ def test_sep_filtered_multi_response(self):
6868
ensure sep ids containing the search query are returned
6969
"""
7070
headers = self.auth_headers_for_user("front_desk")
71-
known_sep_id_contains = 23
71+
known_sep_id_contains = 'ab'
7272

7373
response = self.client.get(
7474
f"/api/participants?sep_id={known_sep_id_contains}", follow=True, **headers
@@ -84,7 +84,7 @@ def test_sep_must_be_unique(self):
8484
"""
8585
headers = self.auth_headers_for_user("front_desk")
8686
participant_1 = {
87-
"sep_id": 11111,
87+
"sep_id": "jr1234",
8888
"pp_id": "pp_1111",
8989
"first_name": "foo",
9090
"last_name": "bar",
@@ -102,7 +102,7 @@ def test_sep_must_be_unique(self):
102102
self.assertEqual(201, response_1.status_code)
103103

104104
participant_2 = {
105-
"sep_id": 11111,
105+
"sep_id": "jr1234",
106106
"pp_id": "pp_1112",
107107
"first_name": "oof",
108108
"last_name": "rab",

frontend/src/components/SepForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const SepForm = ({
133133
validationSchema={SEPSearchSchema}
134134
onSubmit={async (values, { setSubmitting, setFieldValue }) => {
135135
await participantStore.getParticipants({
136-
sep_id: values.sep_id,
136+
sep_id: values.sep_id.toLowerCase(),
137137
last_name: values.last_name,
138138
dob: values.date_of_birth,
139139
maiden_name: values.maiden_name,

frontend/src/stores/ParticipantStore.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ export class ParticipantStore {
8383
this.participant = {
8484
...data,
8585
// eslint-disable-next-line camelcase
86-
sep_id: sep_id ? sep_id.toString() : "",
86+
sep_id: sep_id ? sep_id.toLowerCase() : "",
8787
}
8888
}
8989
@action setVisit = data => {
9090
this.visit = data
9191
}
9292

93+
@action setSEPID = data => {
94+
this.participant.sep_id = data.toLowerCase()
95+
}
96+
9397
// Insurance and Programs Actions
9498
@action setInsurers = data => {
9599
this.insurers = data
@@ -115,6 +119,9 @@ export class ParticipantStore {
115119
case "insurer":
116120
this.setInsurer(value)
117121
break
122+
case "sep_id":
123+
this.setSEPID(value)
124+
break
118125
default:
119126
this.participant[name] = value
120127
}

frontend/src/validation/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const participantSchema = Yup.object().shape({
132132
.max(200),
133133
sep_id: Yup.string()
134134
.required()
135-
.matches(/^\d+$/),
135+
.max(16),
136136
maiden_name: Yup.string()
137137
.notRequired()
138138
.max(100),

frontend/test/ExistingParticipantView.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const history = createMemoryHistory()
1313
const mockParticipant = {
1414
id: participantId,
1515
pp_id: "ZG0DI",
16-
sep_id: 41673,
16+
sep_id: "aq41673",
1717
first_name: "Erik",
1818
last_name: "Wagner",
1919
last_four_ssn: "7241",
@@ -209,7 +209,7 @@ describe("<ExistingParticipantView /> mounting process", () => {
209209
data: {
210210
id: newId,
211211
pp_id: "GFDRT",
212-
sep_id: 10000,
212+
sep_id: "rt10000",
213213
first_name: "Jesse",
214214
last_name: "Owens",
215215
last_four_ssn: "7241",

frontend/test/ParticipantList.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mockRootStore.ParticipantStore.setParticipantsList([
1010
{
1111
id: 6,
1212
pp_id: "ZG0DI",
13-
sep_id: 41673,
13+
sep_id: "er41673",
1414
first_name: "Erik",
1515
last_name: "Wagner",
1616
last_four_ssn: "7241",
@@ -25,7 +25,7 @@ mockRootStore.ParticipantStore.setParticipantsList([
2525
{
2626
id: 7,
2727
pp_id: "8AXHR",
28-
sep_id: 10009,
28+
sep_id: "ab10009",
2929
first_name: "Gabriella",
3030
last_name: "Brown",
3131
last_four_ssn: "8294",

0 commit comments

Comments
 (0)