Skip to content

Commit 21262ac

Browse files
committed
Sanjana | BDSHR - 874 | Cleaning up of computed patient age related columns from encounter and patient death details.Queries to comput age dynamically from patient.since dob can be updated.
1 parent fcffd63 commit 21262ac

File tree

12 files changed

+36
-113
lines changed

12 files changed

+36
-113
lines changed

src/main/java/org/sharedhealth/datasense/handler/DeathNoteHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Date;
1818
import java.util.List;
1919

20-
import static org.sharedhealth.datasense.util.DateUtil.*;
2120
import static org.sharedhealth.datasense.util.TrUrl.isConceptUrl;
2221
import static org.sharedhealth.datasense.util.TrUrl.isReferenceTermUrl;
2322

@@ -95,9 +94,6 @@ private void mapDateOfDeathAndPatientAge(PatientDeathDetails patientDeathDetails
9594
Observation dateOfDeathObs = findObservation(composition, deathNoteObservation, datasenseProperties.getDateOfDeathUuid());
9695
Date dateOfDeath = getDateValue(encounter, dateOfDeathObs);
9796
patientDeathDetails.setDateOfDeath(dateOfDeath);
98-
patientDeathDetails.setPatientAgeInYears(getYears(patientDeathDetails.getPatient().getDateOfBirth(), dateOfDeath));
99-
patientDeathDetails.setPatientAgeInMonths(getMonths(patientDeathDetails.getPatient().getDateOfBirth(), dateOfDeath));
100-
patientDeathDetails.setPatientAgeInDays(getDays(patientDeathDetails.getPatient().getDateOfBirth(), dateOfDeath));
10197
}
10298

10399
private Date getDateValue(Encounter encounter, Observation dateOfDeathObs) {

src/main/java/org/sharedhealth/datasense/model/Encounter.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ public class Encounter {
1212
private Patient patient;
1313
private Date encounterDateTime;
1414
private String locationCode;
15-
private int patientAgeInYears;
16-
private int patientAgeInMonths;
17-
private int patientAgeInDays;
1815

1916
public void setEncounterType(String encounterType) {
2017
this.encounterType = encounterType;
@@ -69,30 +66,6 @@ public String getLocationCode() {
6966
return null;
7067
}
7168

72-
public int getPatientAgeInYears() {
73-
return patientAgeInYears;
74-
}
75-
76-
public void setPatientAgeInYears(int patientAgeInYears) {
77-
this.patientAgeInYears = patientAgeInYears;
78-
}
79-
80-
public int getPatientAgeInMonths() {
81-
return patientAgeInMonths;
82-
}
83-
84-
public void setPatientAgeInMonths(int patientAgeInMonths) {
85-
this.patientAgeInMonths = patientAgeInMonths;
86-
}
87-
88-
public int getPatientAgeInDays() {
89-
return patientAgeInDays;
90-
}
91-
92-
public void setPatientAgeInDays(int patientAgeInDays) {
93-
this.patientAgeInDays = patientAgeInDays;
94-
}
95-
9669
public String getEncounterId() {
9770
return encounterId;
9871
}

src/main/java/org/sharedhealth/datasense/model/PatientDeathDetails.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ public class PatientDeathDetails extends BaseResource {
66
private Patient patient;
77
private Encounter encounter;
88
private Date dateOfDeath;
9-
private int patientAgeInYears;
10-
private int patientAgeInMonths;
11-
private int patientAgeInDays;
129
private String circumstancesOfDeath;
1310
private String causeOfDeathCode;
1411
private String causeOfDeathConceptUuid;
@@ -38,30 +35,6 @@ public void setDateOfDeath(Date dateOfDeath) {
3835
this.dateOfDeath = dateOfDeath;
3936
}
4037

41-
public int getPatientAgeInYears() {
42-
return patientAgeInYears;
43-
}
44-
45-
public void setPatientAgeInYears(int patientAgeInYears) {
46-
this.patientAgeInYears = patientAgeInYears;
47-
}
48-
49-
public int getPatientAgeInMonths() {
50-
return patientAgeInMonths;
51-
}
52-
53-
public void setPatientAgeInMonths(int patientAgeInMonths) {
54-
this.patientAgeInMonths = patientAgeInMonths;
55-
}
56-
57-
public int getPatientAgeInDays() {
58-
return patientAgeInDays;
59-
}
60-
61-
public void setPatientAgeInDays(int patientAgeInDays) {
62-
this.patientAgeInDays = patientAgeInDays;
63-
}
64-
6538
public String getCircumstancesOfDeath() {
6639
return circumstancesOfDeath;
6740
}

src/main/java/org/sharedhealth/datasense/processor/ClinicalEncounterProcessor.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import java.util.Date;
1515

16-
import static org.sharedhealth.datasense.util.DateUtil.*;
17-
1816
@Component("clinicalEncounterProcessor")
1917
public class ClinicalEncounterProcessor implements ResourceProcessor {
2018
private EncounterDao encounterDao;
@@ -57,7 +55,6 @@ private Encounter mapEncounterFields(org.hl7.fhir.instance.model.Encounter fhirE
5755
String encounterDate = composition.getComposition().getDateSimple().toString();
5856
Date encounterDateTime = DateUtil.parseDate(encounterDate);
5957
encounter.setEncounterDateTime(encounterDateTime);
60-
setPatientAge(patient.getDateOfBirth(), encounterDateTime, encounter);
6158
return encounter;
6259
}
6360

@@ -66,9 +63,4 @@ public void setNext(ResourceProcessor nextProcessor) {
6663
this.nextProcessor = nextProcessor;
6764
}
6865

69-
public void setPatientAge(Date birthDate, Date encounterDate, Encounter encounter) {
70-
encounter.setPatientAgeInYears(getYears(birthDate, encounterDate));
71-
encounter.setPatientAgeInMonths(getMonths(birthDate, encounterDate));
72-
encounter.setPatientAgeInDays(getDays(birthDate, encounterDate));
73-
}
7466
}

src/main/java/org/sharedhealth/datasense/repository/EncounterDao.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,12 @@ public void save(Encounter encounter) {
2121
map.put("encounter_type", encounter.getEncounterType());
2222
map.put("visit_type", encounter.getEncounterVisitType());
2323
map.put("patient_hid", encounter.getPatient().getHid());
24-
map.put("patient_age_years", encounter.getPatientAgeInYears());
25-
map.put("patient_age_months", encounter.getPatientAgeInMonths());
26-
map.put("patient_age_days", encounter.getPatientAgeInDays());
2724
map.put("location_id", encounter.getLocationCode());
2825
map.put("facility_id", encounter.getFacility().getFacilityId());
2926
jdbcTemplate.update("insert into encounter (encounter_id, encounter_datetime, encounter_type, visit_type, " +
30-
"patient_hid, " +
31-
"patient_age_years, patient_age_months, patient_age_days, encounter_location_id, facility_id) " +
27+
"patient_hid, encounter_location_id, facility_id) " +
3228
"values(:encounter_id, :encounter_datetime, :encounter_type , :visit_type , :patient_hid, " +
33-
":patient_age_years, :patient_age_months," +
34-
" :patient_age_days , :location_id, :facility_id)", map);
29+
":location_id, :facility_id)", map);
3530
}
3631

3732
public void deleteExisting(String healthId, String encounterId){

src/main/java/org/sharedhealth/datasense/repository/PatientDeathDetailsDao.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ public void save(PatientDeathDetails patientDeathDetails) {
2323
map.put("patient_hid", patientDeathDetails.getPatient().getHid());
2424
map.put("encounter_id", patientDeathDetails.getEncounter().getEncounterId());
2525
map.put("date_of_death", patientDeathDetails.getDateOfDeath());
26-
map.put("patient_age_years", patientDeathDetails.getPatientAgeInYears());
27-
map.put("patient_age_months", patientDeathDetails.getPatientAgeInMonths());
28-
map.put("patient_age_days", patientDeathDetails.getPatientAgeInDays());
2926
map.put("circumstances_of_death", patientDeathDetails.getCircumstancesOfDeath());
3027
map.put("cause_concept_uuid", patientDeathDetails.getCauseOfDeathConceptUuid());
3128
map.put("cause_code", patientDeathDetails.getCauseOfDeathCode());
3229
map.put("uuid", patientDeathDetails.getUuid());
3330

3431

35-
String sql = "insert into patient_death_details (patient_hid, encounter_id, date_of_death, patient_age_years, patient_age_months, patient_age_days," +
32+
String sql = "insert into patient_death_details (patient_hid, encounter_id, date_of_death, " +
3633
"circumstances_of_death, cause_concept_uuid, cause_code, uuid) " +
37-
"values(:patient_hid, :encounter_id, :date_of_death, :patient_age_years, :patient_age_months, :patient_age_days, " +
38-
" :circumstances_of_death, :cause_concept_uuid, :cause_code, :uuid)";
34+
"values(:patient_hid, :encounter_id, :date_of_death, " +
35+
":circumstances_of_death, :cause_concept_uuid, :cause_code, :uuid)";
3936

4037
jdbcTemplate.update(sql, map);
4138
}

src/main/resources/db/changelog/db-changelog.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,16 @@
668668
<column name="updated_at" type="datetime" defaultValueComputed="now()"/>
669669
</addColumn>
670670
</changeSet>
671+
<changeSet id="sharedhealth-datasense-20150818-1513" author="sanjana" context="setup">
672+
<comment>Dropping patient age columns in encounter table</comment>
673+
<dropColumn columnName="patient_age_years" tableName="encounter"/>
674+
<dropColumn columnName="patient_age_months" tableName="encounter"/>
675+
<dropColumn columnName="patient_age_days" tableName="encounter"/>
676+
</changeSet>
677+
<changeSet id="sharedhealth-datasense-20150818-1520" author="sanjana" context="setup">
678+
<comment>Dropping patient age columns in encounter table</comment>
679+
<dropColumn columnName="patient_age_years" tableName="patient_death_details"/>
680+
<dropColumn columnName="patient_age_months" tableName="patient_death_details"/>
681+
<dropColumn columnName="patient_age_days" tableName="patient_death_details"/>
682+
</changeSet>
671683
</databaseChangeLog>

src/test/java/org/sharedhealth/datasense/aqs/AqsExecutorIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public class AqsExecutorIntegrationTest {
3333
public void shouldExecuteMultipleQueriesAndReturnResults() throws ExecutionException, InterruptedException {
3434
QueryDefinition admissionsMale = new QueryDefinition();
3535
admissionsMale.setQueryName("ipd_male_0_to_4");
36-
admissionsMale.setQueryString("select count(distinct e.patient_hid) as v1 from encounter e, patient p where facility_id=':paramFacilityId:' and e.patient_hid=p.patient_hid and e.patient_age_years >= 0 and e.patient_age_years < 5 and p.gender='M' and LOWER(e.visit_type)='inpatient' and e.encounter_datetime =':paramStartDate:';");
36+
admissionsMale.setQueryString("select count(distinct e.patient_hid) as v1 from encounter e, patient p where facility_id=':paramFacilityId:' and e.patient_hid=p.patient_hid and TIMESTAMPDIFF(YEAR, p.dob, e.encounter_datetime) between 0 and 5 and p.gender='M' and LOWER(e.visit_type)='inpatient' and e.encounter_datetime =':paramStartDate:';");
3737

3838
QueryDefinition emergencyVisitsFemale = new QueryDefinition();
3939
emergencyVisitsFemale.setQueryName("emergency_female_15_to_24");
40-
emergencyVisitsFemale.setQueryString("select count(distinct e.patient_hid) as v1 from encounter e, patient p where facility_id=':paramFacilityId:' and e.patient_hid=p.patient_hid and e.patient_age_years >= 15 and e.patient_age_years < 25 and p.gender='F' and LOWER(e.visit_type)='emergency' and e.encounter_datetime=':paramStartDate:';");
40+
emergencyVisitsFemale.setQueryString("select count(distinct e.patient_hid) as v1 from encounter e, patient p where facility_id=':paramFacilityId:' and e.patient_hid=p.patient_hid and TIMESTAMPDIFF(YEAR, p.dob, e.encounter_datetime) between 15 and 25 and p.gender='F' and LOWER(e.visit_type)='emergency' and e.encounter_datetime=':paramStartDate:';");
4141

4242

4343
Map<String, Object> params = new HashMap<String, Object>() {{

src/test/java/org/sharedhealth/datasense/handler/DeathNoteHandlerIT.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ public void shouldSaveDateOfDeathFromDateOfDeathObservationResource() {
9090
assertEquals(DateUtil.parseDate("2014-12-28T00:00:00+05:30"), patientDeathDetails.getDateOfDeath());
9191
}
9292

93-
@Test
94-
public void shouldSavePatientAgeFromDateOfDeathObservationResource() {
95-
deathNoteHandler.process(deathNoteResource, composition);
96-
PatientDeathDetails patientDeathDetails = findByEncounterId("shrEncounterId");
97-
assertEquals(1, patientDeathDetails.getPatientAgeInYears());
98-
assertEquals(12, patientDeathDetails.getPatientAgeInMonths());
99-
assertEquals(365, patientDeathDetails.getPatientAgeInDays());
100-
}
101-
10293
@Test
10394
public void shouldSaveCircumstancesOfDeathObservationResource() {
10495
deathNoteHandler.process(deathNoteResource, composition);
@@ -115,7 +106,7 @@ public void shouldSaveCauseOfDeath() {
115106
}
116107

117108
private PatientDeathDetails findByEncounterId(String shrEncounterId) {
118-
String sql = "select patient_hid, encounter_id, date_of_death, patient_age_years, patient_age_months, patient_age_days, " +
109+
String sql = "select patient_hid, encounter_id, date_of_death, " +
119110
"circumstances_of_death, cause_concept_uuid, cause_code, uuid " +
120111
"from patient_death_details where encounter_id= :encounter_id";
121112
HashMap<String, Object> map = new HashMap<>();
@@ -133,9 +124,6 @@ public PatientDeathDetails mapRow(ResultSet rs, int rowNum) throws SQLException
133124
patientDeathDetails.setEncounter(encounter);
134125

135126
patientDeathDetails.setDateOfDeath(rs.getTimestamp("date_of_death"));
136-
patientDeathDetails.setPatientAgeInYears(rs.getInt("patient_age_years"));
137-
patientDeathDetails.setPatientAgeInMonths(rs.getInt("patient_age_months"));
138-
patientDeathDetails.setPatientAgeInDays(rs.getInt("patient_age_days"));
139127
patientDeathDetails.setCircumstancesOfDeath(rs.getString("circumstances_of_death"));
140128
patientDeathDetails.setCauseOfDeathConceptUuid(rs.getString("cause_concept_uuid"));
141129
patientDeathDetails.setCauseOfDeathCode(rs.getString("cause_code"));

src/test/java/org/sharedhealth/datasense/processor/ClinicalEncounterProcessorIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void shouldSaveEncounter() throws Exception {
8585
private Encounter findEncounterById(String encounterId) {
8686
List<Encounter> encounters = jdbcTemplate.query(
8787
"select encounter_id ,encounter_datetime, encounter_type, visit_type, patient_hid, " +
88-
"patient_age_years, patient_age_months, patient_age_days,encounter_location_id, facility_id " +
88+
"encounter_location_id, facility_id " +
8989
"from encounter where encounter_id= :encounter_id", Collections.singletonMap("encounter_id",
9090
encounterId),
9191
new RowMapper<Encounter>() {
@@ -96,9 +96,6 @@ public Encounter mapRow(ResultSet rs, int rowNum) throws SQLException {
9696
encounter.setEncounterDateTime(new Date(rs.getTimestamp("encounter_datetime").getTime()));
9797
encounter.setEncounterType(rs.getString("encounter_type"));
9898
encounter.setEncounterVisitType(rs.getString("visit_type"));
99-
encounter.setPatientAgeInYears(rs.getInt("patient_age_years"));
100-
encounter.setPatientAgeInMonths(rs.getInt("patient_age_months"));
101-
encounter.setPatientAgeInDays(rs.getInt("patient_age_days"));
10299
encounter.setLocationCode(rs.getString("encounter_location_id"));
103100

104101
Patient patient = new Patient();

0 commit comments

Comments
 (0)