Coverage Report - ca.uhn.hl7v2.model.AbstractSuperMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSuperMessage
92%
25/27
80%
8/10
2.4
 
 1  
 package ca.uhn.hl7v2.model;
 2  
 
 3  
 import java.util.Collections;
 4  
 import java.util.HashMap;
 5  
 import java.util.HashSet;
 6  
 import java.util.Map;
 7  
 import java.util.Set;
 8  
 
 9  
 import ca.uhn.hl7v2.HL7Exception;
 10  
 import ca.uhn.hl7v2.parser.ModelClassFactory;
 11  
 import ca.uhn.hl7v2.util.StringUtil;
 12  
 import ca.uhn.hl7v2.util.Terser;
 13  
 
 14  
 /**
 15  
  * Base class for a {@link SuperStructure} message.
 16  
  * 
 17  
  * @see SuperStructure
 18  
  * @see Message
 19  
  */
 20  
 public abstract class AbstractSuperMessage extends AbstractMessage implements SuperStructure {
 21  
 
 22  5
         private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(AbstractSuperMessage.class);
 23  545
         private Map<String, Set<String>> myChildNameToStructures = new HashMap<String, Set<String>>();
 24  
 
 25  
         private String myName;
 26  
 
 27  
         /**
 28  
          * Constructor
 29  
          * 
 30  
          * @param theFactory
 31  
          *            The model class factory
 32  
          */
 33  
         public AbstractSuperMessage(ModelClassFactory theFactory) {
 34  545
                 super(theFactory);
 35  545
         }
 36  
 
 37  
         protected void addSuperstructureApplication(String theChild, String theStructure) {
 38  316750
                 StringUtil.validateNotEmpty(theChild);
 39  316750
                 StringUtil.validateNotEmpty(theStructure);
 40  
 
 41  316750
                 if (!myChildNameToStructures.containsKey(theChild)) {
 42  17205
                         myChildNameToStructures.put(theChild, new HashSet<String>());
 43  
                 }
 44  316750
                 myChildNameToStructures.get(theChild).add(theStructure);
 45  316750
         }
 46  
 
 47  
         /**
 48  
          * Returns the name of this structure (e.g. "ADT_A01", or "ORU_R01"). Note
 49  
          * that for super structures this value is explicitly set by the parser.
 50  
          */
 51  
         public String getName() {
 52  2030
                 if (StringUtil.isBlank(myName)) {
 53  575
                         String retVal = null;
 54  
                         try {
 55  575
                                 Terser t = new Terser(this);
 56  575
                                 retVal = t.get("/MSH-9-3");
 57  
 
 58  575
                                 if (StringUtil.isBlank(retVal)) {
 59  575
                                         String msh91 = t.get("/MSH-9-1");
 60  575
                                         String msh92 = t.get("/MSH-9-2");
 61  575
                                         if (StringUtil.isNotBlank(msh91) && StringUtil.isNotBlank(msh92)) {
 62  75
                                                 retVal = msh91 + "_" + msh92;
 63  
                                         }
 64  
                                 }
 65  0
                         } catch (HL7Exception e) {
 66  0
                                 ourLog.debug("Failed to retrieve MSH-9", e);
 67  575
                         }
 68  575
                         return retVal;
 69  
                 }
 70  
 
 71  1455
                 return myName;
 72  
         }
 73  
 
 74  
         /**
 75  
          * {@inheritDoc}
 76  
          */
 77  
         public Set<String> getStructuresWhichChildAppliesTo(String theChildName) {
 78  345
                 return Collections.unmodifiableSet(myChildNameToStructures.get(theChildName));
 79  
         }
 80  
 
 81  
         /**
 82  
          * Provide the name that will be returned by {@link #getName()}
 83  
          */
 84  
         public void setName(String theName) {
 85  245
                 myName = theName;
 86  245
         }
 87  
 
 88  
 }