Search in sources :

Example 36 with PartyIdentified

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

the class PersistedPartyProxy method getOrCreate.

/**
 * Get or create a PartyIdentified instance with the given parameters.
 */
public UUID getOrCreate(String name, String code, String scheme, String namespace, String type, List<DvIdentifier> identifiers) {
    // Check conformance to openEHR spec
    if (identifiers == null || identifiers.isEmpty()) {
        throw new IllegalArgumentException("Can't create PartyIdentified with invalid list of identifiers.");
    }
    identifiers.forEach(dv -> {
        if (!isValidDvIdentifier(dv))
            throw new IllegalArgumentException("Can't create PartyIdentified with an invalid identifier.");
    });
    // Create and persist object
    var partyIdentified = new PartyIdentified(new PartyRef(new GenericId(code, scheme), namespace, type), name, identifiers);
    return getOrCreate(partyIdentified);
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified)

Example 37 with PartyIdentified

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

the class PersistedPartyRelated method render.

@Override
public PartyProxy render(PartyIdentifiedRecord partyIdentifiedRecord) {
    // a party identified with a relationship!
    PartyIdentified partyIdentified = (PartyIdentified) new PersistedPartyIdentified(domainAccess).render(partyIdentifiedRecord);
    PartyRelated partyRelated = new PartyRelated();
    partyRelated.setExternalRef(partyIdentified.getExternalRef());
    partyRelated.setName(partyIdentified.getName());
    partyRelated.setIdentifiers(partyIdentified.getIdentifiers());
    partyRelated.setRelationship(new JooqDvCodedText(partyIdentifiedRecord.getRelationship()).toRmInstance());
    return partyRelated;
}
Also used : PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) JooqDvCodedText(org.ehrbase.dao.access.jooq.rmdatavalue.JooqDvCodedText) PartyRelated(com.nedap.archie.rm.generic.PartyRelated)

Example 38 with PartyIdentified

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

the class PersistedPartyRelated method store.

@Override
public UUID store(PartyProxy partyProxy) {
    PartyRefValue partyRefValue = new PartyRefValue(partyProxy).attributes();
    // store a new party identified
    UUID partyIdentifiedUuid = domainAccess.getContext().insertInto(PARTY_IDENTIFIED, PARTY_IDENTIFIED.NAME, PARTY_IDENTIFIED.PARTY_REF_NAMESPACE, PARTY_IDENTIFIED.PARTY_REF_VALUE, PARTY_IDENTIFIED.PARTY_REF_SCHEME, PARTY_IDENTIFIED.PARTY_REF_TYPE, PARTY_IDENTIFIED.PARTY_TYPE, PARTY_IDENTIFIED.OBJECT_ID_TYPE, PARTY_IDENTIFIED.RELATIONSHIP).values(((PartyIdentified) partyProxy).getName(), partyRefValue.getNamespace(), partyRefValue.getValue(), partyRefValue.getScheme(), partyRefValue.getType(), PartyType.party_related, partyRefValue.getObjectIdType(), relationshipAsRecord(partyProxy)).returning(PARTY_IDENTIFIED.ID).fetchOne().getId();
    // store identifiers
    new PartyIdentifiers(domainAccess).store((PartyIdentified) partyProxy, partyIdentifiedUuid);
    return partyIdentifiedUuid;
}
Also used : PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) UUID(java.util.UUID)

Example 39 with PartyIdentified

use of com.nedap.archie.rm.generic.PartyIdentified 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 40 with PartyIdentified

use of com.nedap.archie.rm.generic.PartyIdentified 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

PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)41 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)12 PartySelf (com.nedap.archie.rm.generic.PartySelf)12 Participation (com.nedap.archie.rm.generic.Participation)11 GenericId (com.nedap.archie.rm.support.identification.GenericId)11 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)10 Test (org.junit.Test)10 Composition (com.nedap.archie.rm.composition.Composition)9 DvText (com.nedap.archie.rm.datavalues.DvText)9 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)9 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)8 IOException (java.io.IOException)8 StandardCharsets (java.nio.charset.StandardCharsets)8 IOUtils (org.apache.commons.io.IOUtils)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Tuple (org.assertj.core.groups.Tuple)8 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)7 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)6 Optional (java.util.Optional)6 TestData (org.ehrbase.client.TestData)6