Search in sources :

Example 1 with HL7FHIRResourceTemplateAttributes

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);
    }
}
Also used : HL7MessageModel(io.github.linuxforhealth.hl7.message.HL7MessageModel) HL7FHIRResourceTemplateAttributes(io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplateAttributes) HL7FHIRResourceTemplate(io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplate) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 2 with HL7FHIRResourceTemplateAttributes

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());
}
Also used : Specimen(org.hl7.fhir.r4.model.Specimen) Logger(org.slf4j.Logger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) Resource(org.hl7.fhir.r4.model.Resource) IOException(java.io.IOException) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Collectors(java.util.stream.Collectors) ResourceReader(io.github.linuxforhealth.hl7.resource.ResourceReader) Test(org.junit.jupiter.api.Test) Encounter(org.hl7.fhir.r4.model.Encounter) ResourceType(org.hl7.fhir.r4.model.ResourceType) List(java.util.List) Lists(com.google.common.collect.Lists) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceUtils(io.github.linuxforhealth.hl7.segments.util.ResourceUtils) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) ResourceModel(io.github.linuxforhealth.api.ResourceModel) FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) Observation(org.hl7.fhir.r4.model.Observation) Condition(org.hl7.fhir.r4.model.Condition) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceModel(io.github.linuxforhealth.api.ResourceModel) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)2 List (java.util.List)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Lists (com.google.common.collect.Lists)1 ResourceModel (io.github.linuxforhealth.api.ResourceModel)1 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)1 HL7FHIRResourceTemplate (io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplate)1 HL7FHIRResourceTemplateAttributes (io.github.linuxforhealth.hl7.message.HL7FHIRResourceTemplateAttributes)1 HL7MessageModel (io.github.linuxforhealth.hl7.message.HL7MessageModel)1 ResourceReader (io.github.linuxforhealth.hl7.resource.ResourceReader)1 ResourceUtils (io.github.linuxforhealth.hl7.segments.util.ResourceUtils)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)1 Condition (org.hl7.fhir.r4.model.Condition)1 ConditionEvidenceComponent (org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent)1 Encounter (org.hl7.fhir.r4.model.Encounter)1