- Timestamp:
- 05/15/08 20:28:28 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex-obs/test/api/org/openmrs/test/api/ComplexObsTest.java
r4166 r4232 58 58 public void testSaveGetComplexObs() throws Exception { 59 59 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 */ 63 67 ConceptComplex concept = Context.getConceptService() 64 68 .getConceptComplex(Integer.valueOf(1867)); … … 66 70 .getLocation(Integer.valueOf(1)); 67 71 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 */ 68 79 Obs obs = new Obs(); 69 80 obs.setConcept(concept); 70 // This is a test patient patient_id. Until I create an in-memory71 // database, please change the patient_id to suit your needs.72 81 obs.setPerson(Context.getPatientService() 73 82 .getPatient(Integer.valueOf(48609))); … … 78 87 obs.setVoided(false); 79 88 89 /* 90 * Step 3. Read in an image from the file system. 91 */ 80 92 BufferedImage img = null; 81 93 try { 82 //img = ImageIO.read(new File("/home/bmckown/Desktop/test/McKowsayPost.jpg"));83 94 img = ImageIO.read(new File("/home/bmckown/Desktop/test/logo.png")); 84 95 } catch (IOException e) { … … 86 97 } 87 98 88 //ComplexData cobs = new ComplexData("McKowsayPost01.jpg", img); 99 /* 100 * Step 3. Create a ComplexData 101 */ 102 // ComplexData cobs = new ComplexData("McKowsayPost01.jpg", img); 89 103 ComplexData cdat = new ComplexData("hoss-collab.jpg", img); 90 104 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 */ 95 111 112 /* 113 * Step 4. Persist the Complex Obs. 114 */ 96 115 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 */ 99 124 System.out.println(obs.getObsId()); 100 125 assertNotNull(Context.getObsService().getObs(obs.getObsId())); 101 126 127 /* 128 * Step 6. Assert that the Complex Obs has a valueComplex. 129 */ 102 130 System.out.println(obs.getValueComplex()); 103 131 assertNotNull(obs.getValueComplex()); 104 132 133 /* 134 * Step 7. Retrieve the Complex Obs by Id from the ObsService 135 */ 105 136 Integer obsId = obs.getObsId(); 106 137 Obs cobs = Context.getObsService().getComplexObs(obsId); 107 138 139 /* 140 * Step 8. Save the ComplexData to the file system. 141 * Assert that the ComplexData is not null. 142 */ 108 143 try { 109 144 File outputfile = new File("/home/bmckown/Desktop/test", … … 113 148 System.out.println(e2); 114 149 } 150 assertNotNull(cobs.getComplexData()); 115 151 116 assertNotNull(cobs.getComplexData()); 117 152 /* 153 * Step 9. Print the valueComplex and the valueAsString 154 */ 118 155 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 126 167 } 127 168