Skip to content
cccskills
FreePublished on GitHub

brev

Expert knowledge of Brev (letter generation) in melosys-api. Use when: (1) Producing letters and decision documents (vedtaksbrev), (2) Understanding Dokgen templates and mapping, (3) Configuring letter recipients and distribution, (4) Debugging letter generation issues, (5) Adding new letter types or templates.

The English summary is being prepared. Showing the original description.

See how to install

Files included (4)

  • SKILL.md9.5 KB
  • references/debugging.md6.2 KB
  • references/letter-types.md5.8 KB
  • references/templates.md7.7 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Brev (Letter Generation) System

Melosys generates letters through melosys-dokgen service. Letters include decision letters (vedtaksbrev), information letters (infobrev), and various notifications. After generation, letters are archived in Joark and distributed to recipients.

Quick Reference

Module Structure

service/dokument/
├── DokgenService.java           # Main letter service (new)
├── DokumentService.java         # Legacy document service
├── DokumentServiceFasade.java   # Facade routing to correct service
├── BrevmottakerService.java     # Recipient logic
└── brev/
    ├── BrevbestillingDto.java   # Letter order request
    ├── BrevDataService.java     # Data preparation
    └── mapper/
        ├── DokgenMalMapper.kt           # Template data mapper
        ├── DokumentproduksjonsInfoMapper.java  # Template metadata
        └── *Mapper.java                 # Specific letter mappers

integrasjon/dokgen/
├── DokgenClient.java            # REST client to melosys-dokgen
└── dto/                         # Template DTOs

saksflyt/steg/brev/              # Saga steps orchestrating letter production
├── BestillBrev.java
├── OpprettOgJournalforBrev.java
├── SendVedtaksbrevInnland.java
├── SendForvaltningsmelding.java
├── SendHenleggelsesbrev.java
├── SendOrienteringAnmodningUnntak.java
├── DistribuerJournalpost.java
├── DistribuerJournalpostUtland.java
├── SendOrienteringsbrevTrygdeavgift.kt
└── SendManglendeInnbetalingVarselBrev.kt

Key Services

ServicePurpose
DokgenServiceProduces letters via melosys-dokgen (new)
DokumentServiceLegacy: produces via Team Dokument's doksys
DokumentServiceFasadeRoutes to correct service based on template availability
BrevmottakerServiceDetermines letter recipients
DokgenMalMapperMaps behandling data to template DTOs

Letter Flow

1. BrevbestillingDto created (frontend or saga)
   ↓
2. DokumentServiceFasade.produserDokument()
   ↓
3. Check: erTilgjengeligDokgenmal()?
   ↓ Yes                    ↓ No
4a. DokgenService          4b. DokumentService (legacy)
   ↓                           ↓
5. DokgenMalMapper.mapBehandling()
   ↓
6. DokgenClient.lagPdf()
   ↓
7. JoarkService.opprettJournalpost()
   ↓
8. Distribution (print/digital)

Letter Types (Produserbaredokumenter)

Decision Letters (Vedtaksbrev)

TypeTemplateDescription
INNVILGELSE_FOLKETRYGDLOVENinnvilgelse_ftrlApprove FTRL membership
INNVILGELSE_EFTA_STORBRITANNIAinnvilgelse_efta_storbritanniaApprove EFTA/GB
VEDTAK_OPPHOERT_MEDLEMSKAPvedtak_opphoert_medlemskapTerminate membership
IKKE_YRKESAKTIV_VEDTAKSBREVikke_yrkesaktiv_vedtaksbrevNon-employed decision
PLIKTIG_MEDLEM_FTRLpliktig_medlem_ftrlMandatory FTRL membership
PENSJONIST_PLIKTIG_FTRLpensjonist_pliktig_ftrlPensioner mandatory
PENSJONIST_FRIVILLIG_FTRLpensjonist_frivillig_ftrlPensioner voluntary
AARSAVREGNING_VEDTAKSBREVaarsavregning_vedtaksbrevAnnual settlement
TRYGDEAVTALE_*trygdeavtale_*Bilateral treaty decisions

Rejection Letters

TypeTemplateDescription
AVSLAG_MANGLENDE_OPPLYSNINGERavslag_manglende_opplysningerReject: missing info
AVSLAG_EFTA_STORBRITANNIAavslag_efta_storbritanniaReject EFTA/GB

Information Letters (Infobrev)

TypeTemplateDescription
MELDING_FORVENTET_SAKSBEHANDLINGSTID_SOKNADsaksbehandlingstid_soknadProcessing time notice
MELDING_FORVENTET_SAKSBEHANDLINGSTID_KLAGEsaksbehandlingstid_klageAppeal processing notice
MANGELBREV_BRUKERmangelbrev_brukerMissing info request (person)
MANGELBREV_ARBEIDSGIVERmangelbrev_arbeidsgiverMissing info request (employer)
ORIENTERING_ANMODNING_UNNTAKorientering_anmodning_unntakArt. 16 exception notice
ORIENTERING_TIL_ARBEIDSGIVER_OM_VEDTAKorientering_til_arbeidsgiver_om_vedtakDecision notice to employer
TRYGDEAVGIFT_INFORMASJONSBREVtrygdeavgift_informasjonsbrevCharge information
VARSELBREV_MANGLENDE_INNBETALINGvarsel_manglende_innbetalingMissing payment warning
MELDING_HENLAGT_SAKhenleggelseCase dismissed notice

Free-Text Letters

TypeTemplateDescription
FRITEKSTBREVfritekstbrevGeneric free-text
GENERELT_FRITEKSTBREV_BRUKERfritekstbrevTo person
GENERELT_FRITEKSTBREV_ARBEIDSGIVERfritekstbrevTo employer
GENERELT_FRITEKSTBREV_VIRKSOMHETfritekstbrevTo company
UTENLANDSK_TRYGDEMYNDIGHET_FRITEKSTBREVtrygdeavtale_fritekstbrevTo foreign authority

Key Operations

Produce Letter

// Via facade (recommended) - mottaker/produserbartDokument come from the DTO
dokumentServiceFasade.produserDokument(123L, brevbestillingDto)

// DokgenService directly
dokgenService.produserOgDistribuerBrev(behandlingId, brevbestillingDto)

Produce Draft (Utkast)

val pdfBytes = dokgenService.produserUtkast(behandlingId, brevbestillingDto)
// Returns PDF without archiving/distribution

Check Template Availability

val erTilgjengelig = dokgenService.erTilgjengeligDokgenmal(INNVILGELSE_FOLKETRYGDLOVEN)

Recipients (Mottaker)

Mottakerroller

RoleDescription
BRUKERPrimary person (applicant)
ARBEIDSGIVEREmployer
VIRKSOMHETCompany/organization
UTENLANDSK_TRYGDEMYNDIGHETForeign authority
NORSK_MYNDIGHETNorwegian authority
FULLMEKTIGPower of attorney representative
ANNEN_PERSONOther person

Copy Recipients (Kopimottakere)

brevbestillingDto.kopiMottakere = listOf(
    KopiMottakerDto(rolle = ARBEIDSGIVER, orgnr = "987654321"),
    KopiMottakerDto(rolle = FULLMEKTIG, ident = "12345678901")
)

Template Mapping

DokumentproduksjonsInfo

data class DokumentproduksjonsInfo(
    val dokgenMalnavn: String,      // Template name in melosys-dokgen
    val dokumentKategoriKode: String, // Joark category (IB, VB, etc.)
    val tittel: String,              // Main document title
    val vedleggTittel: String?,      // Attachment title (optional)
    val attestTittel: String?        // Certificate title (optional)
)

Document Categories

CodeDescriptionUsage
VBVedtaksbrevDecision letters
IBInfobrevInformation/notice letters

Kodeverk og enum-tekst i DTO-er

Dokgen har ansvar for presentasjon av malene og eier brevteksten. Api sender koder når det er mulig (enum-navn), ikke ferdig oversatt tekst. Se Templates: Kodeverk og enum-tekst i DTO-er.

Adding New Letter Types

  1. Add enum in melosys-internt-kodeverk:

    enum class Produserbaredokumenter {
        NEW_LETTER_TYPE("Beskrivelse for saksbehandler")
    }
    
  2. Create template in melosys-dokgen:

    • Add HTML template
    • Define JSON schema for data
  3. Add mapping in DokumentproduksjonsInfoMapper:

    .put(NEW_LETTER_TYPE,
        new DokumentproduksjonsInfo("template_name",
            DokumentKategoriKode.VB.getKode(),
            "Journalførings tittel"))
    
  4. Add data mapper in DokgenMalMapper:

    NEW_LETTER_TYPE -> lagNewLetterDto(behandling, bestilling)
    
  5. Configure recipients in BrevmottakerService if needed

Common Issues

Issue: Template Not Found

Symptom: FunksjonellException: "ProduserbartDokument X er ikke støttet"

Check:

  1. Is enum in melosys-internt-kodeverk?
  2. Is mapping in DokumentproduksjonsInfoMapper?
  3. Does template exist in melosys-dokgen?

Issue: Wrong Recipients

Symptom: Letter sent to wrong party

Check:

val mottakerliste = brevmottakerService.hentMottakerliste(produserbartDokument, behandlingId)
log.info("Recipients: ${mottakerliste}")

Issue: Missing Data in Letter

Symptom: Blank fields in generated PDF

Check: Data mapping in DokgenMalMapper.mapBehandling() (and the per-letter lag*/*Mapper.map(...) helpers it delegates to)

Key Code Locations

ComponentLocation
Main Serviceservice/.../dokument/DokgenService.java
Legacy Serviceservice/.../dokument/DokumentService.java
Facadeservice/.../dokument/DokumentServiceFasade.java
Template Mapperservice/.../dokument/brev/mapper/DokgenMalMapper.kt
Production Infoservice/.../dokument/brev/mapper/DokumentproduksjonsInfoMapper.java
REST Clientintegrasjon/.../dokgen/DokgenClient.java
Recipient Serviceservice/.../dokument/BrevmottakerService.java

Detailed Documentation

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Expert knowledge of Altinn A1 application processing for posted workers in melosys-api. Use when: (1) Understanding Altinn søknad/skjema processing, (2) Debugging MedlemskapArbeidEOS form mapping, (3) Understanding SoeknadMapper transformations, (4) Investigating posted worker application issues, (5) Understanding the MOTTAK_SOKNAD_ALTINN saga flow.

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

Expert knowledge of Employer/Employment integration (EREG/AAREG) in melosys-api. Use when: (1) Working with organization data from EREG (Enhetsregisteret), (2) Working with employment data from AAREG (Arbeidsforhold), (3) Understanding employer/organization lookup, (4) Debugging employer or employment issues, (5) Understanding the mapping between register data and domain models. Triggers: orgnummer, arbeidsforhold, EREG, AAREG, Enhetsregisteret, registeropplysninger, ansettelsesperiode, saksopplysning.

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

Modular monolith architecture overview for melosys-api. Use when needing to understand module structure, dependencies between modules, where to place new code, or when changes in one module might affect others. Triggers: "architecture", "module dependencies", "where should I put", "which modules", "dependency graph".

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

Expert knowledge of Behandling (case treatment) domain in melosys-api. Use when: (1) Understanding the behandling lifecycle and status transitions, (2) Debugging issues with behandling creation, status changes, or closure, (3) Understanding relationships between Fagsak, Behandling, and Behandlingsresultat, (4) Investigating why a behandling is stuck or has wrong status, (5) Understanding Behandlingstyper, Behandlingstema, Behandlingsstatus enums, (6) Debugging journalføring or SED-triggered behandling creation, (7) Understanding behandling creation via saksflyt sagas.

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

Expert knowledge of Behandlingsresultat (treatment result) domain in melosys-api. Use when: (1) Understanding result types and their meaning (FASTSATT_LOVVALGSLAND, MEDLEM_I_FOLKETRYGDEN, etc.), (2) Working with periods - Lovvalgsperiode, Medlemskapsperiode, Anmodningsperiode, Utpekingsperiode, (3) Debugging vedtak/decision metadata, criteria evaluation, or social insurance charges, (4) Understanding EU/EEA coordination logic and Article 16 exception handling, (5) Working with trygdeavgift (social insurance charge) calculations.

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

Expert knowledge of the melosys-api Oracle database schema. Use when: (1) Writing SQL queries against the melosys database, (2) Understanding table relationships and foreign keys, (3) Debugging data issues by querying the database, (4) Understanding what data is stored where, (5) Creating or modifying Flyway migrations, (6) Mapping domain entities to database tables. Triggers: SQL against melosys DB, table/column lookup, FK relationships, "where is X stored", "what column stores X", "why is data missing", beh_resultat_id, behandlingsresultat_id, saksnummer, schema.

The English summary is being prepared. Showing the original description.

navikt/melosys-api2Updated Oct 21, 2026

See all skills by navikt

Report a problem with this skill