/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of ims.core.clinical.domain.objects.IntraOperativeCareRecord
   *     objects.
   */
  public static ims.clinical.vo.IntraOperativeCareRecordShortVoCollection
      createIntraOperativeCareRecordShortVoCollectionFromIntraOperativeCareRecord(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.clinical.vo.IntraOperativeCareRecordShortVoCollection voList =
        new ims.clinical.vo.IntraOperativeCareRecordShortVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.core.clinical.domain.objects.IntraOperativeCareRecord domainObject =
          (ims.core.clinical.domain.objects.IntraOperativeCareRecord) iterator.next();
      ims.clinical.vo.IntraOperativeCareRecordShortVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of ims.core.clinical.domain.objects.IntraOperativeCareRecord
   *     objects.
   */
  public static ims.clinical.vo.IntraOperativeCareRecordShortVoCollection
      createIntraOperativeCareRecordShortVoCollectionFromIntraOperativeCareRecord(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.clinical.vo.IntraOperativeCareRecordShortVoCollection voList =
        new ims.clinical.vo.IntraOperativeCareRecordShortVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.core.clinical.domain.objects.IntraOperativeCareRecord domainObject =
          (ims.core.clinical.domain.objects.IntraOperativeCareRecord) domainObjectList.get(i);
      ims.clinical.vo.IntraOperativeCareRecordShortVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject from the ims.core.clinical.domain.objects.IntraOperativeCareRecord
   * object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.clinical.vo.IntraOperativeCareRecordShortVo create(
      DomainObjectMap map, ims.core.clinical.domain.objects.IntraOperativeCareRecord domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.clinical.vo.IntraOperativeCareRecordShortVo valueObject =
        (ims.clinical.vo.IntraOperativeCareRecordShortVo)
            map.getValueObject(domainObject, ims.clinical.vo.IntraOperativeCareRecordShortVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.clinical.vo.IntraOperativeCareRecordShortVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
 public static void fillFieldsfromXML(
     org.dom4j.Element el,
     ims.domain.DomainFactory factory,
     SurgicalOpNotes obj,
     java.util.HashMap domMap)
     throws Exception {
   org.dom4j.Element fldEl;
   fldEl = el.element("careContext");
   if (fldEl != null) {
     fldEl = fldEl.element("class");
     obj.setCareContext(
         ims.core.admin.domain.objects.CareContext.getCareContextfromXML(fldEl, factory, domMap));
   }
   fldEl = el.element("authoringInformation");
   if (fldEl != null) {
     fldEl = fldEl.element("class");
     obj.setAuthoringInformation(
         ims.core.clinical.domain.objects.AuthoringInformation.getAuthoringInformationfromXML(
             fldEl, factory, domMap));
   }
   fldEl = el.element("intraOperativeCareRecord");
   if (fldEl != null) {
     fldEl = fldEl.element("class");
     obj.setIntraOperativeCareRecord(
         ims.core.clinical.domain.objects.IntraOperativeCareRecord
             .getIntraOperativeCareRecordfromXML(fldEl, factory, domMap));
   }
   fldEl = el.element("preOperativeDiagnosis");
   if (fldEl != null) {
     obj.setPreOperativeDiagnosis(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("antibiotics");
   if (fldEl != null) {
     obj.setAntibiotics(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("vTE");
   if (fldEl != null) {
     obj.setVTE(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("incision");
   if (fldEl != null) {
     obj.setIncision(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("findings");
   if (fldEl != null) {
     obj.setFindings(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("procedure");
   if (fldEl != null) {
     obj.setProcedure(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("complications");
   if (fldEl != null) {
     obj.setComplications(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("closure");
   if (fldEl != null) {
     obj.setClosure(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("lAInfiltration");
   if (fldEl != null) {
     obj.setLAInfiltration(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("postOpInstructions");
   if (fldEl != null) {
     obj.setPostOpInstructions(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("eBI");
   if (fldEl != null) {
     obj.setEBI(new String(fldEl.getTextTrim()));
   }
   fldEl = el.element("followUpType");
   if (fldEl != null) {
     fldEl = fldEl.element("lki");
     obj.setFollowUpType(ims.domain.lookups.LookupInstance.fromXMLString(fldEl, factory));
   }
   fldEl = el.element("followUpTypeIn");
   if (fldEl != null) {
     fldEl = fldEl.element("lki");
     obj.setFollowUpTypeIn(ims.domain.lookups.LookupInstance.fromXMLString(fldEl, factory));
   }
 }
  public String toAuditString() {
    StringBuffer auditStr = new StringBuffer();

    auditStr.append("\r\n*careContext* :");
    if (careContext != null) {
      auditStr.append(toShortClassName(careContext));

      auditStr.append(careContext.getId());
    }
    auditStr.append("; ");
    auditStr.append("\r\n*authoringInformation* :");
    if (authoringInformation != null) {
      auditStr.append(toShortClassName(authoringInformation));

      auditStr.append(authoringInformation.toString());
    }
    auditStr.append("; ");
    auditStr.append("\r\n*intraOperativeCareRecord* :");
    if (intraOperativeCareRecord != null) {
      auditStr.append(toShortClassName(intraOperativeCareRecord));

      auditStr.append(intraOperativeCareRecord.getId());
    }
    auditStr.append("; ");
    auditStr.append("\r\n*preOperativeDiagnosis* :");
    auditStr.append(preOperativeDiagnosis);
    auditStr.append("; ");
    auditStr.append("\r\n*antibiotics* :");
    auditStr.append(antibiotics);
    auditStr.append("; ");
    auditStr.append("\r\n*vTE* :");
    auditStr.append(vTE);
    auditStr.append("; ");
    auditStr.append("\r\n*incision* :");
    auditStr.append(incision);
    auditStr.append("; ");
    auditStr.append("\r\n*findings* :");
    auditStr.append(findings);
    auditStr.append("; ");
    auditStr.append("\r\n*procedure* :");
    auditStr.append(procedure);
    auditStr.append("; ");
    auditStr.append("\r\n*complications* :");
    auditStr.append(complications);
    auditStr.append("; ");
    auditStr.append("\r\n*closure* :");
    auditStr.append(closure);
    auditStr.append("; ");
    auditStr.append("\r\n*lAInfiltration* :");
    auditStr.append(lAInfiltration);
    auditStr.append("; ");
    auditStr.append("\r\n*postOpInstructions* :");
    auditStr.append(postOpInstructions);
    auditStr.append("; ");
    auditStr.append("\r\n*eBI* :");
    auditStr.append(eBI);
    auditStr.append("; ");
    auditStr.append("\r\n*followUpType* :");
    if (followUpType != null) auditStr.append(followUpType.getText());
    auditStr.append("; ");
    auditStr.append("\r\n*followUpTypeIn* :");
    if (followUpTypeIn != null) auditStr.append(followUpTypeIn.getText());
    auditStr.append("; ");
    return auditStr.toString();
  }
  public static ims.core.clinical.domain.objects.IntraOperativeCareRecord
      extractIntraOperativeCareRecord(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.clinical.vo.IntraOperativeCareRecordShortVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_IntraOperativeCareRecord();
    ims.core.clinical.domain.objects.IntraOperativeCareRecord domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.clinical.domain.objects.IntraOperativeCareRecord) domMap.get(valueObject);
      }
      // ims.clinical.vo.IntraOperativeCareRecordShortVo ID_IntraOperativeCareRecord field is
      // unknown
      domainObject = new ims.core.clinical.domain.objects.IntraOperativeCareRecord();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_IntraOperativeCareRecord());
      if (domMap.get(key) != null) {
        return (ims.core.clinical.domain.objects.IntraOperativeCareRecord) domMap.get(key);
      }
      domainObject =
          (ims.core.clinical.domain.objects.IntraOperativeCareRecord)
              domainFactory.getDomainObject(
                  ims.core.clinical.domain.objects.IntraOperativeCareRecord.class, id);

      // TODO: Not sure how this should be handled. Effectively it must be a staleobject exception,
      // but maybe should be handled as that further up.
      if (domainObject == null) return null;

      domMap.put(key, domainObject);
    }
    domainObject.setVersion(valueObject.getVersion_IntraOperativeCareRecord());

    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.clinical.domain.objects.IntraOperativeDetails value1 = null;
    if (null != valueObject.getIntraOperativeDetails()) {
      if (valueObject.getIntraOperativeDetails().getBoId() == null) {
        if (domMap.get(valueObject.getIntraOperativeDetails()) != null) {
          value1 =
              (ims.core.clinical.domain.objects.IntraOperativeDetails)
                  domMap.get(valueObject.getIntraOperativeDetails());
        }
      } else {
        value1 =
            (ims.core.clinical.domain.objects.IntraOperativeDetails)
                domainFactory.getDomainObject(
                    ims.core.clinical.domain.objects.IntraOperativeDetails.class,
                    valueObject.getIntraOperativeDetails().getBoId());
      }
    }
    domainObject.setIntraOperativeDetails(value1);
    ims.core.admin.domain.objects.CareContext value2 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value2 =
              (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject.getCareContext());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
      // BO field
      {
        value2 = domainObject.getCareContext();
      } else {
        value2 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value2);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.clinical.domain.objects.PatientProcedure value3 = null;
    if (null != valueObject.getActualProcedure()) {
      if (valueObject.getActualProcedure().getBoId() == null) {
        if (domMap.get(valueObject.getActualProcedure()) != null) {
          value3 =
              (ims.core.clinical.domain.objects.PatientProcedure)
                  domMap.get(valueObject.getActualProcedure());
        }
      } else {
        value3 =
            (ims.core.clinical.domain.objects.PatientProcedure)
                domainFactory.getDomainObject(
                    ims.core.clinical.domain.objects.PatientProcedure.class,
                    valueObject.getActualProcedure().getBoId());
      }
    }
    domainObject.setActualProcedure(value3);
    java.util.Date value4 = null;
    ims.framework.utils.Date date4 = valueObject.getProcedureDate();
    if (date4 != null) {
      value4 = date4.getDate();
    }
    domainObject.setProcedureDate(value4);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.place.domain.objects.Location value5 = null;
    if (null != valueObject.getTheatre()) {
      if (valueObject.getTheatre().getBoId() == null) {
        if (domMap.get(valueObject.getTheatre()) != null) {
          value5 =
              (ims.core.resource.place.domain.objects.Location)
                  domMap.get(valueObject.getTheatre());
        }
      } else {
        value5 =
            (ims.core.resource.place.domain.objects.Location)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Location.class,
                    valueObject.getTheatre().getBoId());
      }
    }
    domainObject.setTheatre(value5);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Hcp value6 = null;
    if (null != valueObject.getSurgeon()) {
      if (valueObject.getSurgeon().getBoId() == null) {
        if (domMap.get(valueObject.getSurgeon()) != null) {
          value6 =
              (ims.core.resource.people.domain.objects.Hcp) domMap.get(valueObject.getSurgeon());
        }
      } else {
        value6 =
            (ims.core.resource.people.domain.objects.Hcp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Hcp.class,
                    valueObject.getSurgeon().getBoId());
      }
    }
    domainObject.setSurgeon(value6);

    return domainObject;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.core.clinical.domain.objects.IntraOperativeCareRecord
   */
  public static ims.clinical.vo.IntraOperativeCareRecordShortVo insert(
      DomainObjectMap map,
      ims.clinical.vo.IntraOperativeCareRecordShortVo valueObject,
      ims.core.clinical.domain.objects.IntraOperativeCareRecord domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_IntraOperativeCareRecord(domainObject.getId());
    valueObject.setIsRIE(domainObject.getIsRIE());

    // If this is a recordedInError record, and the domainObject
    // value isIncludeRecord has not been set, then we return null and
    // not the value object
    if (valueObject.getIsRIE() != null
        && valueObject.getIsRIE().booleanValue() == true
        && !domainObject.isIncludeRecord()) return null;

    // If this is not a recordedInError record, and the domainObject
    // value isIncludeRecord has been set, then we return null and
    // not the value object
    if ((valueObject.getIsRIE() == null || valueObject.getIsRIE().booleanValue() == false)
        && domainObject.isIncludeRecord()) return null;

    // IntraOperativeDetails
    valueObject.setIntraOperativeDetails(
        ims.clinical.vo.domain.IntraOperativeDetailsLiteVoAssembler.create(
            map, domainObject.getIntraOperativeDetails()));
    // CareContext
    if (domainObject.getCareContext() != null) {
      if (domainObject.getCareContext()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
      // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCareContext();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCareContext(new ims.core.admin.vo.CareContextRefVo(id, -1));
      } else {
        valueObject.setCareContext(
            new ims.core.admin.vo.CareContextRefVo(
                domainObject.getCareContext().getId(), domainObject.getCareContext().getVersion()));
      }
    }
    // ActualProcedure
    valueObject.setActualProcedure(
        ims.core.vo.domain.PatientProcedureForSurgicalOperationNotesVoAssembler.create(
            map, domainObject.getActualProcedure()));
    // ProcedureDate
    java.util.Date ProcedureDate = domainObject.getProcedureDate();
    if (null != ProcedureDate) {
      valueObject.setProcedureDate(new ims.framework.utils.Date(ProcedureDate));
    }
    // Theatre
    valueObject.setTheatre(
        ims.core.vo.domain.LocationLiteVoAssembler.create(map, domainObject.getTheatre()));
    // Surgeon
    valueObject.setSurgeon(
        ims.core.vo.domain.HcpLiteVoAssembler.create(map, domainObject.getSurgeon()));
    return valueObject;
  }