001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kim.api.identity.personal;
017    
018    import org.apache.commons.collections.CollectionUtils;
019    import org.apache.commons.lang.StringUtils;
020    import org.apache.log4j.Logger;
021    import org.joda.time.DateTime;
022    import org.joda.time.Years;
023    import org.kuali.rice.core.api.CoreConstants;
024    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
025    import org.kuali.rice.core.api.mo.ModelBuilder;
026    import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
027    import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
028    import org.kuali.rice.kim.api.KimConstants;
029    import org.w3c.dom.Element;
030    
031    import javax.xml.bind.annotation.XmlAccessType;
032    import javax.xml.bind.annotation.XmlAccessorType;
033    import javax.xml.bind.annotation.XmlAnyElement;
034    import javax.xml.bind.annotation.XmlElement;
035    import javax.xml.bind.annotation.XmlElementWrapper;
036    import javax.xml.bind.annotation.XmlRootElement;
037    import javax.xml.bind.annotation.XmlType;
038    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
039    import java.io.Serializable;
040    import java.text.ParseException;
041    import java.text.SimpleDateFormat;
042    import java.util.ArrayList;
043    import java.util.Collection;
044    import java.util.Collections;
045    import java.util.Date;
046    import java.util.List;
047    
048    @XmlRootElement(name = EntityBioDemographicsHistory.Constants.ROOT_ELEMENT_NAME)
049    @XmlAccessorType(XmlAccessType.NONE)
050    @XmlType(name = EntityBioDemographicsHistory.Constants.TYPE_NAME, propOrder = {
051        EntityBioDemographicsHistory.Elements.ENTITY_ID,
052        EntityBioDemographicsHistory.Elements.DECEASED_DATE,
053        EntityBioDemographicsHistory.Elements.BIRTH_DATE,
054        EntityBioDemographicsHistory.Elements.AGE,
055        EntityBioDemographicsHistory.Elements.GENDER_CODE,
056        EntityBioDemographicsHistory.Elements.GENDER_CHANGE_CODE,
057        EntityBioDemographicsHistory.Elements.MARITAL_STATUS_CODE,
058        EntityBioDemographicsHistory.Elements.PRIMARY_LANGUAGE_CODE,
059        EntityBioDemographicsHistory.Elements.SECONDARY_LANGUAGE_CODE,
060        EntityBioDemographicsHistory.Elements.BIRTH_COUNTRY,
061        EntityBioDemographicsHistory.Elements.BIRTH_STATE_PROVINCE_CODE,
062        EntityBioDemographicsHistory.Elements.BIRTH_CITY,
063        EntityBioDemographicsHistory.Elements.GEOGRAPHIC_ORIGIN,
064        EntityBioDemographicsHistory.Elements.BIRTH_DATE_UNMASKED,
065        EntityBioDemographicsHistory.Elements.GENDER_CODE_UNMASKED,
066        EntityBioDemographicsHistory.Elements.GENDER_CHANGE_CODE_UNMASKED,
067        EntityBioDemographicsHistory.Elements.MARITAL_STATUS_CODE_UNMASKED,
068        EntityBioDemographicsHistory.Elements.PRIMARY_LANGUAGE_CODE_UNMASKED,
069        EntityBioDemographicsHistory.Elements.SECONDARY_LANGUAGE_CODE_UNMASKED,
070        EntityBioDemographicsHistory.Elements.BIRTH_COUNTRY_UNMASKED,
071        EntityBioDemographicsHistory.Elements.BIRTH_STATE_PROVINCE_CODE_UNMASKED,
072        EntityBioDemographicsHistory.Elements.BIRTH_CITY_UNMASKED,
073        EntityBioDemographicsHistory.Elements.GEOGRAPHIC_ORIGIN_UNMASKED,
074        EntityBioDemographicsHistory.Elements.NOTE_MESSAGE,
075        EntityBioDemographicsHistory.Elements.SUPPRESS_PERSONAL,
076        EntityBioDemographicsHistory.Elements.DISABLED,
077        EntityBioDemographicsHistory.Elements.DISABILITIES,
078        EntityBioDemographicsHistory.Elements.VETERAN,
079        EntityBioDemographicsHistory.Elements.MILITARY_RECORDS,
080        CoreConstants.CommonElements.HISTORY_ID,
081        CoreConstants.CommonElements.ACTIVE_FROM_DATE,
082        CoreConstants.CommonElements.ACTIVE_TO_DATE,
083        CoreConstants.CommonElements.VERSION_NUMBER,
084        CoreConstants.CommonElements.OBJECT_ID,
085        CoreConstants.CommonElements.FUTURE_ELEMENTS
086    })
087    public final class EntityBioDemographicsHistory extends AbstractDataTransferObject
088        implements EntityBioDemographicsHistoryContract
089    {
090        private static final Logger LOG = Logger.getLogger(EntityBioDemographicsHistory.class);
091    
092        @XmlElement(name = Elements.ENTITY_ID, required = false)
093        private final String entityId;
094        @XmlElement(name = Elements.DECEASED_DATE, required = false)
095        private final String deceasedDate;
096        @XmlElement(name = Elements.BIRTH_DATE, required = false)
097        private final String birthDate;
098        @XmlElement(name = Elements.GENDER_CODE, required = false)
099        private final String genderCode;
100        @XmlElement(name = Elements.GENDER_CHANGE_CODE, required = false)
101        private final String genderChangeCode;
102        @XmlElement(name = Elements.MARITAL_STATUS_CODE, required = false)
103        private final String maritalStatusCode;
104        @XmlElement(name = Elements.PRIMARY_LANGUAGE_CODE, required = false)
105        private final String primaryLanguageCode;
106        @XmlElement(name = Elements.SECONDARY_LANGUAGE_CODE, required = false)
107        private final String secondaryLanguageCode;
108        @XmlElement(name = Elements.BIRTH_COUNTRY, required = false)
109        private final String birthCountry;
110        @XmlElement(name = Elements.BIRTH_STATE_PROVINCE_CODE, required = false)
111        private final String birthStateProvinceCode;
112        @XmlElement(name = Elements.BIRTH_CITY, required = false)
113        private final String birthCity;
114        @XmlElement(name = Elements.GEOGRAPHIC_ORIGIN, required = false)
115        private final String geographicOrigin;
116    
117        @XmlElement(name = Elements.BIRTH_DATE_UNMASKED, required = false)
118        private final String birthDateUnmasked;
119        @XmlElement(name = Elements.GENDER_CODE_UNMASKED, required = false)
120        private final String genderCodeUnmasked;
121        @XmlElement(name = Elements.GENDER_CHANGE_CODE_UNMASKED, required = false)
122        private final String genderChangeCodeUnmasked;
123        @XmlElement(name = Elements.MARITAL_STATUS_CODE_UNMASKED, required = false)
124        private final String maritalStatusCodeUnmasked;
125        @XmlElement(name = Elements.PRIMARY_LANGUAGE_CODE_UNMASKED, required = false)
126        private final String primaryLanguageCodeUnmasked;
127        @XmlElement(name = Elements.SECONDARY_LANGUAGE_CODE_UNMASKED, required = false)
128        private final String secondaryLanguageCodeUnmasked;
129        @XmlElement(name = Elements.BIRTH_COUNTRY_UNMASKED, required = false)
130        private final String birthCountryUnmasked;
131        @XmlElement(name = Elements.BIRTH_STATE_PROVINCE_CODE_UNMASKED, required = false)
132        private final String birthStateProvinceCodeUnmasked;
133        @XmlElement(name = Elements.BIRTH_CITY_UNMASKED, required = false)
134        private final String birthCityUnmasked;
135        @XmlElement(name = Elements.GEOGRAPHIC_ORIGIN_UNMASKED, required = false)
136        private final String geographicOriginUnmasked;
137    
138        @XmlElement(name = Elements.NOTE_MESSAGE, required = false)
139        private final String noteMessage;
140        @XmlElement(name = Elements.SUPPRESS_PERSONAL, required = false)
141        private final boolean suppressPersonal;
142    
143        @XmlElementWrapper(name = Elements.DISABILITIES, required = false)
144        @XmlElement(name = Elements.DISABILITY, required = false)
145        private final List<EntityDisabilityHistory> disabilities;
146        @XmlElementWrapper(name = Elements.MILITARY_RECORDS, required = false)
147        @XmlElement(name = Elements.MILITARY_RECORD, required = false)
148        private final List<EntityMilitaryHistory> militaryRecords;
149        @XmlElement(name = CoreConstants.CommonElements.HISTORY_ID, required = false)
150        private final Long historyId;
151        @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
152        @XmlJavaTypeAdapter(DateTimeAdapter.class)
153        private final DateTime activeFromDate;
154        @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
155        @XmlJavaTypeAdapter(DateTimeAdapter.class)
156        private final DateTime activeToDate;
157    
158        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
159        private final Long versionNumber;
160        @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
161        private final String objectId;
162        @SuppressWarnings("unused")
163        @XmlAnyElement
164        private final Collection<Element> _futureElements = null;
165    
166        /**
167         * Private constructor used only by JAXB.
168         *
169         */
170        private EntityBioDemographicsHistory() {
171            this.entityId = null;
172            this.deceasedDate = null;
173            this.birthDate = null;
174            this.genderCode = null;
175            this.genderChangeCode = null;
176            this.maritalStatusCode = null;
177            this.primaryLanguageCode = null;
178            this.secondaryLanguageCode = null;
179            this.birthCountry = null;
180            this.birthStateProvinceCode = null;
181            this.birthCity = null;
182            this.geographicOrigin = null;
183    
184            this.birthDateUnmasked = null;
185            this.genderCodeUnmasked = null;
186            this.genderChangeCodeUnmasked = null;
187            this.maritalStatusCodeUnmasked = null;
188            this.primaryLanguageCodeUnmasked = null;
189            this.secondaryLanguageCodeUnmasked = null;
190            this.birthCountryUnmasked = null;
191            this.birthStateProvinceCodeUnmasked = null;
192            this.birthCityUnmasked = null;
193            this.geographicOriginUnmasked = null;
194    
195            this.noteMessage = null;
196            this.militaryRecords = null;
197            this.disabilities = null;
198            this.suppressPersonal = false;
199            this.historyId = null;
200            this.activeFromDate = null;
201            this.activeToDate = null;
202            this.versionNumber = null;
203            this.objectId = null;
204        }
205    
206        private EntityBioDemographicsHistory(Builder builder) {
207            this.entityId = builder.getEntityId();
208            this.deceasedDate = builder.getDeceasedDate();
209            this.birthDate = builder.getBirthDate();
210            this.genderCode = builder.getGenderCode();
211            this.genderChangeCode = builder.getGenderChangeCode();
212            this.maritalStatusCode = builder.getMaritalStatusCode();
213            this.primaryLanguageCode = builder.getPrimaryLanguageCode();
214            this.secondaryLanguageCode = builder.getSecondaryLanguageCode();
215            this.birthCountry = builder.getBirthCountry();
216            this.birthStateProvinceCode = builder.getBirthStateProvinceCode();
217            this.birthCity = builder.getBirthCity();
218            this.geographicOrigin = builder.getGeographicOrigin();
219    
220            this.birthDateUnmasked = builder.getBirthDateUnmasked();
221            this.genderCodeUnmasked = builder.getGenderCodeUnmasked();
222            this.genderChangeCodeUnmasked = builder.getGenderChangeCodeUnmasked();
223            this.maritalStatusCodeUnmasked = builder.getMaritalStatusCodeUnmasked();
224            this.primaryLanguageCodeUnmasked = builder.getPrimaryLanguageCodeUnmasked();
225            this.secondaryLanguageCodeUnmasked = builder.getSecondaryLanguageCodeUnmasked();
226            this.birthCountryUnmasked = builder.getBirthCountryUnmasked();
227            this.birthStateProvinceCodeUnmasked = builder.getBirthStateProvinceCodeUnmasked();
228            this.birthCityUnmasked = builder.getBirthCityUnmasked();
229            this.geographicOriginUnmasked = builder.getGeographicOriginUnmasked();
230    
231            this.noteMessage = builder.getNoteMessage();
232            this.disabilities = new ArrayList<EntityDisabilityHistory>();
233            if (CollectionUtils.isNotEmpty(builder.getDisabilities())) {
234                for (EntityDisabilityHistory.Builder disability : builder.getDisabilities()) {
235                    this.disabilities.add(disability.build());
236                }
237            }
238    
239            this.militaryRecords = new ArrayList<EntityMilitaryHistory>();
240            if (CollectionUtils.isNotEmpty(builder.getMilitaryRecords())) {
241                for (EntityMilitaryHistory.Builder military : builder.getMilitaryRecords()) {
242                    this.militaryRecords.add(military.build());
243                }
244            }
245    
246            this.historyId = builder.getHistoryId();
247            this.activeFromDate = builder.getActiveFromDate();
248            this.activeToDate = builder.getActiveToDate();
249            this.suppressPersonal = builder.isSuppressPersonal();
250            this.versionNumber = builder.getVersionNumber();
251            this.objectId = builder.getObjectId();
252        }
253    
254        @Override
255        public String getEntityId() {
256            return this.entityId;
257        }
258    
259        @Override
260        public String getDeceasedDate() {
261            return this.deceasedDate;
262        }
263    
264        @Override
265        public String getBirthDate() {
266            return this.birthDate;
267        }
268    
269        @Override
270        @XmlElement(name = Elements.VETERAN, required = false)
271        public boolean isVeteran() {
272            return CollectionUtils.isNotEmpty(this.militaryRecords);
273        }
274    
275        @Override
276        @XmlElement(name = Elements.DISABLED, required = false)
277        public boolean isDisabled() {
278            return CollectionUtils.isNotEmpty(this.disabilities);
279        }
280    
281        @Override
282        @XmlElement(name = Elements.AGE, required = true)
283        public Integer getAge() {
284            return calculateAge(this.birthDate, this.deceasedDate, isSuppressPersonal());
285        }
286    
287        @Override
288        public String getGenderCode() {
289            return this.genderCode;
290        }
291    
292        @Override
293        public String getGenderChangeCode() {
294            return this.genderChangeCode;
295        }
296    
297        @Override
298        public String getMaritalStatusCode() {
299            return this.maritalStatusCode;
300        }
301    
302        @Override
303        public String getPrimaryLanguageCode() {
304            return this.primaryLanguageCode;
305        }
306    
307        @Override
308        public String getSecondaryLanguageCode() {
309            return this.secondaryLanguageCode;
310        }
311    
312        @Override
313        public String getBirthCountry() {
314            return this.birthCountry;
315        }
316    
317        @Override
318        public String getBirthStateProvinceCode() {
319            return this.birthStateProvinceCode;
320        }
321    
322        @Override
323        public String getBirthCity() {
324            return this.birthCity;
325        }
326    
327        @Override
328        public String getGeographicOrigin() {
329            return this.geographicOrigin;
330        }
331    
332        @Override
333        public String getBirthDateUnmasked() {
334            return this.birthDateUnmasked;
335        }
336    
337        @Override
338        public String getGenderCodeUnmasked() {
339            return this.genderCodeUnmasked;
340        }
341    
342        @Override
343        public String getGenderChangeCodeUnmasked() {
344            return this.genderChangeCodeUnmasked;
345        }
346    
347        @Override
348        public String getMaritalStatusCodeUnmasked() {
349            return this.maritalStatusCodeUnmasked;
350        }
351    
352        @Override
353        public String getPrimaryLanguageCodeUnmasked() {
354            return this.primaryLanguageCodeUnmasked;
355        }
356    
357        @Override
358        public String getSecondaryLanguageCodeUnmasked() {
359            return this.secondaryLanguageCodeUnmasked;
360        }
361    
362        @Override
363        public String getBirthCountryUnmasked() {
364            return this.birthCountryUnmasked;
365        }
366    
367        @Override
368        public String getBirthStateProvinceCodeUnmasked() {
369            return this.birthStateProvinceCodeUnmasked;
370        }
371    
372        @Override
373        public String getBirthCityUnmasked() {
374            return this.birthCityUnmasked;
375        }
376    
377        @Override
378        public String getGeographicOriginUnmasked() {
379            return this.geographicOriginUnmasked;
380        }
381    
382        @Override
383        public String getNoteMessage() {
384            return this.noteMessage;
385        }
386    
387        @Override
388        public boolean isSuppressPersonal() {
389            return this.suppressPersonal;
390        }
391    
392        @Override
393        public Long getVersionNumber() {
394            return this.versionNumber;
395        }
396    
397        @Override
398        public String getObjectId() {
399            return this.objectId;
400        }
401    
402        @Override
403        public List<EntityDisabilityHistory> getDisabilities() {
404            return Collections.unmodifiableList(this.disabilities);
405        }
406    
407        @Override
408        public List<EntityMilitaryHistory> getMilitaryRecords() {
409            return Collections.unmodifiableList(this.militaryRecords);
410        }
411    
412        @Override
413        public Long getHistoryId() {
414            return this.historyId;
415        }
416    
417        @Override
418        public DateTime getActiveFromDate() {
419            return this.activeFromDate;
420        }
421    
422        @Override
423        public DateTime getActiveToDate() {
424            return this.activeToDate;
425        }
426    
427        @Override
428        public boolean isActiveNow() {
429            return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
430        }
431    
432        @Override
433        public boolean isActive(DateTime activeAsOf) {
434            return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
435        }
436    
437        @Override
438        public boolean isActive() {
439            return isActiveNow();
440        }
441    
442    
443        /**
444         * Helper to parse the birth date for age calculation
445         * @param birthDate the birth date in EntityBioDemographicsContract BIRTH_DATE_FORMAT format
446         * @param deceasedDate the deceased date in EntityBioDemographicsContract DECEASED_DATE_FORMAT format
447         * @param suppressPersonal whether personal information is being suppressed
448         * @return the age in years or null if unavailable, suppressed, or an error occurs during calculation
449         */
450        private static Integer calculateAge(String birthDate, String deceasedDate, boolean suppressPersonal) {
451            if (birthDate != null && ! suppressPersonal) {
452                Date parsedBirthDate;
453                try {
454                    parsedBirthDate = new SimpleDateFormat(BIRTH_DATE_FORMAT).parse(birthDate);
455                } catch (ParseException pe) {
456                    LOG.error("Error parsing EntityBioDemographics birth date: '" + birthDate + "'", pe);
457                    return null;
458                }
459                DateTime endDate;
460                if (deceasedDate != null) {
461                    try {
462                       endDate = new DateTime(new SimpleDateFormat(BIRTH_DATE_FORMAT).parse(deceasedDate));
463                    } catch (ParseException pe) {
464                        LOG.error("Error parsing EntityBioDemographics deceased date: '" + deceasedDate+ "'", pe);
465                        return null;
466                    }
467                } else {
468                    endDate = new DateTime();
469                }
470                return Years.yearsBetween(new DateTime(parsedBirthDate), endDate).getYears();
471            }
472            return null;
473        }
474    
475        /**
476         * A builder which can be used to construct {@link org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsHistory} instances.  Enforces the constraints of the {@link org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsContract}.
477         * 
478         */
479        public final static class Builder
480            implements Serializable, ModelBuilder, EntityBioDemographicsHistoryContract
481        {
482    
483            private String entityId;
484            private String deceasedDate;
485            private String birthDate;
486            private String genderCode;
487            private String maritalStatusCode;
488            private String primaryLanguageCode;
489            private String secondaryLanguageCode;
490            private String birthCountry;
491            private String birthStateProvinceCode;
492            private String birthCity;
493            private String geographicOrigin;
494            private String genderChangeCode;
495            private String noteMessage;
496            private boolean suppressPersonal;
497            private List<EntityDisabilityHistory.Builder> disabilities;
498            private List<EntityMilitaryHistory.Builder> militaryRecords;
499            private Long versionNumber;
500            private String objectId;
501            private Long historyId;
502            private DateTime activeFromDate;
503            private DateTime activeToDate;
504    
505            private Builder(String entityId, String genderCode) {
506                setEntityId(entityId);
507                setGenderCode(genderCode);
508            }
509    
510            public static Builder create(String entityId, String genderCode) {
511                // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
512                return new Builder(entityId, genderCode);
513            }
514    
515            public static Builder create(EntityBioDemographicsHistoryContract contract) {
516                if (contract == null) {
517                    throw new IllegalArgumentException("contract was null");
518                }
519                Builder builder = create(contract.getEntityId(), contract.getGenderCode());
520                builder.setDeceasedDate(contract.getDeceasedDate());
521                builder.setBirthDate(contract.getBirthDate());
522                builder.setMaritalStatusCode(contract.getMaritalStatusCode());
523                builder.setPrimaryLanguageCode(contract.getPrimaryLanguageCode());
524                builder.setSecondaryLanguageCode(contract.getSecondaryLanguageCode());
525                builder.setBirthCountry(contract.getBirthCountry());
526                builder.setBirthStateProvinceCode(contract.getBirthStateProvinceCode());
527                builder.setBirthCity(contract.getBirthCity());
528                builder.setGeographicOrigin(contract.getGeographicOrigin());
529                builder.setGenderChangeCode(contract.getGenderChangeCode());
530                builder.setNoteMessage(contract.getNoteMessage());
531                builder.setSuppressPersonal(contract.isSuppressPersonal());
532                if (contract.getDisabilities() != null) {
533                    List<EntityDisabilityHistory.Builder> disabilities = new ArrayList<EntityDisabilityHistory.Builder>();
534                    for (EntityDisabilityHistoryContract disability : contract.getDisabilities()) {
535                        disabilities.add(EntityDisabilityHistory.Builder.create(disability));
536                    }
537                    builder.setDisabilities(disabilities);
538                }
539                if (contract.getMilitaryRecords() != null) {
540                    List<EntityMilitaryHistory.Builder> militaryRecs = new ArrayList<EntityMilitaryHistory.Builder>();
541                    for (EntityMilitaryHistoryContract military : contract.getMilitaryRecords()) {
542                        militaryRecs.add(EntityMilitaryHistory.Builder.create(military));
543                    }
544                    builder.setMilitaryRecords(militaryRecs);
545                }
546    
547                builder.setVersionNumber(contract.getVersionNumber());
548                builder.setObjectId(contract.getObjectId());
549                builder.setHistoryId(contract.getHistoryId());
550                builder.setActiveFromDate(contract.getActiveFromDate());
551                builder.setActiveToDate(contract.getActiveToDate());
552                return builder;
553            }
554    
555            public EntityBioDemographicsHistory build() {
556                return new EntityBioDemographicsHistory(this);
557            }
558    
559            @Override
560            public String getEntityId() {
561                return this.entityId;
562            }
563    
564            @Override
565            public String getDeceasedDate() {
566                return this.deceasedDate;
567            }
568    
569            @Override
570            public String getBirthDate() {
571                if (isSuppressPersonal()) {
572                    return KimConstants.RESTRICTED_DATA_MASK;
573                }
574                return this.birthDate;
575            }
576    
577            @Override
578            public Integer getAge() {
579                return calculateAge(this.birthDate, this.deceasedDate, isSuppressPersonal());
580            }
581    
582            @Override
583            public String getGenderCode() {
584                if (isSuppressPersonal()) {
585                    return KimConstants.RESTRICTED_DATA_MASK;
586                }
587                return this.genderCode;
588            }
589    
590            @Override
591            public String getGenderChangeCode() {
592                if (isSuppressPersonal()) {
593                    return KimConstants.RESTRICTED_DATA_MASK;
594                }
595                return this.genderChangeCode;
596            }
597    
598            @Override
599            public String getMaritalStatusCode() {
600                if (isSuppressPersonal()) {
601                    return KimConstants.RESTRICTED_DATA_MASK;
602                }
603                return this.maritalStatusCode;
604            }
605    
606            @Override
607            public String getPrimaryLanguageCode() {
608                if (isSuppressPersonal()) {
609                    return KimConstants.RESTRICTED_DATA_MASK;
610                }
611                return this.primaryLanguageCode;
612            }
613    
614            @Override
615            public String getSecondaryLanguageCode() {
616                if (isSuppressPersonal()) {
617                    return KimConstants.RESTRICTED_DATA_MASK;
618                }
619                return this.secondaryLanguageCode;
620            }
621    
622            @Override
623            public String getBirthCountry() {
624                if (isSuppressPersonal()) {
625                    return KimConstants.RESTRICTED_DATA_MASK;
626                }
627                return this.birthCountry;
628            }
629    
630            @Override
631            public String getBirthStateProvinceCode() {
632                if (isSuppressPersonal()) {
633                    return KimConstants.RESTRICTED_DATA_MASK;
634                }
635                return this.birthStateProvinceCode;
636            }
637    
638            @Override
639            public String getBirthCity() {
640                if (isSuppressPersonal()) {
641                    return KimConstants.RESTRICTED_DATA_MASK;
642                }
643                return this.birthCity;
644            }
645    
646            @Override
647            public String getGeographicOrigin() {
648                if (isSuppressPersonal()) {
649                    return KimConstants.RESTRICTED_DATA_MASK;
650                }
651                return this.geographicOrigin;
652            }
653    
654            @Override
655            public String getBirthDateUnmasked() {
656                return this.birthDate;
657            }
658    
659            @Override
660            public String getGenderCodeUnmasked() {
661                return this.genderCode;
662            }
663    
664            @Override
665            public String getGenderChangeCodeUnmasked() {
666                return this.genderChangeCode;
667            }
668    
669            @Override
670            public String getMaritalStatusCodeUnmasked() {
671                return this.maritalStatusCode;
672            }
673    
674            @Override
675            public String getPrimaryLanguageCodeUnmasked() {
676                return this.primaryLanguageCode;
677            }
678    
679            @Override
680            public String getSecondaryLanguageCodeUnmasked() {
681                return this.secondaryLanguageCode;
682            }
683    
684            @Override
685            public String getBirthCountryUnmasked() {
686                return this.birthCountry;
687            }
688    
689            @Override
690            public String getBirthStateProvinceCodeUnmasked() {
691                return this.birthStateProvinceCode;
692            }
693    
694            @Override
695            public String getBirthCityUnmasked() {
696                return this.birthCity;
697            }
698    
699            @Override
700            public String getGeographicOriginUnmasked() {
701                return this.geographicOrigin;
702            }
703    
704            @Override
705            public String getNoteMessage() {
706                return this.noteMessage;
707            }
708    
709            @Override
710            public boolean isSuppressPersonal() {
711                return this.suppressPersonal;
712            }
713    
714            @Override
715            public Long getVersionNumber() {
716                return this.versionNumber;
717            }
718    
719            @Override
720            public String getObjectId() {
721                return this.objectId;
722            }
723    
724            @Override
725            public boolean isVeteran() {
726                return CollectionUtils.isNotEmpty(this.militaryRecords);
727            }
728    
729            @Override
730            public boolean isDisabled() {
731                return CollectionUtils.isNotEmpty(this.disabilities);
732            }
733    
734            @Override
735            public List<EntityDisabilityHistory.Builder> getDisabilities() {
736                return this.disabilities;
737            }
738    
739            @Override
740            public List<EntityMilitaryHistory.Builder> getMilitaryRecords() {
741                return this.militaryRecords;
742            }
743    
744            @Override
745            public Long getHistoryId() {
746                return this.historyId;
747            }
748    
749            @Override
750            public boolean isActiveNow() {
751                return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
752            }
753    
754            @Override
755            public boolean isActive(DateTime activeAsOf) {
756                return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
757            }
758    
759            @Override
760            public boolean isActive() {
761                return isActiveNow();
762            }
763    
764            @Override
765            public DateTime getActiveFromDate() {
766                return this.activeFromDate;
767            }
768    
769            @Override
770            public DateTime getActiveToDate() {
771                return this.activeToDate;
772            }
773    
774            public void setHistoryId(Long historyId) {
775                this.historyId = historyId;
776            }
777    
778            public void setActiveFromDate(DateTime activeFromDate) {
779                this.activeFromDate = activeFromDate;
780            }
781    
782            public void setActiveToDate(DateTime activeToDate) {
783                this.activeToDate = activeToDate;
784            }
785    
786            public void setEntityId(String entityId) {
787                if (StringUtils.isEmpty(entityId)) {
788                    throw new IllegalArgumentException("id is empty");
789                }
790                this.entityId = entityId;
791            }
792    
793            public void setDeceasedDate(String deceasedDate) {
794                if (deceasedDate != null) {
795                    SimpleDateFormat format = new SimpleDateFormat(DECEASED_DATE_FORMAT);
796                    try{
797                        format.parse(deceasedDate);
798                        this.deceasedDate = deceasedDate;
799                    }
800                    catch(ParseException e) {
801                        throw new IllegalArgumentException("deceasedDate is not of the format 'yyyy-MM-DD'");
802                    }
803                }
804            }
805    
806            public void setBirthDate(String birthDate) {
807                if (birthDate != null) {
808                    SimpleDateFormat format = new SimpleDateFormat(BIRTH_DATE_FORMAT);
809                    try{
810                        format.parse(birthDate);
811                        this.birthDate = birthDate;
812                    }
813                    catch(ParseException e) {
814                        throw new IllegalArgumentException("birthDate is not of the format 'yyyy-MM-DD'");
815                    }
816                }
817            }
818    
819            public void setDeceasedDate(Date deceasedDate) {
820                this.deceasedDate = new SimpleDateFormat(DECEASED_DATE_FORMAT).format(deceasedDate);
821            }
822    
823            public void setBirthDate(Date birthDate) {
824                this.birthDate = new SimpleDateFormat(BIRTH_DATE_FORMAT).format(birthDate);
825            }
826    
827            public void setGenderCode(String genderCode) {
828                if (StringUtils.isEmpty(genderCode)) {
829                    throw new IllegalArgumentException("genderCode is empty");
830                }
831                this.genderCode = genderCode;
832            }
833    
834            public void setGenderChangeCode(String genderChangeCode) {
835                this.genderChangeCode = genderChangeCode;
836            }
837    
838            public void setMaritalStatusCode(String maritalStatusCode) {
839                this.maritalStatusCode = maritalStatusCode;
840            }
841    
842            public void setPrimaryLanguageCode(String primaryLanguageCode) {
843                this.primaryLanguageCode = primaryLanguageCode;
844            }
845    
846            public void setSecondaryLanguageCode(String secondaryLanguageCode) {
847                this.secondaryLanguageCode = secondaryLanguageCode;
848            }
849    
850            public void setBirthCountry(String birthCountry) {
851                this.birthCountry = birthCountry;
852            }
853    
854            public void setBirthStateProvinceCode(String birthStateProvinceCode) {
855                this.birthStateProvinceCode = birthStateProvinceCode;
856            }
857    
858            public void setBirthCity(String birthCity) {
859                this.birthCity = birthCity;
860            }
861    
862            public void setGeographicOrigin(String geographicOrigin) {
863                this.geographicOrigin = geographicOrigin;
864            }
865    
866            private void setNoteMessage(String noteMessage) {
867                this.noteMessage = noteMessage;
868            }
869    
870            private void setSuppressPersonal(boolean suppressPersonal) {
871                this.suppressPersonal = suppressPersonal;
872            }
873    
874            public void setVersionNumber(Long versionNumber) {
875                this.versionNumber = versionNumber;
876            }
877    
878            public void setObjectId(String objectId) {
879                this.objectId = objectId;
880            }
881    
882            public void setDisabilities(List<EntityDisabilityHistory.Builder> disabilities) {
883                this.disabilities = disabilities;
884            }
885    
886            public void setMilitaryRecords(List<EntityMilitaryHistory.Builder> militaryRecords) {
887                this.militaryRecords = militaryRecords;
888            }
889    
890        }
891    
892    
893        /**
894         * Defines some internal constants used on this class.
895         * 
896         */
897        static class Constants {
898    
899            final static String ROOT_ELEMENT_NAME = "entityBioDemographics";
900            final static String TYPE_NAME = "EntityBioDemographicsType";
901        }
902    
903    
904        /**
905         * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
906         * 
907         */
908        static class Elements {
909    
910            final static String ENTITY_ID = "entityId";
911            final static String DECEASED_DATE = "deceasedDate";
912            final static String BIRTH_DATE = "birthDate";
913            final static String AGE = "age";
914            final static String GENDER_CODE = "genderCode";
915            final static String MARITAL_STATUS_CODE = "maritalStatusCode";
916            final static String PRIMARY_LANGUAGE_CODE = "primaryLanguageCode";
917            final static String SECONDARY_LANGUAGE_CODE = "secondaryLanguageCode";
918            final static String BIRTH_COUNTRY = "birthCountry";
919            final static String BIRTH_STATE_PROVINCE_CODE = "birthStateProvinceCode";
920            final static String BIRTH_CITY = "birthCity";
921            final static String GEOGRAPHIC_ORIGIN = "geographicOrigin";
922            final static String BIRTH_DATE_UNMASKED = "birthDateUnmasked";
923            final static String GENDER_CODE_UNMASKED = "genderCodeUnmasked";
924            final static String MARITAL_STATUS_CODE_UNMASKED = "maritalStatusCodeUnmasked";
925            final static String PRIMARY_LANGUAGE_CODE_UNMASKED = "primaryLanguageCodeUnmasked";
926            final static String SECONDARY_LANGUAGE_CODE_UNMASKED = "secondaryLanguageCodeUnmasked";
927            final static String BIRTH_COUNTRY_UNMASKED = "birthCountryUnmasked";
928            final static String BIRTH_STATE_PROVINCE_CODE_UNMASKED = "birthStateProvinceCodeUnmasked";
929            final static String BIRTH_CITY_UNMASKED = "birthCityUnmasked";
930            final static String GEOGRAPHIC_ORIGIN_UNMASKED = "geographicOriginUnmasked";
931            final static String GENDER_CHANGE_CODE = "genderChangeCode";
932            final static String GENDER_CHANGE_CODE_UNMASKED = "genderChangeCodeUnmasked";
933            final static String NOTE_MESSAGE = "noteMessage";
934    
935            final static String DISABLED = "disabled";
936            final static String DISABILITIES = "disabilities";
937            final static String DISABILITY = "disability";
938            final static String VETERAN = "veteran";
939            final static String MILITARY_RECORDS = "militaryRecords";
940            final static String MILITARY_RECORD = "militaryRecord";
941    
942            final static String SUPPRESS_PERSONAL = "suppressPersonal";
943    
944        }
945    
946    }