@Test public void testCreateUtkastSetsPatientFullNameWithoutMiddlename() { String intygsTyp = "luse"; setupUser(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG, intygsTyp, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST); when(utkastService.createNewDraft(any(CreateNewDraftRequest.class))).thenReturn(new Utkast()); when(patientDetailsResolver.resolvePatient(PATIENT_PERSONNUMMER, intygsTyp, INTYG_TYPE_VERSION)).thenReturn(null); doReturn(AccessResult.noProblem()).when(draftAccessService).allowToCreateDraft(any(), any()); CreateUtkastRequest utkastRequest = buildRequest("luse"); utkastRequest.setPatientMellannamn(null); Response response = utkastController.createUtkast(intygsTyp, utkastRequest); assertEquals(OK.getStatusCode(), response.getStatus()); ArgumentCaptor<CreateNewDraftRequest> requestCaptor = ArgumentCaptor.forClass(CreateNewDraftRequest.class); verify(utkastService).createNewDraft(requestCaptor.capture()); assertNotNull(requestCaptor.getValue().getPatient().getFullstandigtNamn()); assertEquals(PATIENT_FORNAMN + " " + PATIENT_EFTERNAMN, requestCaptor.getValue().getPatient().getFullstandigtNamn()); }
@POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } 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); final AccessResult actionResult = draftAccessService.allowToCreateDraft(intygsTyp, request.getPatientPersonnummer()); if (actionResult.isDenied()) { if (actionResult.getCode() == AccessResultCode.UNIQUE_DRAFT || actionResult.getCode() == AccessResultCode.UNIQUE_CERTIFICATE) { return Response.status(Status.BAD_REQUEST).build(); } else { accessResultExceptionHelper.throwException(actionResult); } } 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(); }
UtkastApiController extends AbstractApiController { @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } 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); final AccessResult actionResult = draftAccessService.allowToCreateDraft(intygsTyp, request.getPatientPersonnummer()); if (actionResult.isDenied()) { if (actionResult.getCode() == AccessResultCode.UNIQUE_DRAFT || actionResult.getCode() == AccessResultCode.UNIQUE_CERTIFICATE) { return Response.status(Status.BAD_REQUEST).build(); } else { accessResultExceptionHelper.throwException(actionResult); } } 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(); } }
UtkastApiController extends AbstractApiController { @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } 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); final AccessResult actionResult = draftAccessService.allowToCreateDraft(intygsTyp, request.getPatientPersonnummer()); if (actionResult.isDenied()) { if (actionResult.getCode() == AccessResultCode.UNIQUE_DRAFT || actionResult.getCode() == AccessResultCode.UNIQUE_CERTIFICATE) { return Response.status(Status.BAD_REQUEST).build(); } else { accessResultExceptionHelper.throwException(actionResult); } } 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(); }  }
UtkastApiController extends AbstractApiController { @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } 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); final AccessResult actionResult = draftAccessService.allowToCreateDraft(intygsTyp, request.getPatientPersonnummer()); if (actionResult.isDenied()) { if (actionResult.getCode() == AccessResultCode.UNIQUE_DRAFT || actionResult.getCode() == AccessResultCode.UNIQUE_CERTIFICATE) { return Response.status(Status.BAD_REQUEST).build(); } else { accessResultExceptionHelper.throwException(actionResult); } } 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(); }  @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request); @GET @Path("/questions/{intygsTyp}/{version}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getQuestions(@PathParam("intygsTyp") String intygsTyp, @PathParam("version") String version); @GET @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response filterDraftsForUnit(@QueryParam("") QueryIntygParameter filterParameters); @GET @Path("/lakare") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getLakareWithDraftsByEnheter(); @GET @Path("/previousIntyg/{personnummer}/{currentDraftId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getPreviousCertificateWarnings(@PathParam("personnummer") String personnummer,
                                                   @PathParam("currentDraftId") String currentDraftId); }
UtkastApiController extends AbstractApiController { @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod 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(); } 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); final AccessResult actionResult = draftAccessService.allowToCreateDraft(intygsTyp, request.getPatientPersonnummer()); if (actionResult.isDenied()) { if (actionResult.getCode() == AccessResultCode.UNIQUE_DRAFT || actionResult.getCode() == AccessResultCode.UNIQUE_CERTIFICATE) { return Response.status(Status.BAD_REQUEST).build(); } else { accessResultExceptionHelper.throwException(actionResult); } } 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(); }  @POST @Path("/{intygsTyp}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request); @GET @Path("/questions/{intygsTyp}/{version}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getQuestions(@PathParam("intygsTyp") String intygsTyp, @PathParam("version") String version); @GET @Path("/") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response filterDraftsForUnit(@QueryParam("") QueryIntygParameter filterParameters); @GET @Path("/lakare") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getLakareWithDraftsByEnheter(); @GET @Path("/previousIntyg/{personnummer}/{currentDraftId}") @Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET) @PrometheusTimeMethod Response getPreviousCertificateWarnings(@PathParam("personnummer") String personnummer,
                                                   @PathParam("currentDraftId") String currentDraftId);  }