Search in sources :

Example 11 with ObjectVersionId

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;
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) Composition(com.nedap.archie.rm.composition.Composition) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) HashMap(java.util.HashMap) RawJson(org.ehrbase.serialisation.dbencoding.RawJson) EntryHistoryRecord(org.ehrbase.jooq.pg.tables.records.EntryHistoryRecord) ArrayList(java.util.ArrayList) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) InternalServerException(org.ehrbase.api.exception.InternalServerException) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) I_EntryAccess(org.ehrbase.dao.access.interfaces.I_EntryAccess) EventContext(com.nedap.archie.rm.composition.EventContext) FeederAuditEncoding(org.ehrbase.serialisation.dbencoding.rmobject.FeederAuditEncoding) UUID(java.util.UUID)

Example 12 with ObjectVersionId

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;
}
Also used : ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess)

Example 13 with ObjectVersionId

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CompositionFormat(org.ehrbase.response.ehrscape.CompositionFormat) ContributionResponseData(org.ehrbase.response.openehr.ContributionResponseData) ContributionDto(org.ehrbase.response.ehrscape.ContributionDto) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) LinkedList(java.util.LinkedList) NotAcceptableException(org.ehrbase.api.exception.NotAcceptableException) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 14 with ObjectVersionId

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);
}
Also used : FolderDto(org.ehrbase.response.ehrscape.FolderDto) OffsetDateTime(java.time.OffsetDateTime) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 15 with ObjectVersionId

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);
}
Also used : InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) GetMapping(org.springframework.web.bind.annotation.GetMapping) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize)

Aggregations

ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)28 UUID (java.util.UUID)17 InternalServerException (org.ehrbase.api.exception.InternalServerException)9 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)7 Composition (com.nedap.archie.rm.composition.Composition)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)5 I_FolderAccess (org.ehrbase.dao.access.interfaces.I_FolderAccess)5 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 HashSet (java.util.HashSet)4 CompositionDto (org.ehrbase.response.ehrscape.CompositionDto)4 Folder (com.nedap.archie.rm.directory.Folder)3 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)3 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)3 I_CompositionAccess (org.ehrbase.dao.access.interfaces.I_CompositionAccess)3 I_EntryAccess (org.ehrbase.dao.access.interfaces.I_EntryAccess)3 CompositionFormat (org.ehrbase.response.ehrscape.CompositionFormat)3 StructuredString (org.ehrbase.response.ehrscape.StructuredString)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3