<commit_before>package org.openmrs.module.shrclient.model.mci.api.model;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.fhir.utils.DateUtil;
import org.openmrs.module.shrclient.model.Address;
import org.openmrs.module.shrclient.model.Patient;
import org.openmrs.module.shrclient.model.Relation;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;

import static org.junit.Assert.assertEquals;

public class PatientJsonTest {

    private Patient patient;
    private ObjectMapper objectMapper;

    public PatientJsonTest() {
    }

    @Before
    public void setup() {
        
        objectMapper = new ObjectMapper();

        patient = new Patient();
        patient.setGivenName("Scott");
        patient.setSurName("Tiger");
        patient.setGender("M");
        Address address = new Address();
        address.setDivisionId("10");
        address.setDistrictId("04");
        address.setUpazilaId("09");
        address.setCityCorporationId("20");
        address.setUnionOrUrbanWardId("01");
        patient.setAddress(address);
    }

    @Test
    public void shouldExcludeEmptyNonMandatoryFields() throws Exception {
        String expected = "{\"nid\":null,\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":null,\"dob_type\":\"1\",\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null,\"hid_card_status\":null}";
        patient.setDobType("1");
        String actual = objectMapper.writeValueAsString(patient);
        assertEquals(expected, actual);
    }

    @Test
    public void shouldIncludeNonEmptyNonMandatoryFields() throws Exception {
        patient.setNationalId("nid-100");
        patient.setActive(true);
        patient.setDobType("2");

        String expected = "{\"nid\":\"nid-100\",\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":null,\"dob_type\":\"2\",\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null," +
                "\"active\":true,\"hid_card_status\":null}";
        String actual = objectMapper.writeValueAsString(patient);
        assertEquals(expected, actual);
    }

    @Test
    public void shouldIncludeRelationsForPatient() throws Exception {
        patient.setNationalId("nid-100");
        patient.setRelations(getRelationsForPatient(patient));
        patient.setActive(false);
        patient.setDateOfBirth(DateUtil.parseDate("1970-11-06T00:00:00+05:30"));
        String expected = "{\"nid\":\"nid-100\",\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":\"1970-11-06T00:00:00+05:30\",\"dob_type\":null,\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null," +
                "\"relations\":[{\"type\":\"mother\",\"given_name\":\"<NAME> Scott\",\"sur_name\":\"Tiger\"}]," +
                "\"active\":false,\"hid_card_status\":null,\"created\": \"2017-01-30T17:28:54.363+05:30\",\n" +
                "  \"modified\": \"2017-01-30T17:28:54.363+05:30\"}";
        Patient expectedPatient = objectMapper.readValue(expected, Patient.class);
        assertEquals(expectedPatient, patient);
    }

    @Test
    public void shouldCreateAPatientFromJson() throws Exception {<commit_msg>Sukreet, dubey | shr-1429 | fixed failing test.<commit_after>package org.openmrs.module.shrclient.model.mci.api.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.module.fhir.utils.DateUtil;
import org.openmrs.module.shrclient.model.Address;
import org.openmrs.module.shrclient.model.Patient;
import org.openmrs.module.shrclient.model.Relation;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Date;

import static org.junit.Assert.assertEquals;

public class PatientJsonTest {

    private Patient patient;
    private ObjectMapper objectMapper;

    public PatientJsonTest() {
    }

    @Before
    public void setup() {

        objectMapper = new ObjectMapper();

        patient = new Patient();
        patient.setGivenName("Scott");
        patient.setSurName("Tiger");
        patient.setGender("M");
        Address address = new Address();
        address.setDivisionId("10");
        address.setDistrictId("04");
        address.setUpazilaId("09");
        address.setCityCorporationId("20");
        address.setUnionOrUrbanWardId("01");
        patient.setAddress(address);
    }

    @Test
    public void shouldExcludeEmptyNonMandatoryFields() throws Exception {
        String expected = "{\"nid\":null,\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":null,\"dob_type\":\"1\",\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null,\"hid_card_status\":null}";
        patient.setDobType("1");
        String actual = objectMapper.writeValueAsString(patient);
        assertEquals(expected, actual);
    }

    @Test
    public void shouldIncludeNonEmptyNonMandatoryFields() throws Exception {
        patient.setNationalId("nid-100");
        patient.setActive(true);
        patient.setDobType("2");

        String expected = "{\"nid\":\"nid-100\",\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":null,\"dob_type\":\"2\",\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null," +
                "\"active\":true,\"hid_card_status\":null}";
        String actual = objectMapper.writeValueAsString(patient);
        assertEquals(expected, actual);
    }

    @Test
    public void shouldIncludeRelationsForPatient() throws Exception {
        patient.setNationalId("nid-100");
        patient.setRelations(getRelationsForPatient(patient));
        patient.setActive(false);
        Date dateOfBirth = DateUtil.parseDate("1970-11-06T00:00:00+05:30");
        patient.setDateOfBirth(dateOfBirth);
        String expected = "{\"nid\":\"nid-100\",\"given_name\":\"Scott\",\"sur_name\":\"Tiger\"," +
                "\"date_of_birth\":\"" + DateUtil.toDateString(dateOfBirth, DateUtil.ISO_8601_DATE_IN_SECS_FORMAT2) +
                "\",\"dob_type\":null,\"gender\":\"M\",\"occupation\":null," +
                "\"edu_level\":null,\"present_address\":{\"address_line\":null,\"division_id\":\"10\"," +
                "\"district_id\":\"04\",\"upazila_id\":\"09\",\"city_corporation_id\":\"20\"," +
                "\"union_or_urban_ward_id\":\"01\"},\"status\":null,\"bin_brn\":null,\"household_code\":null," +
                "\"relations\":[{\"type\":\"mother\",\"given_name\":\"<NAME> Scott\",\"sur_name\":\"Tiger\"}]," +
                "\"active\":false,\"hid_card_status\":null,\"created\": \"2017-01-30T17:28:54.363+05:30\",\n" +
                "  \"modified\": \"2017-01-30T17:28:54.363+05:30\"}";
        Patient expectedPatient = objectMapper.readValue(expected, Patient.class);
        assertEquals(expectedPatient, patient);
    }

    @Test
    public void shouldCreateAPatientFromJson() throws Exception {
{'fraction_non_alphanumeric': 0.20152003684937816, 'fraction_numerical': 0.02982496545370797, 'mean_word_length': 3.071729957805907, 'pattern_counts': {'":': 130, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442056', 'n_tokens_mistral': 2988, 'n_tokens_neox': 2701, 'n_words': 293}