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;
}
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());
}
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());
}
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;
}
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));
}
Aggregations