/** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.eclipse.datatools.connectivity.oda.openmrs.impl; import java.util.logging.Logger; // TODO: Auto-generated Javadoc /** * This is a wrapper class for a token, which is comprised of a String name and * a datatype, represented as an int. Datatypes: Number | Meaning 2 | Decimal * (BigDecimal) 4 | Integer 8 | Double 12 | String 16 | Boolean 91 | Date 92 | * Time 93 | DateTime */ public class Token { private static Logger log = Logger.getLogger(Token.class.getName()); private static final int NUMERIC = 8, TEXT = 12, BOOLEAN = 16, DATETIME = 93, INTEGER = 4; private String name; private Integer type, precision, scale; private String modifiers = null; private String aggregate = null; private String aggregateValue = null; private boolean modified = false; private boolean splitObservationDate = false; private boolean splitEncounterDate = false; private boolean splitObservationLocation = false; private boolean splitEncounterType = false; /** * Checks if the token is modified. * * @return true, if the token is modified */ public boolean isModified() { return modified; } /** * Set to indicate that the token has been modifier. * * @param modified indicate whether or not the token is modified */ private void setModified(boolean modified) { this.modified = modified; } /** * Instantiates a new token. * * @param name the name * @param type the type */ public Token(String name, Integer type) { this(name, type, -1, -1); } /** * Instantiates a new token. * * @param name the name * @param type the type */ public Token(String name, String type) { this(name, type, -1, -1); } /** * Instantiates a new token. * * @param name the name * @param type the type * @param precision the precision * @param scale the scale */ public Token(String name, Integer type, Integer precision, Integer scale) { this.name = name; this.type = type; this.precision = precision; this.scale = scale; } /** * Instantiates a new token. * * @param name the name * @param type the type * @param precision the precision * @param scale the scale */ public Token(String name, String type, Integer precision, Integer scale) { this.name = name; if (type.equals("NULL")) this.type = TEXT; else if (type.equals("NUMERIC")) this.type = NUMERIC; else if (type.equals("DATETIME")) this.type = DATETIME; else if (type.equals("BOOLEAN")) this.type = BOOLEAN; else if (type.equals("INTEGER")) this.type = INTEGER; else this.type = TEXT; this.precision = precision; this.scale = scale; } /** * Gets the token name. * * @return the token name */ public String getName() { return name; } /** * Gets the token type. * * @return the token type */ public Integer getType() { return type; } /** * Gets the precision. * * @return the precision */ public Integer getPrecision() { return precision; } /** * Gets the scale. * * @return the scale */ public Integer getScale() { return scale; } /** * Gets the modifiers. * * @return the modifiers */ public String getModifiers() { return modifiers; } /** * Sets the modifiers. * * @param modifiers the modifiers for the token */ public void setModifiers(String modifiers) { if (!modifiers.equals("")) { log.info("Setting modifier: " + modifiers); setModified(true); this.modifiers = modifiers; } } /** * Checks if token is to be split by observation date. * * @return true, if token is split by observation date */ public boolean isSplitObservationDate() { return splitObservationDate; } /** * Sets if the token is to be split by observation date. * * @param splitDate indicates whether or not to split by observation date */ public void setSplitObservationDate(boolean splitDate) { this.splitObservationDate = splitDate; } /** * Checks if the token is to be split by encounter date. * * @return true, if token is split by encounter date */ public boolean isSplitEncounterDate() { return splitEncounterDate; } /** * Sets if the token is to be split by encounter date. * * @param splitEncounterDate indicates whether or not to split by encounter * date */ public void setSplitEncounterDate(boolean splitEncounterDate) { this.splitEncounterDate = splitEncounterDate; } /** * Checks if the token is to be split by observation location. * * @return true, if token is split by observation location */ public boolean isSplitObservationLocation() { return splitObservationLocation; } /** * Sets if the token is to be split by observation location. * * @param splitObservationLocation indicates whether or not to split by * observation location */ public void setSplitObservationLocation(boolean splitObservationLocation) { this.splitObservationLocation = splitObservationLocation; } /** * Checks if the token is to be split by encounter type. * * @return true, if token is split by encounter type */ public boolean isSplitEncounterType() { return splitEncounterType; } /** * Sets if the token is to be split by encounter type. * * @param splitEncounterType indicates whether or not to split by encounter * type */ public void setSplitEncounterType(boolean splitEncounterType) { this.splitEncounterType = splitEncounterType; } /** * Gets the token's aggregate. * * @return the aggregate */ public String getAggregate() { return aggregate; } /** * Sets the token's aggregate. * * @param aggregate the token's aggregate */ public void setAggregate(String aggregate) { this.aggregate = aggregate; } /** * Gets the aggregate value. * * @return the aggregate value */ public String getAggregateValue() { return aggregateValue; } /** * Sets the aggregate value. * * @param aggregateValue the new aggregate value */ public void setAggregateValue(String aggregateValue) { this.aggregateValue = aggregateValue; } }