use of com.nedap.archie.rm.datavalues.DvIdentifier 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);
}
Aggregations