ca.uhn.fhir.model.dstu2.resource.Patient Java Examples

The following examples show how to use ca.uhn.fhir.model.dstu2.resource.Patient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WrongServiceRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceCallInRHS() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();

    kSession.setGlobal("myConditionsProviderService", new MyConditionsProviderServiceImpl());
    System.out.println(" ---- Starting testServiceCallInRHS() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    FactHandle patientHandle = kSession.insert(patient);

    Assert.assertEquals(50, kSession.fireAllRules());
    
    //A modification of the patient will execute the service 
    patient.addName(new HumanNameDt().addFamily("Richards"));
    kSession.update(patientHandle, patient);
    Assert.assertEquals(50, kSession.fireAllRules());
    
    System.out.println(" ---- Finished testServiceCallInRHS() Test ---");
    kSession.dispose();
}
 
Example #2
Source File: CrossProductRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatientWith3Observations() {
    Assert.assertNotNull(kBaseCrossProduct);
    KieSession kSession = kBaseCrossProduct.newKieSession();
    System.out.println(" ---- Starting testPatientWith3Observations() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    
    Observation observation1 = (Observation) new Observation().setId("Observation/1");
    observation1.setSubject(new ResourceReferenceDt(patient));
    
    Observation observation2 = (Observation) new Observation().setId("Observation/2");
    observation2.setSubject(new ResourceReferenceDt(patient));
    
    Observation observation3 = (Observation) new Observation().setId("Observation/3");
    observation3.setSubject(new ResourceReferenceDt(patient));

    kSession.insert(patient);
    kSession.insert(observation1);
    kSession.insert(observation2);
    kSession.insert(observation3);

    Assert.assertEquals(3, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientWith3Observations() Test ---");
    kSession.dispose();
}
 
Example #3
Source File: NonFactsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testObservationAndPatient() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testObservationAndPatient() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    kSession.insert(patient);
    
    Observation observation = (Observation) new Observation().setId("Observation/1");
    kSession.insert(observation);

    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testObservationAndPatient() Test ---");
    kSession.dispose();
}
 
Example #4
Source File: NonFactsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testObservationAndPatientRelated() {
    
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testObservationAndPatientRelated() Test ---");
    
    Patient patient = (Patient) new Patient().setId("Patient/1");
    Observation observation = (Observation) new Observation().setId("Observation/1");
    observation.setSubject(new ResourceReferenceDt(patient));
    kSession.insert(observation);

    Assert.assertEquals(0, kSession.fireAllRules());
    System.out.println(" ---- Finished testObservationAndPatientRelated() Test ---");
    kSession.dispose();
    
}
 
Example #5
Source File: MultiConditionRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatientAndAnObservation() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testPatientAndAnObservation() Test ---");
    
    kSession.insert(new Patient()
        .setId("Patient/1")
    );
    kSession.insert(new Observation()
        .setId("Observation/1")
    );
    
    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientAndAnObservation() Test ---");
    kSession.dispose();
}
 
Example #6
Source File: MultiConditionRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPatientAndAnRelatedObservation() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testRoomAndHouseRelated() Test ---");
    
    Patient patient = (Patient) new Patient().setId("Patient/1");
    kSession.insert(patient);
    kSession.insert(new Observation()
        .setSubject(new ResourceReferenceDt(patient))
        .setId("Observation/1")
    );

    Assert.assertEquals(2, kSession.fireAllRules());
    System.out.println(" ---- Finished testRoomAndHouseRelated() Test ---");
    kSession.dispose();
}
 
Example #7
Source File: UsingGlobalsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceInAGlobal() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();

    kSession.setGlobal("myService", new MyServiceImpl());
    System.out.println(" ---- Starting testServiceInAGlobal() Test ---");
    
    Patient patient = (Patient) new Patient()
        .setId("Patient/1");
    Condition condition = createAsthmaCondition(patient, "Condition/1");
    kSession.insert(patient);
    kSession.insert(condition);

    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testServiceInAGlobal() Test ---");
    kSession.dispose();
}
 
Example #8
Source File: UsingGlobalsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void testUsingGlobalToTrackRulesFiring() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    List<String> rulesFired = new ArrayList<>();
    kSession.setGlobal("rulesFired", rulesFired);
    System.out.println(" ---- Starting testUsingGlobalToTrackRulesFiring() Test ---");

    Patient patient = (Patient) new Patient()
        .setId("Patient/1");
    Condition condition = createDiabetesCondition(patient, "Condition/1");
    kSession.insert(patient);
    kSession.insert(condition);

    Assert.assertEquals(1, kSession.fireAllRules());
    Assert.assertTrue(rulesFired.contains("Identify Diabetic Patients"));
    
    System.out.println(" ---- Finished testUsingGlobalToTrackRulesFiring() Test ---");
    kSession.dispose();
}
 
Example #9
Source File: AccumulationRulesJUnitTest.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
@Test
public void test20PatientsInALocation() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting test20PatientsInALocation() Test ---");
    
    Location location = (Location) new FixedCapacityLocation()
        .setCapacity(15)
        .setId("Location/1");
    
    List<Patient> patients = generatePatients(20);
    for(Patient p : patients){
        kSession.insert(p);
    }
    kSession.insert(location);

    Assert.assertEquals(1, kSession.fireAllRules());
    
    System.out.println(" ---- Finished test20PatientsInALocation() Test ---");
    kSession.dispose();
}
 
Example #10
Source File: SimpleConditionsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatientRulesWithAPatientFromLondonFrom82() {
    Assert.assertNotNull(kSession);
    System.out.println(" ---- Starting testPatientRulesWithAPatientFromLondonFrom82() Test ---");
    kSession.insert(new Patient()
        .setBirthDateWithDayPrecision(parseDate("1982-01-01"))
        .setGender(AdministrativeGenderEnum.MALE)
        .addAddress(new AddressDt().setCity("London"))
        .setId("Patient/1")
    );

    Assert.assertEquals(4, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientRulesWithAPatientFromLondonFrom82() Test ---");
}
 
Example #11
Source File: ExampleServerDstu2IT.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAndRead() {
	ourLog.info("Base URL is: " +  HapiProperties.getServerAddress());
	String methodName = "testCreateResourceConditional";

	Patient pt = new Patient();
	pt.addName().addFamily(methodName);
	IIdType id = ourClient.create().resource(pt).execute().getId();

	Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
	assertEquals(methodName, pt2.getName().get(0).getFamily().get(0).getValue());
}
 
Example #12
Source File: SimpleConditionsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatientRulesWithAPatientFrom82() {
    Assert.assertNotNull(kSession);
    System.out.println(" ---- Starting testPatientRulesWithAnPatientFrom82() Test ---");
    kSession.insert(new Patient()
        .setBirthDateWithDayPrecision(parseDate("1982-01-01"))
        .setId("Patient/1")
    );

    Assert.assertEquals(2, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientRulesWithAnPatientFrom82() Test ---");
}
 
Example #13
Source File: SimpleConditionsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatientRulesWithJustAPatient() {
    Assert.assertNotNull(kSession);
    System.out.println(" ---- Starting testPatientRulesWithJustAPatient() Test ---");

    kSession.insert(new Patient().setId("Patient/1"));
    
    Assert.assertEquals(1, kSession.fireAllRules());
    System.out.println(" ---- Finished testPatientRulesWithJustAPatient() Test ---");
}
 
Example #14
Source File: UsingGlobalsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private Condition createDiabetesCondition(Patient patient, String id) {
    return (Condition) new Condition()
        .setCode(new CodeableConceptDt("http://snomed.info/sct", "73211009")) //Diabetes mellitus (disorder)
        .setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE)
        .setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED)
        .setPatient(new ResourceReferenceDt(patient))
        .setId(id);
}
 
Example #15
Source File: UsingGlobalsRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private Condition createAsthmaCondition(Patient patient, String id) {
    return (Condition) new Condition()
        .setCode(new CodeableConceptDt("http://snomed.info/sct", "195967001")) //Asthma (disorder)
        .setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE)
        .setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED)
        .setPatient(new ResourceReferenceDt(patient))
        .setId(id);
}
 
Example #16
Source File: AccumulationRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private List<Patient> generatePatients(int amount) {
    List<Patient> results = new ArrayList<>();
    for (int i = 0; i < amount; i++) {
        results.add((Patient) new Patient()
            .setId("Patient/"+(i+1)));
    }
    return results;
}
 
Example #17
Source File: SimpleInferenceRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private Condition createAsthmaCondition(Patient patient, String id, Severity severity ){
    return (Condition) new Condition()
        .setCode(new CodeableConceptDt("http://snomed.info/sct", "195967001"))
        .setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE)
        .setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED)
        .setSeverity(new CodeableConceptDt("http://snomed.info/sct", severity.code))
        .setPatient(new ResourceReferenceDt(patient))
        .setId(id);
}
 
Example #18
Source File: SimpleInferenceRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void testFemaleSevereAsthmaticPatient() {
    Assert.assertNotNull(kBase);
    KieSession kSession = kBase.newKieSession();
    System.out.println(" ---- Starting testFemaleSevereAsthmaticPatient() Test ---");
    
    //Female, Mild Asthmatic Patient
    Patient patient1 = (Patient) new Patient()
        .setGender(AdministrativeGenderEnum.FEMALE)
        .setId("Patient/1");
    Condition condition1 = createAsthmaCondition(patient1, "Condition/1", Severity.MILD);
    kSession.insert(patient1);
    kSession.insert(condition1);
    
    //Male, Severe Asthmatic Patient
    Patient patient2 = (Patient) new Patient()
        .setGender(AdministrativeGenderEnum.MALE)
        .setId("Patient/2");
    Condition condition2 = createAsthmaCondition(patient2, "Condition/2", Severity.SEVERE);
    kSession.insert(patient2);
    kSession.insert(condition2);
    
    //Female, Severe Asthmatic Patient
    Patient patient3 = (Patient) new Patient()
        .setGender(AdministrativeGenderEnum.FEMALE)
        .setId("Patient/3");
    Condition condition3 = createAsthmaCondition(patient3, "Condition/3", Severity.SEVERE);
    kSession.insert(patient3);
    kSession.insert(condition3);
    
    
    
    Assert.assertEquals(3, kSession.fireAllRules());
    System.out.println(" ---- Finished testFemaleSevereAsthmaticPatient() Test ---");
    kSession.dispose();
}
 
Example #19
Source File: QueryRulesJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
private List<Condition> createSnomedConditions(int number, Patient patient) {

        List<Condition> conditions = new ArrayList<>();
        for (int i = 0; i < number; i++) {

            String code = null;
            switch (random.nextInt(3)) {
                case 0:
                    code = "195967001"; //Asthma (disorder)
                    break;
                case 1:
                    code = "73211009"; //Diabetes mellitus (disorder)
                    break;
                case 2:
                    code = "8098009"; //Sexually transmitted infectious disease (disorder)
                    break;
            }

            conditions.add((Condition) new Condition()
                .setCode(new CodeableConceptDt("http://snomed.info/sct", code))
                .setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE)
                .setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED)
                .setPatient(new ResourceReferenceDt(patient))
                .setId("Condition/"+(i+1)));
        }

        return conditions;
    }
 
Example #20
Source File: InfiniteLoopJUnitTest.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateLoop() {
    Assert.assertNotNull(kSession);
    System.out.println(" ---- Starting testUpdateLoop() Test ---");

    Patient patient = (Patient) new Patient().setId("Patient/1");
    
    RiskAssessment riskAssessment = (RiskAssessment) new RiskAssessment().setId("RiskAssessment/1");
    
    Observation smokerObservation = (Observation) new Observation()
        .setCode(new CodeableConceptDt("http://snomed.info/sct", "428041000124106"))
        .setId("Observation/1");
    
    Observation bodyMassIndexObservation = (Observation) new Observation()
        .setCode(new CodeableConceptDt("http://snomed.info/sct", "60621009"))
        .setValue(new IntegerDt(45))
        .setId("Observation/2");

    kSession.insert(patient);
    kSession.insert(riskAssessment);
    kSession.insert(smokerObservation);
    kSession.insert(bodyMassIndexObservation);
    
    Assert.assertEquals(15, kSession.fireAllRules(15));
    System.out.println(" ---- Finished testUpdateLoop() Test ---");
    
}
 
Example #21
Source File: TestDstu2ModelResolver.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
@Test 
public void resolveMissingPropertyReturnsNull() {
    ModelResolver resolver = new Dstu2FhirModelResolver();
    
    Patient p = new Patient();

    Object result = resolver.resolvePath(p, "notapath");
    assertNull(result);
}
 
Example #22
Source File: CrossProductRulesJUnitTest.java    From drools-workshop with Apache License 2.0 4 votes vote down vote up
@Test
public void test2PatientsWith3ObservationsChecked() {
    Assert.assertNotNull(kBaseCrossProductSolution);
    KieSession kSession = kBaseCrossProductSolution.newKieSession();
    System.out.println(" ---- Starting test2PatientsWith3ObservationsChecked() Test ---");

    //1 Patient with 3 Observations
    Patient patient1 = (Patient) new Patient().setId("Patient/1");
    
    Observation observation1 = (Observation) new Observation().setId("Observation/1");
    observation1.setSubject(new ResourceReferenceDt(patient1));
    
    Observation observation2 = (Observation) new Observation().setId("Observation/2");
    observation2.setSubject(new ResourceReferenceDt(patient1));
    
    Observation observation3 = (Observation) new Observation().setId("Observation/3");
    observation3.setSubject(new ResourceReferenceDt(patient1));

    kSession.insert(patient1);
    kSession.insert(observation1);
    kSession.insert(observation2);
    kSession.insert(observation3);
    

    //Another Patient with 3 Observations
    Patient patient2 = (Patient) new Patient().setId("Patient/2");
    
    Observation observation4 = (Observation) new Observation().setId("Observation/4");
    observation4.setSubject(new ResourceReferenceDt(patient2));
    
    Observation observation5 = (Observation) new Observation().setId("Observation/5");
    observation5.setSubject(new ResourceReferenceDt(patient2));
    
    Observation observation6 = (Observation) new Observation().setId("Observation/6");
    observation6.setSubject(new ResourceReferenceDt(patient2));

    kSession.insert(patient2);
    kSession.insert(observation4);
    kSession.insert(observation5);
    kSession.insert(observation6);

    Assert.assertEquals(6, kSession.fireAllRules());
    System.out.println(" ---- Finished test2PatientsWith3ObservationsChecked() Test ---");
    kSession.dispose();
}
 
Example #23
Source File: CrossProductRulesJUnitTest.java    From drools-workshop with Apache License 2.0 4 votes vote down vote up
@Test
public void test2PatientsWith3Observations() {
    Assert.assertNotNull(kBaseCrossProduct);
    KieSession kSession = kBaseCrossProduct.newKieSession();
    System.out.println(" ---- Starting test2PatientsWith3Observations() Test ---");

    //1 Patient with 3 Observations
    Patient patient1 = (Patient) new Patient().setId("Patient/1");
    
    Observation observation1 = (Observation) new Observation().setId("Observation/1");
    observation1.setSubject(new ResourceReferenceDt(patient1));
    
    Observation observation2 = (Observation) new Observation().setId("Observation/2");
    observation2.setSubject(new ResourceReferenceDt(patient1));
    
    Observation observation3 = (Observation) new Observation().setId("Observation/3");
    observation3.setSubject(new ResourceReferenceDt(patient1));

    kSession.insert(patient1);
    kSession.insert(observation1);
    kSession.insert(observation2);
    kSession.insert(observation3);
    

    //Another Patient with 3 Observations
    Patient patient2 = (Patient) new Patient().setId("Patient/2");
    
    Observation observation4 = (Observation) new Observation().setId("Observation/4");
    observation4.setSubject(new ResourceReferenceDt(patient2));
    
    Observation observation5 = (Observation) new Observation().setId("Observation/5");
    observation5.setSubject(new ResourceReferenceDt(patient2));
    
    Observation observation6 = (Observation) new Observation().setId("Observation/6");
    observation6.setSubject(new ResourceReferenceDt(patient2));

    kSession.insert(patient2);
    kSession.insert(observation4);
    kSession.insert(observation5);
    kSession.insert(observation6);
    
    Assert.assertEquals(12, kSession.fireAllRules());
    System.out.println(" ---- Finished test2PatientsWith3Observations() Test ---");
    kSession.dispose();
}