use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class EntryAccess method retrieveInstanceInCompositionVersion.
public static List<I_EntryAccess> retrieveInstanceInCompositionVersion(I_DomainAccess domainAccess, I_CompositionAccess compositionHistoryAccess, int version) {
Result<EntryHistoryRecord> entryHistoryRecords = domainAccess.getContext().selectFrom(ENTRY_HISTORY).where(ENTRY_HISTORY.COMPOSITION_ID.eq(compositionHistoryAccess.getId())).and(ENTRY_HISTORY.SYS_TRANSACTION.eq(compositionHistoryAccess.getSysTransaction())).fetch();
// build the list of parameters to recreate the composition
Map<SystemValue, Object> values = new HashMap<>();
values.put(SystemValue.COMPOSER, new PersistedPartyProxy(domainAccess).retrieve(compositionHistoryAccess.getComposerId()));
EventContext context = I_ContextAccess.retrieveHistoricalEventContext(domainAccess, compositionHistoryAccess.getId(), compositionHistoryAccess.getSysTransaction());
if (context == null) {
// unchanged context use the current one!
// also optional handling of context, because persistent compositions don't have a context
compositionHistoryAccess.getContextId().ifPresent(uuid -> I_ContextAccess.retrieveInstance(domainAccess, uuid).mapRmEventContext());
}
values.put(SystemValue.CONTEXT, context);
values.put(SystemValue.LANGUAGE, new CodePhrase(new TerminologyId("ISO_639-1"), compositionHistoryAccess.getLanguageCode()));
String territory2letters = domainAccess.getContext().fetchOne(TERRITORY, TERRITORY.CODE.eq(compositionHistoryAccess.getTerritoryCode())).getTwoletter();
values.put(SystemValue.TERRITORY, new CodePhrase(new TerminologyId("ISO_3166-1"), territory2letters));
values.put(SystemValue.FEEDER_AUDIT, new FeederAuditEncoding().fromDB(compositionHistoryAccess.getFeederAudit()));
List<I_EntryAccess> content = new ArrayList<>();
try {
EntryAccess entryAccess = new EntryAccess(domainAccess);
for (EntryHistoryRecord record : entryHistoryRecords) {
// set the record UID in the composition
UUID compositionId = compositionHistoryAccess.getId();
values.put(SystemValue.UID, new ObjectVersionId(compositionId.toString() + "::" + domainAccess.getServerConfig().getNodename() + "::" + version));
entryAccess.entryRecord = domainAccess.getContext().newRecord(ENTRY);
entryAccess.entryRecord.from(record);
entryAccess.composition = new RawJson().unmarshal(record.getEntry().data(), Composition.class);
setCompositionAttributes(entryAccess.composition, values);
buildArchetypeDetails(entryAccess);
content.add(entryAccess);
}
} catch (Exception e) {
throw new IllegalArgumentException(DB_INCONSISTENCY + e);
}
return content;
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class FolderAccess method parseObjectRefRecordIntoObjectRef.
/**
* Transforms a ObjectRef DB record into a Reference Model object.
*
* @param objectRefRecord
* @param domainAccess
* @return the reference model object.
*/
private static ObjectRef parseObjectRefRecordIntoObjectRef(ObjectRefRecord objectRefRecord, I_DomainAccess domainAccess) {
ObjectRef result = new ObjectRef();
ObjectRefId oref = new FolderAccess(domainAccess).new ObjectRefId(objectRefRecord.getId().toString());
result.setId(new ObjectVersionId(oref.getValue()));
result.setType(objectRefRecord.getType());
result.setNamespace(objectRefRecord.getIdNamespace());
return result;
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class OpenehrContributionController method buildContributionResponseData.
private <T extends ContributionResponseData> Optional<InternalResponse<T>> buildContributionResponseData(UUID contributionId, UUID ehrId, String accept, URI uri, List<String> headerList, Supplier<T> factory) {
// create either CompositionResponseData or null (means no body, only headers incl. link to resource), via lambda request
T minimalOrRepresentation = factory.get();
// do minimal scope steps
// create and supplement headers with data depending on which headers are requested
HttpHeaders respHeaders = new HttpHeaders();
for (String header : headerList) {
switch(header) {
case LOCATION:
respHeaders.setLocation(uri);
break;
case ETAG:
respHeaders.setETag("\"" + contributionId + "\"");
break;
case LAST_MODIFIED:
// TODO should be VERSION.commit_audit.time_committed.value which is not implemented yet - mock for now
respHeaders.setLastModified(123124442);
break;
default:
}
}
// if response data objects was created as "representation" do all task from wider scope, too
if (minimalOrRepresentation != null) {
// when this "if" is true the following casting can be executed and data manipulated by reference (handled by temporary variable)
ContributionResponseData objByReference = minimalOrRepresentation;
// retrieve contribution
Optional<ContributionDto> contribution = contributionService.getContribution(ehrId, contributionId);
// set all response field according to retrieved contribution
objByReference.setUid(new HierObjectId(contributionId.toString()));
List<ObjectRef<ObjectVersionId>> refs = new LinkedList<>();
contribution.get().getObjectReferences().forEach((id, type) -> refs.add(new ObjectRef<>(new ObjectVersionId(id), "local", type)));
objByReference.setVersions(refs);
objByReference.setAudit(contribution.get().getAuditDetails());
CompositionFormat format = extractCompositionFormat(accept);
// finally set last header
if (format.equals(CompositionFormat.XML)) {
respHeaders.setContentType(MediaType.APPLICATION_XML);
} else if (format.equals(CompositionFormat.JSON) || format.equals(CompositionFormat.FLAT) || format.equals(CompositionFormat.ECISFLAT) || format.equals(CompositionFormat.RAW)) {
respHeaders.setContentType(MediaType.APPLICATION_JSON);
} else {
throw new NotAcceptableException("Wrong Accept header in request");
}
}
return Optional.of(new InternalResponse<>(minimalOrRepresentation, respHeaders));
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class OpenehrDirectoryController method getFolderInDirectoryVersionAtTime.
@Override
@GetMapping(path = "/{ehr_id}/directory")
public ResponseEntity<DirectoryResponseData> getFolderInDirectoryVersionAtTime(@PathVariable(name = "ehr_id") UUID ehrId, @RequestParam(name = "version_at_time", required = false) String versionAtTime, @RequestParam(name = "path", required = false) String path, @RequestHeader(name = ACCEPT, required = false, defaultValue = MediaType.APPLICATION_JSON_VALUE) String accept) {
// Check ehr exists
checkEhrExists(ehrId);
assertValidPath(path);
// Get directory root entry for ehr
UUID directoryUuid = ehrService.getDirectoryId(ehrId);
if (directoryUuid == null) {
throw new ObjectNotFoundException("DIRECTORY", String.format("There is no directory stored for EHR with id %s. Maybe it has been deleted?", ehrId.toString()));
}
ObjectVersionId directoryId = new ObjectVersionId(directoryUuid.toString());
final Optional<FolderDto> foundFolder;
// Get the folder entry from database
Optional<OffsetDateTime> temporal = getVersionAtTimeParam();
if (versionAtTime != null && temporal.isPresent()) {
foundFolder = folderService.getByTimeStamp(directoryId, Timestamp.from(temporal.get().toInstant()), path);
} else {
foundFolder = folderService.getLatest(directoryId, path);
}
if (foundFolder.isEmpty()) {
throw new ObjectNotFoundException("folder", "The FOLDER for ehrId " + ehrId.toString() + " does not exist.");
}
return createDirectoryResponse(HttpMethod.GET, RETURN_REPRESENTATION, accept, foundFolder.get(), ehrId);
}
use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.
the class OpenehrVersionedCompositionController method retrieveVersionOfCompositionByVersionUid.
@GetMapping(path = "/{versioned_object_uid}/version/{version_uid}")
// checkAbacPre /-Post attributes (type, subject, payload, content type)
@PostAuthorize("checkAbacPost(@openehrVersionedCompositionController.COMPOSITION, " + "@ehrService.getSubjectExtRef(#ehrIdString), returnObject, #accept)")
@Override
public ResponseEntity<OriginalVersionResponseData<Composition>> retrieveVersionOfCompositionByVersionUid(@RequestHeader(value = HttpHeaders.ACCEPT, required = false) String accept, @PathVariable(value = "ehr_id") String ehrIdString, @PathVariable(value = "versioned_object_uid") String versionedObjectUid, @PathVariable(value = "version_uid") String versionUid) {
UUID ehrId = getEhrUuid(ehrIdString);
UUID versionedCompoUid = getCompositionVersionedObjectUidString(versionedObjectUid);
// check if parameters are valid
checkForValidEhrAndCompositionParameter(ehrId, versionedCompoUid);
ObjectVersionId compositionVersionId = new ObjectVersionId(versionUid);
if (!compositionVersionId.getRoot().getValue().equals(versionedObjectUid)) {
throw new IllegalArgumentException("Composition parameters are not matching.");
}
// parse given version uid
UUID versionedObjectId;
int version;
try {
versionedObjectId = UUID.fromString(compositionVersionId.getRoot().getValue());
version = Integer.parseInt(compositionVersionId.getVersionTreeId().getValue());
} catch (Exception e) {
throw new InvalidApiParameterException("VERSION UID parameter has wrong format: " + e.getMessage());
}
return getOriginalVersionResponseDataResponseEntity(accept, ehrId, versionedObjectId, version);
}
Aggregations