Skip to content

Commit

Permalink
Alphanumeric sep id 497 (#501)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
JackRyan1989 authored Feb 5, 2021
1 parent ff3398a commit f29b5c6
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 32 deletions.
8 changes: 4 additions & 4 deletions core/fixtures/participants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
race: black (african american)
date_of_birth: 1963-02-17
start_date: 2019-04-21
sep_id: 12345
sep_id: abc12345
maiden_name: momjordan

- model: core.participant
Expand All @@ -23,7 +23,7 @@
race: white (caucasian)
date_of_birth: 1961-01-26
start_date: 2019-04-21
sep_id: 12346
sep_id: abr12346
maiden_name: dwayne


Expand All @@ -38,7 +38,7 @@
race: black (african american)
date_of_birth: 1981-09-26
start_date: 2019-04-21
sep_id: 123
sep_id: rooip123
maiden_name: dunbar

- model: core.participant
Expand All @@ -52,5 +52,5 @@
race: black (african american)
date_of_birth: 1981-09-26
start_date: 2019-04-19
sep_id: 12347
sep_id: ppeo12347
maiden_name: baseball
12 changes: 10 additions & 2 deletions core/management/commands/seed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random, pytz, datetime, json, re
import random, pytz, datetime, json, re, string

from django.utils import timezone
from django.db import IntegrityError
Expand Down Expand Up @@ -154,12 +154,20 @@ def create_insurers(output=True):
)
)

def sep_id_generator(size=6, num_participants=10):
chars=string.ascii_lowercase + string.digits
participant_list = []
for ind in range(num_participants):
sepID = ''.join(random.choice(chars) for _ in range(size))
participant_list.append(sepID)
return participant_list

def create_participants():
"""Create a fake participant, and optionally associated UDS and meds"""
gender_list = list(Gender)
race_list = list(Race)
insurers = Insurer.objects.all()
sep_ids = random.sample(range(1, 99999), DEFAULT_NUMBER_PARTICIPANTS)
sep_ids = sep_id_generator(6, DEFAULT_NUMBER_PARTICIPANTS)

for index in range(DEFAULT_NUMBER_PARTICIPANTS):
last_four = fake.ssn(taxpayer_identification_number_type="SSN")[-4:]
Expand Down
8 changes: 4 additions & 4 deletions core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.13 on 2021-01-25 22:06
# Generated by Django 2.2.13 on 2021-02-02 20:22

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -42,11 +42,11 @@ class Migration(migrations.Migration):
('pp_id', models.CharField(db_index=True, max_length=200, verbose_name='Prevention Point ID')),
('gender', models.CharField(choices=[('male', 'Male'), ('female', 'Female'), ('mtf', 'Mtf'), ('ftm', 'Ftm'), ('gender queer', 'Gender Queer'), ('other', 'Other')], max_length=12)),
('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)),
('date_of_birth', models.DateField()),
('date_of_birth', models.DateField(db_index=True)),
('start_date', models.DateField()),
('is_insured', models.BooleanField(default=False)),
('maiden_name', models.CharField(blank=True, max_length=100, null=True, verbose_name="Mother's Maiden Name")),
('sep_id', models.IntegerField(null=True, unique=True)),
('maiden_name', models.CharField(blank=True, db_index=True, max_length=100, null=True, verbose_name="Mother's Maiden Name")),
('sep_id', models.CharField(blank=True, db_index=True, max_length=16, null=True, unique=True)),
('insurer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Insurer')),
],
),
Expand Down
6 changes: 3 additions & 3 deletions core/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class Participant(models.Model):
)
gender = models.CharField(choices=GENDER_CHOICES, max_length=12)
race = models.CharField(choices=RACE_CHOICES, max_length=24)
date_of_birth = models.DateField()
date_of_birth = models.DateField(db_index=True)
start_date = models.DateField()
is_insured = models.BooleanField(default=False)
insurer = models.ForeignKey(Insurer, on_delete=models.CASCADE, null=True, blank=True)
maiden_name = models.CharField(
maiden_name = models.CharField(db_index=True,
null=True, blank=True, max_length=100, verbose_name="Mother's Maiden Name"
)
sep_id = models.IntegerField(null=True, unique=True)
sep_id = models.CharField(db_index=True, null=True, blank=True, max_length=16, unique=True)

def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
Expand Down
8 changes: 4 additions & 4 deletions core/tests/participants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_sep_filtered_response(self):
ensure known sep id returned when entered completely
"""
headers = self.auth_headers_for_user("front_desk")
known_sep_id = 12347
known_sep_id = 'abr12346'

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

response = self.client.get(
f"/api/participants?sep_id={known_sep_id_contains}", follow=True, **headers
Expand All @@ -84,7 +84,7 @@ def test_sep_must_be_unique(self):
"""
headers = self.auth_headers_for_user("front_desk")
participant_1 = {
"sep_id": 11111,
"sep_id": "jr1234",
"pp_id": "pp_1111",
"first_name": "foo",
"last_name": "bar",
Expand All @@ -102,7 +102,7 @@ def test_sep_must_be_unique(self):
self.assertEqual(201, response_1.status_code)

participant_2 = {
"sep_id": 11111,
"sep_id": "jr1234",
"pp_id": "pp_1112",
"first_name": "oof",
"last_name": "rab",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/SepForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const SepForm = ({
validationSchema={SEPSearchSchema}
onSubmit={async (values, { setSubmitting, setFieldValue }) => {
await participantStore.getParticipants({
sep_id: values.sep_id,
sep_id: values.sep_id.toLowerCase(),
last_name: values.last_name,
dob: values.date_of_birth,
maiden_name: values.maiden_name,
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/stores/ParticipantStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ export class ParticipantStore {
this.participant = {
...data,
// eslint-disable-next-line camelcase
sep_id: sep_id ? sep_id.toString() : "",
sep_id: sep_id ? sep_id.toLowerCase() : "",
}
}
@action setVisit = data => {
this.visit = data
}
@action setSEPID = data => {
this.participant.sep_id = data.toLowerCase()
}
// Insurance and Programs Actions
@action setInsurers = data => {
this.insurers = data
Expand All @@ -115,6 +119,9 @@ export class ParticipantStore {
case "insurer":
this.setInsurer(value)
break
case "sep_id":
this.setSEPID(value)
break
default:
this.participant[name] = value
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/validation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const participantSchema = Yup.object().shape({
.max(200),
sep_id: Yup.string()
.required()
.matches(/^\d+$/),
.max(16),
maiden_name: Yup.string()
.notRequired()
.max(100),
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/ExistingParticipantView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const history = createMemoryHistory()
const mockParticipant = {
id: participantId,
pp_id: "ZG0DI",
sep_id: 41673,
sep_id: "aq41673",
first_name: "Erik",
last_name: "Wagner",
last_four_ssn: "7241",
Expand Down Expand Up @@ -209,7 +209,7 @@ describe("<ExistingParticipantView /> mounting process", () => {
data: {
id: newId,
pp_id: "GFDRT",
sep_id: 10000,
sep_id: "rt10000",
first_name: "Jesse",
last_name: "Owens",
last_four_ssn: "7241",
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/ParticipantList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mockRootStore.ParticipantStore.setParticipantsList([
{
id: 6,
pp_id: "ZG0DI",
sep_id: 41673,
sep_id: "er41673",
first_name: "Erik",
last_name: "Wagner",
last_four_ssn: "7241",
Expand All @@ -25,7 +25,7 @@ mockRootStore.ParticipantStore.setParticipantsList([
{
id: 7,
pp_id: "8AXHR",
sep_id: 10009,
sep_id: "ab10009",
first_name: "Gabriella",
last_name: "Brown",
last_four_ssn: "8294",
Expand Down
7 changes: 3 additions & 4 deletions frontend/test/ParticipantSchema.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { validateForm, PARTICIPANT_SCHEMA } from "../src/validation/index"

//SEP_ID is alphanumeric going forward
let MOCK_SCHEMA = {
first_name: "ted",
last_name: "nougat",
date_of_birth: new Date("1989-07-13"),
pp_id: "12345",
sep_id: "1234",
pp_id: "sb12345",
sep_id: "sd1234",
maiden_name: "Haroldson",
is_insured: true,
insurer: "7",
Expand Down Expand Up @@ -97,7 +96,7 @@ describe("Participant Schema Validation", () => {
const validationErrors = await validateForm(MOCK_SCHEMA, PARTICIPANT_SCHEMA)
expect(validationErrors[0].name).toEqual("sep_id")
expect(validationErrors.length).toEqual(1)
MOCK_SCHEMA.sep_id = "1234"
MOCK_SCHEMA.sep_id = "sd1234"
})

it("should return an error when is_insured is not bool", async () => {
Expand Down
9 changes: 7 additions & 2 deletions frontend/test/ParticipantStore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Participant Store", () => {
date_of_birth: "10-28-1929",
start_date: startDate,
pp_id: "12345",
sep_id: "12345",
sep_id: "ab12345",
maiden_name: "Strangelove",
race: "white (caucasian)",
gender: "male",
Expand All @@ -37,7 +37,7 @@ describe("Participant Store", () => {
expect(store.participant.date_of_birth).toBe("10-28-1929")
expect(store.participant.start_date).toBe(startDate)
expect(store.participant.pp_id).toBe("12345")
expect(store.participant.sep_id).toBe("12345")
expect(store.participant.sep_id).toBe("ab12345")
expect(store.participant.maiden_name).toBe("Strangelove")
expect(store.participant.race).toBe("white (caucasian)")
expect(store.participant.gender).toBe("male")
Expand Down Expand Up @@ -86,6 +86,11 @@ describe("Participant Store", () => {
expect(store.participant.last_four_ssn).toBe("1234")
})

it("lowercases sep_id", () => {
store.setSEPID("ABCD1234")
expect(store.participant.sep_id).toBe("abcd1234")
})

it("sets visit program from user data", () => {
let data = [
{
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/PrevPointTableBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockParticipantsList = [
date_of_birth: "1994/12/01",
start_date: "2019/04/10",
pp_id: "JD1234",
sep_id: "",
sep_id: "694aid",
maiden_name: "",
race: "Other",
gender: "Other",
Expand All @@ -28,7 +28,7 @@ const mockParticipantsList = [
date_of_birth: "1998/20/07",
start_date: "2020/04/04",
pp_id: "JD1234",
sep_id: "",
sep_id: "57hahv",
maiden_name: "",
race: "Other",
gender: "Other",
Expand Down

0 comments on commit f29b5c6

Please sign in to comment.