use of com.nedap.archie.rm.support.identification.HierObjectId in project openEHR_SDK by ehrbase.
the class WebTemplateSkeletonBuilder method build.
@SuppressWarnings("unchecked")
public static <T> T build(WebTemplateNode node, boolean withChildren, Class<T> clazz) {
String rmclass = node.getRmType();
CComplexObject elementConstraint = new CComplexObject();
elementConstraint.setRmTypeName(rmclass);
Object skeleton;
switch(rmclass) {
case "UID_BASED_ID":
skeleton = new HierObjectId();
break;
case "PARTY_PROXY":
skeleton = new PartyIdentified();
break;
case "STRING":
case "LONG":
skeleton = null;
break;
case "BOOLEAN":
skeleton = false;
break;
default:
skeleton = RM_OBJECT_CREATOR.create(elementConstraint);
break;
}
if (withChildren) {
node.getChildren().stream().filter(n -> !List.of("name", "archetype_node_id", "offset").contains(n.getId())).forEach(c -> {
Object childObject = build(c, true, Object.class);
insert(node, (RMObject) skeleton, c, childObject);
});
}
if (skeleton instanceof Locatable) {
Optional<WebTemplateNode> name = node.findChildById("name");
if (name.isPresent()) {
if (name.get().getRmType().equals(RmConstants.DV_CODED_TEXT)) {
((Locatable) skeleton).setName(extractDefault(name.get(), DvCodedText.class).orElseThrow());
} else {
((Locatable) skeleton).setName(extractDefault(name.get(), DvText.class).orElse(new DvText(node.getName())));
}
} else {
((Locatable) skeleton).setName(new DvText(node.getName()));
}
((Locatable) skeleton).setArchetypeNodeId(node.getNodeId());
}
if (skeleton instanceof Entry) {
((Entry) skeleton).setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8"));
node.findChildById("subject").map(n -> build(n, false, PartyProxy.class)).ifPresent(((Entry) skeleton)::setSubject);
}
if (skeleton instanceof Composition) {
node.findChildById("category").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((Composition) skeleton)::setCategory);
}
if (skeleton instanceof DvInterval) {
((DvInterval<?>) skeleton).setLowerIncluded(true);
((DvInterval<?>) skeleton).setUpperIncluded(true);
}
if (skeleton instanceof PartyRelated) {
node.findChildById("relationship").flatMap(n -> extractDefault(n, DvCodedText.class)).ifPresent(((PartyRelated) skeleton)::setRelationship);
}
if (skeleton == null || clazz.isAssignableFrom(skeleton.getClass())) {
return (T) skeleton;
} else {
throw new SdkException(String.format("%s not assignable from %s", skeleton.getClass(), clazz));
}
}
use of com.nedap.archie.rm.support.identification.HierObjectId in project ehrbase by ehrbase.
the class EventContextFactory method makeNull.
public EventContext makeNull() {
PartyRef partyRef = new PartyRef(new HierObjectId("ref"), "null", "null");
PartyIdentified healthcareFacility = new PartyIdentified(partyRef, "null", null);
DvCodedText concept = new DvCodedText("Other Care", new CodePhrase(new TerminologyId("openehr"), "238"));
return new EventContext(healthcareFacility, new DvDateTime(new DateTime(0L).toString()), null, null, null, concept, null);
}
use of com.nedap.archie.rm.support.identification.HierObjectId in project ehrbase by ehrbase.
the class StatusAccess method getStatus.
@Override
public EhrStatus getStatus() {
EhrStatus status = new EhrStatus();
status.setModifiable(getStatusRecord().getIsModifiable());
status.setQueryable(getStatusRecord().getIsQueryable());
// set otherDetails if available
if (getStatusRecord().getOtherDetails() != null) {
status.setOtherDetails(getStatusRecord().getOtherDetails());
}
// Locatable attribute
status.setArchetypeNodeId(getStatusRecord().getArchetypeNodeId());
Object name = new RecordedDvCodedText().fromDB(getStatusRecord(), STATUS.NAME);
status.setName(name instanceof DvText ? (DvText) name : (DvCodedText) name);
UUID statusId = getStatusRecord().getId();
status.setUid(new HierObjectId(statusId.toString() + "::" + getServerConfig().getNodename() + "::" + I_StatusAccess.getLatestVersionNumber(this, statusId)));
PartySelf partySelf = (PartySelf) new PersistedPartyProxy(this).retrieve(getStatusRecord().getParty());
status.setSubject(partySelf);
return status;
}
use of com.nedap.archie.rm.support.identification.HierObjectId in project ehrbase by ehrbase.
the class OpenehrEhrController method buildEhrResponseData.
/**
* Builder method to prepare appropriate HTTP response. Flexible to either allow minimal or full representation of resource.
*
* @param factory Lambda function to constructor of desired object
* @param ehrId Current object's reference
* @param accept Requested content format
* @param headerList Requested headers that need to be set
* @param <T> Either EhrResponseData itself or more specific sub-class EhrResponseDataRepresentation
* @return
*/
private <T extends EhrResponseData> Optional<InternalResponse<T>> buildEhrResponseData(Supplier<T> factory, UUID ehrId, /*Action create,*/
String accept, List<String> headerList) {
// check for valid format header to produce content accordingly
MediaType contentType = resolveContentType(accept);
// Optional<EhrStatusDto> ehrStatus = ehrService.getEhrStatusEhrScape(ehrId, CompositionFormat.FLAT); // older, keep until rework of formatting
Optional<EhrStatus> ehrStatus = ehrService.getEhrStatus(ehrId);
if (ehrStatus.isEmpty()) {
return Optional.empty();
}
// create either null or maximum response data class
T minimalOrRepresentation = factory.get();
if (minimalOrRepresentation != null) {
// populate maximum response data
EhrResponseData objByReference = minimalOrRepresentation;
objByReference.setEhrId(new HierObjectId(ehrId.toString()));
objByReference.setEhrStatus(ehrStatus.get());
objByReference.setSystemId(new HierObjectId(ehrService.getSystemUuid().toString()));
DvDateTime timeCreated = ehrService.getCreationTime(ehrId);
objByReference.setTimeCreated(timeCreated.getValue().toString());
// objByReference.setCompositions(null); // TODO get actual data from service layer
// objByReference.setContributions(null); // TODO get actual data from service layer
}
// create and supplement headers with data depending on which headers are requested
HttpHeaders respHeaders = new HttpHeaders();
for (String header : headerList) {
switch(header) {
case CONTENT_TYPE:
if (// if response is going to have a body
minimalOrRepresentation != null)
respHeaders.setContentType(contentType);
break;
case LOCATION:
try {
URI url = new URI(getBaseEnvLinkURL() + "/rest/openehr/v1/ehr/" + ehrId);
respHeaders.setLocation(url);
} catch (Exception e) {
throw new InternalServerException(e.getMessage());
}
break;
case ETAG:
respHeaders.setETag("\"" + ehrId + "\"");
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:
}
}
return Optional.of(new InternalResponse<>(minimalOrRepresentation, respHeaders));
}
use of com.nedap.archie.rm.support.identification.HierObjectId in project ehrbase by ehrbase.
the class CompositionServiceImp method getVersionedComposition.
@Override
public VersionedComposition getVersionedComposition(UUID ehrId, UUID composition) {
Optional<CompositionDto> dto = retrieve(composition, 1);
VersionedComposition compo = new VersionedComposition();
if (dto.isPresent()) {
compo.setUid(new HierObjectId(dto.get().getUuid().toString()));
compo.setOwnerId(new ObjectRef<>(new HierObjectId(dto.get().getEhrId().toString()), "local", "ehr"));
Map<Integer, I_CompositionAccess> compos = I_CompositionAccess.getVersionMapOfComposition(getDataAccess(), composition);
if (compos.containsKey(1)) {
compo.setTimeCreated(new DvDateTime(OffsetDateTime.of(compos.get(1).getSysTransaction().toLocalDateTime(), OffsetDateTime.now().getOffset())));
} else {
throw new InternalServerException("Inconsistent composition data, no version 1 available");
}
}
return compo;
}
Aggregations