Commit af643c90 authored by R.W.Majeed's avatar R.W.Majeed

better handling of dirty flag for changes in patient and visit

parent 5c32166b
......@@ -24,6 +24,7 @@ package de.sekmi.histream.ext;
import java.time.Instant;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Objects;
public class StoredExtensionType implements IdExtensionType, ExternalSourceType{
......@@ -39,6 +40,12 @@ public class StoredExtensionType implements IdExtensionType, ExternalSourceType{
this.dirty = dirty;
}
public <T> void checkAndUpdateDirty(T oldValue, T newValue){
if( !dirty && !Objects.equals(oldValue, newValue) ){
markDirty(true);
}
}
@Override
public final String getId() {return id;}
......@@ -55,8 +62,8 @@ public class StoredExtensionType implements IdExtensionType, ExternalSourceType{
@Override
public final void setSourceTimestamp(Instant instant) {
checkAndUpdateDirty(this.sourceTimestamp, instant);
this.sourceTimestamp = instant;
markDirty(true);
}
@Override
......@@ -66,8 +73,8 @@ public class StoredExtensionType implements IdExtensionType, ExternalSourceType{
@Override
public final void setSourceId(String sourceSystemId) {
checkAndUpdateDirty(this.sourceSystemId, sourceSystemId);
this.sourceSystemId = sourceSystemId;
markDirty(true);
}
private static final class DirtyIterator<T extends StoredExtensionType> implements Iterator<T>{
......
package de.sekmi.histream.impl;
/*
* #%L
* histream
......@@ -28,7 +29,10 @@ import de.sekmi.histream.ext.StoredExtensionType;
/**
* Implementation of the Patient interface.
* @author Raphael
* All setter methods will call {@code markDirty(true)} if the object was previously
* not dirty and the new value is different from the old one.
*
* @author R.W.Majeed
*
*/
public class PatientImpl extends StoredExtensionType implements Patient {
......@@ -56,19 +60,8 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setBirthDate(DateTimeAccuracy dateTime){
// TODO compare and markDirty if different (also in other setters)
if( this.birthDate == null && dateTime == null ){
// nothing to do
return;
}else if( birthDate != null && dateTime != null ){
// compare
if( birthDate.equals(dateTime) ){
// nothing to do
return;
}
}
checkAndUpdateDirty(this.birthDate, dateTime);
this.birthDate = dateTime;
markDirty(true);
}
@Override
......@@ -78,6 +71,7 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setDeathDate(DateTimeAccuracy dateTime){
checkAndUpdateDirty(this.deathDate, dateTime);
this.deathDate = dateTime;
// non null death date implies patient deceased
if( dateTime != null ){
......@@ -92,13 +86,8 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setSex(Sex sex) {
if( this.sex == null && sex == null ){
return; // nothing to do
}else if( this.sex != null && sex != null && this.sex.equals(sex) ){
return; // nothing to do
}
checkAndUpdateDirty(this.sex, sex);
this.sex = sex;
markDirty(true);
}
@Override
......@@ -108,6 +97,7 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setSurname(String surname) {
checkAndUpdateDirty(this.surname, surname);
this.surname = surname;
}
......@@ -118,6 +108,7 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setGivenName(String givenName) {
checkAndUpdateDirty(this.givenName, givenName);
this.givenName = givenName;
}
......@@ -128,15 +119,14 @@ public class PatientImpl extends StoredExtensionType implements Patient {
@Override
public void setDeceased(Boolean deceased) {
checkAndUpdateDirty(this.deceased, deceased);
this.deceased = deceased;
}
@Override
public String toString(){
return "Patient(id="+getId()+", dob="+getBirthDate()+")";
}
}
package de.sekmi.histream.impl;
/*
* #%L
* histream
......@@ -48,7 +49,12 @@ public class VisitImpl extends StoredExtensionType implements Visit {
public String getPatientId(){return patientId;}
public void setPatientId(String patientId){this.patientId = patientId;}
public void setPatientId(String patientId){
// patient id should not be changed normally.
this.patientId = patientId;
// TODO need to update dirty flag?
markDirty(true);
}
@Override
public DateTimeAccuracy getStartTime() {
......@@ -67,8 +73,8 @@ public class VisitImpl extends StoredExtensionType implements Visit {
@Override
public void setStatus(Status status) {
checkAndUpdateDirty(this.status, status);
this.status = status;
markDirty(true); // maybe compare first
}
@Override
......@@ -78,20 +84,20 @@ public class VisitImpl extends StoredExtensionType implements Visit {
@Override
public void setLocationId(String locationId){
checkAndUpdateDirty(this.locationId, locationId);
this.locationId = locationId;
markDirty(true);
}
@Override
public void setEndTime(DateTimeAccuracy endTime) {
checkAndUpdateDirty(this.endTime, endTime);
this.endTime = endTime;
markDirty(true);
}
@Override
public void setStartTime(DateTimeAccuracy startTime) {
checkAndUpdateDirty(this.startTime, startTime);
this.startTime = startTime;
markDirty(true);
}
......
......@@ -226,6 +226,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
log.warning("Missing row in visit_dimension for encounter_mapping.encounter_num="+num);
}else{
setAliases(visit, aliases.toArray(new String[aliases.size()]), primary);
visit.markDirty(false);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment