Ticket #908: ConceptAnswer.txt
| File ConceptAnswer.txt, 12.6 kB (added by dthomas, 2 years ago) |
|---|
Patch for adding sort weight to ConceptAnswer |
| Line | |
|---|---|
| 1 | Index: C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-data.sql |
| 2 | =================================================================== |
| 3 | --- C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-data.sql (revision 4910) |
| 4 | +++ C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-data.sql (working copy) |
| 5 | @@ -156,6 +156,7 @@ |
| 6 | `concept_id` int(11) NOT NULL default '0', |
| 7 | `answer_concept` int(11) default NULL, |
| 8 | `answer_drug` int(11) default NULL, |
| 9 | + `sort_weight` double default NULL, |
| 10 | `creator` int(11) NOT NULL default '0', |
| 11 | `date_created` datetime NOT NULL default '0000-00-00 00:00:00', |
| 12 | PRIMARY KEY (`concept_answer_id`), |
| 13 | Index: C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-and-demo-data.sql |
| 14 | =================================================================== |
| 15 | --- C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-and-demo-data.sql (revision 4910) |
| 16 | +++ C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-with-core-and-demo-data.sql (working copy) |
| 17 | @@ -151,6 +151,7 @@ |
| 18 | `concept_id` int(11) NOT NULL default '0', |
| 19 | `answer_concept` int(11) default NULL, |
| 20 | `answer_drug` int(11) default NULL, |
| 21 | + `sort_weight` double default NULL, |
| 22 | `creator` int(11) NOT NULL default '0', |
| 23 | `date_created` datetime NOT NULL default '0000-00-00 00:00:00', |
| 24 | PRIMARY KEY (`concept_answer_id`), |
| 25 | Index: C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-only.sql |
| 26 | =================================================================== |
| 27 | --- C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-only.sql (revision 4910) |
| 28 | +++ C:/workspace/openmrs_trunk/metadata/model/1.3.0-schema-only.sql (working copy) |
| 29 | @@ -127,6 +127,7 @@ |
| 30 | `concept_id` int(11) NOT NULL default '0', |
| 31 | `answer_concept` int(11) default NULL, |
| 32 | `answer_drug` int(11) default NULL, |
| 33 | + `sort_weight` double default NULL, |
| 34 | `creator` int(11) NOT NULL default '0', |
| 35 | `date_created` datetime NOT NULL default '0000-00-00 00:00:00', |
| 36 | PRIMARY KEY (`concept_answer_id`), |
| 37 | Index: C:/workspace/openmrs_trunk/metadata/model/update-to-latest-db.mysqldiff.sql |
| 38 | =================================================================== |
| 39 | --- C:/workspace/openmrs_trunk/metadata/model/update-to-latest-db.mysqldiff.sql (revision 4910) |
| 40 | +++ C:/workspace/openmrs_trunk/metadata/model/update-to-latest-db.mysqldiff.sql (working copy) |
| 41 | @@ -1041,6 +1041,68 @@ |
| 42 | delimiter ; |
| 43 | call diff_procedure('1.3.0.13'); |
| 44 | |
| 45 | + |
| 46 | +#---------------------------------------- |
| 47 | +# OpenMRS Datamodel version 1.3.0.14 |
| 48 | +# Dave Thomas July 11, 2008 |
| 49 | +# Adding sort_weight column to conceptName |
| 50 | +#---------------------------------------- |
| 51 | + |
| 52 | +DROP PROCEDURE IF EXISTS diff_procedure; |
| 53 | + |
| 54 | +delimiter // |
| 55 | + |
| 56 | +CREATE PROCEDURE diff_procedure (IN new_db_version VARCHAR(10)) |
| 57 | + BEGIN |
| 58 | + IF (SELECT REPLACE(property_value, '.', '0') < REPLACE(new_db_version, '.', '0') FROM global_property WHERE property = 'database_version') THEN |
| 59 | + SELECT CONCAT('Updating to ', new_db_version) AS 'Datamodel Update:' FROM dual; |
| 60 | + |
| 61 | + ALTER TABLE `concept_answer` ADD COLUMN `sort_weight` double default NULL; |
| 62 | + |
| 63 | + UPDATE `global_property` SET property_value=new_db_version WHERE property = 'database_version'; |
| 64 | + |
| 65 | + DROP TABLE IF EXISTS concept_answer_tmp; |
| 66 | + CREATE TABLE `concept_answer_tmp` ( |
| 67 | + `concept_answer_id` int(11) NOT NULL, |
| 68 | + `concept_id` int(11) NOT NULL default '0', |
| 69 | + `answer_concept` int(11) default NULL, |
| 70 | + `answer_drug` int(11) default NULL, |
| 71 | + `sort_weight` double default NULL, |
| 72 | + `creator` int(11) NOT NULL default '0', |
| 73 | + `date_created` datetime NOT NULL); |
| 74 | + |
| 75 | + INSERT INTO concept_answer_tmp |
| 76 | + SELECT * FROM concept_answer; |
| 77 | + |
| 78 | + DROP TABLE IF EXISTS concept_answer_tmp_counts; |
| 79 | + CREATE TABLE `concept_answer_tmp_counts` ( |
| 80 | + `concept_answer_id` int(11) NOT NULL, |
| 81 | + `concept_id` int(11) NOT NULL default '0', |
| 82 | + `sort_weight_tmp` double default NULL); |
| 83 | + |
| 84 | + INSERT INTO concept_answer_tmp_counts |
| 85 | + SELECT ca.concept_answer_id, ca.concept_id, count(ca1.answer_concept) |
| 86 | + FROM concept_answer ca, concept_answer_tmp ca1 |
| 87 | + WHERE ca.concept_id = ca1.concept_id |
| 88 | + AND ca1.concept_answer_id <= ca.concept_answer_id |
| 89 | + GROUP BY ca.concept_answer_id |
| 90 | + ORDER BY concept_id, count(ca1.answer_concept); |
| 91 | + |
| 92 | + UPDATE concept_answer ca |
| 93 | + LEFT JOIN concept_answer_tmp_counts ctmp on ca.concept_answer_id = ctmp.concept_answer_id |
| 94 | + SET ca.sort_weight = ctmp.sort_weight_tmp |
| 95 | + WHERE ctmp.concept_answer_id = ca.concept_answer_id; |
| 96 | + |
| 97 | + DROP TABLE concept_answer_tmp_counts; |
| 98 | + DROP TABLE concept_answer_tmp; |
| 99 | + |
| 100 | + END IF; |
| 101 | + END; |
| 102 | +// |
| 103 | + |
| 104 | +delimiter ; |
| 105 | +call diff_procedure('1.3.0.14'); |
| 106 | + |
| 107 | #----------------------------------- |
| 108 | # Clean up - Keep this section at the very bottom of diff script |
| 109 | #----------------------------------- |
| 110 | Index: C:/workspace/openmrs_trunk/metadata/model/1.3.0-createdb-from-scratch-with-demo-data.sql |
| 111 | =================================================================== |
| 112 | --- C:/workspace/openmrs_trunk/metadata/model/1.3.0-createdb-from-scratch-with-demo-data.sql (revision 4910) |
| 113 | +++ C:/workspace/openmrs_trunk/metadata/model/1.3.0-createdb-from-scratch-with-demo-data.sql (working copy) |
| 114 | @@ -164,6 +164,7 @@ |
| 115 | `concept_id` int(11) NOT NULL default '0', |
| 116 | `answer_concept` int(11) default NULL, |
| 117 | `answer_drug` int(11) default NULL, |
| 118 | + `sort_weight` double default NULL, |
| 119 | `creator` int(11) NOT NULL default '0', |
| 120 | `date_created` datetime NOT NULL default '0000-00-00 00:00:00', |
| 121 | PRIMARY KEY (`concept_answer_id`), |
| 122 | Index: C:/workspace/openmrs_trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/Concept.hbm.xml |
| 123 | =================================================================== |
| 124 | --- C:/workspace/openmrs_trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/Concept.hbm.xml (revision 4910) |
| 125 | +++ C:/workspace/openmrs_trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/Concept.hbm.xml (working copy) |
| 126 | @@ -41,13 +41,14 @@ |
| 127 | </set> |
| 128 | |
| 129 | <set name="answers" lazy="true" cascade="all,evict" |
| 130 | - table="concept_answer" order-by="concept_answer_id asc" access="field"> |
| 131 | + table="concept_answer" order-by="sort_weight asc" access="field"> |
| 132 | <key column="concept_id" not-null="true" /> |
| 133 | <composite-element class="ConceptAnswer"> |
| 134 | <parent name="concept"/> |
| 135 | <property generated="insert" insert="false" name="conceptAnswerId" type="java.lang.Integer" column="concept_answer_id" /> |
| 136 | <many-to-one name="answerConcept" class="org.openmrs.Concept" column="answer_concept" not-null="true"/> |
| 137 | <many-to-one name="answerDrug" class="org.openmrs.Drug" column="answer_drug" /> |
| 138 | + <property name="sortWeight" type="java.lang.Double" column="sort_weight" length="22" /> |
| 139 | <property name="dateCreated" type="java.util.Date" column="date_created" not-null="true" /> |
| 140 | <many-to-one name="creator" class="User" column="creator" not-null="true"/> |
| 141 | </composite-element> |
| 142 | Index: C:/workspace/openmrs_trunk/src/api/org/openmrs/Concept.java |
| 143 | =================================================================== |
| 144 | --- C:/workspace/openmrs_trunk/src/api/org/openmrs/Concept.java (revision 4910) |
| 145 | +++ C:/workspace/openmrs_trunk/src/api/org/openmrs/Concept.java (working copy) |
| 146 | @@ -135,6 +135,7 @@ |
| 147 | |
| 148 | /** |
| 149 | * @param answers The answers to set. |
| 150 | + * This method assumes that the sort_weight has already been set. |
| 151 | */ |
| 152 | public void setAnswers(Collection<ConceptAnswer> answers) { |
| 153 | this.answers = answers; |
| 154 | @@ -148,6 +149,20 @@ |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | + * |
| 159 | + * @param answers The answers to set. |
| 160 | + * @param buildSortWeight true = rebuild sort_weight, false = do nothing. |
| 161 | + */ |
| 162 | + public void setAnswers(Collection<ConceptAnswer> answers, boolean buildSortWeight){ |
| 163 | + this.answers = answers; |
| 164 | + if (buildSortWeight){ |
| 165 | + double i = 1; |
| 166 | + for (ConceptAnswer ca : answers) |
| 167 | + ca.setSortWeight(i++); |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | * Add the given ConceptAnswer to the list of answers for this Concept |
| 173 | * @param conceptAnswer |
| 174 | */ |
| 175 | @@ -159,6 +174,9 @@ |
| 176 | { |
| 177 | conceptAnswer.setConcept(this); |
| 178 | answers.add(conceptAnswer); |
| 179 | + double i = 1; |
| 180 | + for (ConceptAnswer ca : answers) |
| 181 | + ca.setSortWeight(i++); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | @@ -169,6 +187,9 @@ |
| 186 | public void removeAnswer(ConceptAnswer conceptAnswer) { |
| 187 | if (answers != null) |
| 188 | answers.remove(conceptAnswer); |
| 189 | + double i = 1; |
| 190 | + for (ConceptAnswer ca : answers) |
| 191 | + ca.setSortWeight(i++); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | Index: C:/workspace/openmrs_trunk/src/api/org/openmrs/ConceptAnswer.java |
| 196 | =================================================================== |
| 197 | --- C:/workspace/openmrs_trunk/src/api/org/openmrs/ConceptAnswer.java (revision 4910) |
| 198 | +++ C:/workspace/openmrs_trunk/src/api/org/openmrs/ConceptAnswer.java (working copy) |
| 199 | @@ -31,6 +31,7 @@ |
| 200 | private Concept concept; // concept to answer |
| 201 | private Concept answerConcept; // answer for <code>concept</code> |
| 202 | private Drug answerDrug; // answer in drug form for <code>concept</code> |
| 203 | + private Double sortWeight; |
| 204 | private User creator; |
| 205 | private Date dateCreated; |
| 206 | |
| 207 | @@ -173,4 +174,12 @@ |
| 208 | public void setDateCreated(Date dateCreated) { |
| 209 | this.dateCreated = dateCreated; |
| 210 | } |
| 211 | + |
| 212 | + public Double getSortWeight() { |
| 213 | + return sortWeight; |
| 214 | + } |
| 215 | + |
| 216 | + public void setSortWeight(Double sortWeight) { |
| 217 | + this.sortWeight = sortWeight; |
| 218 | + } |
| 219 | } |
| 220 | \ No newline at end of file |
| 221 | Index: C:/workspace/openmrs_trunk/src/api/org/openmrs/propertyeditor/ConceptAnswersEditor.java |
| 222 | =================================================================== |
| 223 | --- C:/workspace/openmrs_trunk/src/api/org/openmrs/propertyeditor/ConceptAnswersEditor.java (revision 4910) |
| 224 | +++ C:/workspace/openmrs_trunk/src/api/org/openmrs/propertyeditor/ConceptAnswersEditor.java (working copy) |
| 225 | @@ -118,6 +118,14 @@ |
| 226 | for (String i : requestConceptIds) |
| 227 | log.debug("id: " + i); |
| 228 | |
| 229 | + double i = 1; |
| 230 | + for (String conceptId : requestConceptIds) { |
| 231 | + Integer id = getConceptId(conceptId); |
| 232 | + for (ConceptAnswer ca : originalConceptAnswers){ |
| 233 | + if (id.intValue() == ca.getAnswerConcept().getConceptId()) |
| 234 | + ca.setSortWeight(i++); |
| 235 | + } |
| 236 | + } |
| 237 | setValue(originalConceptAnswers); |
| 238 | } |
| 239 | else { |
| 240 | Index: C:/workspace/openmrs_trunk/src/web/org/openmrs/web/controller/ConceptFormController.java |
| 241 | =================================================================== |
| 242 | --- C:/workspace/openmrs_trunk/src/web/org/openmrs/web/controller/ConceptFormController.java (revision 4910) |
| 243 | +++ C:/workspace/openmrs_trunk/src/web/org/openmrs/web/controller/ConceptFormController.java (working copy) |
| 244 | @@ -20,6 +20,7 @@ |
| 245 | import java.util.Collection; |
| 246 | import java.util.HashMap; |
| 247 | import java.util.HashSet; |
| 248 | +import java.util.LinkedHashMap; |
| 249 | import java.util.Locale; |
| 250 | import java.util.Map; |
| 251 | import java.util.Set; |
| 252 | @@ -238,7 +239,6 @@ |
| 253 | if (numberOfNamesSpecified == 0) { |
| 254 | errors.reject("error.names.length"); |
| 255 | } |
| 256 | - |
| 257 | } |
| 258 | } |
| 259 | else { |
| 260 | @@ -367,7 +367,7 @@ |
| 261 | Map<Locale, Collection<ConceptSynonym>> conceptSynonymsByLocale = new HashMap<Locale, Collection<ConceptSynonym>>(); |
| 262 | //Map<String, ConceptName> conceptSets = new TreeMap<String, ConceptName>(); |
| 263 | Map<Double, Object[]> conceptSets = new TreeMap<Double, Object[]>(); |
| 264 | - Map<String, String> conceptAnswers = new TreeMap<String, String>(); |
| 265 | + Map<String, String> conceptAnswers = new LinkedHashMap<String, String>(); |
| 266 | Collection<Form> forms = new HashSet<Form>(); |
| 267 | Map<Integer, String> questionsAnswered = new TreeMap<Integer, String>(); |
| 268 | Map<Integer, String> containedInSets = new TreeMap<Integer, String>(); |
| 269 | Index: C:/workspace/openmrs_trunk/web/WEB-INF/view/dictionary/conceptForm.jsp |
| 270 | =================================================================== |
| 271 | --- C:/workspace/openmrs_trunk/web/WEB-INF/view/dictionary/conceptForm.jsp (revision 4910) |
| 272 | +++ C:/workspace/openmrs_trunk/web/WEB-INF/view/dictionary/conceptForm.jsp (working copy) |
| 273 | @@ -310,6 +310,8 @@ |
| 274 | <td valign="top" class="buttons"> |
| 275 | <span dojoType="ConceptSearch" widgetId="aSearch" includeDrugConcepts="true"></span><span dojoType="OpenmrsPopup" searchWidget="aSearch" searchTitle='<spring:message code="Concept.find"/>' changeButtonValue='<spring:message code="general.add"/>' showConceptIds="true" showIfHiding="true"></span> |
| 276 | <input type="button" value="<spring:message code="general.remove"/>" class="smallButton" onClick="removeItem('answerNames', 'answerIds', ' ');"/><br/> |
| 277 | + <input type="button" value="<spring:message code="general.move_up"/>" class="smallButton" onClick="moveUp('answerNames', 'answerIds');" style="display: block" /> |
| 278 | + <input type="button" value="<spring:message code="general.move_down"/>" class="smallButton" onClick="moveDown('answerNames', 'answerIds');" style="display: block" /> |
| 279 | </td> |
| 280 | </tr> |
| 281 | </table> |
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/