Search in sources :

Example 1 with HierObjectId

use of com.nedap.archie.rm.support.identification.HierObjectId in project fhir-bridge by ehrbase.

the class AbstractSetupIT method setup.

@BeforeAll
static void setup() throws URISyntaxException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("myuser", "myPassword432"));
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
    DefaultRestClient client = new DefaultRestClient(new OpenEhrClientConfig(new URI("http://localhost:8080/ehrbase/")), new ResourceTemplateProvider("classpath:/opt/*.opt"), httpClient);
    PATIENT_ID = UUID.randomUUID().toString();
    EhrStatus ehrStatus = new EhrStatus();
    ehrStatus.setSubject(new PartySelf(new PartyRef(new HierObjectId(PATIENT_ID), "demographic", "PERSON")));
    ehrStatus.setArchetypeNodeId("openEHR-EHR-EHR_STATUS.generic.v1");
    ehrStatus.setName(new DvText("Integration tests status"));
    client.ehrEndpoint().createEhr(ehrStatus);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) DefaultRestClient(org.ehrbase.client.openehrclient.defaultrestclient.DefaultRestClient) URI(java.net.URI) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) PartySelf(com.nedap.archie.rm.generic.PartySelf) DvText(com.nedap.archie.rm.datavalues.DvText) PartyRef(com.nedap.archie.rm.support.identification.PartyRef) OpenEhrClientConfig(org.ehrbase.client.openehrclient.OpenEhrClientConfig) ResourceTemplateProvider(org.ehrbase.fhirbridge.ehr.ResourceTemplateProvider) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with HierObjectId

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

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

the class EhrServiceImp method create.

@Override
public UUID create(EhrStatus status, UUID ehrId) {
    try {
        validationService.check(status);
    } catch (Exception e) {
        // rethrow if this class, but wrap all others in InternalServerException
        if (e.getClass().equals(UnprocessableEntityException.class))
            throw (UnprocessableEntityException) e;
        if (e.getClass().equals(IllegalArgumentException.class))
            throw new ValidationException(e);
        if (e.getClass().equals(ValidationException.class))
            throw e;
        else
            throw new InternalServerException(e);
    }
    if (status == null) {
        // in case of new status with default values
        status = new EhrStatus();
        status.setSubject(new PartySelf(null));
        status.setModifiable(true);
        status.setQueryable(true);
    }
    // server sets own new UUID in both cases (new or given status)
    status.setUid(new HierObjectId(UUID.randomUUID().toString()));
    UUID subjectUuid;
    if (PartyUtils.isEmpty(status.getSubject())) {
        subjectUuid = emptyParty;
    } else {
        subjectUuid = new PersistedPartyProxy(getDataAccess()).getOrCreate(status.getSubject());
        if (I_EhrAccess.checkExist(getDataAccess(), subjectUuid)) {
            throw new StateConflictException("Specified party has already an EHR set (partyId=" + subjectUuid + ")");
        }
    }
    UUID systemId = getSystemUuid();
    UUID committerId = getUserUuid();
    try {
        // this try block sums up a bunch of operations that can throw errors in the following
        I_EhrAccess ehrAccess = I_EhrAccess.getInstance(getDataAccess(), subjectUuid, systemId, null, null, ehrId);
        ehrAccess.setStatus(status);
        return ehrAccess.commit(committerId, systemId, DESCRIPTION);
    } catch (Exception e) {
        throw new InternalServerException("Could not create an EHR with given parameters.", e);
    }
}
Also used : VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Example 4 with HierObjectId

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

the class EhrAccess method getStatus.

// get latest status
@Override
public EhrStatus getStatus() {
    EhrStatus status = new EhrStatus();
    status.setModifiable(isModifiable());
    status.setQueryable(isQueryable());
    // set otherDetails if available
    if (getStatusAccess().getStatusRecord().getOtherDetails() != null) {
        status.setOtherDetails(getStatusAccess().getStatusRecord().getOtherDetails());
    }
    // Locatable attribute
    status.setArchetypeNodeId(getArchetypeNodeId());
    Object name = new RecordedDvCodedText().fromDB(getStatusAccess().getStatusRecord(), STATUS.NAME);
    status.setName(name instanceof DvText ? (DvText) name : (DvCodedText) name);
    UUID statusId = getStatusAccess().getStatusRecord().getId();
    status.setUid(new HierObjectId(statusId.toString() + "::" + getServerConfig().getNodename() + "::" + I_StatusAccess.getLatestVersionNumber(this, statusId)));
    PartySelf partySelf = (PartySelf) new PersistedPartyProxy(this).retrieve(getParty());
    status.setSubject(partySelf);
    return status;
}
Also used : EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvText(com.nedap.archie.rm.datavalues.DvText) RecordedDvText(org.ehrbase.service.RecordedDvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Example 5 with HierObjectId

use of com.nedap.archie.rm.support.identification.HierObjectId 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)

Aggregations

HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)22 EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)12 DvText (com.nedap.archie.rm.datavalues.DvText)8 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)7 PartySelf (com.nedap.archie.rm.generic.PartySelf)7 UUID (java.util.UUID)7 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)6 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)5 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)5 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 Composition (com.nedap.archie.rm.composition.Composition)3 VersionedEhrStatus (com.nedap.archie.rm.ehr.VersionedEhrStatus)3 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)3 SdkException (org.ehrbase.util.exception.SdkException)3 Test (org.junit.Test)3 OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)2 VersionedComposition (com.nedap.archie.rm.ehr.VersionedComposition)2 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)2 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)2 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)2