diff --git a/core/fixtures/participants.yaml b/core/fixtures/participants.yaml index 058e3d7f..2cb63598 100644 --- a/core/fixtures/participants.yaml +++ b/core/fixtures/participants.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/core/management/commands/seed.py b/core/management/commands/seed.py index f8c74793..4a444994 100644 --- a/core/management/commands/seed.py +++ b/core/management/commands/seed.py @@ -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 @@ -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:] diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py index 79d4258f..8c15fe35 100644 --- a/core/migrations/0001_initial.py +++ b/core/migrations/0001_initial.py @@ -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 @@ -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')), ], ), diff --git a/core/models/participant.py b/core/models/participant.py index 26de41aa..e8ccb334 100644 --- a/core/models/participant.py +++ b/core/models/participant.py @@ -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) diff --git a/core/tests/participants.py b/core/tests/participants.py index caf0f706..a6c97873 100644 --- a/core/tests/participants.py +++ b/core/tests/participants.py @@ -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 @@ -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 @@ -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", @@ -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", diff --git a/frontend/src/components/SepForm.js b/frontend/src/components/SepForm.js index 2924d70e..f05849d5 100644 --- a/frontend/src/components/SepForm.js +++ b/frontend/src/components/SepForm.js @@ -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, diff --git a/frontend/src/stores/ParticipantStore.js b/frontend/src/stores/ParticipantStore.js index 41397a2e..1901f07b 100644 --- a/frontend/src/stores/ParticipantStore.js +++ b/frontend/src/stores/ParticipantStore.js @@ -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 @@ -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 } diff --git a/frontend/src/validation/index.js b/frontend/src/validation/index.js index 3a89bec8..5ea18376 100644 --- a/frontend/src/validation/index.js +++ b/frontend/src/validation/index.js @@ -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), diff --git a/frontend/test/ExistingParticipantView.test.js b/frontend/test/ExistingParticipantView.test.js index 45e5a5e6..6e7b29bb 100644 --- a/frontend/test/ExistingParticipantView.test.js +++ b/frontend/test/ExistingParticipantView.test.js @@ -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", @@ -209,7 +209,7 @@ describe(" mounting process", () => { data: { id: newId, pp_id: "GFDRT", - sep_id: 10000, + sep_id: "rt10000", first_name: "Jesse", last_name: "Owens", last_four_ssn: "7241", diff --git a/frontend/test/ParticipantList.test.js b/frontend/test/ParticipantList.test.js index 1d405a56..e81dbe9d 100644 --- a/frontend/test/ParticipantList.test.js +++ b/frontend/test/ParticipantList.test.js @@ -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", @@ -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", diff --git a/frontend/test/ParticipantSchema.test.js b/frontend/test/ParticipantSchema.test.js index 901a512e..d6c4e6d6 100644 --- a/frontend/test/ParticipantSchema.test.js +++ b/frontend/test/ParticipantSchema.test.js @@ -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", @@ -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 () => { diff --git a/frontend/test/ParticipantStore.test.js b/frontend/test/ParticipantStore.test.js index b838c9ad..ed634b1e 100644 --- a/frontend/test/ParticipantStore.test.js +++ b/frontend/test/ParticipantStore.test.js @@ -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", @@ -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") @@ -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 = [ { diff --git a/frontend/test/PrevPointTableBody.test.js b/frontend/test/PrevPointTableBody.test.js index c8d04ae2..ec67054f 100644 --- a/frontend/test/PrevPointTableBody.test.js +++ b/frontend/test/PrevPointTableBody.test.js @@ -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", @@ -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",