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

13 files changed

+51
-32
lines changed

core/fixtures/participants.yaml

+4-4
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

+10-2
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

+4-4
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

+3-3
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

+4-4
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

+1-1
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

+8-1
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

+1-1
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

+2-2
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

+2-2
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",

frontend/test/ParticipantSchema.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { validateForm, PARTICIPANT_SCHEMA } from "../src/validation/index"
22

3-
//SEP_ID is alphanumeric going forward
43
let MOCK_SCHEMA = {
54
first_name: "ted",
65
last_name: "nougat",
76
date_of_birth: new Date("1989-07-13"),
8-
pp_id: "12345",
9-
sep_id: "1234",
7+
pp_id: "sb12345",
8+
sep_id: "sd1234",
109
maiden_name: "Haroldson",
1110
is_insured: true,
1211
insurer: "7",
@@ -97,7 +96,7 @@ describe("Participant Schema Validation", () => {
9796
const validationErrors = await validateForm(MOCK_SCHEMA, PARTICIPANT_SCHEMA)
9897
expect(validationErrors[0].name).toEqual("sep_id")
9998
expect(validationErrors.length).toEqual(1)
100-
MOCK_SCHEMA.sep_id = "1234"
99+
MOCK_SCHEMA.sep_id = "sd1234"
101100
})
102101

103102
it("should return an error when is_insured is not bool", async () => {

frontend/test/ParticipantStore.test.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("Participant Store", () => {
2121
date_of_birth: "10-28-1929",
2222
start_date: startDate,
2323
pp_id: "12345",
24-
sep_id: "12345",
24+
sep_id: "ab12345",
2525
maiden_name: "Strangelove",
2626
race: "white (caucasian)",
2727
gender: "male",
@@ -37,7 +37,7 @@ describe("Participant Store", () => {
3737
expect(store.participant.date_of_birth).toBe("10-28-1929")
3838
expect(store.participant.start_date).toBe(startDate)
3939
expect(store.participant.pp_id).toBe("12345")
40-
expect(store.participant.sep_id).toBe("12345")
40+
expect(store.participant.sep_id).toBe("ab12345")
4141
expect(store.participant.maiden_name).toBe("Strangelove")
4242
expect(store.participant.race).toBe("white (caucasian)")
4343
expect(store.participant.gender).toBe("male")
@@ -86,6 +86,11 @@ describe("Participant Store", () => {
8686
expect(store.participant.last_four_ssn).toBe("1234")
8787
})
8888

89+
it("lowercases sep_id", () => {
90+
store.setSEPID("ABCD1234")
91+
expect(store.participant.sep_id).toBe("abcd1234")
92+
})
93+
8994
it("sets visit program from user data", () => {
9095
let data = [
9196
{

frontend/test/PrevPointTableBody.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const mockParticipantsList = [
1212
date_of_birth: "1994/12/01",
1313
start_date: "2019/04/10",
1414
pp_id: "JD1234",
15-
sep_id: "",
15+
sep_id: "694aid",
1616
maiden_name: "",
1717
race: "Other",
1818
gender: "Other",
@@ -28,7 +28,7 @@ const mockParticipantsList = [
2828
date_of_birth: "1998/20/07",
2929
start_date: "2020/04/04",
3030
pp_id: "JD1234",
31-
sep_id: "",
31+
sep_id: "57hahv",
3232
maiden_name: "",
3333
race: "Other",
3434
gender: "Other",

0 commit comments

Comments
 (0)