001package org.hl7.fhir.dstu3.utils; 002 003/*- 004 * #%L 005 * org.hl7.fhir.dstu3 006 * %% 007 * Copyright (C) 2014 - 2019 Health Level 7 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023 024import java.util.ArrayList; 025import java.util.HashSet; 026import java.util.List; 027import java.util.Set; 028 029import org.hl7.fhir.dstu3.model.StructureDefinition; 030 031public class ValidationProfileSet { 032 033 public static class ProfileRegistration { 034 private String profile; 035 private boolean error; 036 037 public ProfileRegistration(String profile, boolean error) { 038 super(); 039 this.profile = profile; 040 this.error = error; 041 } 042 public String getProfile() { 043 return profile; 044 } 045 public boolean isError() { 046 return error; 047 } 048 049 050 } 051 private List<ProfileRegistration> canonical = new ArrayList<ProfileRegistration>(); 052 private List<StructureDefinition> definitions = new ArrayList<StructureDefinition>(); 053 054 public ValidationProfileSet(String profile, boolean isError) { 055 super(); 056 canonical.add(new ProfileRegistration(profile, isError)); 057 } 058 059 public ValidationProfileSet() { 060 super(); 061 } 062 063 public ValidationProfileSet(StructureDefinition profile) { 064 super(); 065 definitions.add(profile); 066 } 067 068 public ValidationProfileSet(List<String> profiles, boolean isError) { 069 super(); 070 if (profiles != null) 071 for (String p : profiles) 072 canonical.add(new ProfileRegistration(p, isError)); 073 } 074 075 public List<String> getCanonicalUrls() { 076 List<String> res = new ArrayList<String>(); 077 for (ProfileRegistration c : canonical) { 078 res.add(c.getProfile()); 079 } 080 return res; 081 } 082 083 public List<StructureDefinition> getDefinitions() { 084 return definitions; 085 } 086 087 public boolean empty() { 088 return canonical.isEmpty() && definitions.isEmpty(); 089 } 090 091 public List<String> getCanonicalAll() { 092 Set<String> res = new HashSet<String>(); 093 res.addAll(getCanonicalUrls()); 094 for (StructureDefinition sd : definitions) 095 res.add(sd.getUrl()); 096 return new ArrayList<String>(res); 097 } 098 099 public List<ProfileRegistration> getCanonical() { 100 return canonical; 101 } 102 103}