Search in sources :

Example 21 with ObjectVersionId

use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.

the class FolderAccess method retrieveFolderVersionIdsInContribution.

/**
 * Retrieve a set of all folders from a given contribution.
 *
 * @param domainAccess Domain access object
 * @param contribution Given contribution ID to check for
 * @param nodeName     Nodename (e.g. "[...]::NODENAME::[...]") from the service layer, which is
 *                     not accessible in the access layer
 * @return Set of version ID of matching folders
 */
public static Set<ObjectVersionId> retrieveFolderVersionIdsInContribution(I_DomainAccess domainAccess, UUID contribution, String nodeName) {
    // Set, because of unique values
    Set<UUID> folders = new HashSet<>();
    // add all folders having a link to given contribution
    domainAccess.getContext().select(FOLDER.ID).from(FOLDER).where(FOLDER.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> folders.add(rec.value1()));
    // and older versions or deleted ones, too
    domainAccess.getContext().select(FOLDER_HISTORY.ID).from(FOLDER_HISTORY).where(FOLDER_HISTORY.IN_CONTRIBUTION.eq(contribution)).fetch().forEach(rec -> folders.add(rec.value1()));
    // get whole "version map" of each matching folder and do fine-grain check for matching contribution
    // precondition: each UUID in `folders` set is unique, so for each the "version map" is only created once below
    // (meta: can't do that as jooq query, because the specific version number isn't stored in DB)
    Set<ObjectVersionId> result = new HashSet<>();
    for (UUID folderId : folders) {
        Map<Record, Integer> map = getVersionMapOfFolder(domainAccess, folderId);
        // fine-grained contribution ID check
        for (Map.Entry<Record, Integer> entry : map.entrySet()) {
            // record can be of type FolderRecord or FolderHistoryRecord
            if (entry.getKey().getClass().equals(FolderRecord.class)) {
                FolderRecord rec = (FolderRecord) entry.getKey();
                if (rec.getInContribution().equals(contribution)) // set version ID
                {
                    result.add(new ObjectVersionId(rec.getId().toString() + "::" + nodeName + "::" + entry.getValue()));
                }
            } else if (entry.getKey().getClass().equals(FolderHistoryRecord.class)) {
                FolderHistoryRecord rec = (FolderHistoryRecord) entry.getKey();
                if (rec.getInContribution().equals(contribution)) // set version ID
                {
                    result.add(new ObjectVersionId(rec.getId().toString() + "::" + nodeName + "::" + entry.getValue()));
                }
            }
        }
    }
    return result;
}
Also used : FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) FolderRecord(org.ehrbase.jooq.pg.tables.records.FolderRecord) FolderHistoryRecord(org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord) ContributionRecord(org.ehrbase.jooq.pg.tables.records.ContributionRecord) Record(org.jooq.Record) ObjectRefRecord(org.ehrbase.jooq.pg.tables.records.ObjectRefRecord) FolderHierarchyRecord(org.ehrbase.jooq.pg.tables.records.FolderHierarchyRecord) FolderItemsRecord(org.ehrbase.jooq.pg.tables.records.FolderItemsRecord) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) FolderHistoryRecord(org.ehrbase.jooq.pg.tables.records.FolderHistoryRecord) HashSet(java.util.HashSet)

Example 22 with ObjectVersionId

use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.

the class StatusAccess method retrieveInstanceByContribution.

public static Map<ObjectVersionId, I_StatusAccess> retrieveInstanceByContribution(I_DomainAccess domainAccess, UUID contributionId, String node) {
    // Set, because of unique values
    Set<UUID> statuses = new HashSet<>();
    // add all compositions having a link to given contribution
    domainAccess.getContext().select(STATUS.ID).from(STATUS).where(STATUS.IN_CONTRIBUTION.eq(contributionId)).fetch().forEach(rec -> statuses.add(rec.value1()));
    // and older versions or deleted ones, too
    domainAccess.getContext().select(STATUS_HISTORY.ID).from(STATUS_HISTORY).where(STATUS_HISTORY.IN_CONTRIBUTION.eq(contributionId)).fetch().forEach(rec -> statuses.add(rec.value1()));
    // get whole "version map" of each matching status and do fine-grain check for matching contribution
    // precondition: each UUID in `statuses` set is unique, so for each the "version map" is only created once below
    // (meta: can't do that as jooq query, because the specific version number isn't stored in DB)
    Map<ObjectVersionId, I_StatusAccess> resultMap = new HashMap<>();
    for (UUID statusId : statuses) {
        Map<Integer, I_StatusAccess> map = getVersionMapOfStatus(domainAccess, statusId);
        // fine-grained contribution ID check
        map.forEach((k, v) -> {
            if (v.getContributionId().equals(contributionId)) {
                resultMap.put(new ObjectVersionId(statusId.toString(), node, k.toString()), v);
            }
        });
    }
    return resultMap;
}
Also used : HashMap(java.util.HashMap) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) I_StatusAccess(org.ehrbase.dao.access.interfaces.I_StatusAccess) HashSet(java.util.HashSet)

Example 23 with ObjectVersionId

use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.

the class FolderAccessTest method shouldInsertFolderWithNoSubfolders.

@Test
@Ignore
public void shouldInsertFolderWithNoSubfolders() throws Exception {
    // the creation and commit returning valid ids implies that the FolderMockDataProvider.java has provided the corresponding result for each SQL generated when inserting
    // create folder to insert
    Folder folder = new Folder();
    UIDBasedId uid = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
    ObjectVersionId uidim = new ObjectVersionId("f8a2af65-fe89-45a4-9456-07c5e17b1634");
    folder.setUid(uid);
    DvText name = new DvText();
    name.setValue("nameOfFolder");
    folder.setName(name);
    folder.setArchetypeNodeId("archetype_1");
    ItemStructure is = new ItemStructure() {

        @Override
        public List getItems() {
            Item item = new Item() {

                @Override
                public DvText getName() {
                    return new DvText("fol1");
                }
            };
            List<Item> items = new ArrayList<>();
            items.add(item);
            return items;
        }
    };
    folder.setDetails(is);
    // insert folder
    FolderAccess fa1 = new FolderAccess(testDomainAccess);
    FolderAccess fa2 = (FolderAccess) FolderAccess.getNewFolderAccessInstance(fa1, folder, DateTime.now(), UUID.fromString("f6a2af65-fe89-45a4-9456-07c5e17b1634"));
    assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", fa2.getFolderRecord().getId().toString());
    assertEquals("archetype_1", fa2.getFolderRecord().getArchetypeNodeId());
    assertEquals("nameOfFolder", fa2.getFolderRecord().getName());
    String expected = ("'{\n" + "  \"_type\" : \"\",\n" + "  \"items\" : [ {\n" + "    \"name\" : {\n" + "      \"_type\" : \"DV_TEXT\",\n" + "      \"value\" : \"fol1\"\n" + "    }\n" + "  } ]\n" + "}'::jsonb").replaceAll("\\n|\\r\\n", // avoids problems amond different platforms due to different representations of line change.
    System.getProperty("line.separator"));
    StringWriter expectedStringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(expectedStringWriter);
    // avoids problems amond different platforms due to different representations of line change.
    printWriter.print(expected);
    printWriter.close();
    assertEquals(expectedStringWriter.toString(), fa2.getFolderRecord().getDetails().toString());
    // commit and check returned UID is the valid one
    UUID storedFolderUid = fa2.commit(LocalDateTime.now(), UUID.randomUUID());
    assertEquals("f8a2af65-fe89-45a4-9456-07c5e17b1634", storedFolderUid.toString());
}
Also used : UIDBasedId(com.nedap.archie.rm.support.identification.UIDBasedId) ArrayList(java.util.ArrayList) ItemStructure(com.nedap.archie.rm.datastructures.ItemStructure) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Folder(com.nedap.archie.rm.directory.Folder) DvText(com.nedap.archie.rm.datavalues.DvText) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) Item(com.nedap.archie.rm.datastructures.Item) StringWriter(java.io.StringWriter) UUID(java.util.UUID) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with ObjectVersionId

use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.

the class OpenehrDirectoryController method checkDirectoryVersionConflicts.

private void checkDirectoryVersionConflicts(ObjectVersionId requestedFolderId, UUID ehrId) {
    UUID directoryUuid = ehrService.getDirectoryId(ehrId);
    int latestVersion = folderService.getLastVersionNumber(new ObjectVersionId(directoryUuid.toString()));
    // TODO: Change column 'directory' in EHR to String with ObjectVersionId
    String directoryId = String.format("%s::%s::%d", directoryUuid, ehrService.getServerConfig().getNodename(), latestVersion);
    if (requestedFolderId != null && !requestedFolderId.toString().equals(directoryId)) {
        throw new PreconditionFailedException("If-Match version_uid does not match latest version.", directoryId, encodePath(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId.toString() + "/directory/" + directoryId));
    }
}
Also used : PreconditionFailedException(org.ehrbase.api.exception.PreconditionFailedException) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID)

Example 25 with ObjectVersionId

use of com.nedap.archie.rm.support.identification.ObjectVersionId in project ehrbase by ehrbase.

the class ContributionServiceImp method getVersionedUidFromVersion.

/**
 * Create versionUid UUID from retrieved precedingVersionUid from payload (and do sanity checks before continuing), or throw errors if ID is not present nor valid.
 * Note: The precedingVersionUid parameter technically is optional for contributions but necessary when invoking other change types than creation.
 * @param version RM object of Version type
 * @return versionedUid
 * @throws IllegalArgumentException Given {@link Version} has no or no valid precedingVersionUid
 */
private UUID getVersionedUidFromVersion(Version version) {
    ObjectVersionId precedingVersionUid = version.getPrecedingVersionUid();
    if (precedingVersionUid == null) {
        throw new IllegalArgumentException("Input invalid. Composition can't be modified without pointer to precedingVersionUid in Version container.");
    }
    if (precedingVersionUid.toString().split("::").length != 3) {
        throw new IllegalArgumentException("Input invalid. Given precedingVersionUid is not a versionUid.");
    }
    String versionedUid = precedingVersionUid.toString().split("::")[0];
    return UUID.fromString(versionedUid);
}
Also used : ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId)

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