Search in sources :

Example 1 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class IntygResource method updateUtkastForSend.

private void updateUtkastForSend(@PathParam("id") String id) {
    Utkast utkast = utkastRepository.findOne(id);
    if (utkast != null) {
        utkast.setStatus(UtkastStatus.SIGNED);
        Utlatande utlatande = moduleFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), utkast.getModel());
        utlatande.getGrundData().setSigneringsdatum(LocalDateTime.now());
        try {
            CustomObjectMapper mapper = new CustomObjectMapper();
            StringWriter writer = new StringWriter();
            mapper.writeValue(writer, utlatande);
            utkast.setModel(writer.toString());
        } catch (IOException e) {
            LOG.error("Could not update the model of the utkast. Failed with message ", e.getMessage());
        }
        if (utkast.getSignatur() == null) {
            Signatur sig = new Signatur(LocalDateTime.now(), "", id, "", "", "");
            utkast.setSignatur(sig);
        }
        utkast.setSkickadTillMottagare("FKASSA");
        utkast.setSkickadTillMottagareDatum(LocalDateTime.now());
        utkastRepository.save(utkast);
    }
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) StringWriter(java.io.StringWriter) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) CustomObjectMapper(se.inera.intyg.common.util.integration.json.CustomObjectMapper) IOException(java.io.IOException)

Example 2 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromSignedIntyg.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromSignedIntyg(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
public CopyUtkastBuilderResponse populateCopyUtkastFromSignedIntyg(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    String originalIntygsTyp = copyRequest.getOriginalIntygTyp();
    String intygsTyp = copyRequest.getTyp();
    IntygContentHolder signedIntygHolder = intygService.fetchIntygData(orignalIntygsId, originalIntygsTyp, coherentJournaling);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(originalIntygsTyp);
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(signedIntygHolder.getContents());
    } catch (IOException e) {
        throw new ModuleException("Could not convert orignal certificate to Utlatande", e);
    }
    GrundData grundData = signedIntygHolder.getUtlatande().getGrundData();
    se.inera.intyg.common.support.model.common.internal.Vardenhet vardenhet = grundData.getSkapadAv().getVardenhet();
    if (coherentJournaling && enforceEnhet) {
        verifyEnhetsAuth(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), true);
    }
    LOG.debug("Populating copy with details from signed Intyg '{}'", orignalIntygsId);
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(vardenhet.getEnhetsid());
    builderResponse.setOrginalEnhetsNamn(vardenhet.getEnhetsnamn());
    builderResponse.setOrginalVardgivarId(vardenhet.getVardgivare().getVardgivarid());
    builderResponse.setOrginalVardgivarNamn(vardenhet.getVardgivare().getVardgivarnamn());
    ModuleApi moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, intygsTyp, addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        se.inera.intyg.common.support.model.common.internal.Patient patient = signedIntygHolder.getUtlatande().getGrundData().getPatient();
        populatePatientDetailsFromPatient(utkast, patient);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) IOException(java.io.IOException) Relation(se.inera.intyg.common.support.model.common.internal.Relation) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 3 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromOrignalUtkast.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromOrignalUtkast(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public CopyUtkastBuilderResponse populateCopyUtkastFromOrignalUtkast(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    Utkast orgUtkast = utkastRepository.findOne(orignalIntygsId);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(copyRequest.getOriginalIntygTyp());
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(orgUtkast.getModel());
    } catch (IOException e) {
        throw new ModuleException("Could not convert original certificate to Utlatande", e);
    }
    // Perform enhets auth if coherent journaling is not active.
    if (!coherentJournaling || enforceEnhet) {
        verifyEnhetsAuth(orgUtkast.getVardgivarId(), orgUtkast.getEnhetsId(), true);
    } else {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(orgUtkast, coherentJournaling);
        logService.logReadIntyg(logRequest);
    }
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(orgUtkast.getEnhetsId());
    builderResponse.setOrginalEnhetsNamn(orgUtkast.getEnhetsNamn());
    builderResponse.setOrginalVardgivarId(orgUtkast.getVardgivarId());
    builderResponse.setOrginalVardgivarNamn(orgUtkast.getVardgivarNamn());
    LOG.debug("Populating copy with details from Utkast '{}'", orignalIntygsId);
    ModuleApi moduleApi = moduleRegistry.getModuleApi(copyRequest.getTyp());
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, copyRequest.getTyp(), addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        populatePatientDetailsFromUtkast(utkast, orgUtkast);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Relation(se.inera.intyg.common.support.model.common.internal.Relation) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class UtkastModelToXmlConverterServiceImpl method utkastToJAXBObject.

private Intyg utkastToJAXBObject(String intygsTyp, String json) {
    try {
        ModuleApi moduleApi = intygModuleRegistry.getModuleApi(intygsTyp);
        Utlatande utlatandeFromJson = moduleApi.getUtlatandeFromJson(json);
        return moduleApi.getIntygFromUtlatande(utlatandeFromJson);
    } catch (ModuleNotFoundException | IOException | ModuleException e) {
        LOG.error("Error building Intyg JAXB object from Utkast. Message: {}", e.getMessage());
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Example 5 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class UtkastBootstrapBean method init.

@PostConstruct
public void init() throws IOException {
    for (Resource resource : getResourceListing("classpath*:module-bootstrap-certificate/*.xml")) {
        try {
            String moduleName = resource.getFilename().split("__")[0];
            LOG.info("Bootstrapping certificate '{}' from module ", resource.getFilename(), moduleName);
            Utlatande utlatande = buildUtlatande(resource, moduleName);
            if (utkastRepo.findOne(utlatande.getId()) == null) {
                utkastRepo.save(createUtkast(utlatande));
                switch(utlatande.getTyp()) {
                    case Fk7263EntryPoint.MODULE_ID:
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, true, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.WEBCERT, false, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, true));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, false));
                        break;
                    case TsBasEntryPoint.MODULE_ID:
                    case TsDiabetesEntryPoint.MODULE_ID:
                        // These certificates does not support arende or fragaSvar
                        break;
                    default:
                        // SIT certificates
                        setupArende(utlatande, true, true, FrageStallare.FORSAKRINGSKASSAN);
                        setupArende(utlatande, false, false, FrageStallare.WEBCERT);
                        setupArende(utlatande, false, false, FrageStallare.FORSAKRINGSKASSAN);
                        break;
                }
            }
        } catch (ModuleException | ModuleNotFoundException | IOException e) {
            LOG.error("Could not bootstrap {}", resource.getFilename(), e);
        }
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)18 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)14 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)11 IOException (java.io.IOException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Relation (se.inera.intyg.common.support.model.common.internal.Relation)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)7 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)7 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)7 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)6 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)6 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)3