public ims.core.vo.LocationLiteVoCollection listWardsForCurrentLocation(ILocation location) {
    if (location == null) return null;

    OrganisationAndLocation implLoc =
        (OrganisationAndLocation) getDomainImpl(OrganisationAndLocationImpl.class);
    LocationRefVo voRef = new LocationRefVo();
    voRef.setID_Location(location.getID());
    return implLoc.listActiveWardsForHospitalLite(voRef).sort();
  }
  public ims.core.vo.LocationLiteVoCollection listBaysForCurrentWard(ILocation location) {
    if (location == null) throw new DomainRuntimeException("Invalid ILocation");

    String hql =
        "from Location loc where loc.type = "
            + LocationType.BAY.getId()
            + " and loc.isActive = 1 and loc.parentLocation.id = "
            + location.getID();
    return LocationLiteVoAssembler.createLocationLiteVoCollectionFromLocation(
        getDomainFactory().find(hql));
  }
  public ims.core.vo.LocSiteLiteVo getCurrentHospital(ims.framework.interfaces.ILocation location) {
    if (location == null) return null;

    DomainFactory factory = getDomainFactory();

    Location currentHospital =
        getHospital((Location) factory.getDomainObject(Location.class, location.getID()));

    if (currentHospital instanceof LocSite)
      return LocSiteLiteVoAssembler.create((LocSite) currentHospital);

    return null;
  }
  // WDEV-15908
  public LocationLiteVo getCurrentHospital(ILocation location) {
    if (location == null) return null;

    DomainFactory factory = getDomainFactory();

    Location currentHospital =
        getHospital((Location) factory.getDomainObject(Location.class, location.getID()));

    if (currentHospital instanceof LocSite)
      return LocationLiteVoAssembler.create((Location) currentHospital);

    return null;
  }
  public FloorBedSpaceLayoutVo listLayoutForCurrentBay(ILocation location) {
    if (location == null) throw new DomainRuntimeException("Invalid ILocation");

    String hql =
        "select layout from BayConfig as bc left join bc.bay as bay left join bc.floorBedSpaceLayout as layout where layout.status.id = "
            + PreActiveActiveInactiveStatus.ACTIVE.getID()
            + " and  bay.id = "
            + location.getID();
    List layout = getDomainFactory().find(hql);

    FloorBedSpaceLayoutVoCollection voColl =
        FloorBedSpaceLayoutVoAssembler.createFloorBedSpaceLayoutVoCollectionFromFloorBedSpaceLayout(
            layout);

    if (voColl != null && voColl.size() > 0) return voColl.get(voColl.size() - 1);

    return null;
  }
  public void recordReadAudit(ValueObjectRef refVo, String action) {
    if (ConfigFlag.DOM.READ_AUDIT_ENABLED.getValue() != true) return;

    ReadAudit domRead = new ReadAudit();
    domRead.setPatientId(refVo.getBoId());
    domRead.setAuditAction(action);
    domRead.setAuditDateTime(new java.util.Date());

    IAppUser user = getSession().getUser();
    if (user != null) {
      domRead.setAuditUser(user.getUsername());
      domRead.setAuditHost(user.getHostName());
    }
    ILocation loc = getCurrentLocation();
    if (loc != null) domRead.setAuditUserLocation(new Integer(loc.getID()));
    try {
      getDomainFactory().save(domRead);
    } catch (StaleObjectException e) {
      throw new DomainRuntimeException("StaleObjectException occurred saving ReadAudit record");
    }
  }