Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
feat(import data): handle second address (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda authored Mar 22, 2022
1 parent 9fb55f1 commit 0606059
Show file tree
Hide file tree
Showing 25 changed files with 254 additions and 71 deletions.
3 changes: 2 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
NEXT_PUBLIC_MATOMO_URL=https://matomo.fabrique.social.gouv.fr
NEXT_PUBLIC_MATOMO_SITE_ID="59"
NEXT_PUBLIC_SENTRY_DSN=https://36021ef8cb3b4edc99320a1e2fd1f453@sentry.fabrique.social.gouv.fr/61
NEXT_PUBLIC_SENTRY_ENV="production"

NEXT_TELEMETRY_DISABLED=1
DB_LOGGING_ENABLE=false

DEMARCHES_SIMPLIFIEES_TOKEN=api-token
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMjMyMzQyMg==", "secondAddress"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]

NEXT_PUBLIC_NEW_FEATURES=false

Expand Down
4 changes: 3 additions & 1 deletion .env.staging
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
NEXT_TELEMETRY_DISABLED=1
DB_LOGGING_ENABLE=false
NEXT_PUBLIC_SENTRY_DSN=https://36021ef8cb3b4edc99320a1e2fd1f453@sentry.fabrique.social.gouv.fr/61
NEXT_PUBLIC_SENTRY_ENV="development"

DEMARCHES_SIMPLIFIEES_TOKEN=api-tokens
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMjMyMzQyMg==", "secondAddress"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]

NEXT_PUBLIC_NEW_FEATURES=true

Expand Down
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DB_LOGGING_ENABLE=false

DEMARCHES_SIMPLIFIEES_TOKEN=api-token
DEMARCHES_SIMPLIFIEES_ID=52209
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]
DEMARCHES_SIMPLIFIEES_CHAMPS=[["Q2hhbXAtMTYwMzgwNQ==", "phone"], ["Q2hhbXAtMTYyNzkzOQ==", "address"], ["Q2hhbXAtMjMyMzQyMg==", "secondAddress"], ["Q2hhbXAtMTYzOTUyNA==", "teleconsultation"], ["Q2hhbXAtMTY2MDM0Nw==", "languages"], ["Q2hhbXAtMTYzOTQwMQ==", "website"], ["Q2hhbXAtMjI0NzExMg==", "cdsmsp"], ["Q2hhbXAtMjIyMjcwMg==", "public"], ["Q2hhbXAtMTYwMTE4Ng==", "email"], ["Q2hhbXAtMjI1MTk5Mw==", "displayEmail"]]

NEXT_PUBLIC_NEW_FEATURES=true

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ ENV NODE_ENV production

# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js .
COPY --from=builder /app/sentry.client.config.js .
COPY --from=builder /app/sentry.server.config.js .
COPY --from=builder /app/sentry.client.config.ts .
COPY --from=builder /app/sentry.server.config.ts .
COPY --from=builder /app/.sequelizerc .
COPY --from=builder /app/.env.production ./.env
COPY --from=builder /app/package.json .
Expand All @@ -35,4 +35,4 @@ COPY --from=builder --chown=node:node /app/.next ./.next

USER node

CMD ["yarn", "start"]
CMD ["yarn", "start"]
5 changes: 0 additions & 5 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ h1 .fr-text--lead {
color: var(--grey-425);
}

.text-grey img {
position: relative;
top: 4px;
}

.no-bullet {
list-style-type: none;
}
Expand Down
1 change: 1 addition & 0 deletions public/images/icones/chat-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/icones/mail-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/icones/map-pin-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/icones/phone-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions sentry.client.config.js → sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as Sentry from "@sentry/nextjs";

const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
const SENTRY_ENV = process.env.SENTRY_ENV || process.env.NEXT_PUBLIC_SENTRY_ENV;

Sentry.init({
dsn: SENTRY_DSN,
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
dsn: SENTRY_DSN ?? "",
environment: SENTRY_ENV ?? "development",
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
// ...
// Note: if you want to override the automatic release value, do not set a
Expand Down
7 changes: 4 additions & 3 deletions sentry.server.config.js → sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as Sentry from "@sentry/nextjs";

const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
const SENTRY_ENV = process.env.SENTRY_ENV || process.env.NEXT_PUBLIC_SENTRY_ENV;

Sentry.init({
dsn: SENTRY_DSN,
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
dsn: SENTRY_DSN ?? "",
environment: SENTRY_ENV ?? "development",
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1.0,
// ...
// Note: if you want to override the automatic release value, do not set a
Expand Down
16 changes: 9 additions & 7 deletions src/components/Directory/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Header = () => {
<h2>Trouver un psychologue partenaire près de chez soi.</h2>
<p>La liste des psychologues partenaires est actualisée régulièrement.</p>
<Callout className="fr-mb-4w fr-callout--pink-tuile">
<CalloutTitle>A lire, avant de prendre rendez-vous :</CalloutTitle>
<CalloutTitle>A noter</CalloutTitle>
<div className="fr-callout__text fr-text--md">
<ul>
<li>
Expand All @@ -29,13 +29,15 @@ const Header = () => {
<strong>séances de suivi à distance</strong>. La 1ère séance
d’entretien initial est réalisée uniquement en présentiel.
</li>
<li>
<strong>
Le jour du rendez-vous, bien apporter le courrier d’adressage
rédigé par mon médecin
</strong>{" "}
(ainsi que mon attestation de Carte Vitale papier indiquant vos
droits, si je bénéficie d’une exonération d’avance de frais).
</li>
</ul>
<strong>
Le jour de mon rendez-vous, j’apporte le courrier d’adressage rédigé
par mon médecin
</strong>{" "}
(ainsi que mon attestation de Carte Vitale papier indiquant vos
droits, si je bénéficie d’une exonération d’avance de frais).
</div>
</Callout>
</div>
Expand Down
52 changes: 46 additions & 6 deletions src/components/Directory/Psychologist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,26 @@ const Psychologist = ({
</p>
</div>
<div className="fr-tile__desc">
<p className="fr-my-0">{psychologist.address}</p>
<p className="fr-my-0">
<Icon
aria-hidden="true"
alt=""
className="fr-mr-1w"
height="18"
width="18"
src="/images/icones/map-pin-fill.svg"
/>
{psychologist.address}
</p>
<p className="fr-my-0">
<Icon
aria-hidden="true"
alt=""
className="fr-mr-1w"
height="18"
width="18"
src="/images/icones/phone-fill.svg"
/>
{psychologist.phone}{" "}
{psychologist.website && (
<a
Expand All @@ -44,6 +62,14 @@ const Psychologist = ({
</p>
{psychologist.email && (
<p className="fr-my-0">
<Icon
aria-hidden="true"
alt=""
className="fr-mr-1w"
height="18"
width="18"
src="/images/icones/mail-fill.svg"
/>
<a
href={`mailto:${psychologist.email}`}
rel="noreferrer"
Expand All @@ -56,20 +82,29 @@ const Psychologist = ({
<div className="fr-p-1w" />
{psychologist.teleconsultation && (
<p className="fr-my-0 text-grey">
<img
<Icon
aria-hidden="true"
alt=""
className="fr-mr-1w"
height="20"
width="20"
height="18"
width="18"
src="/images/icones/vidicon-fill.svg"
/>
Possibilité de séances à distance
</p>
)}
{psychologist.languages && (
<p className="fr-my-0">
Langue(s) parlée(s): {psychologist.languages}
<p className="fr-my-0 text-grey">
<Icon
aria-hidden="true"
title="Langue(s) parlée(s) en plus du français"
alt=""
className="fr-mr-1w"
height="18"
width="18"
src="/images/icones/chat-fill.svg"
/>
Langue(s): {psychologist.languages}
</p>
)}
</div>
Expand All @@ -93,4 +128,9 @@ const PsychologistTile = styled.div`
`}
`;

const Icon = styled.img`
position: relative;
top: 6px;
`;

export default Psychologist;
8 changes: 8 additions & 0 deletions src/db/migrations/20220105084912-add-psy.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = {
allowNull: false,
type: Sequelize.TEXT,
},
second_address: {
allowNull: true,
type: Sequelize.TEXT,
},
department: {
allowNull: false,
type: Sequelize.STRING,
Expand Down Expand Up @@ -64,6 +68,10 @@ module.exports = {
allowNull: true,
type: Sequelize.GEOMETRY("POINT", 4326),
},
second_address_coordinates: {
allowNull: true,
type: Sequelize.GEOMETRY("POINT", 4326),
},
instructor_id: {
allowNull: false,
type: Sequelize.STRING,
Expand Down
2 changes: 2 additions & 0 deletions src/db/models/psychologist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ export default (sequelize) => {
Psychologist.init(
{
address: DataTypes.TEXT,
secondAddress: DataTypes.TEXT,
archived: DataTypes.BOOLEAN,
cdsmsp: DataTypes.STRING,
coordinates: DataTypes.GEOMETRY("POINT", SRID),
secondAddressCoordinates: DataTypes.GEOMETRY("POINT", SRID),
department: DataTypes.STRING,
displayEmail: DataTypes.BOOLEAN,
email: DataTypes.STRING,
Expand Down
11 changes: 11 additions & 0 deletions src/db/seeds/psychologist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const getOnePsychologist = (
address: `${faker.address.streetAddress()} ${faker.address.zipCode(
"#####"
)} ${faker.address.city()}`,
secondAddress: `${faker.address.streetAddress()} ${faker.address.zipCode(
"#####"
)} ${faker.address.city()}`,
archived: false,
cdsmsp: faker.lorem.word(5),
coordinates: {
Expand All @@ -43,6 +46,14 @@ export const getOnePsychologist = (
crs: { properties: { name: "EPSG:4326" }, type: "name" },
type: "POINT",
},
secondAddressCoordinates: {
coordinates: [
parseFloat(faker.address.longitude(4, -4)),
parseFloat(faker.address.latitude(50, 40)),
],
crs: { properties: { name: "EPSG:4326" }, type: "name" },
type: "POINT",
},
department: instructor.label,
displayEmail: faker.datatype.boolean(),
email: faker.internet.exampleEmail(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,38 @@ describe("parseDossierMetadata", () => {
);

it.each`
input | resultValue
${undefined} | ${undefined}
${null} | ${undefined}
${""} | ${undefined}
${"FRANCAIS"} | ${undefined}
${"Francais"} | ${undefined}
${"francais"} | ${undefined}
${"FRANÇAIS"} | ${undefined}
${"français"} | ${undefined}
${"langue française"} | ${undefined}
${"anglais"} | ${"anglais"}
${"other other"} | ${"other other"}
languages | languagesOther | resultValue
${undefined} | ${undefined} | ${undefined}
${null} | ${undefined} | ${undefined}
${""} | ${undefined} | ${undefined}
${undefined} | ${"Francais"} | ${undefined}
${null} | ${"Francais"} | ${undefined}
${""} | ${"Francais"} | ${undefined}
${"FRANCAIS"} | ${undefined} | ${undefined}
${"Francais"} | ${undefined} | ${undefined}
${"francais"} | ${undefined} | ${undefined}
${"FRANÇAIS"} | ${undefined} | ${undefined}
${"français"} | ${undefined} | ${undefined}
${"langue française"} | ${undefined} | ${undefined}
${"anglais"} | ${undefined} | ${"anglais"}
${"Anglais"} | ${"espagnol"} | ${"Anglais, espagnol"}
${"other other"} | ${undefined} | ${"other other"}
${"Anglais, Italien"} | ${"Japonais"} | ${"Anglais, Italien, Japonais"}
${"Francais, Anglais, Italien"} | ${undefined} | ${"Anglais, Italien"}
${"Francais et Italien"} | ${undefined} | ${"Italien"}
`(
"should parse languages champs for $input",
async ({ input, resultValue }) => {
"should parse languages champs for $languages & $languagesOther",
async ({ languages, languagesOther, resultValue }) => {
const dossierWithLangue = createDossier();
dossierWithLangue.champs.push({
id: "Q2hhbXAtMTY2MDM0Nw==",
label: "Langues de réalisation des séances (optionnel) ?",
stringValue: input,
stringValue: languages,
});
dossierWithLangue.champs.push({
id: "Q2hhbXAtMjM0NjQzNA==",
label: "Si autre(s) langue(s), préciser :",
stringValue: languagesOther,
});
const result = await parseDossierMetadata(dossierWithLangue);

Expand Down
31 changes: 31 additions & 0 deletions src/services/__tests__/get-address-coordinates.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios from "axios";

import getAddressCoordinates from "../getAddressCoordinates";

jest.mock("axios");
describe("getAddressCoordinates.ts", () => {
it.each`
title | features | resultValue
${"no results"} | ${undefined} | ${null}
${"empty results"} | ${[]} | ${null}
${"valid results"} | ${[{
geometry: { coordinates: [1, 2] },
properties: { score: 0.8 },
}]} | ${{ latitude: 2, longitude: 1 }}
${"score too small"} | ${[{
geometry: { coordinates: [1, 2] },
properties: { score: 0.1 },
}]} | ${null}
`(
"should handle api response for $title",
async ({ features, resultValue }) => {
// @ts-ignore
axios.get.mockImplementationOnce(() =>
Promise.resolve({ data: { features: features } })
);
const result = await getAddressCoordinates("123", "My Address");

expect(result).toEqual(resultValue);
}
);
});
4 changes: 3 additions & 1 deletion src/services/__tests__/psychologists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ describe("Service psychologists", () => {

const updateableFields = [
"address",
"secondAddress",
"coordinates",
"cdsmsp",
"displayEmail",
"email",
Expand All @@ -212,7 +214,7 @@ describe("Service psychologists", () => {
});

Object.keys(updatedPsy).forEach((key) => {
if (key === "coordinates") {
if (key === "coordinates" || key === "secondAddressCoordinates") {
expect(updatedPsy[key].coordinates).toEqual([123, 456]);
expect(updatedPsy[key].type).toEqual("Point");
} else if (updateableFields.includes(key)) {
Expand Down
Loading

0 comments on commit 0606059

Please sign in to comment.