Advertisement
Guest User

Untitled

a guest
Jun 15th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. /**
  2.  * The contents of this file are subject to the OpenMRS Public License
  3.  * Version 1.0 (the "License"); you may not use this file except in
  4.  * compliance with the License. You may obtain a copy of the License at
  5.  * http://license.openmrs.org
  6.  *
  7.  * Software distributed under the License is distributed on an "AS IS"
  8.  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9.  * License for the specific language governing rights and limitations
  10.  * under the License.
  11.  *
  12.  * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
  13.  */
  14. package org.openmrs.api.handler;
  15.  
  16. import java.util.Date;
  17.  
  18. import org.openmrs.Encounter;
  19. import org.openmrs.Obs;
  20. import org.openmrs.User;
  21. import org.openmrs.annotation.Handler;
  22. import org.openmrs.api.APIException;
  23. import org.openmrs.api.context.Context;
  24.  
  25. /**
  26.  *
  27.  */
  28. @Handler(supports = Encounter.class)
  29. public class EncounterSaveHandler implements SaveHandler<Encounter> {
  30.    
  31.     /**
  32.      * @see org.openmrs.api.handler.SaveHandler#handle(org.openmrs.OpenmrsObject, org.openmrs.User,
  33.      *      java.util.Date, java.lang.String)
  34.      */
  35.     @Override
  36.     public void handle(Encounter object, User creator, Date dateCreated, String other) {
  37.         for (Obs obs : object.getAllObs()) {
  38.             if (obs.getConcept().getDatatype().isComplex()) {
  39.                 System.out.println("got obs");
  40.                 String handlerString = Context.getConceptService().getConceptComplex(obs.getConcept().getConceptId())
  41.                         .getHandler();
  42.        
  43.                 if (handlerString == null)
  44.                     throw new APIException("Unable to get the handler for obs: " + obs + " and concept: " + obs.getConcept()
  45.                             + " because the handler is null");
  46.                 Context.getObsService().getHandler(handlerString).saveObs(obs);
  47.             }
  48.            
  49.         }
  50.     }
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement