use of io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplateAttributes in project hl7v2-fhir-converter by LinuxForHealth.
the class ResourceReader method getMessageModel.
private HL7MessageModel getMessageModel(String templateName) {
// Allow for names that already have .yml extension
String yamlizedTemplateName = templateName.endsWith(".yml") ? templateName : templateName + ".yml";
String templateFileContent = getResourceInHl7Folder(Constants.MESSAGE_BASE_PATH + yamlizedTemplateName);
if (StringUtils.isNotBlank(templateFileContent)) {
try {
JsonNode parent = ObjectMapperUtil.getYAMLInstance().readTree(templateFileContent);
Preconditions.checkState(parent != null, "Parent node from template file cannot be null");
JsonNode resourceNodes = parent.get("resources");
Preconditions.checkState(resourceNodes != null && !resourceNodes.isEmpty(), "List of resources from Parent node from template file cannot be null or empty");
List<HL7FHIRResourceTemplateAttributes> templateAttributes = ObjectMapperUtil.getYAMLInstance().convertValue(resourceNodes, new TypeReference<List<HL7FHIRResourceTemplateAttributes>>() {
});
List<HL7FHIRResourceTemplate> templates = new ArrayList<>();
templateAttributes.forEach(t -> templates.add(new HL7FHIRResourceTemplate(t)));
Preconditions.checkState(templateAttributes != null && !templateAttributes.isEmpty(), "TemplateAttributes generated from template file cannot be null or empty");
return new HL7MessageModel(templateName, templates);
} catch (IOException e) {
throw new IllegalArgumentException("Error encountered in processing the template" + templateName, e);
}
} else {
throw new IllegalArgumentException("File not present:" + templateName);
}
}
use of io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplateAttributes in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_observation_condition.
@Test
void test_observation_condition() throws IOException {
ResourceModel obsModel = ResourceReader.getInstance().generateResourceModel("resource/Observation");
HL7FHIRResourceTemplateAttributes attributesObs = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Observation").withResourceModel(obsModel).withSegment(".PROBLEM_OBSERVATION.OBX").withIsReferenced(true).withRepeats(true).withGroup("PROBLEM").build();
HL7FHIRResourceTemplate obsTemplate = new HL7FHIRResourceTemplate(attributesObs);
ResourceModel condModel = ResourceReader.getInstance().generateResourceModel("resource/Condition");
HL7FHIRResourceTemplateAttributes attributesCond = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("Condition").withResourceModel(condModel).withSegment(".PRB").withIsReferenced(false).withRepeats(true).withGroup("PROBLEM").build();
HL7FHIRResourceTemplate conditionTemplate = new HL7FHIRResourceTemplate(attributesCond);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(obsTemplate, conditionTemplate));
String hl7message = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|200603081747|security|PPR^PC1^PPR_PC1|1|P^I|2.6||||||ASCII||\r" + "PID|||555444222111^^^MPI&GenHosp&L^MR||james^anderson||19600614|M||C|99 Oakland #106^^qwerty^OH^44889||^^^^^626^5641111|^^^^^626^5647654|||||343132266|||N\r" + "PV1||I|6N^1234^A^GENHOS||||0100^ANDERSON^CARL|0148^ADDISON^JAMES||SUR|||||||0148^ANDERSON^CARL|S|1400|A|||||||||||||||||||SF|K||||199501102300\r" + "PRB|AD|200603150625|aortic stenosis|53692||2||200603150625\r" + "NTE|1|P|Problem Comments\r" + "VAR|varid1|200603150610\r" + // Two observation records
"OBX|1|ST|0135-4^TotalProtein||6.4|gm/dl|5.9-8.4||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F|\r" + "OBX|2|ST|0135-4^TotalProtein||7.8|gm/dl|5.9-8.4||||F|||||2740^Tsadok^Janetary~2913^Merrit^Darren^F|\r";
String json = message.convert(hl7message, engine);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> observationResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(observationResource).hasSize(2);
List<String> ids = observationResource.stream().map(m -> m.getId()).collect(Collectors.toList());
List<Resource> conditionResource = e.stream().filter(v -> ResourceType.Condition == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(conditionResource).hasSize(1);
Condition cond = ResourceUtils.getResourceCondition(conditionResource.get(0), context);
List<ConditionEvidenceComponent> evidences = cond.getEvidence();
assertThat(evidences).hasSize(2);
assertThat(evidences.get(0).hasDetail()).isTrue();
assertThat(evidences.get(0).getDetail().get(0).getReference()).isIn(ids);
assertThat(evidences.get(1).getDetail().get(0).getReference()).isIn(ids);
assertThat(evidences.get(0).getDetail().get(0).getReference()).isNotEqualTo(evidences.get(1).getDetail().get(0).getReference());
}
Aggregations