Skip to content

Commit

Permalink
fikser sirkulære deps
Browse files Browse the repository at this point in the history
  • Loading branch information
hallvardastark committed Nov 27, 2023
1 parent 38b713a commit 009bfc2
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { FormProvider, useForm } from 'react-hook-form';
import { InnleggelsesperiodeDryRunResponse } from '../../../api/api';
import AddButton from '../add-button/AddButton';
import DeleteButton from '../delete-button/DeleteButton';
import { FieldName } from '../innleggelsesperiodeoversikt/Innleggelsesperiodeoversikt';
import styles from './innleggelsesperiodeFormModal.css';

export enum FieldName {
INNLEGGELSESPERIODER = 'innleggelsesperioder',
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyType = any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import { InnleggelsesperiodeResponse } from '../../../types/InnleggelsesperiodeR
import { findLinkByRel } from '../../../util/linkUtils';
import ContainerContext from '../../context/ContainerContext';
import AddButton from '../add-button/AddButton';
import InnleggelsesperiodeFormModal from '../innleggelsesperiodeFormModal/InnleggelsesperiodeFormModal';
import InnleggelsesperiodeFormModal, { FieldName } from '../innleggelsesperiodeFormModal/InnleggelsesperiodeFormModal';
import Innleggelsesperiodeliste from '../innleggelsesperiodeliste/Innleggelsesperiodeliste';
import WriteAccessBoundContent from '../write-access-bound-content/WriteAccessBoundContent';
import styles from './innleggelsesperiodeoversikt.css';

export enum FieldName {
INNLEGGELSESPERIODER = 'innleggelsesperioder',
}

interface InnleggelsesperiodeoversiktProps {
onInnleggelsesperioderUpdated: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
finnMaksavgrensningerForPerioder,
slåSammenSammenhengendePerioder,
} from '../../../util/periodUtils';
import { lagLangvarigSykdomVurdering } from '../../../util/vurderingUtils';
import ContainerContext from '../../context/ContainerContext';
import { fomDatoErFørTomDato, harBruktDokumentasjon, required } from '../../form/validators';
import AddButton from '../add-button/AddButton';
Expand All @@ -24,6 +23,7 @@ import StjerneIkon from '../vurdering-av-form/StjerneIkon';
import styles from '../vurdering-av-form/vurderingForm.css';
import VurderingDokumentfilter from '../vurdering-dokumentfilter/VurderingDokumentfilter';
import vurderingDokumentfilterOptions from '../vurdering-dokumentfilter/vurderingDokumentfilterOptions';
import { finnBenyttedeDokumenter } from '../../../util/dokumentUtils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyType = any;
Expand All @@ -36,6 +36,25 @@ export enum FieldName {
PERIODER = 'perioder',
}

const lagLangvarigSykdomVurdering = (
formState: VurderingLangvarigSykdomFormState,
alleDokumenter: Dokument[],
): Partial<Vurderingsversjon> => {
const resultat = formState[FieldName.HAR_LANGVARIG_SYKDOM];
const tekst = formState[FieldName.VURDERING_LANGVARIG_SYKDOM];
const dokumenter = finnBenyttedeDokumenter(formState[FieldName.DOKUMENTER], alleDokumenter);
const perioder = formState[FieldName.PERIODER].map(
periodeWrapper => new Period((periodeWrapper as AnyType).period.fom, (periodeWrapper as AnyType).period.tom),
);

return {
resultat,
tekst,
perioder,
dokumenter,
};
};

export interface VurderingLangvarigSykdomFormState {
[FieldName.VURDERING_LANGVARIG_SYKDOM]?: string;
[FieldName.HAR_LANGVARIG_SYKDOM]?: Vurderingsresultat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
finnMaksavgrensningerForPerioder,
slåSammenSammenhengendePerioder,
} from '../../../util/periodUtils';
import { lagSluttfaseVurdering } from '../../../util/vurderingUtils';
import ContainerContext from '../../context/ContainerContext';
import { fomDatoErFørTomDato, harBruktDokumentasjon, required } from '../../form/validators';
import AddButton from '../add-button/AddButton';
Expand All @@ -24,6 +23,7 @@ import StjerneIkon from '../vurdering-av-form/StjerneIkon';
import styles from '../vurdering-av-form/vurderingForm.css';
import VurderingDokumentfilter from '../vurdering-dokumentfilter/VurderingDokumentfilter';
import vurderingDokumentfilterOptions from '../vurdering-dokumentfilter/vurderingDokumentfilterOptions';
import { finnBenyttedeDokumenter } from '../../../util/dokumentUtils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyType = any;
Expand All @@ -36,6 +36,25 @@ export enum FieldName {
PERIODER = 'perioder',
}

const lagSluttfaseVurdering = (
formState: VurderingAvLivetsSluttfaseFormState,
alleDokumenter: Dokument[],
): Partial<Vurderingsversjon> => {
const resultat = formState[FieldName.ER_I_LIVETS_SLUTTFASE];
const tekst = formState[FieldName.VURDERING_AV_LIVETS_SLUTTFASE];
const dokumenter = finnBenyttedeDokumenter(formState[FieldName.DOKUMENTER], alleDokumenter);
const perioder = formState[FieldName.PERIODER].map(
periodeWrapper => new Period((periodeWrapper as AnyType).period.fom, (periodeWrapper as AnyType).period.tom),
);

return {
resultat,
tekst,
perioder,
dokumenter,
};
};

export interface VurderingAvLivetsSluttfaseFormState {
[FieldName.VURDERING_AV_LIVETS_SLUTTFASE]?: string;
[FieldName.ER_I_LIVETS_SLUTTFASE]?: Vurderingsresultat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
finnMaksavgrensningerForPerioder,
slåSammenSammenhengendePerioder,
} from '../../../util/periodUtils';
import { lagTilsynsbehovVurdering } from '../../../util/vurderingUtils';
import ContainerContext from '../../context/ContainerContext';
import { fomDatoErFørTomDato, harBruktDokumentasjon, required } from '../../form/validators';
import AddButton from '../add-button/AddButton';
Expand All @@ -23,6 +22,8 @@ import VurderingDokumentfilter from '../vurdering-dokumentfilter/VurderingDokume
import vurderingDokumentfilterOptions from '../vurdering-dokumentfilter/vurderingDokumentfilterOptions';
import StjerneIkon from '../vurdering-av-form/StjerneIkon';
import styles from '../vurdering-av-form/vurderingForm.css';
import Vurderingsresultat from '../../../types/Vurderingsresultat';
import { finnBenyttedeDokumenter } from '../../../util/dokumentUtils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyType = any;
Expand All @@ -34,6 +35,27 @@ export enum FieldName {
DOKUMENTER = 'dokumenter',
}

const lagTilsynsbehovVurdering = (
formState: VurderingAvTilsynsbehovFormState,
alleDokumenter: Dokument[],
): Partial<Vurderingsversjon> => {
const resultat = formState[FieldName.HAR_BEHOV_FOR_KONTINUERLIG_TILSYN_OG_PLEIE]
? Vurderingsresultat.OPPFYLT
: Vurderingsresultat.IKKE_OPPFYLT;

const perioder = formState[FieldName.PERIODER].map(
periodeWrapper => new Period((periodeWrapper as AnyType).period.fom, (periodeWrapper as AnyType).period.tom),
);
const begrunnelse = formState[FieldName.VURDERING_AV_KONTINUERLIG_TILSYN_OG_PLEIE];

return {
resultat,
perioder,
tekst: begrunnelse,
dokumenter: finnBenyttedeDokumenter(formState[FieldName.DOKUMENTER], alleDokumenter),
};
};

export interface VurderingAvTilsynsbehovFormState {
[FieldName.VURDERING_AV_KONTINUERLIG_TILSYN_OG_PLEIE]?: string;
[FieldName.HAR_BEHOV_FOR_KONTINUERLIG_TILSYN_OG_PLEIE]?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {
finnMaksavgrensningerForPerioder,
slåSammenSammenhengendePerioder,
} from '../../../util/periodUtils';
import { lagToOmsorgspersonerVurdering } from '../../../util/vurderingUtils';
import ContainerContext from '../../context/ContainerContext';
import { fomDatoErFørTomDato, harBruktDokumentasjon, required } from '../../form/validators';
import AddButton from '../add-button/AddButton';
import DeleteButton from '../delete-button/DeleteButton';
import DetailViewVurdering from '../detail-view-vurdering/DetailViewVurdering';
import DokumentLink from '../dokument-link/DokumentLink';
import styles from '../vurdering-av-form/vurderingForm.css';
import { finnBenyttedeDokumenter } from '../../../util/dokumentUtils';
import Vurderingsresultat from '../../../types/Vurderingsresultat';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyType = any;
Expand All @@ -30,6 +31,26 @@ export enum FieldName {
DOKUMENTER = 'dokumenter',
}

const lagToOmsorgspersonerVurdering = (
formState: VurderingAvToOmsorgspersonerFormState,
alleDokumenter: Dokument[],
): Partial<Vurderingsversjon> => {
const resultat = formState[FieldName.HAR_BEHOV_FOR_TO_OMSORGSPERSONER]
? Vurderingsresultat.OPPFYLT
: Vurderingsresultat.IKKE_OPPFYLT;
const perioder = formState[FieldName.PERIODER].map(
periodeWrapper => new Period((periodeWrapper as AnyType).period.fom, (periodeWrapper as AnyType).period.tom),
);
const begrunnelse = formState[FieldName.VURDERING_AV_TO_OMSORGSPERSONER];

return {
resultat,
perioder,
tekst: begrunnelse,
dokumenter: finnBenyttedeDokumenter(formState[FieldName.DOKUMENTER], alleDokumenter),
};
};

export interface VurderingAvToOmsorgspersonerFormState {
[FieldName.VURDERING_AV_TO_OMSORGSPERSONER]?: string;
[FieldName.HAR_BEHOV_FOR_TO_OMSORGSPERSONER]?: boolean;
Expand Down
3 changes: 1 addition & 2 deletions packages/fakta-medisinsk-vilkår/src/util/dokumentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
StrukturerDokumentFormFieldName as FieldName,
StrukturerDokumentFormState,
} from '../types/StrukturerDokumentFormState';
import { ikkeDuplikatValue } from '../ui/components/strukturer-dokument-form/StrukturerDokumentForm';

export const finnBenyttedeDokumenter = (benyttedeDokumentIder: string[], alleDokumenter: Dokument[]): Dokument[] =>
alleDokumenter.filter(dokument => benyttedeDokumentIder.includes(dokument.id));
Expand All @@ -13,7 +12,7 @@ export const lagStrukturertDokument = (formState: StrukturerDokumentFormState, d
...dokument,
type: formState[FieldName.INNEHOLDER_MEDISINSKE_OPPLYSNINGER],
datert: formState[FieldName.DATERT],
duplikatAvId: formState[FieldName.DUPLIKAT_AV_ID] === ikkeDuplikatValue ? null : formState[FieldName.DUPLIKAT_AV_ID],
duplikatAvId: formState[FieldName.DUPLIKAT_AV_ID] === 'ikkeDuplikat' ? null : formState[FieldName.DUPLIKAT_AV_ID],
});

export const dokumentSorter = (dok1: Dokument, dok2: Dokument): number => {
Expand Down
103 changes: 0 additions & 103 deletions packages/fakta-medisinsk-vilkår/src/util/vurderingUtils.ts

This file was deleted.

20 changes: 12 additions & 8 deletions packages/fakta-omsorgsdager/src/types/Period.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dateFromString } from '../util/dateUtils';
import dayjs from 'dayjs';

export class Period {
fom: string;
Expand All @@ -10,10 +10,14 @@ export class Period {
this.tom = tom;
}

dateFromString(dateString: string) {
return dayjs(dateString, ['YYYY-MM-DD', 'DD.MM.YYYY']).utc(true);
}

includesDate(dateString: string) {
const dateInQuestion = dateFromString(dateString);
const fomDayjs = dateFromString(this.fom);
const tomDayjs = dateFromString(this.tom);
const dateInQuestion = this.dateFromString(dateString);
const fomDayjs = this.dateFromString(this.fom);
const tomDayjs = this.dateFromString(this.tom);
return (
(dateInQuestion.isSame(fomDayjs) || dateInQuestion.isAfter(fomDayjs)) &&
(dateInQuestion.isSame(tomDayjs) || dateInQuestion.isBefore(tomDayjs))
Expand All @@ -37,14 +41,14 @@ export class Period {
}

startsBefore(otherPeriod: Period) {
const dateInQuestion = dateFromString(otherPeriod.fom);
const periodFom = dateFromString(this.fom);
const dateInQuestion = this.dateFromString(otherPeriod.fom);
const periodFom = this.dateFromString(this.fom);
return periodFom.isBefore(dateInQuestion);
}

endsAfter(otherPeriod: Period) {
const dateInQuestion = dateFromString(otherPeriod.tom);
const periodTom = dateFromString(this.tom);
const dateInQuestion = this.dateFromString(otherPeriod.tom);
const periodTom = this.dateFromString(this.tom);
return periodTom.isAfter(dateInQuestion);
}
}

0 comments on commit 009bfc2

Please sign in to comment.