Search in sources :

Example 16 with HierObjectId

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));
    }
}
Also used : java.util(java.util) Composition(com.nedap.archie.rm.composition.Composition) RMObjectCreator(com.nedap.archie.creation.RMObjectCreator) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SdkException(org.ehrbase.util.exception.SdkException) Archetyped(com.nedap.archie.rm.archetyped.Archetyped) ArchieRMInfoLookup(com.nedap.archie.rminfo.ArchieRMInfoLookup) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) RmConstants(org.ehrbase.util.rmconstants.RmConstants) Locatable(com.nedap.archie.rm.archetyped.Locatable) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvText(com.nedap.archie.rm.datavalues.DvText) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) ArchetypeID(com.nedap.archie.rm.support.identification.ArchetypeID) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) RMAttributeInfo(com.nedap.archie.rminfo.RMAttributeInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) RM_VERSION_1_4_0(org.ehrbase.util.rmconstants.RmConstants.RM_VERSION_1_4_0) FlatPath(org.ehrbase.webtemplate.parser.FlatPath) RMObject(com.nedap.archie.rm.RMObject) TemplateId(com.nedap.archie.rm.archetyped.TemplateId) CComplexObject(com.nedap.archie.aom.CComplexObject) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Composition(com.nedap.archie.rm.composition.Composition) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) CComplexObject(com.nedap.archie.aom.CComplexObject) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) DvText(com.nedap.archie.rm.datavalues.DvText) DvInterval(com.nedap.archie.rm.datavalues.quantity.DvInterval) Entry(com.nedap.archie.rm.composition.Entry) SdkException(org.ehrbase.util.exception.SdkException) RMObject(com.nedap.archie.rm.RMObject) CComplexObject(com.nedap.archie.aom.CComplexObject) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) Locatable(com.nedap.archie.rm.archetyped.Locatable)

Example 17 with HierObjectId

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);
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) EventContext(com.nedap.archie.rm.composition.EventContext) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DateTime(org.joda.time.DateTime) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 18 with HierObjectId

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;
}
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) PartySelf(com.nedap.archie.rm.generic.PartySelf) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Example 19 with HierObjectId

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) InternalServerException(org.ehrbase.api.exception.InternalServerException) URI(java.net.URI) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) StateConflictException(org.ehrbase.api.exception.StateConflictException) InternalServerException(org.ehrbase.api.exception.InternalServerException) InvalidApiParameterException(org.ehrbase.api.exception.InvalidApiParameterException) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) MediaType(org.springframework.http.MediaType) EhrResponseData(org.ehrbase.response.openehr.EhrResponseData) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 20 with HierObjectId

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;
}
Also used : InternalServerException(org.ehrbase.api.exception.InternalServerException) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) I_CompositionAccess(org.ehrbase.dao.access.interfaces.I_CompositionAccess) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

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