Search in sources :

Example 1 with QuestionToFkType

use of se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType in project webcert by sklintyg.

the class FKQuestionConverterTest method inflateQuestionToFK.

private QuestionToFkType inflateQuestionToFK() throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(QuestionToFkType.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    return unmarshaller.unmarshal(new StreamSource(new ClassPathResource("FragaSvarConverterTest/question_to_fk.xml").getInputStream()), QuestionToFkType.class).getValue();
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 2 with QuestionToFkType

use of se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType in project webcert by sklintyg.

the class FKQuestionConverterTest method testConvertQuestion.

@Test
public void testConvertQuestion() throws Exception {
    QuestionFromFkType questionFromFK = inflateQuestionFromFK();
    QuestionToFkType referenceQuestionToFK = inflateQuestionToFK();
    // convert QuestionFromFK to FragaSvar entity
    FragaSvar fragaSvar = fragaSvarConverter.convert(questionFromFK);
    // add some data
    fragaSvar.setAmne(Amne.KONTAKT);
    fragaSvar.setInternReferens(321L);
    // convert fragaSvar entity to QuestionToFK
    QuestionToFkType convertedQuestionToFK = FKQuestionConverter.convert(fragaSvar);
    // compare convertedQuestionToFK to reference
    String expected = jaxbToXml(referenceQuestionToFK);
    String actual = jaxbToXml(convertedQuestionToFK);
    assertEquals(expected, actual);
}
Also used : QuestionFromFkType(se.inera.ifv.insuranceprocess.healthreporting.receivemedicalcertificatequestionsponder.v1.QuestionFromFkType) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) Test(org.junit.Test)

Example 3 with QuestionToFkType

use of se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType in project webcert by sklintyg.

the class FKQuestionConverter method convert.

public static QuestionToFkType convert(FragaSvar fs) {
    QuestionToFkType fkQuestion = new QuestionToFkType();
    fkQuestion.setAmne(ConvertToFKTypes.toAmneTyp(fs.getAmne()));
    fkQuestion.setAdressVard(ConvertToFKTypes.toVardAdresseringsType(fs.getVardperson()));
    fkQuestion.setAvsantTidpunkt(fs.getFrageSkickadDatum());
    fkQuestion.setFraga(ConvertToFKTypes.toInnehallType(fs.getFrageText(), fs.getFrageSigneringsDatum()));
    fkQuestion.setLakarutlatande(ConvertToFKTypes.toLakarUtlatande(fs.getIntygsReferens()));
    fkQuestion.setVardReferensId(fs.getInternReferens().toString());
    return fkQuestion;
}
Also used : QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType)

Example 4 with QuestionToFkType

use of se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType 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;
}
Also used : Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) LocalDateTime(java.time.LocalDateTime) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 5 with QuestionToFkType

use of se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType in project webcert by sklintyg.

the class SendQuestionStub method sendMedicalCertificateQuestion.

@Override
public SendMedicalCertificateQuestionResponseType sendMedicalCertificateQuestion(AttributedURIType logicalAddress, SendMedicalCertificateQuestionType parameters) {
    SendMedicalCertificateQuestionResponseType response = new SendMedicalCertificateQuestionResponseType();
    if (logicalAddress == null) {
        response.setResult(ResultOfCallUtil.failResult("Ingen LogicalAddress är satt"));
    } else if (!LOGICAL_ADDRESS.equals(logicalAddress.getValue())) {
        response.setResult(ResultOfCallUtil.failResult("LogicalAddress '" + logicalAddress.getValue() + "' är inte samma som '" + LOGICAL_ADDRESS + "'"));
    } else if ("error".equalsIgnoreCase(parameters.getQuestion().getFraga().getMeddelandeText())) {
        response.setResult(ResultOfCallUtil.failResult("Du ville ju få ett fel"));
    } else {
        QuestionToFkType questionType = parameters.getQuestion();
        SendMedicalCertificateQuestionValidator validator = new SendMedicalCertificateQuestionValidator(questionType);
        try {
            validator.validateAndCorrect();
            response.setResult(ResultOfCallUtil.okResult());
        } catch (ValidationException e) {
            response.setResult(ResultOfCallUtil.failResult(e.getMessage()));
        }
        questionAnswerStore.addQuestion(parameters.getQuestion());
    }
    return response;
}
Also used : ValidationException(se.inera.intyg.webcert.fkstub.validation.ValidationException) SendMedicalCertificateQuestionValidator(se.inera.intyg.webcert.fkstub.validation.SendMedicalCertificateQuestionValidator) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType)

Aggregations

QuestionToFkType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType)5 JAXBContext (javax.xml.bind.JAXBContext)2 SendMedicalCertificateQuestionResponseType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType)2 FragaSvar (se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 LocalDateTime (java.time.LocalDateTime)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 AttributedURIType (org.w3.wsaddressing10.AttributedURIType)1 QuestionFromFkType (se.inera.ifv.insuranceprocess.healthreporting.receivemedicalcertificatequestionsponder.v1.QuestionFromFkType)1 ObjectFactory (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.ObjectFactory)1 SendMedicalCertificateQuestionType (se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType)1 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 SendMedicalCertificateQuestionValidator (se.inera.intyg.webcert.fkstub.validation.SendMedicalCertificateQuestionValidator)1