| 156 | | String query = "INSERT INTO patient_program " + |
|---|
| 157 | | "(patient_id, program_id, date_enrolled, creator, date_created, changed_by, date_changed) " + |
|---|
| 158 | | "SELECT DISTINCT encounter.patient_id, " + program.getProgramId() + ", encounter.date_created, " + program.getProgramId() + |
|---|
| 159 | | ", '" + df.format(day) + "', " + user.getUserId() + ", '" + df.format(day) + "' FROM encounter WHERE encounter.encounter_type in " + |
|---|
| 160 | | "(select form2program_map.encounter_type from form2program_map where form2program_map.program = " + program.getProgramId() + |
|---|
| 161 | | ") AND encounter.patient_id not in (select patient_id from patient_program where patient_program.program_id = " + program.getProgramId() + |
|---|
| 162 | | " and patient_program.date_completed is null ) GROUP BY encounter.patient_id ORDER BY encounter.date_created ASC"; |
|---|
| | 160 | String query = "INSERT INTO patient_program " + |
|---|
| | 161 | "(patient_id, program_id, date_enrolled, creator, date_created, changed_by, date_changed) " + |
|---|
| | 162 | "SELECT DISTINCT encounter.patient_id, " + program.getProgramId() + ", encounter.encounter_datetime, " + user.getUserId() + |
|---|
| | 163 | ", '" + df.format(day) + "', " + user.getUserId() + ", '" + df.format(day) + "' FROM encounter WHERE encounter.encounter_type in " + |
|---|
| | 164 | "(select form2program_map.encounter_type from form2program_map where form2program_map.program = " + program.getProgramId() + |
|---|
| | 165 | ") AND encounter.patient_id not in (select patient_id from patient_program where patient_program.program_id = " + program.getProgramId() + |
|---|
| | 166 | " and patient_program.date_completed is null ) " + |
|---|
| | 167 | "AND encounter.encounter_datetime = (select min(e.encounter_datetime) from encounter e where e.patient_id = encounter.patient_id and e.encounter_type in " + |
|---|
| | 168 | "( select form2program_map.encounter_type from form2program_map where form2program_map.program = " + program.getProgramId() + " ) ) " + |
|---|
| | 169 | "GROUP BY encounter.patient_id ORDER BY encounter.encounter_datetime ASC"; |
|---|
| 183 | | String query = "INSERT INTO patient_program " + |
|---|
| 184 | | "(patient_id, program_id, date_enrolled, creator, date_created, changed_by, date_changed) " + |
|---|
| 185 | | "SELECT DISTINCT encounter.patient_id, " + program.getProgramId() + ", encounter.date_created, " + program.getProgramId() + |
|---|
| 186 | | ", '" + df.format(day) + "', " + user.getUserId() + ", '" + df.format(day) + "' FROM encounter WHERE encounter.encounter_type = " + encounterType.getEncounterTypeId() + |
|---|
| 187 | | " AND encounter.patient_id not in (select patient_id from patient_program where patient_program.program_id = " + program.getProgramId() + |
|---|
| 188 | | " and patient_program.date_completed is null ) GROUP BY encounter.patient_id ORDER BY encounter.date_created ASC"; |
|---|
| 189 | | |
|---|
| | 194 | String query = "INSERT INTO patient_program " + |
|---|
| | 195 | "(patient_id, program_id, date_enrolled, creator, date_created, changed_by, date_changed) " + |
|---|
| | 196 | "SELECT DISTINCT encounter.patient_id, " + program.getProgramId() + ", encounter.encounter_datetime, " + user.getUserId() + |
|---|
| | 197 | ", '" + df.format(day) + "', " + user.getUserId() + ", '" + df.format(day) + "' FROM encounter WHERE encounter.encounter_type = " + encounterType.getEncounterTypeId() + |
|---|
| | 198 | " AND encounter.patient_id not in (select patient_id from patient_program where patient_program.program_id = " + program.getProgramId() + |
|---|
| | 199 | " and patient_program.date_completed is null ) " + |
|---|
| | 200 | "AND encounter.encounter_datetime = (select min(e.encounter_datetime) from encounter e where e.patient_id = encounter.patient_id and e.encounter_type = " + |
|---|
| | 201 | encounterType.getEncounterTypeId() + " ) GROUP BY encounter.patient_id ORDER BY encounter.encounter_datetime ASC"; |
|---|
| | 202 | |
|---|