Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search filters #23

Merged
merged 13 commits into from
Sep 17, 2024
30 changes: 1 addition & 29 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
export {
GetProvidersInputSchema,
GetProvidersResponseSchema,
type GetProvidersInputType,
type GetProvidersResponseType,
Gender,
Genders as GenderSchema,
Ethnicity,
Ethnicities as EthnicitySchema,
Modality,
ClinicalFocus,
DeliveryMethod
} from './providers.schema';

export {
GetAvailabilitiesInputSchema,
GetAvailabilitiesResponseSchema,
type GetAvailabilitiesInputType,
type GetAvailabilitiesResponseType
} from './availabilities.schema';

export {
BookAppointmentInputSchema,
BookAppointmentResponseSchema,
type BookAppointmentInputType,
type BookAppointmentResponseType
} from './booking.schema';

export { type SlotType } from './shared.schema';
export * from './schema';
119 changes: 0 additions & 119 deletions src/lib/api/providers.schema.ts

This file was deleted.

31 changes: 31 additions & 0 deletions src/lib/api/schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
These Zod schemas and enums can be used for a variety of use cases:

- Populating UI elements in the front-end like dropdowns
- Validating and parsing API inputs
- Validating and parsing API responses.

## On Validating and Parsing Responses

When it comes to validating and parsing API responses, it might be better to keep the response schemas more flexible. For example, we don't necessarily need to validate that the `ClinicalFocus` field in the response strictly matches the list of predefined enums. Instead, we could simply check that it's an array of strings. However, validating and parsing `ClinicalFocus` on the input side of the API is more crucial, as we want to ensure that what we send to the API is valid and supported.

We can decide on a field-by-field basis how strictly we want to define schemas and types for API inputs and responses.

### Example

**API input schema:**

```
const ApiInputSchema = z.object({
clinicalFocus: z
.array(z.enum(['Option 1', 'Option 2']))
.optional(),
});
```

**API output schema:**

```
const ApiResponseSchema = z.object({
clinicalFocus: z.array(z.string()).optional(),
});
```
3 changes: 3 additions & 0 deletions src/lib/api/schema/atoms/age.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { z } from 'zod';

export const AgeSchema = z.coerce.string(); // Both number and string will work
22 changes: 22 additions & 0 deletions src/lib/api/schema/atoms/clinicalFocus.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { z } from 'zod';

export enum ClinicalFocus {
ADHD = 'ADHD',
Anxiety = 'Anxiety d/o',
Autism = 'Autism spectrum',
'Gender dysphoria' = 'Gender dysphoria',
'Trauma (including PTSD)' = 'Trauma (including PTSD)',
Depression = 'Depressive d/o',
'Bipolar spectrum' = 'Bipolar spectrum',
'Anger management' = 'Anger management',
OCD = 'OCD',
'Personality d/o' = 'Personality d/o',
'Substance use' = 'Substance use',
Eating_Disorder = 'Eating d/o',
'Psychosis (e.g. schizophrenia)' = 'Psychosis (e.g. schizophrenia)',
'Dissociative d/o' = 'Dissociative d/o',
'Developmental delay' = 'Developmental delay',
'Traumatic brain injury' = 'Traumatic brain injury'
}
nckhell marked this conversation as resolved.
Show resolved Hide resolved

export const ClinicalFocusSchema = z.array(z.nativeEnum(ClinicalFocus));
8 changes: 8 additions & 0 deletions src/lib/api/schema/atoms/deliveryMethod.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from 'zod';

export enum DeliveryMethod {
'Virtual' = 'virtual',
'In-person' = 'in-person'
nckhell marked this conversation as resolved.
Show resolved Hide resolved
}

export const DeliveryMethodSchema = z.nativeEnum(DeliveryMethod);
10 changes: 10 additions & 0 deletions src/lib/api/schema/atoms/ethnicity.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from 'zod';

export enum Ethnicity {
'Asian' = 'Asian',
'Black or African American' = 'Black or African American',
'Hispanic or Latinx' = 'Hispanic or Latinx',
'White' = 'White',
'Other' = 'Other'
nckhell marked this conversation as resolved.
Show resolved Hide resolved
}
export const EthnicitySchema = z.nativeEnum(Ethnicity);
9 changes: 9 additions & 0 deletions src/lib/api/schema/atoms/gender.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { z } from 'zod';

export enum Gender {
Male = 'M',
Female = 'F',
'Non-binary/non-conforming' = 'Non-binary/non-conforming'
nckhell marked this conversation as resolved.
Show resolved Hide resolved
}

export const GenderSchema = z.nativeEnum(Gender);
9 changes: 9 additions & 0 deletions src/lib/api/schema/atoms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export * from './age.schema';
export * from './clinicalFocus.schema';
export * from './deliveryMethod.schema';
export * from './ethnicity.schema';
export * from './gender.schema';
export * from './language.schema';
export * from './locationFacility.schema';
export * from './locationState.schema';
export * from './therapeuticModality.schema';
3 changes: 3 additions & 0 deletions src/lib/api/schema/atoms/language.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { z } from 'zod';

export const LanguageSchema = z.string();
36 changes: 36 additions & 0 deletions src/lib/api/schema/atoms/locationFacility.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { z } from 'zod';

export enum LocationFacility {
CherryCreek = 'Cherry Creek',
GreenwoodVillage = 'Greenwood Village',
CentralPark = 'Central Park',
Lakewood = 'Lakewood',
Boulder = 'Boulder',
HighlandsRanch = 'Highlands Ranch',
Broomfield = 'Broomfield',
Parker = 'Parker',
Gaithersburg = 'Gaithersburg',
Frederick = 'Frederick',
Ballston = 'Ballston',
Downtown = 'Downtown',
Tysons = 'Tysons',
SilverSpring = 'Silver Spring',
BrooklynHeights = 'Brooklyn Heights',
UnionSquare = 'Union Square',
LongIslandCity = 'Long Island City',
ColumbusCircle = 'Columbus Circle',
Williamsburg = 'Williamsburg',
WallStreet = 'Wall Street',
Astoria = 'Astoria',
Gowanus = 'Gowanus',
MidtownEast = 'Midtown East',
Manhasset = 'Manhasset',
Melville = 'Melville',
ValleyStream = 'Valley Stream',
Massapequa = 'Massapequa',
Woodlands = 'Woodlands',
UpperKirby = 'Upper Kirby',
Austin = 'Austin'
}

export const LocationFacilitySchema = z.nativeEnum(LocationFacility);
16 changes: 16 additions & 0 deletions src/lib/api/schema/atoms/locationState.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from 'zod';

export enum LocationState {
CO = 'CO',
NY = 'NY',
TX = 'TX',
VA = 'VA',
MD = 'MD',
DC = 'DC'
}

/**
* The back-end can receive any string (no validation) but the front-end needs to display
* a list of supported states
*/
export const LocationStateSchema = z.nativeEnum(LocationState);
8 changes: 8 additions & 0 deletions src/lib/api/schema/atoms/therapeuticModality.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from 'zod';

export enum Modality {
'Psychiatric' = 'Psychiatric',
'Therapy' = 'Therapy'
}

export const TherapeuticModalitySchema = z.nativeEnum(Modality);
File renamed without changes.
24 changes: 24 additions & 0 deletions src/lib/api/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export * from './atoms';

export {
GetProvidersInputSchema,
GetProvidersResponseSchema,
type GetProvidersInputType,
type GetProvidersResponseType
} from './providers.schema';

export {
GetAvailabilitiesInputSchema,
GetAvailabilitiesResponseSchema,
type GetAvailabilitiesInputType,
type GetAvailabilitiesResponseType
} from './availabilities.schema';

export {
BookAppointmentInputSchema,
BookAppointmentResponseSchema,
type BookAppointmentInputType,
type BookAppointmentResponseType
} from './booking.schema';

export { type SlotType } from './shared.schema';
Loading