Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 3991

Show
Ignore:
Timestamp:
04/22/08 15:16:07 (9 months ago)
Author:
bwolfe
Message:

Fixed obs group id not being created for child objects - #693, #695
Author: dthomas

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/Obs.hbm.xml

    r3847 r3991  
    6262                <!-- many-to-one association from this obs to its parent grouping obs --> 
    6363                <!-- insert/update=false because the groupMembers set is doing the saving for us --> 
    64                 <many-to-one name="obsGroup" class="Obs" column="obs_group_id" insert="false" update="false"/> 
     64                <many-to-one name="obsGroup" class="Obs" column="obs_group_id" insert="true" update="true"/> 
    6565                 
    6666                <!-- one-to-many association to all obs in this grouping --> 
  • openmrs/trunk/test/api/org/openmrs/test/api/ObsServiceTest.java

    r3847 r3991  
    304304                Obs o4 = obsService.getObs(o.getObsId()); 
    305305                 
     306                assertNotNull(o4.getVoidReason()); 
    306307                assertTrue(o4.getVoidReason().equals("testing void function")); 
    307308                assertTrue(o4.getVoidedBy().equals(o3.getVoidedBy())); 
     
    315316        }        
    316317         
     318        /** 
     319         * Auto generated method comment 
     320         *  
     321         * @throws Exception 
     322         */ 
    317323        public void testObsValidator() throws Exception { 
    318324                executeDataSet(INITIAL_OBS_XML); 
     
    686692                assertTrue(childLeafObs.isVoided()); 
    687693                 
    688                 childLeafObs.setDateVoided(new Date()); 
     694                childLeafObs.setDateVoided(new Date(childLeafObs.getDateVoided().getTime() - 5000));  
    689695                os.updateObs(childLeafObs); 
    690696                os.unvoidObs(oGGGP); 
     
    693699                Obs childLeafObsTwo = os.getObs(childTwoId); 
    694700                 
    695                 //childLeafObs had its date voided date changed, so it shoul not get unvoided by the unvoid cascade 
     701                //childLeafObs had its date voided date changed, so it should not get unvoided by the unvoid cascade 
    696702                //childLeafObsTwo should be unvoided, as the dateVoided date is still the same as the great-great 
    697703                //grandparent Obs 
     
    708714                assertNull(os.getObs(childTwoId)); 
    709715        } 
    710                  
     716         
     717        /** 
     718         * This test makes sure that child obs on a parent obs are given an obs group id when the  
     719         * parent obs is created 
     720         *  
     721         * @throws Throwable 
     722         */ 
     723        public void testCreateObsGroupId() throws Throwable { 
     724                 
     725                executeDataSet(INITIAL_OBS_XML); 
     726 
     727                ConceptService cs = Context.getConceptService(); 
     728                ObsService os = Context.getObsService(); 
     729                 
     730                Obs o2 = new Obs(); 
     731                o2.setConcept(cs.getConcept(1)); 
     732                o2.setDateCreated(new Date()); 
     733                o2.setCreator(Context.getAuthenticatedUser()); 
     734                o2.setLocation(new Location(1)); 
     735                o2.setObsDatetime(new Date()); 
     736                o2.setValueText("test"); 
     737                o2.setPerson(new Patient(2)); 
     738 
     739                //create a parent obs 
     740                Obs oParent = new Obs(); 
     741                oParent.setConcept(cs.getConcept(2)); //in the concept set table as a set 
     742                oParent.setDateCreated(new Date()); 
     743                oParent.setCreator(Context.getAuthenticatedUser()); 
     744                oParent.setLocation(new Location(1)); 
     745                oParent.setObsDatetime(new Date()); 
     746                oParent.setPerson(new Patient(2)); 
     747                 
     748                oParent.addGroupMember(o2); 
     749                 
     750                os.createObs(oParent); 
     751                 
     752                // save the obs ids 
     753                Integer parentObsId = oParent.getObsId(); 
     754                assertNotNull(parentObsId); 
     755                 
     756                Integer childObsId = o2.getObsId(); 
     757                assertNotNull(childObsId); 
     758                 
     759                // clear out the session so we can refetch and test that it saved correctly 
     760                oParent = null; 
     761                o2 = null; 
     762                Context.clearSession(); 
     763                 
     764                // try to get the same obs back and make sure it has children 
     765                 
     766                Obs fetchedParent = os.getObs(parentObsId); 
     767                assertTrue(fetchedParent.isObsGrouping()); 
     768                assertEquals(1, fetchedParent.getGroupMembers().size()); 
     769                 
     770                 
     771        } 
    711772}