Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/15/08 20:28:28 (8 months ago)
Author:
bmckown
Message:

complex_obs branch: Added ComplexObsServlet. Added extra (copied) ComplexObsHandler. Changed conceptForm.jsp to reflect api changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/test/api/org/openmrs/test/api/ComplexObsTest.java

    r4166 r4232  
    5858        public void testSaveGetComplexObs() throws Exception { 
    5959 
    60                 // Previously created concept that is created as complex. Until 
    61                 // in-memory database is created, change concept_id to one that suits 
    62                 // your needs. 
     60                /* 
     61                 * Step 1. Get a ConceptComplex from the ConceptService 
     62                 *  
     63                 * TODO: Previously created concept that is created as complex. Until 
     64                 * in-memory database is created, change concept_id to one that suits 
     65                 * your needs. 
     66                 */ 
    6367                ConceptComplex concept = Context.getConceptService() 
    6468                                                .getConceptComplex(Integer.valueOf(1867)); 
     
    6670                                           .getLocation(Integer.valueOf(1)); 
    6771 
     72                /* 
     73                 * Step 2. Create an Obs, set its concept as the ConceptComplex, and set 
     74                 * all other required properties 
     75                 *  
     76                 * TODO: This is a test patient patient_id. Until I create an in-memory 
     77                 * database, please change the patient_id to suit your needs. 
     78                 */ 
    6879                Obs obs = new Obs(); 
    6980                obs.setConcept(concept); 
    70                 // This is a test patient patient_id. Until I create an in-memory 
    71                 // database, please change the patient_id to suit your needs. 
    7281                obs.setPerson(Context.getPatientService() 
    7382                                     .getPatient(Integer.valueOf(48609))); 
     
    7887                obs.setVoided(false); 
    7988 
     89                /* 
     90                 * Step 3. Read in an image from the file system. 
     91                 */ 
    8092                BufferedImage img = null; 
    8193                try { 
    82                         //img = ImageIO.read(new File("/home/bmckown/Desktop/test/McKowsayPost.jpg")); 
    8394                        img = ImageIO.read(new File("/home/bmckown/Desktop/test/logo.png")); 
    8495                } catch (IOException e) { 
     
    8697                } 
    8798 
    88                 //ComplexData cobs = new ComplexData("McKowsayPost01.jpg", img); 
     99                /* 
     100                 * Step 3. Create a ComplexData 
     101                 */ 
     102                // ComplexData cobs = new ComplexData("McKowsayPost01.jpg", img); 
    89103                ComplexData cdat = new ComplexData("hoss-collab.jpg", img); 
    90104                obs.setComplexData(cdat); 
    91                 //TODO: At this point the obs.isComplex() will return false. 
    92                 // This is because we do not want the Obs pojo to know anyting of the ComplexObsHandler, 
    93                 // and it is the responsibility of the ComplexObsHandler to set the valueComplex for the Obs. 
    94                 // An Obs is considered complex if obs.getValueComplex() != null. 
     105                /* TODO: At this point the obs.isComplex() will return false. This is 
     106                 * because we do not want the Obs pojo to know anyting of the 
     107                 * ComplexObsHandler, and it is the responsibility of the 
     108                 * ComplexObsHandler to set the valueComplex for the Obs. An Obs is 
     109                 * considered complex if obs.getValueComplex() != null. 
     110                 */ 
    95111                 
     112                /* 
     113                 * Step 4. Persist the Complex Obs.  
     114                 */ 
    96115                Context.getObsService().createObs((Obs) obs); 
    97                 //TODO: Starting here the obs.isComplex() will return true. 
    98  
     116                /*TODO: Starting here the obs.isComplex() will return true. 
     117                 */ 
     118                // Save a complex obs to the database for testing. 
     119                //setComplete(); 
     120                 
     121                /* 
     122                 * Step 5. Assert that the Complex Obs now has an obsId. 
     123                 */ 
    99124                System.out.println(obs.getObsId()); 
    100125                assertNotNull(Context.getObsService().getObs(obs.getObsId())); 
    101126 
     127                /* 
     128                 * Step 6. Assert that the Complex Obs has a valueComplex. 
     129                 */ 
    102130                System.out.println(obs.getValueComplex()); 
    103131                assertNotNull(obs.getValueComplex()); 
    104132 
     133                /* 
     134                 * Step 7. Retrieve the Complex Obs by Id from the ObsService 
     135                 */ 
    105136                Integer obsId = obs.getObsId(); 
    106137                Obs cobs = Context.getObsService().getComplexObs(obsId); 
    107138 
     139                /* 
     140                 * Step 8. Save the ComplexData to the file system. 
     141                 * Assert that the ComplexData is not null. 
     142                 */ 
    108143                try { 
    109144                        File outputfile = new File("/home/bmckown/Desktop/test", 
     
    113148                        System.out.println(e2); 
    114149                } 
     150                assertNotNull(cobs.getComplexData()); 
    115151 
    116                 assertNotNull(cobs.getComplexData()); 
    117                  
     152                /* 
     153                 * Step 9. Print the valueComplex and the valueAsString 
     154                 */ 
    118155                System.out.println("Obs.getValueComplex(): " + cobs.getValueComplex()); 
    119                 System.out.println("Obs.getValueAsString(): " + cobs.getValueAsString(null)); 
    120                  
    121                 System.out.println(Context.getObsService().getHandlers()); 
    122                 //Map<Class<? extends ComplexObsHandler>, ComplexObsHandler> handlers = Context.getObsService().getHandlers(); 
    123                 List handlers = Context.getObsService().getComplexObsHandlers();  
    124                          
    125                  
     156                System.out.println("Obs.getValueAsString(): " 
     157                        + cobs.getValueAsString(null)); 
     158 
     159                /* 
     160                 * Step 10. Print the list of registered ComplexObsHandlers. 
     161                 */ 
     162                List handlers = Context.getObsService().getComplexObsHandlers(); 
     163                for (int i=0; i<handlers.size(); i++)  { 
     164                        System.out.println(handlers.get(i).getClass()); 
     165                } 
     166 
    126167        } 
    127168