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);
}
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);
}
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);
}
}
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;
}
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));
}
Aggregations