Search in sources :

Example 11 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.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.createdraftcertificateresponder.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 13 with Intyg

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.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 14 with Intyg

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

the class CertificateStatusUpdateForCareResponderStub method certificateStatusUpdateForCare.

@Override
public CertificateStatusUpdateForCareResponseType certificateStatusUpdateForCare(String logicalAddress, CertificateStatusUpdateForCareType request) {
    Intyg intyg = request.getIntyg();
    String handelseKod = request.getHandelse().getHandelsekod().getCode();
    String intygsId = intyg.getIntygsId().getExtension();
    StringBuilder sb = new StringBuilder();
    if (intyg.getSigneringstidpunkt() != null) {
        sb.append(" Signeringstidpunkt: " + intyg.getSigneringstidpunkt());
        sb.append("\n");
    }
    if (intyg.getPatient() != null) {
        sb.append(" Patient: " + intyg.getPatient().getPersonId().getExtension());
        sb.append("\n");
    }
    Arenden skickadeFragor = request.getSkickadeFragor();
    sb.append(" Skickade fragor totalt: " + skickadeFragor.getTotalt());
    sb.append(" Skickade fragor hanterade: " + skickadeFragor.getHanterade());
    sb.append(" Skickade fragor besvarade: " + skickadeFragor.getBesvarade());
    sb.append(" Skickade fragor ej besvarade: " + skickadeFragor.getEjBesvarade());
    sb.append("\n");
    Arenden mottagnaFragor = request.getMottagnaFragor();
    sb.append(" Mottagna fragor totalt: " + mottagnaFragor.getTotalt());
    sb.append(" Mottagna fragor hanterade: " + mottagnaFragor.getHanterade());
    sb.append(" Mottagna fragor besvarade: " + mottagnaFragor.getBesvarade());
    sb.append(" Mottagna fragor ej besvarade: " + mottagnaFragor.getEjBesvarade());
    sb.append("\n");
    LOG.info("\n*********************************************************************************\n" + " Request to address '{}' recieved for intyg: {} handelse: {}.\n" + "{}" + "*********************************************************************************", logicalAddress, intygsId, handelseKod, sb.toString());
    notificationStoreV3.put(request);
    CertificateStatusUpdateForCareResponseType response = new CertificateStatusUpdateForCareResponseType();
    response.setResult(ResultTypeUtil.okResult());
    LOG.debug("Request set to 'OK'");
    return response;
}
Also used : Arenden(se.riv.clinicalprocess.healthcond.certificate.v3.Arenden) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)

Example 15 with Intyg

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

the class NotificationTestHelper method createIntyg.

public static Intyg createIntyg(String intygsTyp) {
    Intyg intyg = new Intyg();
    IntygId intygId = new IntygId();
    intygId.setExtension("intyg123");
    intyg.setIntygsId(intygId);
    TypAvIntyg typAvIntyg = new TypAvIntyg();
    typAvIntyg.setCode(intygsTyp);
    intyg.setTyp(typAvIntyg);
    intyg.setPatient(buildPatient());
    HosPersonal hosPersonal = new HosPersonal();
    Enhet enhet = new Enhet();
    enhet.setVardgivare(new Vardgivare());
    enhet.setArbetsplatskod(new ArbetsplatsKod());
    hosPersonal.setEnhet(enhet);
    intyg.setSkapadAv(hosPersonal);
    // DatePeriodType and PartialDateType must be allowed
    intyg.getSvar().add(InternalConverterUtil.aSvar("").withDelsvar("", InternalConverterUtil.aDatePeriod(LocalDate.now(), LocalDate.now().plusDays(1))).withDelsvar("", InternalConverterUtil.aPartialDate(PartialDateTypeFormatEnum.YYYY, Year.of(1999))).build());
    return intyg;
}
Also used : HosPersonal(se.riv.clinicalprocess.healthcond.certificate.v3.HosPersonal) Enhet(se.riv.clinicalprocess.healthcond.certificate.v3.Enhet) TypAvIntyg(se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg) ArbetsplatsKod(se.riv.clinicalprocess.healthcond.certificate.types.v3.ArbetsplatsKod) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) TypAvIntyg(se.riv.clinicalprocess.healthcond.certificate.types.v3.TypAvIntyg) Vardgivare(se.riv.clinicalprocess.healthcond.certificate.v3.Vardgivare) IntygId(se.riv.clinicalprocess.healthcond.certificate.types.v3.IntygId)

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 NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)5 Patient (se.riv.clinicalprocess.healthcond.certificate.v3.Patient)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 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 HosPersonal (se.riv.clinicalprocess.healthcond.certificate.v3.HosPersonal)3 Vardgivare (se.riv.clinicalprocess.healthcond.certificate.v3.Vardgivare)3