use of org.ehrbase.service.RecordedDvText 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())));
}
}
Aggregations