<commit_before>package uk.gov.hscic.patient.careRecordHtml;

import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.NarrativeDt;
import ca.uhn.fhir.model.dstu2.resource.Composition;
import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum;
import java.util.List;
import uk.gov.hscic.OperationConstants;

public final class FhirSectionBuilder {

    private FhirSectionBuilder(){
    }
    
    public static Composition.Section build(HtmlPage htmlPage) {
        CodingDt coding = new CodingDt().setSystem(OperationConstants.SYSTEM_RECORD_SECTION).setCode(htmlPage.getCode()).setDisplay(htmlPage.getHeader());
        CodeableConceptDt codableConcept = new CodeableConceptDt().addCoding(coding);
        codableConcept.setText(htmlPage.getHeader());
        NarrativeDt narrative = new NarrativeDt();
        narrative.setStatus(NarrativeStatusEnum.GENERATED);
        narrative.setDivAsString(createHtmlContent(htmlPage));
        Composition.Section section = new Composition.Section();
        section.setTitle(htmlPage.getName()).setCode(codableConcept).setText(narrative);
        return section;
    }
    
    public static String createHtmlContent(HtmlPage htmlPage){
        
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<div>");
        
        // Add sections
        for(PageSection pageSection : htmlPage.getPageSections()){
            
            stringBuilder.append("<div>");
            
            // Header
            stringBuilder.append("<h2>").append(pageSection.getHeader()).append("</h2>");
            
            // Date Range Banner
            if(pageSection.getFromDate() != null && pageSection.getToDate() != null){
                stringBuilder.append("<div><p>For the period '").append(pageSection.getFromDate()).append("' to '").append(pageSection.getToDate()).append("'</p></div>");
            } else {
                stringBuilder.append("<div><p>All relevant items subject to Patient preferences and/or legal exclusions</p></div>");
            }
            
            // Additional Banners
            if(pageSection.getBanners().size() > 0){
                stringBuilder.append("<div>");
                for (String banner : pageSection.getBanners()) {
                    stringBuilder.append("<p>").append(banner).append("</p>");
                }<commit_msg>Updated date format in html<commit_after>package uk.gov.hscic.patient.careRecordHtml;

import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.NarrativeDt;
import ca.uhn.fhir.model.dstu2.resource.Composition;
import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum;
import java.text.SimpleDateFormat;
import java.util.List;
import uk.gov.hscic.OperationConstants;

public final class FhirSectionBuilder {

    private FhirSectionBuilder(){
    }
    
    public static Composition.Section build(HtmlPage htmlPage) {
        CodingDt coding = new CodingDt().setSystem(OperationConstants.SYSTEM_RECORD_SECTION).setCode(htmlPage.getCode()).setDisplay(htmlPage.getHeader());
        CodeableConceptDt codableConcept = new CodeableConceptDt().addCoding(coding);
        codableConcept.setText(htmlPage.getHeader());
        NarrativeDt narrative = new NarrativeDt();
        narrative.setStatus(NarrativeStatusEnum.GENERATED);
        narrative.setDivAsString(createHtmlContent(htmlPage));
        Composition.Section section = new Composition.Section();
        section.setTitle(htmlPage.getName()).setCode(codableConcept).setText(narrative);
        return section;
    }
    
    public static String createHtmlContent(HtmlPage htmlPage){
        
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<div>");
        
        // Add sections
        for(PageSection pageSection : htmlPage.getPageSections()){
            
            stringBuilder.append("<div>");
            
            // Header
            stringBuilder.append("<h2>").append(pageSection.getHeader()).append("</h2>");
            
            // Date Range Banner
            if(pageSection.getFromDate() != null && pageSection.getToDate() != null){
                SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
                stringBuilder.append("<div><p>For the period '").append(dateFormat.format(pageSection.getFromDate())).append("' to '").append(dateFormat.format(pageSection.getToDate())).append("'</p></div>");
            } else {
                stringBuilder.append("<div><p>All relevant items subject to Patient preferences and/or legal exclusions</p></div>");
            }
            
            // Additional Banners
            if(pageSection.getBanners().size() > 0){
                stringBuilder.append("<div>");
                for (String banner : pageSection.getBanners()) {
                    stringBuilder.append("<p>").append(banner).append("</p>");
                }
{'fraction_non_alphanumeric': 0.12578740157480314, 'fraction_numerical': 0.0031496062992125984, 'mean_word_length': 2.8905053598774884, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2282709', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1431, 'n_words': 212}