Search in sources :

Example 6 with PartyProxy

use of com.nedap.archie.rm.generic.PartyProxy in project openEHR_SDK by ehrbase.

the class PartyIdentifiedStdConfig method buildChildValues.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> buildChildValues(String currentTerm, PartyIdentified rmObject, Context<Map<String, Object>> context) {
    Map<String, Object> result = new HashMap<>();
    addValue(result, currentTerm, "name", rmObject.getName());
    addValue(result, currentTerm, "id", Optional.of(rmObject).map(PartyProxy::getExternalRef).map(ObjectRef::getId).map(ObjectId::getValue).orElse(null));
    addValue(result, currentTerm, "id_namespace", Optional.of(rmObject).map(PartyProxy::getExternalRef).map(ObjectRef::getNamespace).orElse(null));
    GenericId genericId = Optional.of(rmObject).map(PartyProxy::getExternalRef).map(ObjectRef::getId).filter(i -> i.getClass().equals(GenericId.class)).map(i -> (GenericId) i).orElse(null);
    if (genericId != null) {
        addValue(result, currentTerm, "id_scheme", genericId.getScheme());
    }
    if (rmObject.getIdentifiers() != null) {
        IntStream.range(0, rmObject.getIdentifiers().size()).forEach(i -> result.putAll(DV_IDENTIFIER_CONFIG.buildChildValues(currentTerm + "/_identifier:" + i, rmObject.getIdentifiers().get(i), context)));
    }
    return result;
}
Also used : PartyProxy(com.nedap.archie.rm.generic.PartyProxy) IntStream(java.util.stream.IntStream) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) Context(org.ehrbase.serialisation.walker.Context) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) GenericId(com.nedap.archie.rm.support.identification.GenericId) Map(java.util.Map) Optional(java.util.Optional) HashMap(java.util.HashMap) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) GenericId(com.nedap.archie.rm.support.identification.GenericId) HashMap(java.util.HashMap) ObjectId(com.nedap.archie.rm.support.identification.ObjectId) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Example 7 with PartyProxy

use of com.nedap.archie.rm.generic.PartyProxy in project openEHR_SDK by ehrbase.

the class EventContextValueInserter method insert.

@Override
public void insert(EventContext rmObject, DefaultValues defaultValues) {
    if (RMHelper.isEmpty(rmObject.getStartTime()) && defaultValues.containsDefaultValue(DefaultValuePath.TIME)) {
        rmObject.setStartTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getEndTime()) && defaultValues.containsDefaultValue(DefaultValuePath.END_TIME)) {
        rmObject.setEndTime(new DvDateTime(defaultValues.getDefaultValue(DefaultValuePath.END_TIME)));
    }
    if (RMHelper.isEmpty(rmObject.getHealthCareFacility()) && (defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_NAME) || defaultValues.containsDefaultValue(DefaultValuePath.HEALTHCARE_FACILITY_ID))) {
        rmObject.setHealthCareFacility(buildPartyIdentified(defaultValues, DefaultValuePath.HEALTHCARE_FACILITY_NAME, DefaultValuePath.HEALTHCARE_FACILITY_ID, rmObject.getHealthCareFacility()));
    }
    if (RMHelper.isEmpty(rmObject.getLocation()) && defaultValues.containsDefaultValue(DefaultValuePath.LOCATION)) {
        rmObject.setLocation(defaultValues.getDefaultValue(DefaultValuePath.LOCATION));
    }
    if (RMHelper.isEmpty(rmObject.getSetting()) && defaultValues.containsDefaultValue(DefaultValuePath.SETTING)) {
        Setting defaultValue = defaultValues.getDefaultValue(DefaultValuePath.SETTING);
        rmObject.setSetting(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
    }
    if (RMHelper.isEmpty(rmObject.getParticipations()) && defaultValues.containsDefaultValue(DefaultValuePath.PARTICIPATION)) {
        rmObject.setParticipations(defaultValues.getDefaultValue(DefaultValuePath.PARTICIPATION));
    }
    if (rmObject.getParticipations() != null) {
        rmObject.getParticipations().stream().map(Participation::getPerformer).filter(Objects::nonNull).map(PartyProxy::getExternalRef).filter(Objects::nonNull).filter(ref -> ref.getId() != null).forEach(ref -> {
            if (ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_NAMESPACE)) {
                ref.setNamespace(defaultValues.getDefaultValue(DefaultValuePath.ID_NAMESPACE));
            }
            if (ref.getId() instanceof GenericId && ref.getNamespace() == null && defaultValues.containsDefaultValue(DefaultValuePath.ID_SCHEME)) {
                ((GenericId) ref.getId()).setScheme(defaultValues.getDefaultValue(DefaultValuePath.ID_SCHEME));
            }
        });
    }
}
Also used : PartyProxy(com.nedap.archie.rm.generic.PartyProxy) Objects(java.util.Objects) EventContext(com.nedap.archie.rm.composition.EventContext) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RMHelper(org.ehrbase.serialisation.walker.RMHelper) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Participation(com.nedap.archie.rm.generic.Participation) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) GenericId(com.nedap.archie.rm.support.identification.GenericId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Setting(org.ehrbase.client.classgenerator.shareddefinition.Setting) Objects(java.util.Objects) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 8 with PartyProxy

use of com.nedap.archie.rm.generic.PartyProxy in project ehrbase by ehrbase.

the class ContributionServiceImp method retrieveAuditDetails.

/**
 * retrieval and building of AuditDetails object attached to the given contribution context
 * @param contributionId ID of contribution
 * @return {@link AuditDetails} object from contribution
 */
private AuditDetails retrieveAuditDetails(UUID contributionId) {
    UUID auditId = I_ContributionAccess.retrieveInstance(this.getDataAccess(), contributionId).getHasAuditDetails();
    I_AuditDetailsAccess auditDetailsAccess = new AuditDetailsAccess(this.getDataAccess()).retrieveInstance(this.getDataAccess(), auditId);
    String systemId = auditDetailsAccess.getSystemId().toString();
    PartyProxy committer = new PersistedPartyProxy(this.getDataAccess()).retrieve(auditDetailsAccess.getCommitter());
    DvDateTime timeCommitted = new DvDateTime(LocalDateTime.ofInstant(auditDetailsAccess.getTimeCommitted().toInstant(), ZoneId.of(auditDetailsAccess.getTimeCommittedTzId())));
    int changeTypeCode = I_ConceptAccess.ContributionChangeType.valueOf(auditDetailsAccess.getChangeType().getLiteral().toUpperCase()).getCode();
    // FIXME: what's the terminology ID of the official change type terminology?
    DvCodedText changeType = new DvCodedText(auditDetailsAccess.getChangeType().getLiteral(), new CodePhrase(new TerminologyId("audit change type"), String.valueOf(changeTypeCode)));
    DvText description = new DvText(auditDetailsAccess.getDescription());
    return new AuditDetails(systemId, committer, timeCommitted, changeType, description);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) AuditDetailsAccess(org.ehrbase.dao.access.jooq.AuditDetailsAccess) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) DvText(com.nedap.archie.rm.datavalues.DvText) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) AuditDetails(com.nedap.archie.rm.generic.AuditDetails)

Example 9 with PartyProxy

use of com.nedap.archie.rm.generic.PartyProxy in project ehrbase by ehrbase.

the class ContextAccess method retrieveHistoricalEventContext.

/**
 * @throws InternalServerException on failure of decoding DvText or DvDateTime
 */
public static EventContext retrieveHistoricalEventContext(I_DomainAccess domainAccess, UUID compositionId, Timestamp transactionTime) {
    // use fetch any since duplicates are possible during tests...
    EventContextHistoryRecord eventContextHistoryRecord = domainAccess.getContext().fetchAny(EVENT_CONTEXT_HISTORY, EVENT_CONTEXT_HISTORY.COMPOSITION_ID.eq(compositionId).and(EVENT_CONTEXT_HISTORY.SYS_TRANSACTION.eq(transactionTime)));
    // no matching version for this composition
    if (eventContextHistoryRecord == null)
        return null;
    // get the facility entry
    PartyIdentified healthCareFacility = null;
    if (eventContextHistoryRecord.getFacility() != null) {
        PartyIdentifiedRecord partyIdentifiedRecord = domainAccess.getContext().fetchOne(PARTY_IDENTIFIED, PARTY_IDENTIFIED.ID.eq(eventContextHistoryRecord.getFacility()));
        if (partyIdentifiedRecord != null) {
            List<DvIdentifier> identifiers = new ArrayList<>();
            domainAccess.getContext().fetch(IDENTIFIER, IDENTIFIER.PARTY.eq(partyIdentifiedRecord.getId())).forEach(record -> {
                DvIdentifier dvIdentifier = new DvIdentifier();
                dvIdentifier.setIssuer(record.getIssuer());
                dvIdentifier.setAssigner(record.getAssigner());
                dvIdentifier.setId(record.getIdValue());
                dvIdentifier.setType(record.getTypeName());
                identifiers.add(dvIdentifier);
            });
            // get PartyRef values from record
            healthCareFacility = getPartyIdentifiedFromRecord(partyIdentifiedRecord, identifiers);
        }
    }
    List<Participation> participationList = new ArrayList<>();
    // get the participations
    domainAccess.getContext().fetch(PARTICIPATION_HISTORY, PARTICIPATION_HISTORY.EVENT_CONTEXT.eq(eventContextHistoryRecord.getId()).and(PARTICIPATION_HISTORY.SYS_TRANSACTION.eq(transactionTime))).forEach(record -> {
        // retrieve performer
        PartyProxy performer = new PersistedPartyProxy(domainAccess).retrieve(record.getPerformer());
        DvInterval<DvDateTime> startTime = convertDvIntervalDvDateTimeFromRecord(eventContextHistoryRecord);
        DvCodedText mode = convertModeFromRecord(eventContextHistoryRecord);
        Participation participation = new Participation(performer, (DvText) new RecordedDvCodedText().fromDB(record, PARTICIPATION.FUNCTION), mode, startTime);
        participationList.add(participation);
    });
    DvCodedText setting = (DvCodedText) new RecordedDvCodedText().fromDB(eventContextHistoryRecord, EVENT_CONTEXT_HISTORY.SETTING);
    return new EventContext(healthCareFacility, new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getStartTime(), eventContextHistoryRecord.getStartTimeTzid()), new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getEndTime(), eventContextHistoryRecord.getEndTimeTzid()), participationList.isEmpty() ? null : participationList, eventContextHistoryRecord.getLocation(), setting, null);
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) PartyIdentifiedRecord(org.ehrbase.jooq.pg.tables.records.PartyIdentifiedRecord) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ArrayList(java.util.ArrayList) DvIdentifier(com.nedap.archie.rm.datavalues.DvIdentifier) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) EventContext(com.nedap.archie.rm.composition.EventContext) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) EventContextHistoryRecord(org.ehrbase.jooq.pg.tables.records.EventContextHistoryRecord) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy)

Example 10 with PartyProxy

use of com.nedap.archie.rm.generic.PartyProxy in project ehrbase by ehrbase.

the class ContextAccess method setRecordFields.

/**
 * setup an EventContextRecord instance based on values from an EventContext instance
 *
 * @param id
 * @param eventContext
 */
@Override
public void setRecordFields(UUID id, EventContext eventContext) {
    RecordedDvDateTime recordedDvDateTime = new RecordedDvDateTime(eventContext.getStartTime());
    eventContextRecord.setStartTime(recordedDvDateTime.toTimestamp());
    recordedDvDateTime.zoneId().ifPresent(eventContextRecord::setStartTimeTzid);
    if (eventContext.getEndTime() != null) {
        recordedDvDateTime = new RecordedDvDateTime(eventContext.getEndTime());
        eventContextRecord.setEndTime(recordedDvDateTime.toTimestamp());
        recordedDvDateTime.zoneId().ifPresent(eventContextRecord::setEndTimeTzid);
    }
    eventContextRecord.setId(id != null ? id : UUID.randomUUID());
    // Health care facility
    if (eventContext.getHealthCareFacility() != null) {
        UUID healthcareFacilityId = new PersistedPartyProxy(this).getOrCreate(eventContext.getHealthCareFacility());
        eventContextRecord.setFacility(healthcareFacilityId);
    }
    // location
    if (eventContext.getLocation() != null)
        eventContextRecord.setLocation(eventContext.getLocation());
    new RecordedDvCodedText().toDB(eventContextRecord, EVENT_CONTEXT.SETTING, eventContext.getSetting());
    if (eventContext.getParticipations() != null) {
        for (Participation participation : eventContext.getParticipations()) {
            ParticipationRecord participationRecord = getContext().newRecord(PARTICIPATION);
            participationRecord.setEventContext(eventContextRecord.getId());
            new RecordedDvText().toDB(participationRecord, PARTICIPATION.FUNCTION, participation.getFunction());
            if (participation.getMode() != null)
                new RecordedDvCodedText().toDB(participationRecord, PARTICIPATION.MODE, participation.getMode());
            if (participation.getTime() != null) {
                DvDateTime lower = participation.getTime().getLower();
                if (lower != null) {
                    recordedDvDateTime = new RecordedDvDateTime(lower);
                    participationRecord.setTimeLower(recordedDvDateTime.toTimestamp());
                    recordedDvDateTime.zoneId().ifPresent(participationRecord::setTimeLowerTz);
                }
                DvDateTime upper = participation.getTime().getUpper();
                if (upper != null) {
                    recordedDvDateTime = new RecordedDvDateTime(upper);
                    participationRecord.setTimeUpper(recordedDvDateTime.toTimestamp());
                    recordedDvDateTime.zoneId().ifPresent(participationRecord::setTimeUpperTz);
                }
            }
            // only PartyIdentified performer is supported now
            PartyIdentified performer;
            PartyProxy setPerformer = participation.getPerformer();
            if (!(setPerformer instanceof PartyIdentified)) {
                log.warn("Set performer is using unsupported type: {}", setPerformer);
                break;
            }
            performer = (PartyIdentified) setPerformer;
            UUID performerUuid = new PersistedPartyProxy(this).getOrCreate(performer);
            // set the performer
            participationRecord.setPerformer(performerUuid);
            participations.add(participationRecord);
        }
    }
    // other context
    if (eventContext.getOtherContext() != null && CollectionUtils.isNotEmpty(eventContext.getOtherContext().getItems())) {
        // set up the JSONB field other_context
        eventContextRecord.setOtherContext(JSONB.valueOf(new RawJson().marshal(eventContext.getOtherContext())));
    }
}
Also used : Participation(com.nedap.archie.rm.generic.Participation) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) ParticipationRecord(org.ehrbase.jooq.pg.tables.records.ParticipationRecord) RawJson(org.ehrbase.serialisation.dbencoding.RawJson) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvDateTime(org.ehrbase.service.RecordedDvDateTime) RecordedDvText(org.ehrbase.service.RecordedDvText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy) PartyProxy(com.nedap.archie.rm.generic.PartyProxy) UUID(java.util.UUID)

Aggregations

PartyProxy (com.nedap.archie.rm.generic.PartyProxy)10 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)7 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)6 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)6 Participation (com.nedap.archie.rm.generic.Participation)5 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)5 DvText (com.nedap.archie.rm.datavalues.DvText)4 GenericId (com.nedap.archie.rm.support.identification.GenericId)4 EventContext (com.nedap.archie.rm.composition.EventContext)3 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)3 AuditDetails (com.nedap.archie.rm.generic.AuditDetails)3 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)3 Context (org.ehrbase.serialisation.walker.Context)3 RecordedDvCodedText (org.ehrbase.service.RecordedDvCodedText)3 RecordedDvDateTime (org.ehrbase.service.RecordedDvDateTime)3 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)2 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)2 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2