Package uk.nhs.interoperability.payloads.helpers

Source Code of uk.nhs.interoperability.payloads.helpers.HelperUtils

/*
    Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
package uk.nhs.interoperability.payloads.helpers;

import java.util.List;

import uk.nhs.interoperability.payloads.CodedValue;
import uk.nhs.interoperability.payloads.exceptions.ParsePayloadContentException;
import uk.nhs.interoperability.payloads.vocabularies.VocabularyEntry;

public class HelperUtils {

  public static VocabularyEntry safelyMapCodedValueToVocabEntry(CodedValue codedEntry, VocabularyEntry vocab) {
    return safelyMapCodedValueToVocabEntry(codedEntry, vocab, null, null, false);
  }
 
  public static VocabularyEntry safelyMapCodedValueToVocabEntry(CodedValue codedEntry, VocabularyEntry vocab,
                    String fieldName, ParsePayloadContentException errors, boolean mandatory) {
    if (codedEntry == null) {
      if (mandatory) {
        if (errors != null) {
          errors.addParseError(fieldName, "This coded entry must be provided");
        }
      }
      return null;
    }
    VocabularyEntry entry = vocab.getByCode(codedEntry.getCode());
    if (entry.getOID().equals(codedEntry.getOID())) {
      return entry;
    } else {
      if (errors != null) {
        errors.addParseError(fieldName, "Coded value does not appear to be from correct vocabulary - expected OID:" + entry.getOID() + " but got OID:" + codedEntry.getOID());
      }
    }
    return null;
  }
 
  /**
   * Strips the prefix from telephone numbers (tel: or fax:)
   * @param input Telecom value to strip prefix from
   * @return Telephone number without prefix
   */
  public static String stripPrefixFromTelecom(String input) {
    int idx = input.indexOf(':');
    if (idx > -1) {
      return input.substring(idx+1);
    } else {
      return input;
    }
  }
 
  public static boolean isFax(String input) {
    return (input.startsWith("fax:"));
  }
 
  public static boolean isTel(String input) {
    return (input.startsWith("tel:"));
  }
}
TOP

Related Classes of uk.nhs.interoperability.payloads.helpers.HelperUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.