| 42 | | public void testAddNameToConcept() throws Exception { |
|---|
| 43 | | runSyncTest(new SyncTestHelper() { |
|---|
| 44 | | ConceptService cs = Context.getConceptService(); |
|---|
| 45 | | int numNamesBefore; |
|---|
| 46 | | public void runOnChild() { |
|---|
| 47 | | Concept wt = cs.getConceptByName("WEIGHT"); |
|---|
| 48 | | numNamesBefore = wt.getNames().size(); |
|---|
| 49 | | wt.addName(new ConceptName("POIDS", null, "Weight in french", Locale.FRENCH)); |
|---|
| 50 | | cs.saveConcept(wt); |
|---|
| 51 | | } |
|---|
| 52 | | public void runOnParent() { |
|---|
| 53 | | Concept wt = cs.getConceptByName("WEIGHT"); |
|---|
| 54 | | assertNotNull(wt); |
|---|
| 55 | | assertEquals("Should be one more name than before", numNamesBefore + 1, wt.getNames().size()); |
|---|
| 56 | | assertEquals("Incorrect french name", wt.getName(Locale.FRENCH).getName(), "POIDS"); |
|---|
| 57 | | } |
|---|
| 58 | | }); |
|---|
| 59 | | } |
|---|
| 60 | | |
|---|
| 61 | | |
|---|
| 62 | | public void testCreateCodedConcept() throws Exception { |
|---|
| 63 | | runSyncTest(new SyncTestHelper() { |
|---|
| 64 | | private int conceptId = 0; |
|---|
| | 42 | public void testSaveConceptCoded() throws Exception { |
|---|
| | 43 | runSyncTest(new SyncTestHelper() { |
|---|
| | 44 | private int conceptId = 99999; |
|---|
| 123 | | |
|---|
| 124 | | Concept coded = new Concept(conceptIdCoded); |
|---|
| | 93 | } |
|---|
| | 94 | public void runOnParent() { |
|---|
| | 95 | //Concept c = cs.getConceptByName("SOMETHING NUMERIC"); |
|---|
| | 96 | // assertNotNull("Failed to create numeric", c); |
|---|
| | 97 | assertEquals(cs.getConcept(conceptId).getName().getName(), "SOMETHING NUMERIC"); |
|---|
| | 98 | ConceptNumeric cn = cs.getConceptNumeric(conceptId); |
|---|
| | 99 | assertEquals("Concept numeric absolute low values do not match", 0d, cn.getLowAbsolute()); |
|---|
| | 100 | assertEquals("Concept nuermic high critical values do not match", 100d, cn.getHiCritical()); |
|---|
| | 101 | assertEquals("Concept numeric datatypes does not match", "Numeric", cn.getDatatype().getName()); |
|---|
| | 102 | assertEquals("Concept numeric classes does not match", "Question", cn.getConceptClass().getName()); |
|---|
| | 103 | |
|---|
| | 104 | } |
|---|
| | 105 | }); |
|---|
| | 106 | } |
|---|
| | 107 | |
|---|
| | 108 | |
|---|
| | 109 | |
|---|
| | 110 | |
|---|
| | 111 | |
|---|
| | 112 | |
|---|
| | 113 | public void testSaveConceptSet() throws Exception { |
|---|
| | 114 | runSyncTest(new SyncTestHelper() { |
|---|
| | 115 | ConceptService cs; |
|---|
| | 116 | private int conceptNumericId=99997; |
|---|
| | 117 | private int conceptCodedId=99998; |
|---|
| | 118 | private int conceptSetId=99999; |
|---|
| | 119 | |
|---|
| | 120 | private String guid = ""; |
|---|
| | 121 | |
|---|
| | 122 | public void runOnChild() { |
|---|
| | 123 | cs = Context.getConceptService(); |
|---|
| | 124 | |
|---|
| | 125 | ConceptNumeric cn = new ConceptNumeric(conceptNumericId); |
|---|
| | 126 | cn.addName(new ConceptName("SOMETHING NUMERIC", "SUM NUM", "A numeric concept", Context.getLocale())); |
|---|
| | 127 | cn.setDatatype(cs.getConceptDatatypeByName("Numeric")); |
|---|
| | 128 | cn.setConceptClass(cs.getConceptClassByName("Question")); |
|---|
| | 129 | cn.setSet(false); |
|---|
| | 130 | cn.setPrecise(true); |
|---|
| | 131 | cn.setLowAbsolute(0d); |
|---|
| | 132 | cn.setHiCritical(100d); |
|---|
| | 133 | cs.saveConcept(cn); |
|---|
| | 134 | |
|---|
| | 135 | Concept coded = new Concept(conceptCodedId); |
|---|
| 130 | | coded.addAnswer(new ConceptAnswer(cs.getConceptByName("OTHER NON-CODED"))); |
|---|
| 131 | | coded.addAnswer(new ConceptAnswer(cs.getConceptByName("NONE"))); |
|---|
| | 141 | |
|---|
| | 142 | Concept other = cs.getConceptByName("OTHER NON-CODED"); |
|---|
| | 143 | assertNotNull("Failed to get concept OTHER NON-CODED", other); |
|---|
| | 144 | |
|---|
| | 145 | Concept none = cs.getConceptByName("NONE"); |
|---|
| | 146 | assertNotNull("Failed to get concept NONE", none); |
|---|
| | 147 | |
|---|
| | 148 | coded.addAnswer(new ConceptAnswer(other)); |
|---|
| | 149 | coded.addAnswer(new ConceptAnswer(none)); |
|---|
| 146 | | } |
|---|
| 147 | | public void runOnParent() { |
|---|
| 148 | | //Concept c = cs.getConceptByName("SOMETHING NUMERIC"); |
|---|
| 149 | | // assertNotNull("Failed to create numeric", c); |
|---|
| 150 | | assertEquals(cs.getConcept(99997).getName().getName(), "SOMETHING NUMERIC"); |
|---|
| 151 | | ConceptNumeric cn = cs.getConceptNumeric(99997); |
|---|
| 152 | | assertEquals(cn.getLowAbsolute(), 0d); |
|---|
| 153 | | assertEquals(cn.getHiCritical(), 100d); |
|---|
| 154 | | assertEquals(cn.getDatatype().getName(), "Numeric"); |
|---|
| 155 | | assertEquals(cn.getConceptClass().getName(), "Question"); |
|---|
| 156 | | |
|---|
| 157 | | Concept c = cs.getConceptByName("SOMETHING CODED"); |
|---|
| 158 | | assertNotNull("Failed to create coded", c); |
|---|
| | 171 | |
|---|
| | 172 | guid = set.getGuid(); |
|---|
| | 173 | log.info("GUID: " + set.getGuid()); |
|---|
| | 174 | } |
|---|
| | 175 | public void runOnParent() { |
|---|
| | 176 | Concept c = cs.getConceptByName("SOMETHING NUMERIC"); |
|---|
| | 177 | assertNotNull("Failed to create numeric", c); |
|---|
| | 178 | |
|---|
| | 179 | Concept set = cs.getConcept(conceptSetId); |
|---|
| | 180 | |
|---|
| | 181 | set = cs.getConceptByName("A CONCEPT SET"); |
|---|
| | 182 | |
|---|
| | 183 | |
|---|
| | 184 | assertEquals("Concept names do not match", "SOMETHING NUMERIC", cs.getConcept(conceptNumericId).getName().getName()); |
|---|
| | 185 | |
|---|
| | 186 | |
|---|
| | 187 | ConceptNumeric cn = cs.getConceptNumeric(conceptNumericId); |
|---|
| | 188 | assertEquals("Concept numeric absolute low values do not match", 0d, cn.getLowAbsolute()); |
|---|
| | 189 | assertEquals("Concept numeric critical high values do not match", 100d, cn.getHiCritical()); |
|---|
| | 190 | assertEquals("Concept numeric datatypes do not match", "Numeric", cn.getDatatype().getName()); |
|---|
| | 191 | assertEquals("Concept numeric classes do not match", "Question", cn.getConceptClass().getName()); |
|---|
| 164 | | |
|---|
| 165 | | c = cs.getConceptByName("A CONCEPT SET"); |
|---|
| 166 | | assertNotNull("Failed to create set", c); |
|---|
| 167 | | assertEquals(c.getConceptSets().size(), 2); |
|---|
| 168 | | } |
|---|
| 169 | | }); |
|---|
| 170 | | } |
|---|
| | 197 | |
|---|
| | 198 | // Test the coded concept |
|---|
| | 199 | Concept conceptCoded = cs.getConcept(conceptCodedId); |
|---|
| | 200 | assertNotNull("Failed to save coded concept - Could not retrieve concept by ID", conceptCoded); |
|---|
| | 201 | |
|---|
| | 202 | conceptCoded = cs.getConceptByName("SOMETHING CODED"); |
|---|
| | 203 | assertNotNull("Failed to save coded concept - Could not retrieve concept by name", conceptCoded); |
|---|
| | 204 | |
|---|
| | 205 | |
|---|
| | 206 | // Test the concept set |
|---|
| | 207 | |
|---|
| | 208 | Concept conceptSet = cs.getConcept(conceptSetId); |
|---|
| | 209 | assertNotNull("Failed to save concept set - Could not retrieve concept by ID", conceptSet); |
|---|
| | 210 | |
|---|
| | 211 | conceptSet = cs.getConceptByName("A CONCEPT SET"); |
|---|
| | 212 | assertNotNull("Failed to create coded concept - Could not retrieve code concept by name", conceptSet); |
|---|
| | 213 | |
|---|
| | 214 | |
|---|
| | 215 | assertEquals("Failed to create concept set - Concept set should have two elements", conceptSet.getConceptSets().size(), 2); |
|---|
| | 216 | |
|---|
| | 217 | |
|---|
| | 218 | } |
|---|
| | 219 | }); |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 266 | |
|---|
| | 267 | public void testAddNameToConcept() throws Exception { |
|---|
| | 268 | runSyncTest(new SyncTestHelper() { |
|---|
| | 269 | ConceptService cs = Context.getConceptService(); |
|---|
| | 270 | int numNamesBefore; |
|---|
| | 271 | public void runOnChild() { |
|---|
| | 272 | Concept wt = cs.getConceptByName("WEIGHT"); |
|---|
| | 273 | numNamesBefore = wt.getNames().size(); |
|---|
| | 274 | wt.addName(new ConceptName("POIDS", null, "Weight in french", Locale.FRENCH)); |
|---|
| | 275 | cs.saveConcept(wt); |
|---|
| | 276 | } |
|---|
| | 277 | public void runOnParent() { |
|---|
| | 278 | Concept wt = cs.getConceptByName("WEIGHT"); |
|---|
| | 279 | assertNotNull(wt); |
|---|
| | 280 | assertEquals("Should be one more name than before", numNamesBefore + 1, wt.getNames().size()); |
|---|
| | 281 | assertEquals("Incorrect french name", wt.getName(Locale.FRENCH).getName(), "POIDS"); |
|---|
| | 282 | } |
|---|
| | 283 | }); |
|---|
| | 284 | } |
|---|
| | 285 | |
|---|
| | 286 | |
|---|
| | 287 | |
|---|