Search in sources :

Example 1 with CreateNewDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest in project webcert by sklintyg.

the class CreateDraftCertificateResponderImplTest method testCreateDraftCertificateMultipleMIUs.

@Test
public void testCreateDraftCertificateMultipleMIUs() {
    CreateNewDraftRequest draftRequest = createCreateNewDraftRequest(createVardenhet(createVardgivare()));
    CreateDraftCertificateType certificateType = createCertificateType();
    VardpersonReferens vardperson = createVardpersonReferens(certificateType.getIntyg().getSkapadAv().getPersonalId().getRoot(), certificateType.getIntyg().getSkapadAv().getFullstandigtNamn());
    Utkast utkast = createUtkast(UTKAST_ID, Long.parseLong(UTKAST_VERSION), UTKAST_TYPE, UtkastStatus.DRAFT_INCOMPLETE, UTKAST_JSON, vardperson);
    when(mockValidator.validate(any(Intyg.class))).thenReturn(new ResultValidator());
    when(mockRequestBuilder.buildCreateNewDraftRequest(any(Intyg.class), any(IntygUser.class))).thenReturn(draftRequest);
    when(mockUtkastService.createNewDraft(any(CreateNewDraftRequest.class))).thenReturn(utkast);
    when(takService.verifyTakningForCareUnit(any(String.class), any(String.class), any(SchemaVersion.class), any(IntygUser.class))).thenReturn(new TakResult(true, Lists.emptyList()));
    CreateDraftCertificateResponseType response = responder.createDraftCertificate(LOGICAL_ADDR, certificateType);
    verify(mockUtkastService).createNewDraft(any(CreateNewDraftRequest.class));
    verify(mockIntegreradeEnheterService).putIntegreradEnhet(any(IntegreradEnhetEntry.class), eq(false), eq(true));
    assertNotNull(response);
    assertEquals(response.getResult().getResultCode(), ResultCodeType.OK);
    assertEquals(response.getIntygsId().getExtension(), UTKAST_ID);
}
Also used : CreateDraftCertificateResponseType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateResponseType) IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) CreateDraftCertificateType(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TypAvIntyg(se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg) Intyg(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) VardpersonReferens(se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest) Test(org.junit.Test)

Example 2 with CreateNewDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest in project webcert by sklintyg.

the class CreateNewDraftRequestBuilderTest method test.

@Test
public void test() {
    // given
    Utlatande utlatande = createUtlatande();
    // when
    CreateNewDraftRequest res = builder.buildCreateNewDraftRequest(utlatande, user);
    // then
    assertNotNull(res);
    assertEquals(CERT_TYPE, res.getIntygType());
    assertEquals(USER_HSAID, res.getHosPerson().getPersonId());
    assertNotNull(res.getHosPerson().getFullstandigtNamn());
    assertEquals(UNIT_HSAID, res.getHosPerson().getVardenhet().getEnhetsid());
    assertNotNull(res.getHosPerson().getVardenhet().getEnhetsnamn());
    assertNotNull(res.getHosPerson().getVardenhet().getArbetsplatsKod());
    assertNotNull(res.getHosPerson().getVardenhet().getTelefonnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostadress());
    assertNotNull(res.getHosPerson().getVardenhet().getPostnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostort());
    assertEquals(CAREGIVER_HSAID, res.getHosPerson().getVardenhet().getVardgivare().getVardgivarid());
    assertNotNull(res.getHosPerson().getVardenhet().getVardgivare().getVardgivarnamn());
    assertEquals(PERSNR, res.getPatient().getPersonId().getPersonnummerWithDash());
    assertEquals("Adam Bertil", res.getPatient().getFornamn());
    assertEquals("Cesarsson Davidsson", res.getPatient().getMellannamn());
    assertEquals("Eriksson", res.getPatient().getEfternamn());
}
Also used : CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Test(org.junit.Test) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)

Example 3 with CreateNewDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest in project webcert by sklintyg.

the class CreateNewDraftRequestBuilderTest method testBuildCreateNewDraftRequest.

@Test
public void testBuildCreateNewDraftRequest() {
    CreateNewDraftRequest res = builder.buildCreateNewDraftRequest(createIntyg(), user);
    assertNotNull(res);
    assertEquals(CERT_TYPE.toLowerCase(), res.getIntygType());
    assertEquals(USER_HSAID, res.getHosPerson().getPersonId());
    assertNotNull(res.getHosPerson().getFullstandigtNamn());
    assertEquals(UNIT_HSAID, res.getHosPerson().getVardenhet().getEnhetsid());
    assertNotNull(res.getHosPerson().getVardenhet().getEnhetsnamn());
    assertNotNull(res.getHosPerson().getVardenhet().getArbetsplatsKod());
    assertNotNull(res.getHosPerson().getVardenhet().getTelefonnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostadress());
    assertNotNull(res.getHosPerson().getVardenhet().getPostnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostort());
    assertEquals(CAREGIVER_HSAID, res.getHosPerson().getVardenhet().getVardgivare().getVardgivarid());
    assertNotNull(res.getHosPerson().getVardenhet().getVardgivare().getVardgivarnamn());
    assertEquals(PERSONNUMMER, res.getPatient().getPersonId().getPersonnummer());
    assertEquals(FORNAMN, res.getPatient().getFornamn());
    assertEquals(MELLANNAMN, res.getPatient().getMellannamn());
    assertEquals(EFTERNAMN, res.getPatient().getEfternamn());
    assertEquals(PATIENT_POSTADRESS, res.getPatient().getPostadress());
    assertEquals(PATIENT_POSTNUMMER, res.getPatient().getPostnummer());
    assertEquals(PATIENT_POSTORT, res.getPatient().getPostort());
}
Also used : CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) Test(org.junit.Test) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)

Example 4 with CreateNewDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest in project webcert by sklintyg.

the class UtkastApiController method createUtkast.

/**
 * Create a new draft.
 */
@POST
@Path("/{intygsTyp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request) {
    try {
        if (moduleRegistry.getIntygModule(intygsTyp).isDeprecated()) {
            LOG.error("Request for deprecated module {}", intygsTyp);
            return Response.status(Status.BAD_REQUEST).build();
        }
    } catch (ModuleNotFoundException e) {
        LOG.error("Request for unknown module {}", intygsTyp);
        return Response.status(Status.BAD_REQUEST).build();
    }
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(request.getPatientPersonnummer());
    if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
    }
    // INTYG-4086: If the patient is sekretessmarkerad, we need an additional check.
    boolean sekr = sekretessStatus == SekretessStatus.TRUE;
    if (sekr) {
        authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
    }
    if (!request.isValid()) {
        LOG.error("Request is invalid: " + request.toString());
        return Response.status(Status.BAD_REQUEST).build();
    }
    LOG.debug("Attempting to create draft of type '{}'", intygsTyp);
    if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
        Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(request.getPatientPersonnummer(), getWebCertUserService().getUser());
        Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
        Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
        if (utkastExists != null && utkastExists) {
            if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
        if (intygExists != null) {
            if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            } else if (intygExists && authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
    }
    CreateNewDraftRequest serviceRequest = createServiceRequest(request);
    Utkast utkast = utkastService.createNewDraft(serviceRequest);
    LOG.debug("Created a new draft of type '{}' with id '{}'", intygsTyp, utkast.getIntygsId());
    return Response.ok().entity(utkast).build();
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with CreateNewDraftRequest

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest in project webcert by sklintyg.

the class UtkastApiController method createServiceRequest.

private CreateNewDraftRequest createServiceRequest(CreateUtkastRequest req) {
    Patient pat = patientDetailsResolver.resolvePatient(req.getPatientPersonnummer(), req.getIntygType());
    // CreateUtkastRequest is the manual entry.
    if (pat == null) {
        pat = new Patient();
        pat.setPersonId(req.getPatientPersonnummer());
        pat.setFornamn(req.getPatientFornamn());
        pat.setMellannamn(req.getPatientMellannamn());
        pat.setEfternamn(req.getPatientEfternamn());
        pat.setFullstandigtNamn(IntygConverterUtil.concatPatientName(pat.getFornamn(), pat.getMellannamn(), pat.getEfternamn()));
        pat.setPostadress(req.getPatientPostadress());
        pat.setPostnummer(req.getPatientPostnummer());
        pat.setPostort(req.getPatientPostort());
    }
    return new CreateNewDraftRequest(null, req.getIntygType(), null, createHoSPersonFromUser(), pat);
}
Also used : CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Aggregations

CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)23 Test (org.junit.Test)14 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)10 BaseCreateDraftCertificateTest (se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)9 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)4 SchemaVersion (se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion)4 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)4 TakResult (se.inera.intyg.webcert.integration.tak.model.TakResult)4 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)4 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)4 ResultValidator (se.inera.intyg.webcert.web.integration.validators.ResultValidator)4 Utlatande (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande)3 CreateDraftCertificateResponseType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateResponseType)3 CreateDraftCertificateType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.CreateDraftCertificateType)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg)3 TypAvUtlatande (se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande)3 TypAvIntyg (se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg)3 Response (javax.ws.rs.core.Response)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 QueryIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.QueryIntygResponse)2