Changeset 5215 for openmrs/branches/data_synchronization_bidirectional/test/api/org/openmrs/test/synchronization/engine/SyncPatientTest.java
- Timestamp:
- 08/09/08 16:18:42 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/data_synchronization_bidirectional/test/api/org/openmrs/test/synchronization/engine/SyncPatientTest.java
r5163 r5215 14 14 package org.openmrs.test.synchronization.engine; 15 15 16 import static org.junit.Assert.assertEquals; 17 import static org.junit.Assert.assertNotSame; 18 import static org.junit.Assert.assertTrue; 19 import static org.junit.Assert.assertFalse; 20 import static org.junit.Assert.assertNull; 21 import static org.junit.Assert.assertNotNull; 22 16 23 import java.text.SimpleDateFormat; 17 24 import java.util.ArrayList; … … 22 29 import java.util.Set; 23 30 24 import org. hibernate.Session;31 import org.junit.Test; 25 32 import org.openmrs.Concept; 26 33 import org.openmrs.Encounter; … … 30 37 import org.openmrs.PatientIdentifier; 31 38 import org.openmrs.PatientIdentifierType; 32 import org.openmrs.PatientState;33 39 import org.openmrs.PatientProgram; 34 40 import org.openmrs.PersonName; … … 41 47 import org.openmrs.util.OpenmrsUtil; 42 48 49 import org.springframework.test.annotation.NotTransactional; 50 import org.springframework.transaction.annotation.Transactional; 51 import org.springframework.test.annotation.Rollback; 52 43 53 /** 44 54 * Tests creating various pieces of data via synchronization … … 51 61 } 52 62 53 54 public void testEnrollInProgram() throws Exception { 63 @Test 64 @NotTransactional 65 public void shouldEnrollInProgram() throws Exception { 55 66 runSyncTest(new SyncTestHelper() { 56 67 int numberEnrolledBefore = 0; … … 83 94 } 84 95 85 public void testEnrollInProgramAndState() throws Exception { 96 @Test 97 @NotTransactional 98 public void shouldEnrollInProgramAndState() throws Exception { 86 99 runSyncTest(new SyncTestHelper() { 87 100 int numberEnrolledBefore = 0; … … 130 143 } 131 144 132 public void testChangeState() throws Exception { 145 @Test 146 @NotTransactional 147 public void shouldChangeState() throws Exception { 133 148 runSyncTest(new SyncTestHelper() { 134 149 Program hivProgram; … … 155 170 } 156 171 172 @Test 173 @NotTransactional 174 public void shouldCreateEncounterAndObs() throws Exception { 175 runSyncTest(new CreateEncounterAndObsTest()); 176 } 157 177 private class CreateEncounterAndObsTest implements SyncTestHelper { 158 178 int numEncountersSoFar = 0; … … 166 186 Concept reason = cs.getConceptByName("REASON ORDER STOPPED"); 167 187 Concept other = cs.getConceptByName("OTHER NON-CODED"); 168 Location loc = Context.get EncounterService().getLocationByName("Someplace");188 Location loc = Context.getLocationService().getLocation("Someplace"); 169 189 170 190 User u = Context.getUserService().getUser(1); 171 191 Patient p = Context.getPatientService().getPatient(2); 172 numEncountersSoFar = Context.getEncounterService().getEncounters (p).size();192 numEncountersSoFar = Context.getEncounterService().getEncountersByPatient(p).size(); 173 193 174 194 Encounter enc = new Encounter(); … … 187 207 enc.addObs(o1); 188 208 enc.addObs(o2); 189 Context.getEncounterService(). createEncounter(enc);209 Context.getEncounterService().saveEncounter(enc); 190 210 191 211 Obs noEnc = new Obs(); … … 195 215 noEnc.setPerson(p); 196 216 noEnc.setLocation(loc); 197 Context.getObsService(). createObs(noEnc);217 Context.getObsService().saveObs(noEnc,null); 198 218 } 199 200 219 public void runOnParent() { 201 220 … … 204 223 Concept reason = cs.getConceptByName("REASON ORDER STOPPED"); 205 224 Concept other = cs.getConceptByName("OTHER NON-CODED"); 206 Location loc = Context.get EncounterService().getLocationByName("Someplace");225 Location loc = Context.getLocationService().getLocation("Someplace"); 207 226 Patient p = Context.getPatientService().getPatient(2); 208 227 209 228 210 List<Encounter> encs = Context.getEncounterService().getEncounters (p);229 List<Encounter> encs = Context.getEncounterService().getEncountersByPatient(p); 211 230 assertEquals("Should now have one more encounter than before", 212 231 numEncountersSoFar + 1, … … 222 241 assertEquals(lookAt.getLocation(), loc); 223 242 224 assertEquals("Should have two obs", lookAt.getObs().size(), 2); 243 //reload lookAt 244 int lookAtId = lookAt.getEncounterId(); 245 Context.evictFromSession(lookAt); 246 lookAt = Context.getEncounterService().getEncounter(lookAtId); 247 assertEquals("Should have two obs", 2,lookAt.getObs().size()); 225 248 for (Obs o : lookAt.getObs()) { 226 249 if (o.getConcept().equals(weight)) { 227 assertEquals("Weight should be 74.0", o.getValueNumeric(), 74.0);250 assertEquals("Weight should be 74.0", o.getValueNumeric(), (Double)74.0); 228 251 } else { 229 252 assertEquals("Reason should be OTHER NON-CODED", o.getValueCoded(), other); … … 232 255 233 256 boolean found = false; 234 for (Obs o : Context.getObsService().getObservations (p, false)) {257 for (Obs o : Context.getObsService().getObservationsByPerson(p)) { 235 258 if ( (OpenmrsUtil.compare(o.getObsDatetime(), anotherDate) == 0) && o.getConcept().equals(weight) && o.getValueNumeric().equals(12.3)) 236 259 found = true; … … 238 261 assertTrue("Cannot find newly created encounter-less obs", found); 239 262 } 240 }241 242 public void testCreateEncounterAndObs() throws Exception {243 runSyncTest(new CreateEncounterAndObsTest());244 263 } 245 264 … … 249 268 * @throws Exception 250 269 */ 251 public void testEditEncounter() throws Exception { 270 @Test 271 @NotTransactional 272 public void shouldEditEncounter() throws Exception { 252 273 runSyncTest(new SyncTestHelper() { 253 274 Date d1 = ymd.parse("1978-01-01"); … … 274 295 } 275 296 276 public void testEditObs() throws Exception { 297 @Test 298 @NotTransactional 299 public void shouldEditObs() throws Exception { 277 300 runSyncTest(new SyncTestHelper() { 278 301 Date d = ymd.parse("1978-04-11"); 279 302 Concept weight = null; 303 int obsCount = 0; 280 304 public void runOnChild(){ 281 305 weight = Context.getConceptService().getConceptByName("WEIGHT"); 282 306 Patient p = Context.getPatientService().getPatient(2); 283 307 Obs obs = null; 284 for (Obs o : Context.getObsService().getObservations (p, weight, false)) {285 if (OpenmrsUtil.compare(o.getObsDatetime(), d) == 0) 308 for (Obs o : Context.getObsService().getObservationsByPersonAndConcept(p, weight)) { 309 if (OpenmrsUtil.compare(o.getObsDatetime(), d) == 0) { 286 310 obs = o; 311 } 287 312 } 313 314 obsCount = obs.getEncounter().getObs().size(); 288 315 assertNotNull("Before test, could not find expected obs", obs); 289 316 Context.getObsService().voidObs(obs, "Data entry error"); 317 318 assertEquals(obsCount - 1,obs.getEncounter().getObs().size() ); 319 obsCount = obs.getEncounter().getObs().size(); 290 320 291 321 Obs newObs = new Obs(); … … 298 328 newObs.setValueNumeric(99.9); 299 329 newObs.setEncounter(obs.getEncounter()); 300 Context.getObsService().createObs(newObs); 301 } 302 public void runOnParent() { 303 Patient p = Context.getPatientService().getPatient(2); 304 boolean found = false; 305 for (Obs o : Context.getObsService().getObservations(p, weight, false)) 330 newObs = Context.getObsService().saveObs(newObs, null); 331 obsCount++; 332 333 int encId = newObs.getEncounter().getEncounterId(); 334 Context.evictFromSession(newObs.getEncounter()); 335 assertEquals(obsCount,Context.getEncounterService().getEncounter(encId).getObs().size()); 336 } 337 public void runOnParent() { 338 int encId = 0; 339 Patient p = Context.getPatientService().getPatient(2); 340 Obs obs = null; 341 for (Obs o : Context.getObsService().getObservationsByPersonAndConcept(p, weight)) 306 342 if (OpenmrsUtil.compare(o.getObsDatetime(),d)==0) { 307 assertEquals(o.getEncounter().getObs().size(), 3); 308 assertEquals(o.getValueNumeric(), 99.9); 309 found = true; 343 obs = o; 344 break; 310 345 } 311 assertTrue(found); 312 } 313 }); 314 } 315 316 public void testCreatePatient() throws Exception { 346 assertNotNull(obs); 347 assertEquals( (Double)99.9, obs.getValueNumeric()); 348 encId = obs.getEncounter().getEncounterId(); 349 Context.evictFromSession(obs.getEncounter()); 350 assertEquals(obsCount,Context.getEncounterService().getEncounter(encId).getObs().size()); 351 } 352 }); 353 } 354 355 @Test 356 @NotTransactional 357 public void shouldCreatePatient() throws Exception { 358 317 359 runSyncTest(new SyncTestHelper() { 318 360 public void runOnChild() { … … 353 395 } 354 396 355 public void testEditPatient() throws Exception { 397 @Test 398 @NotTransactional 399 public void shouldEditPatient() throws Exception { 356 400 runSyncTest(new SyncTestHelper() { 357 401 PatientIdentifierType pit; … … 380 424 }); 381 425 } 382 383 426 }