use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.
the class IntygApiControllerTest method testListIntyg.
@Test
public void testListIntyg() {
// Mock call to Intygstjanst
when(intygService.listIntyg(ENHET_IDS, PNR)).thenReturn(intygItemListResponse);
Response response = intygCtrl.listDraftsAndIntygForPerson(PNR.getPersonnummer());
@SuppressWarnings("unchecked") List<ListIntygEntry> res = (List<ListIntygEntry>) response.getEntity();
assertNotNull(res);
assertEquals(2, res.size());
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.
the class IntygAPIControllerIT method testNotifiedOnUtkast.
@Test
public void testNotifiedOnUtkast() {
RestAssured.sessionId = getAuthSession(DEFAULT_LAKARE);
String utkastId = createUtkast("lisjp", DEFAULT_PATIENT_PERSONNUMMER);
Map<String, String> pathParams = new HashMap<>();
pathParams.put("intygsTyp", "lisjp");
pathParams.put("intygsId", utkastId);
pathParams.put("version", "0");
NotifiedState notifiedState = new NotifiedState();
notifiedState.setNotified(true);
ListIntygEntry updatedIntyg = given().cookie("ROUTEID", BaseRestIntegrationTest.routeId).contentType(ContentType.JSON).and().body(notifiedState).and().pathParams(pathParams).expect().statusCode(200).when().put("api/intyg/{intygsTyp}/{intygsId}/{version}/vidarebefordra").then().body(matchesJsonSchemaInClasspath("jsonschema/webcert-put-notified-utkast-response-schema.json")).extract().response().as(ListIntygEntry.class);
assertNotNull(updatedIntyg);
assertEquals(utkastId, updatedIntyg.getIntygId());
assertEquals("lisjp", updatedIntyg.getIntygType());
// it's been updated, so version should have been incremented
assertEquals(1, updatedIntyg.getVersion());
// and of course it should have been vidarebefordrad as we instructed
assertTrue(updatedIntyg.isVidarebefordrad());
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.
the class IntygApiController method listDraftsAndIntygForPerson.
/**
* Compiles a list of Intyg from two data sources. Signed Intyg are
* retrieved from IntygstjÀnst, drafts are retrieved from Webcerts db. Both
* types of Intyg are converted and merged into one sorted list.
*
* @param personNummerIn personnummer
* @return a Response carrying a list containing all Intyg for a person.
*/
@GET
@Path("/person/{personNummer}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response listDraftsAndIntygForPerson(@PathParam("personNummer") String personNummerIn) {
Personnummer personNummer = createPnr(personNummerIn);
LOG.debug("Retrieving intyg for person {}", personNummer.getPersonnummerHash());
// INTYG-4086 (epic) - make sure only users with HANTERA_SEKRETESSMARKERAD_PATIENT can list intyg for patient
// with sekretessmarkering.
SekretessStatus patientSekretess = patientDetailsResolver.getSekretessStatus(personNummer);
if (patientSekretess == SekretessStatus.UNDEFINED) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Error checking sekretessmarkering state in PU-service.");
}
authoritiesValidator.given(getWebCertUserService().getUser()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, patientSekretess == SekretessStatus.TRUE).orThrow();
List<String> enhetsIds = getEnhetIdsForCurrentUser();
if (enhetsIds.isEmpty()) {
LOG.error("Current user has no assignments");
return Response.status(Status.BAD_REQUEST).build();
}
Pair<List<ListIntygEntry>, Boolean> intygItemListResponse = intygService.listIntyg(enhetsIds, personNummer);
LOG.debug("Got #{} intyg", intygItemListResponse.getLeft().size());
List<Utkast> utkastList;
if (authoritiesValidator.given(getWebCertUserService().getUser()).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).isVerified()) {
Set<String> intygstyper = authoritiesHelper.getIntygstyperForPrivilege(getWebCertUserService().getUser(), AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(personNummer), enhetsIds, ALL_DRAFTS, intygstyper);
LOG.debug("Got #{} utkast", utkastList.size());
} else {
utkastList = Collections.emptyList();
}
List<ListIntygEntry> allIntyg = IntygDraftsConverter.merge(intygItemListResponse.getLeft(), utkastList);
// INTYG-4477
if (patientSekretess == SekretessStatus.TRUE) {
Set<String> allowedTypes = authoritiesHelper.getIntygstyperAllowedForSekretessmarkering();
allIntyg = allIntyg.stream().filter(intyg -> allowedTypes.contains(intyg.getIntygType())).collect(Collectors.toList());
}
Response.ResponseBuilder responseBuilder = Response.ok(allIntyg);
if (intygItemListResponse.getRight()) {
responseBuilder = responseBuilder.header(OFFLINE_MODE, Boolean.TRUE.toString());
}
return responseBuilder.build();
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.
the class IntygApiController method setNotifiedOnIntyg.
/**
* Sets the notified flag on an Intyg.
*
* @param intygsId Id of the Intyg
* @param notifiedState True or False
* @return Response
*/
@PUT
@Path("/{intygsTyp}/{intygsId}/{version}/vidarebefordra")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
@Consumes(MediaType.APPLICATION_JSON)
public Response setNotifiedOnIntyg(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, NotifiedState notifiedState) {
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_VIDAREBEFORDRA_UTKAST).orThrow();
Utkast updatedIntyg;
try {
updatedIntyg = utkastService.setNotifiedOnDraft(intygsId, version, notifiedState.isNotified());
} catch (OptimisticLockException | OptimisticLockingFailureException e) {
monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
}
LOG.debug("Set forward to {} on intyg {} with id '{}'", new Object[] { updatedIntyg.getVidarebefordrad(), intygsTyp, updatedIntyg.getIntygsId() });
ListIntygEntry intygEntry = IntygDraftsConverter.convertUtkastToListIntygEntry(updatedIntyg);
return Response.ok(intygEntry).build();
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry in project webcert by sklintyg.
the class UtkastApiController method performUtkastFilterQuery.
private QueryIntygResponse performUtkastFilterQuery(UtkastFilter filter) {
// INTYG-4486: We can not get a totalCount with pageSize set if since we need to lookup/verify
// sekretess!=UNDEFINED each entry from puService - even if user has authority to view sekretessmarkerade
// resources.
Integer pageSize = filter.getPageSize();
filter.setPageSize(null);
List<ListIntygEntry> listIntygEntries = IntygDraftsConverter.convertUtkastsToListIntygEntries(utkastService.filterIntyg(filter));
// INTYG-4486, INTYG-4086: Always filter out any items with UNDEFINED sekretessmarkering status and not
// authorized
Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(listIntygEntries.stream().map(lie -> lie.getPatientId()).collect(Collectors.toList()));
final WebCertUser user = getWebCertUserService().getUser();
listIntygEntries = listIntygEntries.stream().filter(lie -> this.passesSekretessCheck(lie.getPatientId(), lie.getIntygType(), user, sekretessStatusMap)).collect(Collectors.toList());
// INTYG-4086: Mark all remaining ListIntygEntry having a patient with sekretessmarkering
listIntygEntries.stream().forEach(lie -> markSekretessMarkering(lie, sekretessStatusMap));
int totalCountOfFilteredIntyg = listIntygEntries.size();
// logic
if (filter.getStartFrom() < listIntygEntries.size()) {
int toIndex = filter.getStartFrom() + pageSize;
if (toIndex > listIntygEntries.size()) {
toIndex = listIntygEntries.size();
}
listIntygEntries = listIntygEntries.subList(filter.getStartFrom(), toIndex);
} else {
// Index out of range
listIntygEntries.clear();
}
QueryIntygResponse response = new QueryIntygResponse(listIntygEntries);
response.setTotalCount(totalCountOfFilteredIntyg);
return response;
}
Aggregations