use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ADLImporter method execute.
private void execute() throws Exception {
// load config
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
// load ADL
builder = factory.newDocumentBuilder();
adl = builder.parse(new FileInputStream(source)).getDocumentElement();
check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
// create structure definition
StructureDefinition sd = new StructureDefinition();
sd.setId(id);
// populate metadata
Element description = XMLUtil.getNamedChild(adl, "description");
Element details = XMLUtil.getNamedChild(description, "details");
sd.setDescription(XMLUtil.getNamedChild(details, "purpose").getTextContent());
sd.setCopyright(XMLUtil.getNamedChild(details, "copyright").getTextContent());
sd.setPurpose("Use:\r\n" + XMLUtil.getNamedChild(details, "use").getTextContent() + "\r\n\r\nMisuse:\r\n" + XMLUtil.getNamedChild(details, "misuse").getTextContent());
List<Element> set = new ArrayList<Element>();
XMLUtil.getNamedChildren(details, "keywords", set);
for (Element e : set) sd.addKeyword().setDisplay(e.getTextContent());
String status = XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent();
if ("CommitteeDraft".equals(status) || "AuthorDraft".equals(status))
sd.setStatus(PublicationStatus.DRAFT);
else
throw new Exception("Unknown life cycle state " + XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent());
// load texts from ontology
Element ontology = XMLUtil.getNamedChild(adl, "ontology");
Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
set.clear();
XMLUtil.getNamedChildren(term_definitions, "items", set);
for (Element item : set) {
processTextItem(item);
}
// load data and protocol
Element definition = XMLUtil.getNamedChild(adl, "definition");
NodeTreeEntry root = new NodeTreeEntry();
root.setTypeName(XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent());
root.setAtCode(XMLUtil.getNamedChild(definition, "node_id").getTextContent());
root.setName(generateToken(root.getAtCode(), true));
sd.setName(root.getName());
root.setCardinality(readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences")));
set.clear();
XMLUtil.getNamedChildren(definition, "attributes", set);
for (Element item : set) {
// we're actually skipping this level - we don't care about data protocol etc.
// XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
Element attributes = item;
loadChildren(root.getAtCode(), root, attributes);
}
dumpChildren("", root);
genElements(sd, root.getName(), root);
// save
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
System.out.println("done. saved as " + dest);
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class LoincToDEConvertor method processLoincCodes.
private void processLoincCodes() {
Element row = XMLUtil.getFirstChild(xml.getDocumentElement());
int i = 0;
while (row != null) {
i++;
if (i % 1000 == 0)
System.out.print(".");
String code = col(row, "LOINC_NUM");
String comp = col(row, "COMPONENT");
DataElement de = new DataElement();
de.setId("loinc-" + code);
de.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
bundle.getEntry().add(new BundleEntryComponent().setResource(de));
Identifier id = new Identifier();
id.setSystem("http://hl7.org/fhir/commondataelement/loinc");
id.setValue(code);
de.addIdentifier(id);
de.setPublisher("Regenstrief + FHIR Project Team");
if (!col(row, "STATUS").equals("ACTIVE"))
// till we get good at this
de.setStatus(ConformanceResourceStatus.DRAFT);
else
de.setStatus(ConformanceResourceStatus.RETIRED);
de.setDateElement(DateTimeType.now());
de.setName(comp);
ElementDefinition dee = de.addElement();
// PROPERTY ignore
// TIME_ASPCT
// SYSTEM
// SCALE_TYP
// METHOD_TYP
// dee.getCategory().add(new CodeableConcept().setText(col(row, "CLASS")));
// SOURCE
// DATE_LAST_CHANGED - should be in ?
// CHNG_TYPE
dee.setComments(col(row, "COMMENTS"));
if (hasCol(row, "CONSUMER_NAME"))
dee.addAlias(col(row, "CONSUMER_NAME"));
// SURVEY_QUEST_SRC
if (hasCol(row, "RELATEDNAMES2")) {
String n = col(row, "RELATEDNAMES2");
for (String s : n.split("\\;")) {
if (!Utilities.noString(s))
dee.addAlias(s);
}
}
dee.addAlias(col(row, "SHORTNAME"));
// ORDER_OBS
// CDISC Code
// HL7_FIELD_SUBFIELD_ID
// ------------------ EXTERNAL_COPYRIGHT_NOTICE todo
dee.setDefinition(col(row, "LONG_COMMON_NAME"));
// HL7_V2_DATATYPE
String cc = makeType(col(row, "HL7_V3_DATATYPE"), code);
if (cc != null)
dee.addType().setCode(cc);
// todo... CURATED_RANGE_AND_UNITS
// todo: DOCUMENT_SECTION
// STATUS_REASON
// STATUS_TEXT
// CHANGE_REASON_PUBLIC
// COMMON_TEST_RANK
// COMMON_ORDER_RANK
// COMMON_SI_TEST_RANK
// HL7_ATTACHMENT_STRUCTURE
// units:
// UNITSREQUIRED
// SUBMITTED_UNITS
ToolingExtensions.setAllowableUnits(dee, makeUnits(col(row, "EXAMPLE_UNITS"), col(row, "EXAMPLE_UCUM_UNITS")));
// EXAMPLE_SI_UCUM_UNITS
row = XMLUtil.getNextSibling(row);
}
System.out.println("done");
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method expand.
@Override
public ValueSetExpansionOutcome expand(ValueSet source) {
try {
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
handleDefine(source, focus.getExpansion().getParameter());
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter());
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c))) {
focus.getExpansion().getContains().add(c);
}
}
return new ValueSetExpansionOutcome(focus, null);
} catch (Exception e) {
// that might fail too, but it might not, later.
return new ValueSetExpansionOutcome(new ValueSetCheckerSimple(source, factory, context), e.getMessage());
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeDocumentManifest.
protected void composeDocumentManifest(Complex parent, String parentType, String name, DocumentManifest element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeDomainResource(t, "DocumentManifest", name, element, index);
if (element.hasMasterIdentifier())
composeIdentifier(t, "DocumentManifest", "masterIdentifier", element.getMasterIdentifier(), -1);
for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "DocumentManifest", "identifier", element.getIdentifier().get(i), i);
if (element.hasSubject())
composeReference(t, "DocumentManifest", "subject", element.getSubject(), -1);
for (int i = 0; i < element.getRecipient().size(); i++) composeReference(t, "DocumentManifest", "recipient", element.getRecipient().get(i), i);
if (element.hasType())
composeCodeableConcept(t, "DocumentManifest", "type", element.getType(), -1);
for (int i = 0; i < element.getAuthor().size(); i++) composeReference(t, "DocumentManifest", "author", element.getAuthor().get(i), i);
if (element.hasCreatedElement())
composeDateTime(t, "DocumentManifest", "created", element.getCreatedElement(), -1);
if (element.hasSourceElement())
composeUri(t, "DocumentManifest", "source", element.getSourceElement(), -1);
if (element.hasStatusElement())
composeEnum(t, "DocumentManifest", "status", element.getStatusElement(), -1);
if (element.hasDescriptionElement())
composeString(t, "DocumentManifest", "description", element.getDescriptionElement(), -1);
for (int i = 0; i < element.getContent().size(); i++) composeDocumentManifestDocumentManifestContentComponent(t, "DocumentManifest", "content", element.getContent().get(i), i);
for (int i = 0; i < element.getRelated().size(); i++) composeDocumentManifestDocumentManifestRelatedComponent(t, "DocumentManifest", "related", element.getRelated().get(i), i);
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project org.hl7.fhir.core by hapifhir.
the class ValueSetExpanderSimple method expand.
@Override
public ValueSetExpansionOutcome expand(ValueSet source) {
try {
focus = source.copy();
focus.setExpansion(new ValueSet.ValueSetExpansionComponent());
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
if (source.hasCompose())
handleCompose(source.getCompose(), focus.getExpansion().getParameter());
for (ValueSetExpansionContainsComponent c : codes) {
if (map.containsKey(key(c))) {
focus.getExpansion().getContains().add(c);
}
}
return new ValueSetExpansionOutcome(focus, null);
} catch (RuntimeException e) {
// it swallows bugs.. what would be expected to be caught there?
throw e;
} catch (Exception e) {
// that might fail too, but it might not, later.
return new ValueSetExpansionOutcome(new ValueSetCheckerSimple(source, factory, context), e.getMessage());
}
}
Aggregations