Search in sources :

Example 1 with Utlatande

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande in project webcert by sklintyg.

the class CreateDraftCertificateValidatorImplTest method buildIntyg.

private Utlatande buildIntyg(String intygsKod, String patientEfternamn, String patientFornamn, String patientPersonId, String hosPersonalFullstandigtNamn, String hosPersonalHsaId, String enhetsnamn, String enhetHsaId, boolean createUnit) {
    Utlatande intyg = new Utlatande();
    TypAvUtlatande typAvIntyg = new TypAvUtlatande();
    typAvIntyg.setCode(intygsKod);
    intyg.setTypAvUtlatande(typAvIntyg);
    Patient patient = new Patient();
    patient.setEfternamn(patientEfternamn);
    if (patientFornamn != null) {
        patient.getFornamn().add(patientFornamn);
    }
    if (patientPersonId != null) {
        patient.setPersonId(new PersonId());
        patient.getPersonId().setExtension(patientPersonId);
    }
    intyg.setPatient(patient);
    HosPersonal hosPersonal = new HosPersonal();
    hosPersonal.setFullstandigtNamn(hosPersonalFullstandigtNamn);
    if (hosPersonalHsaId != null) {
        hosPersonal.setPersonalId(new HsaId());
        hosPersonal.getPersonalId().setExtension(hosPersonalHsaId);
    }
    if (createUnit) {
        Enhet enhet = new Enhet();
        enhet.setEnhetsnamn(enhetsnamn);
        if (enhetHsaId != null) {
            enhet.setEnhetsId(new HsaId());
            enhet.getEnhetsId().setExtension(enhetHsaId);
        }
        hosPersonal.setEnhet(enhet);
    }
    intyg.setSkapadAv(hosPersonal);
    return intyg;
}
Also used : HosPersonal(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.HosPersonal) Enhet(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Enhet) PersonId(se.riv.clinicalprocess.healthcond.certificate.types.v1.PersonId) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) Patient(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Patient) HsaId(se.riv.clinicalprocess.healthcond.certificate.types.v1.HsaId) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande)

Example 2 with Utlatande

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande in project webcert by sklintyg.

the class CreateNewDraftRequestBuilderTest method test.

@Test
public void test() {
    // given
    Utlatande utlatande = createUtlatande();
    // when
    CreateNewDraftRequest res = builder.buildCreateNewDraftRequest(utlatande, user);
    // then
    assertNotNull(res);
    assertEquals(CERT_TYPE, res.getIntygType());
    assertEquals(USER_HSAID, res.getHosPerson().getPersonId());
    assertNotNull(res.getHosPerson().getFullstandigtNamn());
    assertEquals(UNIT_HSAID, res.getHosPerson().getVardenhet().getEnhetsid());
    assertNotNull(res.getHosPerson().getVardenhet().getEnhetsnamn());
    assertNotNull(res.getHosPerson().getVardenhet().getArbetsplatsKod());
    assertNotNull(res.getHosPerson().getVardenhet().getTelefonnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostadress());
    assertNotNull(res.getHosPerson().getVardenhet().getPostnummer());
    assertNotNull(res.getHosPerson().getVardenhet().getPostort());
    assertEquals(CAREGIVER_HSAID, res.getHosPerson().getVardenhet().getVardgivare().getVardgivarid());
    assertNotNull(res.getHosPerson().getVardenhet().getVardgivare().getVardgivarnamn());
    assertEquals(PERSNR, res.getPatient().getPersonId().getPersonnummerWithDash());
    assertEquals("Adam Bertil", res.getPatient().getFornamn());
    assertEquals("Cesarsson Davidsson", res.getPatient().getMellannamn());
    assertEquals("Eriksson", res.getPatient().getEfternamn());
}
Also used : CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Test(org.junit.Test) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)

Example 3 with Utlatande

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande in project webcert by sklintyg.

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Utlatande utkastsParams = parameters.getUtlatande();
    // Redo this: Build a full Vårdgivare -> Vårdenhet -> Mottagning tree and then check.
    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 '{}'", invokingUserHsaId, invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!checkMIU(user, invokingUnitHsaId)) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = utkastsParams.getTypAvUtlatande().getCode().toLowerCase();
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft reques"));
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp + " 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
        SchemaVersion schemaVersion = integreradeEnheterRegistry.getSchemaVersion(invokingUnitHsaId, intygsTyp).orElse(SchemaVersion.VERSION_1);
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, schemaVersion, 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());
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) 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) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map)

Example 4 with Utlatande

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande in project webcert by sklintyg.

the class CreateNewDraftRequestBuilderTest method createUtlatande.

private Utlatande createUtlatande() {
    Utlatande utlatande = new Utlatande();
    // Type
    TypAvUtlatande utlTyp = new TypAvUtlatande();
    utlTyp.setCode(CERT_TYPE);
    utlatande.setTypAvUtlatande(utlTyp);
    // HoSPerson
    HsaId userHsaId = new HsaId();
    userHsaId.setExtension(USER_HSAID);
    userHsaId.setRoot("USERHSAID");
    HosPersonal hosPerson = new HosPersonal();
    hosPerson.setPersonalId(userHsaId);
    hosPerson.setFullstandigtNamn(FULLSTANDIGT_NAMN);
    HsaId unitHsaId = new HsaId();
    unitHsaId.setExtension(UNIT_HSAID);
    unitHsaId.setRoot("UNITHSAID");
    Enhet hosEnhet = new Enhet();
    hosEnhet.setEnhetsId(unitHsaId);
    hosPerson.setEnhet(hosEnhet);
    utlatande.setSkapadAv(hosPerson);
    // Patient
    PersonId personId = new PersonId();
    personId.setRoot("PERSNR");
    personId.setExtension(PERSNR);
    Patient patType = new Patient();
    patType.setPersonId(personId);
    patType.getFornamn().add("Adam");
    patType.getFornamn().add("Bertil");
    patType.getMellannamn().add("Cesarsson");
    patType.getMellannamn().add("Davidsson");
    patType.setEfternamn("Eriksson");
    utlatande.setPatient(patType);
    return utlatande;
}
Also used : HosPersonal(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.HosPersonal) Enhet(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Enhet) PersonId(se.riv.clinicalprocess.healthcond.certificate.types.v1.PersonId) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Patient(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Patient) HsaId(se.riv.clinicalprocess.healthcond.certificate.types.v1.HsaId) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande)

Example 5 with Utlatande

use of se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande in project webcert by sklintyg.

the class CreateNewDraftRequestBuilderTest method testWithHsaBefattningAndSpecialityNames.

@Test
public void testWithHsaBefattningAndSpecialityNames() {
    // given
    Utlatande utlatande = createUtlatande();
    // when
    CreateNewDraftRequest res = builder.buildCreateNewDraftRequest(utlatande, user);
    // then
    assertNotNull(res);
    assertNotNull(res.getHosPerson());
    assertEquals(TITLE_CODE, res.getHosPerson().getBefattningar().get(0));
    assertEquals(ALLMAN_MEDICIN, res.getHosPerson().getSpecialiteter().get(0));
    assertEquals(INVARTES_MEDICIN, res.getHosPerson().getSpecialiteter().get(1));
}
Also used : CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) TypAvUtlatande(se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande) Test(org.junit.Test) BaseCreateDraftCertificateTest(se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)

Aggregations

Utlatande (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande)6 TypAvUtlatande (se.riv.clinicalprocess.healthcond.certificate.types.v1.TypAvUtlatande)5 Enhet (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Enhet)3 HosPersonal (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.HosPersonal)3 Patient (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Patient)3 HsaId (se.riv.clinicalprocess.healthcond.certificate.types.v1.HsaId)3 PersonId (se.riv.clinicalprocess.healthcond.certificate.types.v1.PersonId)3 Test (org.junit.Test)2 BaseCreateDraftCertificateTest (se.inera.intyg.webcert.web.integration.interactions.createdraftcertificate.BaseCreateDraftCertificateTest)2 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)2 Map (java.util.Map)1 SchemaVersion (se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion)1 IntygUser (se.inera.intyg.infra.security.common.model.IntygUser)1 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 TakResult (se.inera.intyg.webcert.integration.tak.model.TakResult)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 ResultValidator (se.inera.intyg.webcert.web.integration.validators.ResultValidator)1 CreateDraftCertificateType (se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.CreateDraftCertificateType)1