Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/missing_azure_app_client
Browse files Browse the repository at this point in the history
# Conflicts:
#	apps/sykemelding-api/src/main/resources/application-local.yml
  • Loading branch information
rfc3092 committed Dec 11, 2024
2 parents 6153153 + 783636c commit 0204e10
Show file tree
Hide file tree
Showing 43 changed files with 1,526 additions and 151 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.dolly.bestilling.sykemelding;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.core.util.Json;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.bestilling.ConsumerStatus;
import no.nav.dolly.bestilling.sykemelding.command.SykemeldingPostCommand;
Expand Down Expand Up @@ -41,7 +42,7 @@ public SykemeldingConsumer(
@Timed(name = "providers", tags = { "operation", "detaljertsykemelding_opprett" })
public Mono<SykemeldingResponse> postDetaljertSykemelding(DetaljertSykemeldingRequest detaljertSykemeldingRequest) {

log.info("Detaljert Sykemelding sendt {}", detaljertSykemeldingRequest);
log.info("Detaljert Sykemelding sendt {}", Json.pretty(detaljertSykemeldingRequest));

return tokenService.exchange(serverProperties)
.flatMap(token -> new SykemeldingPostCommand(webClient, detaljertSykemeldingRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ private void fixPerson(String ident) {
.forEach(MetadataTidspunkterService::fixVersioning);
person.getBostedsadresse()
.forEach(MetadataTidspunkterService::fixAdresser);
fixOpphoert(person.getBostedsadresse());
fixAddrOpphoert(person.getBostedsadresse());
person.getOppholdsadresse()
.forEach(MetadataTidspunkterService::fixAdresser);
fixOpphoert(person.getOppholdsadresse());
fixAddrOpphoert(person.getOppholdsadresse());
person.getKontaktadresse()
.forEach(MetadataTidspunkterService::fixAdresser);
fixOpphoert(person.getKontaktadresse());
fixAddrOpphoert(person.getKontaktadresse());
person.getDeltBosted()
.forEach(MetadataTidspunkterService::fixDeltBosted);
person.getDoedfoedtBarn()
Expand Down Expand Up @@ -120,6 +120,12 @@ private void fixPerson(String ident) {
});
}

private static void fixAddrOpphoert(List<? extends AdresseDTO> adresseopplysning) {

adresseopplysning.forEach(adresse ->
adresse.getFolkeregistermetadata().setOpphoerstidspunkt(adresse.getGyldigTilOgMed()));
}

private static void fixOpphoert(List<? extends DbVersjonDTO> opplysningstype) {

for (var i = opplysningstype.size() - 1; i > 0; i--) {
Expand Down Expand Up @@ -220,8 +226,8 @@ private static void fixSivilstand(PersonDTO person) {
person.getSivilstand().sort(Comparator.comparing(SivilstandDTO::getId).reversed());

var counter = new AtomicInteger(0);
person.getSivilstand().stream()
.forEachOrdered(sivilstand -> {
person.getSivilstand()
.forEach(sivilstand -> {
fixFolkeregisterMetadata(sivilstand);
if (isNull(sivilstand.getFolkeregistermetadata().getGyldighetstidspunkt())) {

Expand Down
1 change: 1 addition & 0 deletions apps/sykemelding-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ghcr.io/navikt/baseimages/temurin:21
LABEL maintainer="Team Dolly"

ENV JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"
ADD /build/libs/app.jar /app/app.jar

EXPOSE 8080
3 changes: 2 additions & 1 deletion apps/sykemelding-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-security"

implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:$versions.springdoc"
implementation "io.swagger.core.v3:swagger-annotations-jakarta:$versions.swagger"

implementation "com.ibm.mq:mq-jms-spring-boot-starter:$versions.mq"
implementation "jakarta.xml.bind:jakarta.xml.bind-api:$versions.jakartaXmlBindApi"
implementation "jakarta.activation:jakarta.activation-api:$versions.jakartaActivation"
implementation "org.glassfish.jaxb:jaxb-runtime:$versions.jaxb"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml"

implementation "ma.glasnost.orika:orika-core:$versions.orika"

testImplementation "no.nav.testnav.libs:testing"
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.cloud:spring-cloud-contract-wiremock"
Expand Down
2 changes: 2 additions & 0 deletions apps/sykemelding-api/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
- application: testnav-oversikt-frontend
- application: testnav-synt-sykemelding-api-dev
outbound:
rules:
- application: testnav-sykemelding-proxy
external:
- host: mqls04.preprod.local
ports:
Expand Down
2 changes: 2 additions & 0 deletions apps/sykemelding-api/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
- application: testnav-oversikt-frontend
- application: testnav-synt-sykemelding-api
outbound:
rules:
- application: testnav-sykemelding-proxy
external:
- host: mqls04.preprod.local
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package no.nav.registre.testnorge.sykemelding.config;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import no.nav.testnav.libs.securitycore.domain.ServerProperties;

import static lombok.AccessLevel.PACKAGE;

@Configuration
@ConfigurationProperties(prefix = "consumers")
@NoArgsConstructor(access = PACKAGE)
@Getter
@Setter(PACKAGE)
public class Consumers {

private ServerProperties sykemeldingProxy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package no.nav.registre.testnorge.sykemelding.config;

import lombok.RequiredArgsConstructor;
import ma.glasnost.orika.CustomConverter;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import no.nav.registre.testnorge.sykemelding.mapper.MappingStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

import static java.util.Objects.nonNull;

@Configuration
@RequiredArgsConstructor
public class MapperFacadeConfig {

@Bean
MapperFacade mapperFacade(List<MappingStrategy> mappingStrategies, List<CustomConverter> customConverters) {
DefaultMapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

if (nonNull(mappingStrategies)) {
for (MappingStrategy mapper : mappingStrategies) {
mapper.register(mapperFactory);
}
}

if (nonNull(customConverters)) {
for (CustomConverter converter : customConverters) {
mapperFactory.getConverterFactory().registerConverter(converter);
}
}

return mapperFactory.getMapperFacade();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Slf4j
@Component
@Service
public class SyfoConsumer {

private final JmsTemplate jmsTemplate;
private final String queueName;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.nav.registre.testnorge.sykemelding.consumer;

import no.nav.registre.testnorge.sykemelding.config.Consumers;
import no.nav.registre.testnorge.sykemelding.consumer.command.SyfosmreglerPostValidateCommand;
import no.nav.registre.testnorge.sykemelding.dto.ReceivedSykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.ValidationResultDTO;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class SyfosmreglerConsumer {

private final ServerProperties properties;
private final TokenExchange tokenExchange;
private final WebClient webClient;

public SyfosmreglerConsumer(Consumers consumers, WebClient.Builder webClientBuilder, TokenExchange tokenExchange) {

this.properties = consumers.getSykemeldingProxy();
this.tokenExchange = tokenExchange;
this.webClient = webClientBuilder
.baseUrl(properties.getUrl())
.build();
}

public Mono<ValidationResultDTO> validate(ReceivedSykemeldingDTO sykemelding) {

return tokenExchange.exchange(properties)
.flatMap(token -> new SyfosmreglerPostValidateCommand(webClient, sykemelding, token.getTokenValue()).call());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package no.nav.registre.testnorge.sykemelding.consumer.command;

import io.swagger.v3.core.util.Json;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.registre.testnorge.sykemelding.dto.ReceivedSykemeldingDTO;
import no.nav.testnav.libs.dto.sykemelding.v1.ValidationResultDTO;
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.concurrent.Callable;

@Slf4j
@RequiredArgsConstructor
public class SyfosmreglerPostValidateCommand implements Callable<Mono<ValidationResultDTO>> {

private static final String SYFOSMREGLER_VALIDATE_URL = "/v1/rules/validate";

private final WebClient webClient;
private final ReceivedSykemeldingDTO receivedSykemelding;
private final String accessToken;

@Override
public Mono<ValidationResultDTO> call() {

log.info("Sender til syfosmregler {}", Json.pretty(receivedSykemelding));

return webClient.post()
.uri(uriBuilder -> uriBuilder.path(SYFOSMREGLER_VALIDATE_URL).build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
.bodyValue(receivedSykemelding)
.retrieve()
.bodyToMono(ValidationResultDTO.class)
.doOnError(WebClientFilter::logErrorMessage)
.onErrorResume(error -> Mono.just(ValidationResultDTO.builder()
.httpStatus(WebClientFilter.getStatus(error))
.message(WebClientFilter.getMessage(error))
.build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import no.nav.registre.testnorge.sykemelding.external.xmlstds.helseopplysningerarbeidsuforhet._2013_10_01.XMLHelseOpplysningerArbeidsuforhet;
import no.nav.testnav.libs.dto.sykemelding.v1.PeriodeDTO;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

class Aktivitet {
private final XMLHelseOpplysningerArbeidsuforhet.Aktivitet xmlAktivitet;

Aktivitet(List<PeriodeDTO> dtos, boolean manglendeTilretteleggingPaaArbeidsplassen) {

if (dtos.isEmpty()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Perioder må angis");
}
this.xmlAktivitet = new XMLHelseOpplysningerArbeidsuforhet.Aktivitet()
.withPeriode(
dtos.stream()
.map(value -> new Periode(value, manglendeTilretteleggingPaaArbeidsplassen))
.map(Periode::getXmlObject)
.collect(Collectors.toList())
.toList()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import static java.util.Objects.nonNull;

public class Arbeidsgiver {
private XMLHelseOpplysningerArbeidsuforhet.Arbeidsgiver xmlArbeidsgiver;
private final XMLHelseOpplysningerArbeidsuforhet.Arbeidsgiver xmlArbeidsgiver;

Arbeidsgiver(ArbeidsgiverDTO dto) {
xmlArbeidsgiver = new XMLHelseOpplysningerArbeidsuforhet.Arbeidsgiver()
.withHarArbeidsgiver(new XMLCS()
.withDN("En arbeidsgiver")
.withV("1"))
.withDN(nonNull(dto) ? "En arbeidsgiver" : "Ingen arbeidsgiver")
.withV(nonNull(dto) ? "1" : "3"))
.withNavnArbeidsgiver(nonNull(dto) ? dto.getNavn() : null)
.withYrkesbetegnelse(nonNull(dto) ? dto.getYrkesbetegnelse() : null)
.withStillingsprosent(nonNull(dto) ? getStillingsprosent(dto) : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Dokument {

var prognose = new Prognose(fomIArbeid, dto.getDetaljer());
var helsepersonell = new Helsepersonell(dto.getHelsepersonell());
var kontaktMedPasient = new KontaktMedPasient(dto.getKontaktMedPasient());

xmlHelseOpplysningerArbeidsuforhet = new XMLHelseOpplysningerArbeidsuforhet()
.withSyketilfelleStartDato(dto.getStartDato())
Expand All @@ -28,15 +29,14 @@ class Dokument {
.withMedisinskVurdering(medisinskVurdering.getXmlObject())
.withAktivitet(aktivitet.getXmlObject())
.withPrognose(prognose.getXmlObject())
.withUtdypendeOpplysninger(new UtdypendeOpplysninger(dto.getUtdypendeOpplysninger()).getXmlObject())
.withTiltak(
new XMLHelseOpplysningerArbeidsuforhet.Tiltak()
.withTiltakArbeidsplassen(dto.getDetaljer().getTiltakArbeidsplass())
.withTiltakNAV(dto.getDetaljer().getTiltakNav())
.withAndreTiltak(dto.getDetaljer().getAndreTiltak())
)
.withKontaktMedPasient(
new XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient()
.withBehandletDato(fom.atStartOfDay())
)
.withKontaktMedPasient(kontaktMedPasient.getXmlObject())
.withBehandler(helsepersonell.getXmlObject())
.withAvsenderSystem(new XMLHelseOpplysningerArbeidsuforhet.AvsenderSystem()
.withSystemNavn(applicationInfo.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package no.nav.registre.testnorge.sykemelding.domain;

import no.nav.registre.testnorge.sykemelding.external.xmlstds.helseopplysningerarbeidsuforhet._2013_10_01.XMLHelseOpplysningerArbeidsuforhet;
import no.nav.testnav.libs.dto.sykemelding.v1.KontaktMedPasientDTO;

import static java.util.Objects.nonNull;

class KontaktMedPasient {

private final XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient xmlKontaktMedPasient;

KontaktMedPasient(KontaktMedPasientDTO dto) {

xmlKontaktMedPasient = nonNull(dto) ? new XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient()
.withKontaktDato(dto.getKontaktDato())
.withBegrunnIkkeKontakt(dto.getBegrunnelseIkkeKontakt()) : null;
}

XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient getXmlObject() {
return xmlKontaktMedPasient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

class MedisinskVurdering {

private final XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering medisinskVurdering;
private final XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering xmlMedisinskVurdering;

MedisinskVurdering(LocalDate fom, DiagnoseDTO hovedDiagnose, List<DiagnoseDTO> biDiagnoser) {

medisinskVurdering = new XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering()
xmlMedisinskVurdering = new XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering()
.withHovedDiagnose(new XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering.HovedDiagnose()
.withDiagnosekode(new XMLCV()
.withDN(hovedDiagnose.getDiagnose())
Expand All @@ -29,19 +28,19 @@ class MedisinskVurdering {
.withS(value.getSystem())
.withV(value.getDiagnosekode())
)
.collect(Collectors.toList())
.toList()
)
)
.withYrkesskade(false)
.withYrkesskadeDato(fom)
.withSvangerskap(false)
.withAnnenFraversArsak(
new XMLArsakType().withBeskriv("Medising årsak i kategorien annet")
new XMLArsakType().withBeskriv("Medisinsk årsak i kategorien annet")
)
.withSkjermesForPasient(false);
}

XMLHelseOpplysningerArbeidsuforhet.MedisinskVurdering getXmlObject() {
return medisinskVurdering;
return xmlMedisinskVurdering;
}
}
Loading

0 comments on commit 0204e10

Please sign in to comment.