Search in sources :

Example 46 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7PatientFHIRConversionTest method patientNameTest.

@Test
void patientNameTest() {
    String patientHasMiddleName = "MSH|^~\\&|MyEMR|DE-000001| |CAIRLO|20160701123030-0700||VXU^V04^VXU_V04|CA0001|P|2.6|||ER|AL|||||Z22^CDCPHINVS|DE-000001\r" + // PID 5 fields (name) are extracted and tested
    "PID|1||PA123456^^^MYEMR^MR||JONES^GEORGE^Q^III^MR^^B||||||||||||||||||||\r";
    Patient patientObjUsualName = PatientUtils.createPatientFromHl7Segment(ftv, patientHasMiddleName);
    java.util.List<org.hl7.fhir.r4.model.HumanName> name = patientObjUsualName.getName();
    List<StringType> givenName = name.get(0).getGiven();
    List<StringType> suffixes = name.get(0).getSuffix();
    assertThat(suffixes).hasSize(1);
    List<StringType> prefixes = name.get(0).getPrefix();
    assertThat(prefixes).hasSize(1);
    String fullName = name.get(0).getText();
    assertThat(prefixes.get(0).toString()).hasToString("MR");
    assertThat(givenName.get(0).toString()).hasToString("GEORGE");
    assertThat(givenName.get(1).toString()).hasToString("Q");
    assertThat(suffixes.get(0).toString()).hasToString("III");
    assertThat(fullName).isEqualTo("MR GEORGE Q JONES III");
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) StringType(org.hl7.fhir.r4.model.StringType) Patient(org.hl7.fhir.r4.model.Patient) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project VERDICT by ge-high-assurance.

the class VerdictSynthesis method performSynthesisMaxSmt.

/**
 * Perform synthesis using Z3 MaxSMT.
 *
 * @param tree
 * @param targetDal
 * @param factory
 * @return
 * @deprecated use the multi-requirement approach instead
 */
@Deprecated
public static Optional<Pair<Set<ComponentDefense>, Double>> performSynthesisMaxSmt(DTree tree, int targetDal, DLeaf.Factory factory) {
    Context context = new Context();
    Optimize optimizer = context.mkOptimize();
    Collection<ComponentDefense> pairs = factory.allComponentDefensePairs();
    int costLcd = normalizeCosts(pairs);
    for (ComponentDefense pair : pairs) {
        if (pair.dalToNormCost(targetDal) > 0) {
            // this id ("cover") doesn't matter but we have to specify something
            optimizer.AssertSoft(context.mkNot(pair.toZ3(context)), pair.dalToNormCost(targetDal), "cover");
        }
    }
    optimizer.Assert(tree.toZ3(context));
    if (optimizer.Check().equals(Status.SATISFIABLE)) {
        Set<ComponentDefense> output = new LinkedHashSet<>();
        int totalNormalizedCost = 0;
        Model model = optimizer.getModel();
        for (ComponentDefense pair : pairs) {
            Expr expr = model.eval(pair.toZ3(context), true);
            switch(expr.getBoolValue()) {
                case Z3_L_TRUE:
                    output.add(pair);
                    totalNormalizedCost += pair.dalToNormCost(targetDal);
                    break;
                case Z3_L_FALSE:
                    break;
                case Z3_L_UNDEF:
                default:
                    throw new RuntimeException("Synthesis: Undefined variable in output model: " + pair.toString());
            }
        }
        return Optional.of(new Pair<>(output, ((double) totalNormalizedCost) / costLcd));
    } else {
        System.err.println("Synthesis: SMT not satisfiable, perhaps there are unmitigatable attacks");
        return Optional.empty();
    }
}
Also used : Context(com.microsoft.z3.Context) LinkedHashSet(java.util.LinkedHashSet) BoolExpr(com.microsoft.z3.BoolExpr) ArithExpr(com.microsoft.z3.ArithExpr) Expr(com.microsoft.z3.Expr) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Model(com.microsoft.z3.Model) Optimize(com.microsoft.z3.Optimize)

Example 48 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project VERDICT by ge-high-assurance.

the class VerdictSynthesis method addExtraImplDefenses.

/**
 * Returns a new results instance with any extraneous defenses from the provided list added to
 * the results items liset as removals.
 *
 * @param results the input results to use as a baseline
 * @param implCompDefPairs the set of all implemented component-defense pairs
 * @param costModel the cost model
 * @return a new results instance with the extraneous defenses included
 */
public static ResultsInstance addExtraImplDefenses(ResultsInstance results, Map<com.ge.verdict.attackdefensecollector.Pair<String, String>, Integer> implCompDefPairs, CostModel costModel) {
    List<ResultsInstance.Item> items = new ArrayList<>(results.items);
    Fraction inputCost = results.inputCost;
    Fraction outputCost = results.outputCost;
    // find all of the pairs already in the defense tree
    Set<com.ge.verdict.attackdefensecollector.Pair<String, String>> accountedCompDefPairs = results.items.stream().map(item -> new com.ge.verdict.attackdefensecollector.Pair<>(item.component, item.defenseProperty)).collect(Collectors.toSet());
    for (Map.Entry<com.ge.verdict.attackdefensecollector.Pair<String, String>, Integer> entry : implCompDefPairs.entrySet()) {
        // only add if not already accounted for
        if (!accountedCompDefPairs.contains(entry.getKey())) {
            String comp = entry.getKey().left;
            String defProp = entry.getKey().right;
            int implDal = entry.getValue();
            // compute cost of the implemented pair
            Fraction pairInputCost = costModel.cost(defProp, comp, implDal);
            Fraction pairOutputCost = costModel.cost(defProp, comp, 0);
            // the item will be a removal, so from implDal -> 0 DAL
            items.add(new ResultsInstance.Item(comp, defProp, implDal, 0, pairInputCost, pairOutputCost));
            inputCost = inputCost.add(pairInputCost);
            // this may seem silly, but in theory we can have a non-zero cost for DAL 0
            outputCost = outputCost.add(pairOutputCost);
        }
    }
    return new ResultsInstance(results.partialSolution, results.meritAssignment, results.inputSat, inputCost, outputCost, items);
}
Also used : IntStream(java.util.stream.IntStream) Optimize(com.microsoft.z3.Optimize) Context(com.microsoft.z3.Context) Formula(org.logicng.formulas.Formula) Assignment(org.logicng.datastructures.Assignment) MaxSATSolver(org.logicng.solvers.MaxSATSolver) RatNum(com.microsoft.z3.RatNum) ArrayList(java.util.ArrayList) Map(java.util.Map) FormulaFactory(org.logicng.formulas.FormulaFactory) BoolExpr(com.microsoft.z3.BoolExpr) Status(com.microsoft.z3.Status) DTree(com.ge.verdict.synthesis.dtree.DTree) ArithExpr(com.microsoft.z3.ArithExpr) LinkedHashSet(java.util.LinkedHashSet) DLeaf(com.ge.verdict.synthesis.dtree.DLeaf) PrintWriter(java.io.PrintWriter) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) ComponentDefense(com.ge.verdict.synthesis.dtree.DLeaf.ComponentDefense) Model(com.microsoft.z3.Model) List(java.util.List) Fraction(org.apache.commons.math3.fraction.Fraction) ArithmeticUtils(org.apache.commons.math3.util.ArithmeticUtils) Pair(com.ge.verdict.synthesis.util.Pair) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Expr(com.microsoft.z3.Expr) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ArrayList(java.util.ArrayList) Fraction(org.apache.commons.math3.fraction.Fraction) ResultsInstance(com.ge.verdict.vdm.synthesis.ResultsInstance) Map(java.util.Map) Pair(com.ge.verdict.synthesis.util.Pair)

Example 49 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project modello by codehaus-plexus.

the class PackageVersionVerifier method testModelAddMailingList.

public void testModelAddMailingList() {
    Model model = new Model();
    model.addMailingList(createMailingList(0));
    model.addMailingList(createMailingList(1));
    model.addMailingList(createMailingList(2));
    List actual = model.getMailingLists();
    Assert.assertEquals("/model/mailinglists.size", 3, actual.size());
    for (int i = 0; i < 3; i++) {
        assertMailingList(createMailingList(i), (MailingList) actual.get(i));
    }
}
Also used : Model(org.apache.maven.model.v4_0_0.Model) List(java.util.List) MailingList(org.apache.maven.model.v4_0_0.MailingList) ArrayList(java.util.ArrayList)

Example 50 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model in project cqf-ruler by DBCG.

the class CompositionSectionComponentBuilder method initializeDstu2_1.

@Override
protected void initializeDstu2_1(T theResource) {
    super.initializeDstu2_1(theResource);
    org.hl7.fhir.dstu2016may.model.Composition.SectionComponent section = (org.hl7.fhir.dstu2016may.model.Composition.SectionComponent) theResource;
    section.setTitle(myTitle).setId(getId());
    getEntries().forEach(entry -> section.addEntry(new Reference(entry)));
    if (myText != null) {
        Narrative narrative = new Narrative();
        narrative.setStatusAsString(myText.getStatus());
        narrative.setDivAsString(myText.getText());
        section.setText(narrative);
    }
// no focus
}
Also used : Narrative(org.hl7.fhir.dstu2016may.model.Narrative) Reference(org.hl7.fhir.dstu2016may.model.Reference)

Aggregations

Test (org.junit.jupiter.api.Test)435 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)289 ArrayList (java.util.ArrayList)112 FHIRException (org.hl7.fhir.exceptions.FHIRException)111 IOException (java.io.IOException)84 List (java.util.List)73 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)66 File (java.io.File)61 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 InputStream (java.io.InputStream)55 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Bundle (org.hl7.fhir.dstu3.model.Bundle)49 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Collectors (java.util.stream.Collectors)48 Arrays (java.util.Arrays)46