|
| 1 | +package org.labkey.snprc_ehr.services; |
| 2 | + |
| 3 | +import org.labkey.api.data.CompareType; |
| 4 | +import org.labkey.api.data.Container; |
| 5 | +import org.labkey.api.data.SimpleFilter; |
| 6 | +import org.labkey.api.data.TableInfo; |
| 7 | +import org.labkey.api.data.TableSelector; |
| 8 | +import org.labkey.api.query.FieldKey; |
| 9 | +import org.labkey.api.query.QueryService; |
| 10 | +import org.labkey.api.query.UserSchema; |
| 11 | +import org.labkey.api.query.ValidationException; |
| 12 | +import org.labkey.api.security.User; |
| 13 | +import org.labkey.snprc_ehr.domain.NewAnimalData; |
| 14 | + |
| 15 | +import java.util.Map; |
| 16 | + |
| 17 | +public class SNPRC_EHRValidator |
| 18 | +{ |
| 19 | + public static void validateNewAnimalData(Container c, User u, NewAnimalData newAnimalData) throws ValidationException |
| 20 | + { |
| 21 | + // birthdate and acquisition dates |
| 22 | + if (newAnimalData.getBirthDate() == null) |
| 23 | + throw new ValidationException("Birthdate is required"); |
| 24 | + if (newAnimalData.getAcqDate() == null) |
| 25 | + throw new ValidationException("Acquisition daate is required"); |
| 26 | + if (newAnimalData.getBirthDate().after(newAnimalData.getAcqDate())) |
| 27 | + throw new ValidationException("Birthdate is greater than Acquisition date"); |
| 28 | + |
| 29 | + // species |
| 30 | + |
| 31 | + try |
| 32 | + { |
| 33 | + if (newAnimalData.getSpecies() == null) |
| 34 | + throw new ValidationException("Species is required"); |
| 35 | + |
| 36 | + // species exists - make sure it is valid |
| 37 | + Map<String, Object> row; |
| 38 | + UserSchema schema = QueryService.get().getUserSchema(u, c, "snprc_ehr"); |
| 39 | + TableInfo ti = schema.getTable("CurrentSpeciesLookup", schema.getDefaultContainerFilter()); |
| 40 | + SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("SpeciesCode"), newAnimalData.getSpecies(), CompareType.EQUAL); |
| 41 | + TableSelector ts = new TableSelector(ti, filter, null); |
| 42 | + row = ts.getMap(); |
| 43 | + //ts.getRowCount(); |
| 44 | + //if (ts.getRowCount() != 1) |
| 45 | + |
| 46 | + if (row == null || !row.get("speciesCode").toString().equals(newAnimalData.getSpecies())) |
| 47 | + throw new ValidationException("Invalid Species code entered:" + newAnimalData.getSpecies()); |
| 48 | + } |
| 49 | + catch (Exception e) |
| 50 | + { |
| 51 | + throw e; |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + // bdstatus |
| 56 | + if (newAnimalData.getBirthCode() == null) |
| 57 | + throw new ValidationException("Birthdate status is required"); |
| 58 | + // acquisitionType |
| 59 | + if (newAnimalData.getAcquisitionType() == null) |
| 60 | + throw new ValidationException("Acquisition type is required"); |
| 61 | + // gender |
| 62 | + if (newAnimalData.getGender() == null) |
| 63 | + throw new ValidationException("Gender is required"); |
| 64 | + // sire |
| 65 | + |
| 66 | + // dam |
| 67 | + |
| 68 | + // colony |
| 69 | + |
| 70 | + // animalAccount |
| 71 | + if (newAnimalData.getAnimalAccount() == null) |
| 72 | + throw new ValidationException("Animal Account is required"); |
| 73 | + // ownerInstitution |
| 74 | + if (newAnimalData.getOwnerInstitution() == null) |
| 75 | + throw new ValidationException("Owner Institution is required"); |
| 76 | + //responsibleInstitution |
| 77 | + if (newAnimalData.getResponsibleInstitution() == null) |
| 78 | + throw new ValidationException("Responsible Institution is required"); |
| 79 | + // room |
| 80 | + if (newAnimalData.getRoom() == null) |
| 81 | + throw new ValidationException("Room is required"); |
| 82 | + // cage |
| 83 | + |
| 84 | + // diet |
| 85 | + if (newAnimalData.getDiet() == null) |
| 86 | + throw new ValidationException("Diet is required"); |
| 87 | + // pedigree |
| 88 | + |
| 89 | + // IACUC |
| 90 | + if (newAnimalData.getIacuc() == null) |
| 91 | + throw new ValidationException("IACUC is required"); |
| 92 | + } |
| 93 | +} |
0 commit comments