use of org.hl7.fhir.r4.model.Type in project tdi-studio-se by Talend.
the class HL7MessageTreeLabelProvider method getColumnText.
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Type) {
Type datatype = (Type) element;
return datatype.getName();
}
if (element instanceof IModel) {
if (element instanceof TypeModel) {
TypeModel tm = (TypeModel) element;
allPrimitives.addAll(Arrays.asList(tm.getPrimitives()));
}
return ((IModel) element).getDisplayName();
}
// }
if (element instanceof Group) {
Group group = (Group) element;
String groupName = group.getName();
groupName = groupName.substring(groupName.lastIndexOf('.') + 1, groupName.length());
return groupName;
}
if (element instanceof Structure) {
Structure structure = (Structure) element;
return structure.getName();
}
return null;
}
use of org.hl7.fhir.r4.model.Type in project tdi-studio-se by Talend.
the class TypeModel method getComponent.
private Type getComponent(Type type, int comp) {
Type ret = null;
if (Varies.class.isAssignableFrom(type.getClass())) {
Varies v = (Varies) type;
try {
if (comp > 1 && GenericPrimitive.class.isAssignableFrom(v.getData().getClass())) {
v.setData(new GenericComposite(v.getMessage()));
}
} catch (DataTypeException de) {
String message = "Unexpected exception copying data to generic composite: " + de.getMessage();
throw new Error(message);
}
ret = getComponent(v.getData(), comp);
} else {
if (Primitive.class.isAssignableFrom(type.getClass()) && comp == 1) {
ret = type;
} else if (GenericComposite.class.isAssignableFrom(type.getClass()) || (Composite.class.isAssignableFrom(type.getClass()) && comp <= numStandardComponents(type))) {
try {
ret = ((Composite) type).getComponent(comp - 1);
} catch (Exception e) {
throw new Error("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e);
}
} else {
ret = type.getExtraComponents().getComponent(comp - numStandardComponents(type) - 1);
}
}
return ret;
}
use of org.hl7.fhir.r4.model.Type in project tdi-studio-se by Talend.
the class SegmentModel method generateDataTypes.
private void generateDataTypes() {
int number = this.seg.numFields();
ArrayList<TypeModel> datatypes = new ArrayList<TypeModel>();
Method method = null;
try {
for (Method curMethod : seg.getClass().getDeclaredMethods()) {
if (curMethod.getName().equals("createNewTypeWithoutReflection")) {
method = curMethod;
method.setAccessible(true);
break;
}
}
if (method != null) {
// so add test of null in case this method doesn't exist, even if it should be in every subclass.
for (int i = 0; i < number; i++) {
Type type = (Type) method.invoke(seg, i);
TypeModel tm = new TypeModel(type, seg, 0, i + 1);
datatypes.add(tm);
}
}
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (method == null) {
// but it means it won't get optional fields.
try {
int lastNotEmptyFiledIndex = 0;
for (int i = 1; i < number; i++) {
Type[] reps = seg.getField(i);
if (reps.length > 0) {
lastNotEmptyFiledIndex = i;
}
}
for (int i = 1; i <= lastNotEmptyFiledIndex; i++) {
Type[] reps = seg.getField(i);
if (reps.length > 0) {
for (int j = 0; j < reps.length; j++) {
TypeModel tm = new TypeModel(reps[j], seg, j, i);
datatypes.add(tm);
}
} else {
// for empty column
TypeModel tm = new TypeModel(null, seg, 0, i);
datatypes.add(tm);
}
}
} catch (HL7Exception e) {
e.printStackTrace();
}
}
this.types = datatypes.toArray(new TypeModel[0]);
}
use of org.hl7.fhir.r4.model.Type in project tdi-studio-se by Talend.
the class TypeModel method getPrimitive.
public Primitive getPrimitive(Type type, int component, int subcomponent) {
Type comp = getComponent(type, component);
Type sub = getComponent(comp, subcomponent);
return getPrimitive(sub);
}
use of org.hl7.fhir.r4.model.Type in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method valiateGender.
private void valiateGender(Patient patient) {
AdministrativeGender gender = patient.getGender();
if (gender != null) {
EnumSet<AdministrativeGender> genderList = EnumSet.allOf(AdministrativeGender.class);
Boolean valid = false;
for (AdministrativeGender genderItem : genderList) {
if (genderItem.toCode().equalsIgnoreCase(gender.toString())) {
valid = true;
break;
}
}
if (!valid) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("The supplied Patient gender %s is an unrecognised type.", gender)), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
}
}
Aggregations