use of se.riv.clinicalprocess.healthcond.certificate.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());
}
use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.
the class SendMessageToRecipientProcessor method process.
public void process(@Body String xmlBody, @Header(Constants.INTYGS_ID) String intygsId, @Header(Constants.LOGICAL_ADDRESS) String logicalAddress) throws TemporaryException, PermanentException {
try {
SendMessageToRecipientType parameters = SendMessageToRecipientTypeConverter.fromXml(xmlBody);
SendMessageToRecipientResponseType response = sendMessageToRecipientResponder.sendMessageToRecipient(logicalAddress, parameters);
ResultType result = response.getResult();
switch(result.getResultCode()) {
case OK:
case INFO:
return;
case ERROR:
switch(result.getErrorId()) {
case REVOKED:
case VALIDATION_ERROR:
LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}, ErrorId: {}." + " Rethrowing as PermanentException", intygsId, result.getResultText(), result.getErrorId());
throw new PermanentException(result.getResultText());
case APPLICATION_ERROR:
case TECHNICAL_ERROR:
LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}, ErrorId: {}." + " Rethrowing as TemporaryException", intygsId, result.getResultText(), result.getErrorId());
throw new TemporaryException(result.getResultText());
}
}
} catch (JAXBException e) {
LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}. Rethrowing as PermanentException", intygsId, e.getMessage());
throw new PermanentException(e.getMessage());
} catch (WebServiceException e) {
LOG.error("Call to sendMessageToRecipient for intyg {} caused an error: {}. Will retry", intygsId, e.getMessage());
throw new TemporaryException(e.getMessage());
}
}
use of se.riv.clinicalprocess.healthcond.certificate.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());
}
}
use of se.riv.clinicalprocess.healthcond.certificate.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);
}
use of se.riv.clinicalprocess.healthcond.certificate.v3.Intyg in project webcert by sklintyg.
the class UtkastBootstrapBean method buildUtlatande.
// INTYG-4086: An incredibly ugly hack to mitigate the fact that we're populating test-data using the XML format
// and also directly to WC instead of storing in IT where these actually belong...
private Utlatande buildUtlatande(Resource resource, String moduleName) throws ModuleException, ModuleNotFoundException, IOException {
String xml = Resources.toString(resource.getURL(), Charsets.UTF_8);
Utlatande utlatande = registry.getModuleApi(moduleName).getUtlatandeFromXml(xml);
switch(moduleName) {
case "luse":
case "luae_fs":
case "luae_na":
case "lisjp":
RegisterCertificateType jaxbObject = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterCertificateType.class);
Patient patient = jaxbObject.getIntyg().getPatient();
utlatande.getGrundData().getPatient().setFornamn(patient.getFornamn());
utlatande.getGrundData().getPatient().setMellannamn(patient.getMellannamn());
utlatande.getGrundData().getPatient().setEfternamn(patient.getEfternamn());
utlatande.getGrundData().getPatient().setFullstandigtNamn(IntygConverterUtil.concatPatientName(patient.getFornamn(), patient.getMellannamn(), patient.getEfternamn()));
break;
case "fk7263":
RegisterMedicalCertificateType jaxbObject2 = JAXB.unmarshal(new StringReader(Resources.toString(resource.getURL(), Charsets.UTF_8)), RegisterMedicalCertificateType.class);
PatientType patient2 = jaxbObject2.getLakarutlatande().getPatient();
utlatande.getGrundData().getPatient().setEfternamn(patient2.getFullstandigtNamn());
utlatande.getGrundData().getPatient().setFullstandigtNamn(patient2.getFullstandigtNamn());
break;
case "ts-bas":
case "ts-diabetes":
break;
}
return utlatande;
}
Aggregations