use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class CreateUtkastFromTemplateBuilderTest method testPopulateRenewalUtkastFromSignedIntyg.
@Test
public void testPopulateRenewalUtkastFromSignedIntyg() throws Exception {
IntygContentHolder ich = createIntygContentHolder();
when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE_1, false)).thenReturn(ich);
CreateUtkastFromTemplateRequest createUtkastFromTemplateRequest = buildCreateUtkastFromTemplateRequest();
Person patientDetails = new Person(PATIENT_SSN, false, false, PATIENT_FNAME, PATIENT_MNAME, PATIENT_LNAME, "Postadr", "12345", "postort");
when(mockModuleApi2.createNewInternalFromTemplate(any(CreateDraftCopyHolder.class), any())).thenReturn(INTYG_JSON);
ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
when(mockModuleApi2.validateDraft(anyString())).thenReturn(vdr);
CopyUtkastBuilderResponse builderResponse = createUtkastFromTemplateBuilder.populateCopyUtkastFromSignedIntyg(createUtkastFromTemplateRequest, patientDetails, false, false, false);
assertNotNull(builderResponse.getUtkastCopy());
assertNotNull(builderResponse.getUtkastCopy().getModel());
assertEquals(INTYG_TYPE_2, builderResponse.getUtkastCopy().getIntygsTyp());
assertEquals(PATIENT_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
assertEquals(PATIENT_FNAME, builderResponse.getUtkastCopy().getPatientFornamn());
assertEquals(PATIENT_MNAME, builderResponse.getUtkastCopy().getPatientMellannamn());
assertEquals(PATIENT_LNAME, builderResponse.getUtkastCopy().getPatientEfternamn());
ArgumentCaptor<CreateDraftCopyHolder> requestCaptor = ArgumentCaptor.forClass(CreateDraftCopyHolder.class);
verify(mockModuleApi2).createNewInternalFromTemplate(requestCaptor.capture(), any());
// verify full name is set
assertNotNull(requestCaptor.getValue().getPatient().getFullstandigtNamn());
assertEquals(PATIENT_FNAME + " " + PATIENT_MNAME + " " + PATIENT_LNAME, requestCaptor.getValue().getPatient().getFullstandigtNamn());
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class FragaSvarServiceImpl method saveNewQuestion.
@Override
public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) {
// Argument check
if (Strings.isNullOrEmpty(frageText)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!");
}
if (amne == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!");
} else if (!VALID_VARD_AMNEN.contains(amne)) {
// Businessrule RE-013
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
}
// Fetch from Intygstjansten. Note that if Intygstjansten is unresponsive, the Intyg will be loaded from WebCert
// if possible.
IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false);
WebCertUser user = webCertUserService.getUser();
// Get vardperson that posed the question
// Is user authorized to save an answer to this question?
verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false);
// Verksamhetsregel FS-001 (Is the certificate sent to FK)
if (!isCertificateSentToFK(intyg.getStatuses())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!");
}
// Verify that certificate is not revoked
if (intyg.isRevoked()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!");
}
IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande());
HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null);
Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal);
FragaSvar fraga = new FragaSvar();
fraga.setFrageStallare(FrageStallare.WEBCERT.getKod());
fraga.setAmne(amne);
fraga.setFrageText(frageText);
LocalDateTime now = LocalDateTime.now();
fraga.setFrageSkickadDatum(now);
fraga.setFrageSigneringsDatum(now);
fraga.setIntygsReferens(intygsReferens);
fraga.setVardperson(vardPerson);
fraga.setStatus(Status.PENDING_EXTERNAL_ACTION);
fraga.setVardAktorHsaId(user.getHsaId());
fraga.setVardAktorNamn(user.getNamn());
// Ok, lets save the question
FragaSvar saved = fragaSvarRepository.save(fraga);
// Send to external party (FK)
SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType();
QuestionToFkType question = FKQuestionConverter.convert(saved);
// Remove ASAP.
if ("true".equalsIgnoreCase(forceFullstandigtNamn)) {
question.getLakarutlatande().getPatient().setFullstandigtNamn("---");
}
sendType.setQuestion(question);
AttributedURIType logicalAddress = new AttributedURIType();
logicalAddress.setValue(sendQuestionToFkLogicalAddress);
SendMedicalCertificateQuestionResponseType response;
try {
response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType);
} catch (SOAPFaultException e) {
LOGGER.error("Failed to send question to FK, error was: " + e.getMessage());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage());
}
if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) {
LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult().getErrorText());
}
monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardAktorHsaId(), saved.getAmne());
// Notify stakeholders
sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE);
arendeDraftService.delete(intygId, null);
return saved;
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceImpl method revokeIntyg.
/*
* (non-Javadoc)
*
* @see se.inera.intyg.webcert.web.service.intyg.IntygService#revokeIntyg(java.lang.String, java.lang.String)
*/
@Override
public IntygServiceResult revokeIntyg(String intygsId, String intygsTyp, String revokeMessage, String reason) {
LOG.debug("Attempting to revoke intyg {}", intygsId);
IntygContentHolder intyg = getIntygData(intygsId, intygsTyp, false);
verifyEnhetsAuth(intyg.getUtlatande(), true);
verifyIsSigned(intyg.getStatuses());
if (intyg.isRevoked()) {
LOG.debug("Certificate with id '{}' is already revoked", intygsId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificate is already revoked");
}
try {
certificateSenderService.revokeCertificate(intygsId, modelFacade.getRevokeCertificateRequest(intygsTyp, intyg.getUtlatande(), IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null), revokeMessage), intygsTyp);
whenSuccessfulRevoke(intyg.getUtlatande(), reason);
return IntygServiceResult.OK;
} catch (CertificateSenderException | ModuleException | IntygModuleFacadeException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, e.getMessage());
}
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygServiceImpl method fetchIntygAsPdf.
@Override
public IntygPdf fetchIntygAsPdf(String intygsId, String intygsTyp, boolean isEmployer) {
try {
LOG.debug("Fetching intyg '{}' as PDF", intygsId);
IntygContentHolder intyg = getIntygDataPreferWebcert(intygsId, intygsTyp);
//
verifyPuServiceAvailable(intyg);
boolean coherentJournaling = userIsDjupintegreradWithSjf();
if (!coherentJournaling) {
verifyEnhetsAuth(intyg.getUtlatande(), true);
}
IntygPdf intygPdf = modelFacade.convertFromInternalToPdfDocument(intygsTyp, intyg.getContents(), intyg.getStatuses(), isEmployer);
// Log print as PDF to PDL log
logPdfPrinting(intyg, coherentJournaling);
return intygPdf;
} catch (IntygModuleFacadeException e) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
}
}
use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testGetIntyg.
@Test
public void testGetIntyg() {
final String intygsTyp = "fk7263";
final String intygContent = "CONTENTS";
setupUser(AuthoritiesConstants.PRIVILEGE_VISA_INTYG, intygsTyp, false, true);
IntygContentHolder content = mock(IntygContentHolder.class);
when(content.getContents()).thenReturn(intygContent);
when(intygService.fetchIntygDataWithRelations(eq(CERTIFICATE_ID), eq(intygsTyp), eq(false))).thenReturn(content);
Response response = moduleApiController.getIntyg(intygsTyp, CERTIFICATE_ID);
assertEquals(OK.getStatusCode(), response.getStatus());
assertEquals(intygContent, ((IntygContentHolder) response.getEntity()).getContents());
verify(intygService).fetchIntygDataWithRelations(eq(CERTIFICATE_ID), eq(intygsTyp), eq(false));
}
Aggregations