use of org.ehrbase.dao.access.interfaces.I_AuditDetailsAccess in project ehrbase by ehrbase.
the class CompositionAccess method retrieveCompositionVersion.
/**
* @throws IllegalArgumentException when version number is not greater 0
* @throws ObjectNotFoundException when no composition could be found with given input
*/
public static I_CompositionAccess retrieveCompositionVersion(I_DomainAccess domainAccess, UUID id, int version) {
if (version < 1) {
throw new IllegalArgumentException("Version number must be > 0 please check your code");
}
// check if this version number matches the current version
if (getLastVersionNumber(domainAccess, id) == version) {
// current version
return retrieveInstance(domainAccess, id);
}
// FIXME make jooq compliant
String versionQuery = "select " + "row_id, " + "in_contribution, " + "ehr_id, " + "language, " + "territory, " + "composer, " + "sys_transaction, " + "has_audit," + "attestation_ref, " + "feeder_audit, " + "links from \n" + " (select ROW_NUMBER() OVER (ORDER BY sys_transaction ASC ) AS row_id, * from ehr.composition_history " + " WHERE id = ?) \n" + " AS Version WHERE row_id = ?;";
Connection connection = domainAccess.getConnection();
I_CompositionAccess compositionHistoryAccess = null;
try (PreparedStatement preparedStatement = connection.prepareStatement(versionQuery)) {
preparedStatement.setObject(1, id);
preparedStatement.setInt(2, version);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
CompositionRecord compositionRecord1 = domainAccess.getContext().newRecord(COMPOSITION);
compositionRecord1.setId(id);
compositionRecord1.setInContribution(UUID.fromString(resultSet.getString("in_contribution")));
compositionRecord1.setEhrId(UUID.fromString(resultSet.getString("ehr_id")));
compositionRecord1.setLanguage(resultSet.getString("language"));
compositionRecord1.setTerritory(resultSet.getInt("territory"));
compositionRecord1.setComposer(UUID.fromString(resultSet.getString("composer")));
compositionRecord1.setSysTransaction(resultSet.getTimestamp("sys_transaction"));
compositionRecord1.setHasAudit(UUID.fromString(resultSet.getString("has_audit")));
compositionRecord1.setFeederAudit(JSONB.valueOf(resultSet.getString("feeder_audit")));
/* TODO: uncomment when links encode/decode is fully implemented
compositionRecord1.setLinks(JSONB.valueOf(resultSet.getString("links")));
*/
compositionHistoryAccess = new CompositionAccess(domainAccess, compositionRecord1);
}
}
} catch (SQLException e) {
throw new ObjectNotFoundException(COMPOSITION_LITERAL, "Composition not found or or invalid DB content", e);
}
if (compositionHistoryAccess != null) {
compositionHistoryAccess.setContent(I_EntryAccess.retrieveInstanceInCompositionVersion(domainAccess, compositionHistoryAccess, version));
// retrieve the corresponding contribution
I_ContributionAccess contributionAccess = I_ContributionAccess.retrieveInstance(domainAccess, compositionHistoryAccess.getContributionId());
compositionHistoryAccess.setContributionAccess(contributionAccess);
I_AuditDetailsAccess auditDetailsAccess = new AuditDetailsAccess(domainAccess.getDataAccess()).retrieveInstance(domainAccess.getDataAccess(), compositionHistoryAccess.getAuditDetailsId());
compositionHistoryAccess.setAuditDetailsAccess(auditDetailsAccess);
// retrieve versioned context
EventContext historicalEventContext = I_ContextAccess.retrieveHistoricalEventContext(domainAccess, id, compositionHistoryAccess.getSysTransaction());
// adjust context for entries
if (historicalEventContext != null) {
for (I_EntryAccess entryAccess : compositionHistoryAccess.getContent()) {
entryAccess.getComposition().setContext(historicalEventContext);
}
}
}
domainAccess.releaseConnection(connection);
return compositionHistoryAccess;
}
use of org.ehrbase.dao.access.interfaces.I_AuditDetailsAccess in project ehrbase by ehrbase.
the class CompositionAccess method retrieveInstance.
public static I_CompositionAccess retrieveInstance(I_DomainAccess domainAccess, UUID id) {
I_CompositionAccess compositionAccess = new CompositionAccess(domainAccess);
CompositionRecord compositionRecord = domainAccess.getContext().selectFrom(COMPOSITION).where(COMPOSITION.ID.eq(id)).fetchOne();
if (compositionRecord == null) {
return null;
}
compositionAccess.setCompositionRecord(compositionRecord);
compositionAccess.setContent(I_EntryAccess.retrieveInstanceInComposition(domainAccess, compositionAccess));
// retrieve the corresponding contribution
I_ContributionAccess contributionAccess = I_ContributionAccess.retrieveInstance(domainAccess, compositionAccess.getContributionId());
compositionAccess.setContributionAccess(contributionAccess);
// retrieve corresponding audit
I_AuditDetailsAccess auditAccess = new AuditDetailsAccess(domainAccess.getDataAccess()).retrieveInstance(domainAccess.getDataAccess(), compositionAccess.getAuditDetailsId());
compositionAccess.setAuditDetailsAccess(auditAccess);
return compositionAccess;
}
use of org.ehrbase.dao.access.interfaces.I_AuditDetailsAccess in project ehrbase by ehrbase.
the class StatusAccess method createStatusAccessForRetrieval.
/**
* Helper to create a new {@link StatusAccess} instance from a queried record (either as {@link
* StatusRecord} or {@link StatusHistoryRecord}), to return to service layer.
*
* @param domainAccess General access
* @param record Queried {@link StatusRecord} which contains ID of linked EHR, audit and
* contribution. Give null if not used
* @param historyRecord Option: Same as record but as history input type. Give null if not used
* @return Resulting access object
*/
private static I_StatusAccess createStatusAccessForRetrieval(I_DomainAccess domainAccess, StatusRecord record, StatusHistoryRecord historyRecord) {
StatusAccess statusAccess;
if (record != null) {
statusAccess = new StatusAccess(domainAccess, record.getEhrId());
statusAccess.setStatusRecord(record);
} else if (historyRecord != null) {
statusAccess = new StatusAccess(domainAccess, historyRecord.getEhrId());
statusAccess.setStatusRecord(historyRecord);
} else {
throw new InternalServerException("Error creating version map of EHR_STATUS");
}
// retrieve corresponding audit
I_AuditDetailsAccess auditAccess = new AuditDetailsAccess(domainAccess.getDataAccess()).retrieveInstance(domainAccess.getDataAccess(), statusAccess.getAuditDetailsId());
statusAccess.setAuditDetailsAccess(auditAccess);
// retrieve corresponding contribution
I_ContributionAccess retContributionAccess = I_ContributionAccess.retrieveInstance(domainAccess, statusAccess.getContributionId());
statusAccess.setContributionAccess(retContributionAccess);
return statusAccess;
}
Aggregations