Search in sources :

Example 16 with HoSPersonal

use of se.inera.intyg.common.support.model.common.internal.HoSPersonal 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 17 with HoSPersonal

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

the class SendCertificateServiceClientImpl method sendCertificate.

@Override
public SendCertificateToRecipientResponseType sendCertificate(String intygsId, String personId, String skickatAvJson, String recipient, String logicalAddress) {
    validateArgument(intygsId, "Cannot send certificate, argument 'intygsId' is null or empty.");
    validateArgument(personId, "Cannot send certificate, argument 'personId' is null or empty.");
    validateArgument(skickatAvJson, "Cannot send certificate, argument 'skickatAvJson' is null or empty.");
    validateArgument(recipient, "Cannot send certificate, argument 'recipient' is null or empty.");
    validateArgument(logicalAddress, "Cannot send certificate, argument 'logicalAddress' is null or empty.");
    HoSPersonal skickatAv = parseJson(skickatAvJson);
    SendCertificateToRecipientType request = SendCertificateToRecipientTypeConverter.convert(intygsId, personId, skickatAv, recipient);
    return sendService.sendCertificateToRecipient(logicalAddress, request);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) SendCertificateToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendCertificateToRecipient.v2.SendCertificateToRecipientType)

Example 18 with HoSPersonal

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

the class SendCertificateToRecipientTypeConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    final String intygsId = "intygsid";
    final String enhetsId = "enhetsid";
    final String enhetsnamn = "enhetsnamn";
    final String patientPersonId = "201212121212";
    final String skapadAvFullstandigtNamn = "fullstÃĪndigt namn";
    final String skapadAvPersonId = "skapad av pid";
    final String arbetsplatsKod = "arbetsplatsKod";
    final String postadress = "postadress";
    final String postNummer = "postNummer";
    final String postOrt = "postOrt";
    final String epost = "epost";
    final String telefonNummer = "telefonNummer";
    final String vardgivarid = "vardgivarid";
    final String vardgivarNamn = "vardgivarNamn";
    final String forskrivarKod = "forskrivarKod";
    final String recipient = "TRANSP";
    HoSPersonal skickatAv = buildHosPersonal(enhetsId, enhetsnamn, skapadAvFullstandigtNamn, skapadAvPersonId, arbetsplatsKod, postadress, postNummer, postOrt, epost, telefonNummer, vardgivarid, vardgivarNamn, forskrivarKod);
    SendCertificateToRecipientType result = SendCertificateToRecipientTypeConverter.convert(intygsId, patientPersonId, skickatAv, recipient);
    assertNotNull(result.getIntygsId().getRoot());
    assertEquals(intygsId, result.getIntygsId().getExtension());
    assertNotNull(result.getPatientPersonId().getRoot());
    assertEquals(patientPersonId, result.getPatientPersonId().getExtension());
    assertEquals(skapadAvFullstandigtNamn, result.getSkickatAv().getHosPersonal().getFullstandigtNamn());
    assertNotNull(result.getSkickatAv().getHosPersonal().getPersonalId().getRoot());
    assertEquals(skapadAvPersonId, result.getSkickatAv().getHosPersonal().getPersonalId().getExtension());
    assertNotNull(result.getSkickatAv().getHosPersonal().getEnhet().getEnhetsId().getRoot());
    assertEquals(enhetsId, result.getSkickatAv().getHosPersonal().getEnhet().getEnhetsId().getExtension());
    assertNotNull(result.getSkickatAv().getHosPersonal().getEnhet().getEnhetsId().getExtension());
    assertEquals(enhetsnamn, result.getSkickatAv().getHosPersonal().getEnhet().getEnhetsnamn());
    assertNotNull(result.getSkickatAv().getHosPersonal().getEnhet().getArbetsplatskod().getRoot());
    assertEquals(arbetsplatsKod, result.getSkickatAv().getHosPersonal().getEnhet().getArbetsplatskod().getExtension());
    assertEquals(postadress, result.getSkickatAv().getHosPersonal().getEnhet().getPostadress());
    assertEquals(postNummer, result.getSkickatAv().getHosPersonal().getEnhet().getPostnummer());
    assertEquals(postOrt, result.getSkickatAv().getHosPersonal().getEnhet().getPostort());
    assertEquals(epost, result.getSkickatAv().getHosPersonal().getEnhet().getEpost());
    assertEquals(telefonNummer, result.getSkickatAv().getHosPersonal().getEnhet().getTelefonnummer());
    assertNotNull(result.getSkickatAv().getHosPersonal().getEnhet().getVardgivare().getVardgivareId().getRoot());
    assertEquals(vardgivarid, result.getSkickatAv().getHosPersonal().getEnhet().getVardgivare().getVardgivareId().getExtension());
    assertEquals(vardgivarNamn, result.getSkickatAv().getHosPersonal().getEnhet().getVardgivare().getVardgivarnamn());
    assertEquals(forskrivarKod, result.getSkickatAv().getHosPersonal().getForskrivarkod());
    assertNotNull(result.getSkickatTidpunkt());
    assertNotNull(result.getMottagare().getCodeSystem());
    assertEquals("TRANSP", result.getMottagare().getCode());
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) SendCertificateToRecipientType(se.riv.clinicalprocess.healthcond.certificate.sendCertificateToRecipient.v2.SendCertificateToRecipientType) Test(org.junit.Test)

Example 19 with HoSPersonal

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

the class CreateNewDraftRequestBuilderImpl method createHoSPerson.

private HoSPersonal createHoSPerson(HosPersonal hoSPersonType, Vardenhet vardenhet) {
    HoSPersonal hoSPerson = new HoSPersonal();
    hoSPerson.setFullstandigtNamn(hoSPersonType.getFullstandigtNamn());
    hoSPerson.setPersonId(hoSPersonType.getPersonalId().getExtension());
    hoSPerson.setVardenhet(vardenhet);
    return hoSPerson;
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal)

Example 20 with HoSPersonal

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

the class CreateNewDraftRequestBuilderImpl method buildCreateNewDraftRequest.

@Override
public CreateNewDraftRequest buildCreateNewDraftRequest(Intyg intyg, IntygUser user) {
    HoSPersonal hosPerson = createHoSPerson(intyg.getSkapadAv(), HoSPersonHelper.createVardenhetFromIntygUser(intyg.getSkapadAv().getEnhet().getEnhetsId().getExtension(), user));
    HoSPersonHelper.enrichHoSPerson(hosPerson, user);
    return new CreateNewDraftRequest(null, moduleRegistry.getModuleIdFromExternalId(intyg.getTypAvIntyg().getCode()), null, hosPerson, TransportConverterUtil.getPatient(intyg.getPatient(), true), intyg.getRef());
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)

Aggregations

HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)38 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)15 Test (org.junit.Test)13 Patient (se.inera.intyg.common.support.model.common.internal.Patient)11 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)10 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)10 Before (org.junit.Before)8 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)7 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)5 Vardgivare (se.inera.intyg.common.support.model.common.internal.Vardgivare)5 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)4 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)4 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)4 UpdatePatientOnDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest)4 AbstractVardenhet (se.inera.intyg.infra.integration.hsa.model.AbstractVardenhet)3 SaveDraftResponse (se.inera.intyg.webcert.web.service.utkast.dto.SaveDraftResponse)3