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);
}
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());
}
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());
}
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();
}
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);
}
Aggregations