Search in sources :

Example 1 with ObjectRef

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

the class CompositionServiceImp method getOriginalVersionComposition.

@Override
public Optional<OriginalVersion<Composition>> getOriginalVersionComposition(UUID versionedObjectUid, int version) {
    // check for valid version parameter
    if ((version == 0) || I_CompositionAccess.getLastVersionNumber(getDataAccess(), versionedObjectUid) < version) {
        throw new ObjectNotFoundException("versioned_composition", "No VERSIONED_COMPOSITION with given version: " + version);
    }
    // retrieve requested object
    I_CompositionAccess compositionAccess = I_CompositionAccess.retrieveCompositionVersion(getDataAccess(), versionedObjectUid, version);
    if (compositionAccess == null) {
        return Optional.empty();
    }
    // create data for output, i.e. fields of the OriginalVersion<Composition>
    ObjectVersionId versionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + version);
    DvCodedText lifecycleState = new DvCodedText("complete", new CodePhrase(// TODO: once lifecycle state is supported, get it here dynamically
    "532"));
    AuditDetails commitAudit = compositionAccess.getAuditDetailsAccess().getAsAuditDetails();
    ObjectRef<HierObjectId> contribution = new ObjectRef<>(new HierObjectId(compositionAccess.getContributionId().toString()), "openehr", "contribution");
    List<UUID> attestationIdList = I_AttestationAccess.retrieveListOfAttestationsByRef(getDataAccess(), compositionAccess.getAttestationRef());
    List<Attestation> attestations = // as default, gets content if available in the following lines
    null;
    if (!attestationIdList.isEmpty()) {
        attestations = new ArrayList<>();
        for (UUID id : attestationIdList) {
            I_AttestationAccess a = new AttestationAccess(getDataAccess()).retrieveInstance(id);
            attestations.add(a.getAsAttestation());
        }
    }
    ObjectVersionId precedingVersionId = null;
    // check if there is a preceding version and set it, if available
    if (version > 1) {
        // in the current scope version is an int and therefore: preceding = current - 1
        precedingVersionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + (version - 1));
    }
    Optional<CompositionDto> compositionDto = retrieve(versionedObjectUid, version);
    Composition composition = null;
    if (compositionDto.isPresent()) {
        composition = compositionDto.get().getComposition();
    }
    OriginalVersion<Composition> versionComposition = new OriginalVersion<>(versionId, precedingVersionId, composition, lifecycleState, commitAudit, contribution, null, null, attestations);
    return Optional.of(versionComposition);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) Composition(com.nedap.archie.rm.composition.Composition) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) AttestationAccess(org.ehrbase.dao.access.jooq.AttestationAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Attestation(com.nedap.archie.rm.generic.Attestation) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) I_CompositionAccess(org.ehrbase.dao.access.interfaces.I_CompositionAccess) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 2 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef 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 3 with ObjectRef

use of com.nedap.archie.rm.support.identification.ObjectRef 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 4 with ObjectRef

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

the class DefaultRestFolderDAO method addCompositionEntity.

@Override
public <T> T addCompositionEntity(T entity) {
    T updatedEntity = directoryEndpoint.getCompositionEndpoint().mergeCompositionEntity(entity);
    UUID uuid = DefaultRestCompositionEndpoint.extractVersionUid(updatedEntity).orElseThrow(() -> new ClientException(String.format("No Id Element for %s", entity.getClass()))).getUuid();
    Folder folder = getFolder();
    if (folder.getItems() == null) {
        folder.setItems(new ArrayList<>());
    }
    folder.getItems().add(new ObjectRef(new ObjectVersionId(uuid.toString()), "dffddfd", "VERSIONED_COMPOSITION"));
    directoryEndpoint.saveToDb();
    return updatedEntity;
}
Also used : ClientException(org.ehrbase.client.exception.ClientException) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) Folder(com.nedap.archie.rm.directory.Folder) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Example 5 with ObjectRef

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

the class EntryPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, Entry rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    consumedPaths.add(term + PATH_DIVIDER + "encoding|code");
    consumedPaths.add(term + PATH_DIVIDER + "encoding|terminology");
    Map<FlatPathDto, String> subjectValues = FlatHelper.filter(values, term + "/subject", false);
    if (!subjectValues.isEmpty()) {
        if (rmObject.getSubject() == null) {
            // If it was PartyRelated it would be set by now do to the relationship  and if it was
            // PartySelf subjectValues would be empty
            rmObject.setSubject(new PartyIdentified());
        }
        callUnmarshal(term, "subject", rmObject.getSubject(), values, consumedPaths, context, context.getNodeDeque().peek().findChildById("subject").orElse(buildDummyChild("subject", context.getNodeDeque().peek())));
    }
    PartyProxy subject = rmObject.getSubject();
    if (subject == null || (subject instanceof PartyIdentified && ((PartyIdentified) subject).getName() == null && CollectionUtils.isEmpty(((PartyIdentified) subject).getIdentifiers()) && subject.getExternalRef() == null && (!(subject instanceof PartyRelated) || ((PartyRelated) subject).getRelationship() == null || StringUtils.isEmpty(((PartyRelated) subject).getRelationship().getValue())))) {
        rmObject.setSubject(new PartySelf());
    }
    Map<FlatPathDto, String> providerList = values.entrySet().stream().filter(e -> e.getKey().startsWith(term + PATH_DIVIDER + "_provider")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    if (!MapUtils.isEmpty(providerList)) {
        if (!(rmObject.getProvider() instanceof PartyIdentified)) {
            rmObject.setProvider(new PartyIdentified());
        }
        PartyIdentifiedRMUnmarshaller partyIdentifiedRMUnmarshaller = new PartyIdentifiedRMUnmarshaller();
        partyIdentifiedRMUnmarshaller.handle(term + PATH_DIVIDER + "_provider", (PartyIdentified) rmObject.getProvider(), providerList, null, consumedPaths);
    }
    Map<Integer, Map<String, String>> other = extractMultiValued(term, "_other_participation", values);
    other.values().stream().map(Map::entrySet).map(s -> s.stream().collect(Collectors.toMap(e -> "ctx/" + DefaultValuePath.PARTICIPATION.getPath() + "_" + e.getKey().replace("identifiers_", "identifiers|"), e -> StringUtils.wrap(e.getValue(), '"'))).entrySet()).map(DefaultValues::buildParticipation).forEach(rmObject::addOtherParticipant);
    consumeAllMatching(term + PATH_DIVIDER + "_other_participation", values, consumedPaths, false);
    Map<FlatPathDto, String> workflowIdValues = filter(values, term + "/_work_flow_id", false);
    if (!workflowIdValues.isEmpty()) {
        ObjectRef<GenericId> ref = new ObjectRef<>();
        ref.setId(new GenericId());
        rmObject.setWorkflowId(ref);
        setValue(term + "/_work_flow_id", "id", workflowIdValues, s -> ref.getId().setValue(s), String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "id_scheme", workflowIdValues, s -> ref.getId().setScheme(s), String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "namespace", workflowIdValues, ref::setNamespace, String.class, consumedPaths);
        setValue(term + "/_work_flow_id", "type", workflowIdValues, ref::setType, String.class, consumedPaths);
    }
}
Also used : Entry(com.nedap.archie.rm.composition.Entry) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PartySelf(com.nedap.archie.rm.generic.PartySelf) MapUtils(org.apache.commons.collections4.MapUtils) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) PartyIdentifiedRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.PartyIdentifiedRMUnmarshaller) PATH_DIVIDER(org.ehrbase.webtemplate.parser.OPTParser.PATH_DIVIDER) GenericId(com.nedap.archie.rm.support.identification.GenericId) Map(java.util.Map) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) PartySelf(com.nedap.archie.rm.generic.PartySelf) PartyIdentifiedRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.PartyIdentifiedRMUnmarshaller) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Map(java.util.Map)

Aggregations

ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)18 GenericId (com.nedap.archie.rm.support.identification.GenericId)7 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)7 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)5 OffsetDateTime (java.time.OffsetDateTime)5 Map (java.util.Map)5 UUID (java.util.UUID)5 Test (org.junit.Test)5 Composition (com.nedap.archie.rm.composition.Composition)4 Entry (com.nedap.archie.rm.composition.Entry)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 ArrayList (java.util.ArrayList)4 WorkflowIdTest (care.better.platform.web.template.WorkflowIdTest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Section (com.nedap.archie.rm.composition.Section)3 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)3 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)3 ZoneId (java.time.ZoneId)3 ZonedDateTime (java.time.ZonedDateTime)3