/** * save */ public ims.emergency.vo.DischargeServicesAndAdviceVo saveSupportServices(ims.emergency.vo.DischargeServicesAndAdviceVo voSupportServices) throws ims.domain.exceptions.StaleObjectException { if(!voSupportServices.isValidated()) { throw new DomainRuntimeException("DischargeServicesAndAdviceVo Value Object has not been validated"); } DomainFactory factory = getDomainFactory(); DischargeServicesAndAdvice doDS = DischargeServicesAndAdviceVoAssembler.extractDischargeServicesAndAdvice(factory, voSupportServices); if (voSupportServices.getID_DischargeServicesAndAdvice() == null) { //Double check one does not already exist - saved from another session if (this.getSupportServices(null, voSupportServices.getAttendance()) != null) throw new StaleObjectException(doDS); } factory.save(doDS); return DischargeServicesAndAdviceVoAssembler.create(doDS); }
public DischargeServicesAndAdviceVo getDischargeServiceAndAdvice(CareContextRefVo careContext) { if (careContext == null || careContext.getID_CareContext() == null) return null; StringBuilder query = new StringBuilder(); query.append("SELECT discharge FROM DischargeServicesAndAdvice AS discharge LEFT JOIN discharge.attendance AS context "); query.append("WHERE context.id = ").append(careContext.getID_CareContext()); return DischargeServicesAndAdviceVoAssembler.create((DischargeServicesAndAdvice) getDomainFactory().findFirst(query.toString())); }
public DischargeServicesAndAdviceVo save(DischargeServicesAndAdviceVo dischargeServices) throws StaleObjectException { // Check parameter if (dischargeServices == null) throw new CodingRuntimeException("Can not save null record"); // Check for validation if (!dischargeServices.isValidated()) throw new CodingRuntimeException("Can not save record not validated"); // Check for a previously saved record if (dischargeServices.getID_DischargeServicesAndAdvice() == null) { StringBuilder query = new StringBuilder(); query.append("SELECT COUNT(discharge) FROM DischargeServicesAndAdvice AS discharge LEFT JOIN discharge.attendance AS context WHERE context.id = :CONTEXT"); long count = getDomainFactory().countWithHQL(query.toString(), new String[] {"CONTEXT"}, new Object[] {dischargeServices.getAttendance().getID_CareContext()}); if (count > 0) throw new StaleObjectException(null); } // Commit to database DischargeServicesAndAdvice domainRecord = DischargeServicesAndAdviceVoAssembler.extractDischargeServicesAndAdvice(getDomainFactory(), dischargeServices); getDomainFactory().save(domainRecord); // Return saved object return DischargeServicesAndAdviceVoAssembler.create(domainRecord); }