Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 3410

Show
Ignore:
Timestamp:
02/18/08 17:31:24 (11 months ago)
Author:
bmckown
Message:

form2program module: Changed enrollment date of patient program to be the encounter datetime instead of today's date. Also fixed an error where patient program creator was wrongly set as the program id.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/form2program/src/org/openmrs/module/form2program/advice/EncounterCreatedAfterAdvice.java

    r2352 r3410  
    5151                                if (f2pService.existsForm2ProgramMap(fpm.getProgram(), encounterType)) 
    5252                                        if (!this.getProgramWorkflowService().isInProgram(patient, fpm.getProgram(), today, null)) { 
    53                                                 this.getProgramWorkflowService().enrollPatientInProgram(patient, fpm.getProgram(), today, null); 
     53                                                this.getProgramWorkflowService().enrollPatientInProgram(patient, fpm.getProgram(), encounter.getEncounterDatetime(), null); 
    5454                                } 
    5555                        } 
  • openmrs-modules/form2program/src/org/openmrs/module/form2program/db/hibernate/HibernateForm2ProgramDAO.java

    r2888 r3410  
    151151         * This applies to all org.openmrs.EncounterType that are mapped to the @param program. 
    152152         * (non-Javadoc) 
     153         *  
     154         * Enrollment date is the encounter datetime of a patient's first encounter with an encounter type mapped to  
     155         * the @param program. 
     156         *  
    153157         * @see org.openmrs.module.form2program.db.Form2ProgramDAO#applyForm2ProgramMap(org.openmrs.Program, org.openmrs.User, java.util.Date) 
    154158         */ 
    155159        public int applyForm2ProgramMap(Program program, User user, java.util.Date day) { 
    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"; 
    163170 
    164171                int rows = 0; 
     
    177184         * Apply Form2ProgramMap to patients that are already in the database who have not yet been enrolled in the program. 
    178185         * This applies only to the @param org.openmrs.EncounterType that is mapped to the @param Program. 
     186         *  
     187     * Enrollment date is the encounter datetime of a patient's first encounter with an encounter type  
     188     * equal to @param encounterType. 
     189         *  
    179190         * (non-Javadoc) 
    180191         * @see org.openmrs.module.form2program.db.Form2ProgramDAO#applyForm2ProgramMap(org.openmrs.Program, org.openmrs.EncounterType, org.openmrs.User, java.util.Date) 
    181192         */ 
    182193        public int applyForm2ProgramMap(Program program, EncounterType encounterType, User user, java.util.Date day) { 
    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         
    190203        int rows = 0; 
    191204        try {