Skip to content

Commit

Permalink
feat: simple sykmelding mock creator
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed Dec 14, 2023
1 parent e0befcb commit a71d78d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Nå er du klar til å bruke `tsm`!
* `prs` - get all open pull requests
* `repos` - get all repos
* `git` - keep our repos in sync, ex: tsm git sync
* `mock` - do stuff with the mock
* `team` - get all team members
* `sync-file` - sync a file across specified repos
* `primary-branch` - get misc repo metadata
Expand Down
74 changes: 74 additions & 0 deletions src/actions/mock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import chalk from 'chalk'

import packageJson from '../../../tsm-cli/package.json'
import { log } from '../../common/log.ts'
import { subtractDays } from '../../common/date-utils.ts'

export async function createSimpleSykmelding(fnr: string): Promise<void> {
log(chalk.blue(`Creating simple sykmelding for ${chalk.yellow(fnr)}...`))

const response = await postSykmelding(fnr)

log(chalk.green(response.message))
}

async function postSykmelding(sykmeldtId: string): Promise<{ message: string }> {
const headers = {
'User-Agent': `TSM ${packageJson.version}`,
Accept: '*/*',
'Content-Type': 'application/json',
Pragma: 'no-cache',
'Cache-Control': 'no-cache',
}

const weekAgo = subtractDays(7)
const payload = {
fnr: sykmeldtId,
syketilfelleStartdato: weekAgo,
behandletDato: weekAgo,
perioder: [
{
fom: weekAgo,
tom: subtractDays(1),
type: 'HUNDREPROSENT',
},
],
hoveddiagnose: {
system: 'icd10',
code: 'H100',
text: 'Mukopurulent konjunktivitt',
},
arbeidsgiverNavn: 'Eksempel Arbeidsgiversen AS',
fnrLege: '04056600324',
herId: null,
hprNummer: '9144889',
yrkesskade: false,
meldingTilArbeidsgiver: null,
beskrivBistandNav: null,
annenFraverGrunn: null,
begrunnIkkeKontakt: null,
vedlegg: false,
vedleggMedVirus: false,
virksomhetsykmelding: false,
utdypendeOpplysninger: null,
regelsettVersjon: '3',
kontaktDato: null,
bidiagnoser: [],
diagnosekodesystem: 'icd10',
diagnosekode: 'H100',
}

const response = await fetch('https://teamsykmelding-mock.intern.dev.nav.no/api/proxy/sykmelding/opprett', {
credentials: 'include',
headers: headers,
body: JSON.stringify(payload),
method: 'POST',
mode: 'cors',
})

if (!response.ok) {
throw new Error(`Could not post sykmelding: ${response.status} ${response.statusText}`)
}

return (await response.json()) as { message: string }
}
6 changes: 5 additions & 1 deletion src/common/date-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import { differenceInDays, formatDistanceStrict } from 'date-fns'
import { differenceInDays, formatDistanceStrict, formatISO, subDays } from 'date-fns'

export function coloredTimestamp(timestamp: Date): string {
const now = new Date()
Expand All @@ -13,3 +13,7 @@ export function coloredTimestamp(timestamp: Date): string {
return chalk.cyan(distance)
}
}

export function subtractDays(days: number): string {
return formatISO(subDays(new Date(), days), { representation: 'date' })
}
32 changes: 32 additions & 0 deletions src/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { cleanup, kafkaConfig } from './actions/kafka.ts'
import { azure } from './actions/azure.ts'
import { updateAnalytics } from './analytics'
import { showUsageAnalytics } from './analytics/analytics-global.ts'
import { createSimpleSykmelding } from './actions/mock'

export const getYargsParser = (argv: string[]): Argv =>
yargs(hideBin(argv))
Expand Down Expand Up @@ -88,6 +89,37 @@ export const getYargsParser = (argv: string[]): Argv =>
log('\ttsm git sync')
},
)

.command(
'mock',
'do stuff with the mock',
(yargs) =>
yargs.command(
'simple-sykmelding',
'create a basic 100% sykmelding',
(yargs) =>
yargs.positional('fnr', {
type: 'string',
demandOption: true,
}),
async (args) => {
if (args.fnr == null) {
log(
`${chalk.red('Fnr required, run: ')}${chalk.yellow(
'tsm mock simple-sykmelding fnr=<fnr>',
)}`,
)
process.exit(1)
}

await createSimpleSykmelding(args.fnr)
},
),
() => {
log('Use one of the following commands:')
log('\ttsm mock simple-sykmelding fnr=<fnr>')
},
)
.command(
'team',
'get all team members',
Expand Down

0 comments on commit a71d78d

Please sign in to comment.