Search in sources :

Example 11 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.

the class NotificationTypeConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    final String intygsId = "intygsid";
    final LocalDateTime handelsetid = LocalDateTime.now().minusDays(1);
    final HandelsekodEnum handelsetyp = HandelsekodEnum.ANDRAT;
    final int skickadeFragorTotalt = 8;
    final int skickadeFragorHanterade = 7;
    final int skickadeFragorBesvarade = 6;
    final int skickadeFragorEjBesvarade = 5;
    final int mottagnaFragorTotalt = 4;
    final int mottagnaFragorHanterade = 3;
    final int mottagnaFragorBesvarade = 2;
    final int mottagnaFragorEjBesvarade = 1;
    final Intyg intyg = buildIntyg();
    ArendeCount skickadeFragor = new ArendeCount(skickadeFragorTotalt, skickadeFragorEjBesvarade, skickadeFragorBesvarade, skickadeFragorHanterade);
    ArendeCount mottagnaFragor = new ArendeCount(mottagnaFragorTotalt, mottagnaFragorEjBesvarade, mottagnaFragorBesvarade, mottagnaFragorHanterade);
    NotificationMessage msg = new NotificationMessage(intygsId, "luse", handelsetid, handelsetyp, "address", "", null, skickadeFragor, mottagnaFragor, SchemaVersion.VERSION_3, "ref");
    CertificateStatusUpdateForCareType res = NotificationTypeConverter.convert(msg, intyg);
    assertEquals(intyg, res.getIntyg());
    assertEquals(HandelsekodEnum.ANDRAT.value(), res.getHandelse().getHandelsekod().getCode());
    assertEquals(HandelsekodEnum.ANDRAT.description(), res.getHandelse().getHandelsekod().getDisplayName());
    assertEquals(handelsetid, res.getHandelse().getTidpunkt());
    assertNotNull(res.getHandelse().getHandelsekod().getCodeSystem());
    // handelsekod -> codeSystemName is not valid in schema but incorrectly generated in java class
    // therefore we should not populate this field
    assertNull(res.getHandelse().getHandelsekod().getCodeSystemName());
    assertSkickadeFrågor(skickadeFragorTotalt, skickadeFragorHanterade, skickadeFragorBesvarade, skickadeFragorEjBesvarade, res);
    assertMottagnaFragor(mottagnaFragorTotalt, mottagnaFragorHanterade, mottagnaFragorBesvarade, mottagnaFragorEjBesvarade, res);
    // Make sure we have a valid Intyg according to service contract
    assertEquals(NotificationTypeConverter.TEMPORARY_ARBETSPLATSKOD, res.getIntyg().getSkapadAv().getEnhet().getArbetsplatskod().getExtension());
    assertNull(res.getIntyg().getSkapadAv().getEnhet().getEpost());
}
Also used : LocalDateTime(java.time.LocalDateTime) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) CertificateStatusUpdateForCareType(se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType) HandelsekodEnum(se.inera.intyg.common.support.common.enumerations.HandelsekodEnum) Test(org.junit.Test)

Example 12 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.

the class SendMessageToRecipientProcessor method process.

public void process(@Body String xmlBody, @Header(Constants.INTYGS_ID) String intygsId, @Header(Constants.LOGICAL_ADDRESS) String logicalAddress) throws TemporaryException, PermanentException {
    try {
        SendMessageToRecipientType parameters = SendMessageToRecipientTypeConverter.fromXml(xmlBody);
        SendMessageToRecipientResponseType response = sendMessageToRecipientResponder.sendMessageToRecipient(logicalAddress, parameters);
        ResultType result = response.getResult();
        switch(result.getResultCode()) {
            case OK:
            case INFO:
                return;
            case ERROR:
                switch(result.getErrorId()) {
                    case REVOKED:
                    case VALIDATION_ERROR:
                        LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}, ErrorId: {}." + " Rethrowing as PermanentException", intygsId, result.getResultText(), result.getErrorId());
                        throw new PermanentException(result.getResultText());
                    case APPLICATION_ERROR:
                    case TECHNICAL_ERROR:
                        LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}, ErrorId: {}." + " Rethrowing as TemporaryException", intygsId, result.getResultText(), result.getErrorId());
                        throw new TemporaryException(result.getResultText());
                }
        }
    } catch (JAXBException e) {
        LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}. Rethrowing as PermanentException", intygsId, e.getMessage());
        throw new PermanentException(e.getMessage());
    } catch (WebServiceException e) {
        LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}. Will retry", intygsId, e.getMessage());
        throw new TemporaryException(e.getMessage());
    }
}
Also used : TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) WebServiceException(javax.xml.ws.WebServiceException) PermanentException(se.inera.intyg.webcert.common.sender.exception.PermanentException) JAXBException(javax.xml.bind.JAXBException) SendMessageToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientType) ResultType(se.riv.clinicalprocess.healthcond.certificate.v3.ResultType) SendMessageToRecipientResponseType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToRecipient.v2.SendMessageToRecipientResponseType)

Example 13 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.

the class UtkastModelToXmlConverterServiceImpl method utkastToXml.

public String utkastToXml(Utkast utkast) {
    String intygsTyp = utkast.getIntygsTyp();
    String json = utkast.getModel();
    try {
        Intyg intyg = utkastToJAXBObject(intygsTyp, json);
        // This context may need to be created dynamically based on the Intygstyp, given that not all intygstyper
        // are based on the same contract / domain version. Get from ModuleApi?
        JAXBContext context = JAXBContext.newInstance(RegisterCertificateType.class, DatePeriodType.class);
        QName qname = new QName("urn:riv:clinicalprocess:healthcond:certificate:RegisterCertificateResponder:3", "Intyg");
        JAXBElement<Intyg> root = new JAXBElement<>(qname, Intyg.class, intyg);
        return marshal(context.createMarshaller(), root);
    } catch (JAXBException e) {
        LOG.error("Caught JAXBException: {}. Error code: {}", e.getMessage(), e.getErrorCode());
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement)

Example 14 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Intyg utkastsParams = parameters.getIntyg();
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", utkastsParams.getSkapadAv().getPersonalId().getExtension(), invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!HoSPersonHelper.findVardenhetEllerMottagning(user, invokingUnitHsaId).isPresent()) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = moduleRegistry.getModuleIdFromExternalId(utkastsParams.getTypAvIntyg().getCode());
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft request"));
    SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp.toUpperCase() + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, SchemaVersion.VERSION_3, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId(), invokingUnitHsaId);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Intyg(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) Map(java.util.Map) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 15 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.

the class UtkastBootstrapBean method buildUtlatande.

// INTYG-4086: An incredibly ugly hack to mitigate the fact that we're populating test-data using the XML format
// and also directly to WC instead of storing in IT where these actually belong...
private Utlatande buildUtlatande(Resource resource, String moduleName) throws ModuleException, ModuleNotFoundException, IOException {
    String xml = Resources.toString(resource.getURL(), Charsets.UTF_8);
    Utlatande utlatande = registry.getModuleApi(moduleName).getUtlatandeFromXml(xml);
    switch(moduleName) {
        case "luse":
        case "luae_fs":
        case "luae_na":
        case "lisjp":
            RegisterCertificateType jaxbObject = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterCertificateType.class);
            Patient patient = jaxbObject.getIntyg().getPatient();
            utlatande.getGrundData().getPatient().setFornamn(patient.getFornamn());
            utlatande.getGrundData().getPatient().setMellannamn(patient.getMellannamn());
            utlatande.getGrundData().getPatient().setEfternamn(patient.getEfternamn());
            utlatande.getGrundData().getPatient().setFullstandigtNamn(IntygConverterUtil.concatPatientName(patient.getFornamn(), patient.getMellannamn(), patient.getEfternamn()));
            break;
        case "fk7263":
            RegisterMedicalCertificateType jaxbObject2 = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterMedicalCertificateType.class);
            PatientType patient2 = jaxbObject2.getLakarutlatande().getPatient();
            utlatande.getGrundData().getPatient().setEfternamn(patient2.getFullstandigtNamn());
            utlatande.getGrundData().getPatient().setFullstandigtNamn(patient2.getFullstandigtNamn());
            break;
        case "ts-bas":
        case "ts-diabetes":
            break;
    }
    return utlatande;
}
Also used : RegisterMedicalCertificateType(se.inera.ifv.insuranceprocess.healthreporting.registermedicalcertificateresponder.v3.RegisterMedicalCertificateType) PatientType(se.inera.ifv.insuranceprocess.healthreporting.v2.PatientType) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) StringReader(java.io.StringReader) Patient(se.riv.clinicalprocess.healthcond.certificate.v3.Patient) RegisterCertificateType(se.riv.clinicalprocess.healthcond.certificate.registerCertificate.v3.RegisterCertificateType)

Aggregations

Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)15 TypAvIntyg (se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg)7 Test (org.junit.Test)6 Patient (se.riv.clinicalprocess.healthcond.certificate.v3.Patient)6 NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)5 ArendeCount (se.inera.intyg.common.support.modules.support.api.notification.ArendeCount)4 CertificateStatusUpdateForCareType (se.riv.clinicalprocess.healthcond.certificate.certificatestatusupdateforcareresponder.v3.CertificateStatusUpdateForCareType)4 Intyg (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg)4 HsaId (se.riv.clinicalprocess.healthcond.certificate.types.v3.HsaId)4 Enhet (se.riv.clinicalprocess.healthcond.certificate.v3.Enhet)4 LocalDateTime (java.time.LocalDateTime)3 HandelsekodEnum (se.inera.intyg.common.support.common.enumerations.HandelsekodEnum)3 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)3 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 PermanentException (se.inera.intyg.webcert.common.sender.exception.PermanentException)3 TemporaryException (se.inera.intyg.webcert.common.sender.exception.TemporaryException)3 Enhet (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Enhet)3 HosPersonal (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.HosPersonal)3 ArbetsplatsKod (se.riv.clinicalprocess.healthcond.certificate.types.v3.ArbetsplatsKod)3 PersonId (se.riv.clinicalprocess.healthcond.certificate.types.v3.PersonId)3