Search in sources :

Example 21 with AuditEvent

use of org.hl7.fhir.r4.model.AuditEvent in project summary-care-record-api by NHSDigital.

the class AlertRequestValidator method isValid.

@Override
public boolean isValid(String alert, ConstraintValidatorContext context) {
    try {
        AuditEvent auditEvent = fhirParser.parseResource(alert, AuditEvent.class);
        checkId(auditEvent);
        checkExtension(auditEvent);
        checkType(auditEvent.getType());
        checkSubtype(auditEvent.getSubtype());
        checkRecorded(auditEvent.getRecorded());
        checkSource(auditEvent.getSource());
        checkEntity(auditEvent.getEntity());
        checkPatient(auditEvent.getAgent());
        checkOrganization(auditEvent.getAgent());
        checkPerson(auditEvent.getAgent());
    } catch (FhirValidationException exc) {
        setErrorMessage(context, exc.getMessage());
        return false;
    }
    return true;
}
Also used : AuditEvent(org.hl7.fhir.r4.model.AuditEvent) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 22 with AuditEvent

use of org.hl7.fhir.r4.model.AuditEvent in project fhir-bridge by ehrbase.

the class ProvideResourceAuditHandler method process.

@Override
public void process(Exchange exchange) throws Exception {
    RequestDetails requestDetails = getRequestDetails(exchange);
    AuditEvent auditEvent = new AuditEvent(new Coding("http://terminology.hl7.org/CodeSystem/audit-event-type", "rest", "RESTful Operation"), new InstantType(new Date()), getSource());
    getSubtype(requestDetails).ifPresent(auditEvent::addSubtype);
    getAction(requestDetails).ifPresent(auditEvent::setAction);
    Throwable ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    if (ex == null) {
        auditEvent.setOutcome(AuditEvent.AuditEventOutcome._0);
        auditEvent.setOutcomeDesc("Operation completed successfully");
    } else {
        auditEvent.setOutcome(AuditEvent.AuditEventOutcome._8);
        auditEvent.setOutcomeDesc("Operation failed: " + ex.getMessage());
    }
    auditEvent.addAgent(getAgent(exchange));
    getEntity(exchange, requestDetails).ifPresent(auditEvent::addEntity);
    MethodOutcome outcome = auditEventDao.create(auditEvent, requestDetails);
    LOG.debug("Created AuditEvent: id={}", outcome.getId());
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) AuditEvent(org.hl7.fhir.r4.model.AuditEvent) InstantType(org.hl7.fhir.r4.model.InstantType) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Date(java.util.Date)

Example 23 with AuditEvent

use of org.hl7.fhir.r4.model.AuditEvent in project fhir-bridge by ehrbase.

the class AuditEventReportIT method createResourceAndSearchAuditEvent.

@Test
void createResourceAndSearchAuditEvent() throws IOException {
    Date now = new Date();
    String resource = IOUtils.toString(new ClassPathResource("DiagnosticReport/create-diagnosticReport.json").getInputStream(), StandardCharsets.UTF_8);
    MethodOutcome outcome = client.create().resource(resource.replaceAll(PATIENT_ID_TOKEN, PATIENT_ID)).execute();
    assertNotNull(outcome.getId());
    assertEquals(true, outcome.getCreated());
    Bundle bundle = client.search().forResource(AuditEvent.class).where(AuditEvent.DATE.afterOrEquals().day(now)).and(AuditEvent.ENTITY.hasId(outcome.getResource().getIdElement())).returnBundle(Bundle.class).execute();
    assertNotNull(bundle);
    assertEquals(1, bundle.getTotal());
    AuditEvent auditEvent = (AuditEvent) bundle.getEntryFirstRep().getResource();
    assertEquals(AuditEvent.AuditEventOutcome._0, auditEvent.getOutcome());
    assertEquals(outcome.getResource().getIdElement(), auditEvent.getEntity().get(0).getWhat().getReferenceElement());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) AuditEvent(org.hl7.fhir.r4.model.AuditEvent) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Date(java.util.Date) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 24 with AuditEvent

use of org.hl7.fhir.r4.model.AuditEvent in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeAuditEventAuditEventAgentComponent.

protected void composeAuditEventAuditEventAgentComponent(Complex parent, String parentType, String name, AuditEvent.AuditEventAgentComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "agent", name, element, index);
    for (int i = 0; i < element.getRole().size(); i++) composeCodeableConcept(t, "AuditEvent", "role", element.getRole().get(i), i);
    if (element.hasReference())
        composeReference(t, "AuditEvent", "reference", element.getReference(), -1);
    if (element.hasUserId())
        composeIdentifier(t, "AuditEvent", "userId", element.getUserId(), -1);
    if (element.hasAltIdElement())
        composeString(t, "AuditEvent", "altId", element.getAltIdElement(), -1);
    if (element.hasNameElement())
        composeString(t, "AuditEvent", "name", element.getNameElement(), -1);
    if (element.hasRequestorElement())
        composeBoolean(t, "AuditEvent", "requestor", element.getRequestorElement(), -1);
    if (element.hasLocation())
        composeReference(t, "AuditEvent", "location", element.getLocation(), -1);
    for (int i = 0; i < element.getPolicy().size(); i++) composeUri(t, "AuditEvent", "policy", element.getPolicy().get(i), i);
    if (element.hasMedia())
        composeCoding(t, "AuditEvent", "media", element.getMedia(), -1);
    if (element.hasNetwork())
        composeAuditEventAuditEventAgentNetworkComponent(t, "AuditEvent", "network", element.getNetwork(), -1);
    for (int i = 0; i < element.getPurposeOfUse().size(); i++) composeCodeableConcept(t, "AuditEvent", "purposeOfUse", element.getPurposeOfUse().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 25 with AuditEvent

use of org.hl7.fhir.r4.model.AuditEvent in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeAuditEvent.

protected void composeAuditEvent(Complex parent, String parentType, String name, AuditEvent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "AuditEvent", name, element, index);
    if (element.hasType())
        composeCoding(t, "AuditEvent", "type", element.getType(), -1);
    for (int i = 0; i < element.getSubtype().size(); i++) composeCoding(t, "AuditEvent", "subtype", element.getSubtype().get(i), i);
    if (element.hasActionElement())
        composeEnum(t, "AuditEvent", "action", element.getActionElement(), -1);
    if (element.hasPeriod())
        composePeriod(t, "AuditEvent", "period", element.getPeriod(), -1);
    if (element.hasRecordedElement())
        composeInstant(t, "AuditEvent", "recorded", element.getRecordedElement(), -1);
    if (element.hasOutcomeElement())
        composeEnum(t, "AuditEvent", "outcome", element.getOutcomeElement(), -1);
    if (element.hasOutcomeDescElement())
        composeString(t, "AuditEvent", "outcomeDesc", element.getOutcomeDescElement(), -1);
    for (int i = 0; i < element.getPurposeOfEvent().size(); i++) composeCodeableConcept(t, "AuditEvent", "purposeOfEvent", element.getPurposeOfEvent().get(i), i);
    for (int i = 0; i < element.getAgent().size(); i++) composeAuditEventAuditEventAgentComponent(t, "AuditEvent", "agent", element.getAgent().get(i), i);
    if (element.hasSource())
        composeAuditEventAuditEventSourceComponent(t, "AuditEvent", "source", element.getSource(), -1);
    for (int i = 0; i < element.getEntity().size(); i++) composeAuditEventAuditEventEntityComponent(t, "AuditEvent", "entity", element.getEntity().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

AuditEvent (org.hl7.fhir.r4.model.AuditEvent)10 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)6 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 Reference (org.hl7.fhir.r4.model.Reference)5 Coding (org.hl7.fhir.r4.model.Coding)4 AuditSourceType (org.hl7.fhir.r4.model.codesystems.AuditSourceType)3 Test (org.junit.jupiter.api.Test)3 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)2 Date (java.util.Date)2 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 StringType (org.hl7.fhir.r4.model.StringType)2 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)1 ArrayList (java.util.ArrayList)1 AuditEvent (org.hl7.fhir.dstu3.model.AuditEvent)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 Identifier (org.hl7.fhir.r4.model.Identifier)1 InstantType (org.hl7.fhir.r4.model.InstantType)1 Period (org.hl7.fhir.r4.model.Period)1